https://blog.csdn.net/a572423926/article/details/126551079
源码位置:frameworks/native/cmds/service/service.cpp
main方法
94 sp<IServiceManager> sm = defaultServiceManager();
...
104 if (strcmp(argv[optind], "check") == 0) {
105 optind++;
106 if (optind < argc) {
107 sp<IBinder> service = sm->checkService(String16(argv[optind]));
108 aout << "Service " << argv[optind] <<
109 (service == nullptr ? ": not found" : ": found") << endl;
110 } else {
111 aerr << "service: No service specified for check" << endl;
112 wantsUsage = true;
113 result = 10;
114 }
115 }
116 else if (strcmp(argv[optind], "list") == 0) {
117 Vector<String16> services = sm->listServices();
118 aout << "Found " << services.size() << " services:" << endl;
119 for (unsigned i = 0; i < services.size(); i++) {
120 String16 name = services[i];
121 sp<IBinder> service = sm->checkService(name);
122 aout << i
123 << "\t" << good_old_string(name)
124 << ": [" << good_old_string(get_interface_name(service)) << "]"
125 << endl;
126 }
127 }
...
→defaultServiceManager()
见https://blog.csdn.net/tkwxty/article/details/103034523
源码位置:frameworks/native/libs/binder/IServiceManager.cpp
最终获取的其实是:
gDefaultServiceManager = new BpServiceManager(new BpBinder(0));
0 条评论