sp<IBinder> ServiceManager::tryGetService(const std::string& name, bool startIfNotFound){ auto ctx = mAccess->getCallingContext(); sp<IBinder> out; Service* service = nullptr; if (auto it = mNameToService.find(name); it != mNameToService.end()) { service = &(it->second); if (!service->allowIsolated) { uid_t appid = multiuser_get_app_id(ctx.uid); bool isIsolated = appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END; if (isIsolated) { LOG(ERROR) << "Invalid service name: " << name << " isIsolated!"; returnnullptr; } } out = service->binder; } if (!mAccess->canFind(ctx, name)) { LOG(ERROR) << "Invalid service name: " << name << " mAccess->canFind fail!"; returnnullptr; } if (!out && startIfNotFound) { tryStartService(name); } if (out) { // Setting this guarantee each time we hand out a binder ensures that the client-checking // loop knows about the event even if the client immediately drops the service service->guaranteeClient = true; } LOG(ERROR) << "service name: "<< name << "address" << static_cast<void*>(out.get()); return out; }