summaryrefslogtreecommitdiffstats
path: root/ServiceManager.cpp
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2019-03-11 17:50:47 -0700
committerXin Li <delphij@google.com>2019-03-11 18:10:06 -0700
commitbf44d5a44c2ab8ed169a53f9fc1b561d50d4342b (patch)
tree34f34247d91a8dd279783c23c80a69b2a4e26a1f /ServiceManager.cpp
parent629d1e5b22ba7681cf2372fb558b03202229b9a9 (diff)
parent32b535a6d8de293b78cf60fa64980999bd82e244 (diff)
downloadplatform_system_hwservicemanager-bf44d5a44c2ab8ed169a53f9fc1b561d50d4342b.tar.gz
platform_system_hwservicemanager-bf44d5a44c2ab8ed169a53f9fc1b561d50d4342b.tar.bz2
platform_system_hwservicemanager-bf44d5a44c2ab8ed169a53f9fc1b561d50d4342b.zip
DO NOT MERGE - Merge PPRL.190305.001 into masterandroid-q-preview-1android-o-mr1-iot-release-1.0.10
Bug: 127812889 Change-Id: Ic7c1bcb7afbd1c076a06400e05fa6352372ef3e7
Diffstat (limited to 'ServiceManager.cpp')
-rw-r--r--ServiceManager.cpp81
1 files changed, 43 insertions, 38 deletions
diff --git a/ServiceManager.cpp b/ServiceManager.cpp
index 9f45801..f76afcd 100644
--- a/ServiceManager.cpp
+++ b/ServiceManager.cpp
@@ -36,6 +36,23 @@ namespace hidl {
namespace manager {
namespace implementation {
+AccessControl::CallingContext getBinderCallingContext() {
+ const auto& self = IPCThreadState::self();
+
+ pid_t pid = self->getCallingPid();
+ const char* sid = self->getCallingSid();
+
+ if (sid == nullptr) {
+ if (pid != getpid()) {
+ android_errorWriteLog(0x534e4554, "121035042");
+ }
+
+ return AccessControl::getCallingContext(pid);
+ } else {
+ return { true, sid, pid };
+ }
+}
+
static constexpr uint64_t kServiceDiedCookie = 0;
static constexpr uint64_t kPackageListenerDiedCookie = 1;
static constexpr uint64_t kServiceListenerDiedCookie = 2;
@@ -244,8 +261,7 @@ Return<sp<IBase>> ServiceManager::get(const hidl_string& hidlFqName,
const std::string fqName = hidlFqName;
const std::string name = hidlName;
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canGet(fqName, pid)) {
+ if (!mAcl.canGet(fqName, getBinderCallingContext())) {
return nullptr;
}
@@ -284,11 +300,10 @@ Return<bool> ServiceManager::add(const hidl_string& name, const sp<IBase>& servi
return false;
}
- pid_t pid = IPCThreadState::self()->getCallingPid();
- auto context = mAcl.getContext(pid);
+ auto pidcon = getBinderCallingContext();
auto ret = service->interfaceChain([&](const auto &interfaceChain) {
- addSuccess = addImpl(name, service, interfaceChain, context, pid);
+ addSuccess = addImpl(name, service, interfaceChain, pidcon);
});
if (!ret.isOk()) {
@@ -302,8 +317,7 @@ Return<bool> ServiceManager::add(const hidl_string& name, const sp<IBase>& servi
bool ServiceManager::addImpl(const hidl_string& name,
const sp<IBase>& service,
const hidl_vec<hidl_string>& interfaceChain,
- const AccessControl::Context &context,
- pid_t pid) {
+ const AccessControl::CallingContext& callingContext) {
if (interfaceChain.size() == 0) {
LOG(WARNING) << "Empty interface chain for " << name;
return false;
@@ -313,7 +327,7 @@ bool ServiceManager::addImpl(const hidl_string& name,
for(size_t i = 0; i < interfaceChain.size(); i++) {
const std::string fqName = interfaceChain[i];
- if (!mAcl.canAdd(fqName, context, pid)) {
+ if (!mAcl.canAdd(fqName, callingContext)) {
return false;
}
}
@@ -346,9 +360,9 @@ bool ServiceManager::addImpl(const hidl_string& name,
if (hidlService == nullptr) {
ifaceMap.insertService(
- std::make_unique<HidlService>(fqName, name, service, pid));
+ std::make_unique<HidlService>(fqName, name, service, callingContext.pid));
} else {
- hidlService->setService(service, pid);
+ hidlService->setService(service, callingContext.pid);
}
ifaceMap.sendPackageRegistrationNotification(fqName, name);
@@ -366,8 +380,7 @@ Return<ServiceManager::Transport> ServiceManager::getTransport(const hidl_string
const hidl_string& name) {
using ::android::hardware::getTransport;
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canGet(fqName, pid)) {
+ if (!mAcl.canGet(fqName, getBinderCallingContext())) {
return Transport::EMPTY;
}
@@ -383,8 +396,7 @@ Return<ServiceManager::Transport> ServiceManager::getTransport(const hidl_string
}
Return<void> ServiceManager::list(list_cb _hidl_cb) {
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canList(pid)) {
+ if (!mAcl.canList(getBinderCallingContext())) {
_hidl_cb({});
return Void();
}
@@ -405,8 +417,7 @@ Return<void> ServiceManager::list(list_cb _hidl_cb) {
Return<void> ServiceManager::listByInterface(const hidl_string& fqName,
listByInterface_cb _hidl_cb) {
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canGet(fqName, pid)) {
+ if (!mAcl.canGet(fqName, getBinderCallingContext())) {
_hidl_cb({});
return Void();
}
@@ -449,8 +460,7 @@ Return<bool> ServiceManager::registerForNotifications(const hidl_string& fqName,
return false;
}
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canGet(fqName, pid)) {
+ if (!mAcl.canGet(fqName, getBinderCallingContext())) {
return false;
}
@@ -532,8 +542,7 @@ Return<bool> ServiceManager::registerClientCallback(const hidl_string& hidlFqNam
// only the server of the interface can register a client callback
pid_t pid = IPCThreadState::self()->getCallingPid();
- auto context = mAcl.getContext(pid);
- if (!mAcl.canAdd(fqName, context, pid)) {
+ if (!mAcl.canAdd(fqName, getBinderCallingContext())) {
return false;
}
@@ -544,7 +553,7 @@ Return<bool> ServiceManager::registerClientCallback(const hidl_string& hidlFqNam
}
// sanity
- if (registered->getPid() != pid) {
+ if (registered->getDebugPid() != pid) {
LOG(WARNING) << "Only a server can register for client callbacks (for " << fqName
<< "/" << name << ")";
return false;
@@ -599,16 +608,14 @@ Return<bool> ServiceManager::addWithChain(const hidl_string& name,
return false;
}
- pid_t pid = IPCThreadState::self()->getCallingPid();
- auto context = mAcl.getContext(pid);
+ auto callingContext = getBinderCallingContext();
- return addImpl(name, service, chain, context, pid);
+ return addImpl(name, service, chain, callingContext);
}
Return<void> ServiceManager::listManifestByInterface(const hidl_string& fqName,
listManifestByInterface_cb _hidl_cb) {
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canGet(fqName, pid)) {
+ if (!mAcl.canGet(fqName, getBinderCallingContext())) {
_hidl_cb({});
return Void();
}
@@ -630,17 +637,15 @@ Return<bool> ServiceManager::tryUnregister(const hidl_string& hidlFqName,
return false;
}
- pid_t pid = IPCThreadState::self()->getCallingPid();
- auto context = mAcl.getContext(pid);
-
- if (!mAcl.canAdd(fqName, context, pid)) {
+ if (!mAcl.canAdd(fqName, getBinderCallingContext())) {
return false;
}
HidlService* registered = lookup(fqName, name);
// sanity
- if (registered->getPid() != pid) {
+ pid_t pid = IPCThreadState::self()->getCallingPid();
+ if (registered->getDebugPid() != pid) {
LOG(WARNING) << "Only a server can unregister itself (for " << fqName
<< "/" << name << ")";
return false;
@@ -680,8 +685,7 @@ Return<bool> ServiceManager::tryUnregister(const hidl_string& hidlFqName,
}
Return<void> ServiceManager::debugDump(debugDump_cb _cb) {
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canList(pid)) {
+ if (!mAcl.canList(getBinderCallingContext())) {
_cb({});
return Void();
}
@@ -697,7 +701,7 @@ Return<void> ServiceManager::debugDump(debugDump_cb _cb) {
}
list.push_back({
- .pid = service->getPid(),
+ .pid = service->getDebugPid(),
.interfaceName = service->getInterfaceName(),
.instanceName = service->getInstanceName(),
.clientPids = clientPids,
@@ -714,8 +718,9 @@ Return<void> ServiceManager::debugDump(debugDump_cb _cb) {
Return<void> ServiceManager::registerPassthroughClient(const hidl_string &fqName,
const hidl_string &name) {
- pid_t pid = IPCThreadState::self()->getCallingPid();
- if (!mAcl.canGet(fqName, pid)) {
+ auto callingContext = getBinderCallingContext();
+
+ if (!mAcl.canGet(fqName, callingContext)) {
/* We guard this function with "get", because it's typically used in
* the getService() path, albeit for a passthrough service in this
* case
@@ -735,10 +740,10 @@ Return<void> ServiceManager::registerPassthroughClient(const hidl_string &fqName
if (service == nullptr) {
auto adding = std::make_unique<HidlService>(fqName, name);
- adding->registerPassthroughClient(pid);
+ adding->registerPassthroughClient(callingContext.pid);
ifaceMap.insertService(std::move(adding));
} else {
- service->registerPassthroughClient(pid);
+ service->registerPassthroughClient(callingContext.pid);
}
return Void();
}