android4.0平台service程序分析
来源:互联网 发布:淘宝店铺背景图片尺寸 编辑:程序博客网 时间:2024/06/06 10:41
service程序源代码路径frameworks/base/cmds/service/service.cpp
int main()
{
// 获得ServiceManager服务的接口sm, 通过这个接口客户获得其他服务信息
sp<IServiceManager> sm = defaultServiceManager();
// 使stdout清空,立刻输出所有在缓冲区中的内容
fflush(stdout);
if (sm == NULL) { //获取ServiceManager服务接口失败, 直接返回
aerr << "service: Unable to get default service manager!" << endl;
return 20;
}
bool wantsUsage = false;// 是否需要显示帮助信息, false不打印帮助信息, true打印帮助信息
int result = 0;
while (1) {
// getopt()函数的原型为getopt(int argc,char *const argv[],const char *optstring)。
// optstring是一段自己规定的选项串,例如本例中的"h?",表示可以有,-h,-?这几个参数。
int ic = getopt(argc, argv, "h?");
if (ic < 0)
break;
switch (ic) {
case 'h':
case '?':
wantsUsage = true;
break;
default:
aerr << "service: Unknown option -" << ic << endl;
wantsUsage = true;
result = 10;
break;
}
// 全域变量optind指示下一个要读取的参数在argv中的位置。
if (optind >= argc) {
wantsUsage = true;
} else if (!wantsUsage) {
if (strcmp(argv[optind], "check") == 0) { // service check activity
optind++; // 下一个需要读取的位置加1
if (optind < argc) { // 还有读取参数activity
// 在serviceManager中查找是否有activityManagerService服务,
// 这个服务注册到ServiceManager的时候名字为"activity"
sp<IBinder> service = sm->checkService(String16(argv[optind]));
aout << "Service " << argv[optind] <<(service == NULL ? ": not found" : ": found") << endl;
} else {
aerr << "service: No service specified for check" << endl;
wantsUsage = true;
result = 10;
}
} // endif
else if (strcmp(argv[optind], "list") == 0) {// 命令为adb shell service list
// 列出所有在ServiceManager中注册的服务的名称
Vector<String16> services = sm->listServices();
aout << "Found " << services.size() << " services:" << endl;
for (unsigned i = 0; i < services.size(); i++) {
String16 name = services[i];
sp<IBinder> service = sm->checkService(name); // 根据服务的名称查找对应服务的代理对象
aout << i << "\t" << good_old_string(name)
<< ": [" << good_old_string(get_interface_name(service)) << "]"
<< endl;
}
} else if (strcmp(argv[optind], "call") == 0) { // 通过adb shell service call 调用某一个服务
// 一般格式如下: adb shell servie call window 74 i32 0
// widdow 服务名称; 74表示函数 i32参数类型为整形, 0 为参数值
// 不过adb shell service call 命令调用一般使用比较少。
}
}
一般使用方式为 adb shell service list
- android4.0平台service程序分析
- android4.4组件分析--service组件
- Android4.0图库Gallery2代码分析(一) 程序总体结构
- Android4.0图库Gallery2代码分析(一) 程序总体结构
- Android4.0图库Gallery2代码分析(一) 程序总体结构
- rk3128 android4.4 平台内核驱动分析
- Android4.0 WIFI分析
- android4.4组件分析--service组件-bindService源码分析
- android4.0 WindowManagerService的分析
- android4.0 输入法框架分析
- android4.0 WindowManagerService的分析
- Android4.0 无线网络代码分析
- android4.0 蓝牙启动分析
- Android4.0 Toast显示问题分析
- Android4.0 Launcher源码分析系列(四)
- Android4.0 Launcher 源码分析系列
- Android4.0 时间更新分析 NTPServer更改
- 菜鸟Android4.0 Settings分析(一)
- 黑马程序员--Java基础之集合框架工具类
- Python笔记-排序算法(2)
- android官方技术文档翻译——aar 格式
- ASCII简介及不经过比较转换字母大小写。
- java-学习笔记-线程&进程
- android4.0平台service程序分析
- SQL改写的书终于出版了
- 从输入网址到显示网页的全过程分析
- storm文档(10)----容错
- 理解一个简单的网页请求过程
- Unity新UI系统概述——Interaction Components
- Presenting view controllers on detached view controllers 警告根由
- bzoj1070: [SCOI2007]修车 费用流
- 黑马程序员-c语言学习之数据类型的整理