ServiceManager: support debug dump w/ PIDs
To enable binder service-name based dumps of services when the same
interface might be registered from multiple different processes.
The getDebugPid command can't be sent instead to specific instances,
since if they are hung, the PID couldn't be retrieved.
For partiy w/ HIDL, this uses the 'list' selinux permission to control
reading debug dumps.
Bug: 175322136
Test: using this info to dump AIDL HALs in ANR
Change-Id: I4bc7c2df5faa6be1cdcc69b2a7fc882293f1d249
diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp
index b21010d..0dbab4e 100644
--- a/cmds/servicemanager/ServiceManager.cpp
+++ b/cmds/servicemanager/ServiceManager.cpp
@@ -623,4 +623,21 @@
return Status::ok();
}
+Status ServiceManager::getServiceDebugInfo(std::vector<ServiceDebugInfo>* outReturn) {
+ if (!mAccess->canList(mAccess->getCallingContext())) {
+ return Status::fromExceptionCode(Status::EX_SECURITY);
+ }
+
+ outReturn->reserve(mNameToService.size());
+ for (auto const& [name, service] : mNameToService) {
+ ServiceDebugInfo info;
+ info.name = name;
+ info.debugPid = service.debugPid;
+
+ outReturn->push_back(std::move(info));
+ }
+
+ return Status::ok();
+}
+
} // namespace android