Loading libs/binder/IServiceManager.cpp +138 −113 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,36 @@ static_assert(AidlServiceManager::DUMP_FLAG_PRIORITY_DEFAULT == IServiceManager: static_assert(AidlServiceManager::DUMP_FLAG_PRIORITY_ALL == IServiceManager::DUMP_FLAG_PRIORITY_ALL); static_assert(AidlServiceManager::DUMP_FLAG_PRIORITY_ALL == IServiceManager::DUMP_FLAG_PRIORITY_ALL); static_assert(AidlServiceManager::DUMP_FLAG_PROTO == IServiceManager::DUMP_FLAG_PROTO); static_assert(AidlServiceManager::DUMP_FLAG_PROTO == IServiceManager::DUMP_FLAG_PROTO); const String16& IServiceManager::getInterfaceDescriptor() const { return AidlServiceManager::descriptor; } IServiceManager::IServiceManager() {} IServiceManager::~IServiceManager() {} // From the old libbinder IServiceManager interface to IServiceManager. class ServiceManagerShim : public IServiceManager { public: explicit ServiceManagerShim (const sp<AidlServiceManager>& impl); sp<IBinder> getService(const String16& name) const override; sp<IBinder> checkService(const String16& name) const override; status_t addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) override; Vector<String16> listServices(int dumpsysPriority) override; sp<IBinder> waitForService(const String16& name16) override; // for legacy ABI const String16& getInterfaceDescriptor() const override { return mTheRealServiceManager->getInterfaceDescriptor(); } IBinder* onAsBinder() override { return IInterface::asBinder(mTheRealServiceManager).get(); } private: sp<AidlServiceManager> mTheRealServiceManager; }; sp<IServiceManager> defaultServiceManager() sp<IServiceManager> defaultServiceManager() { { static Mutex gDefaultServiceManagerLock; static Mutex gDefaultServiceManagerLock; Loading @@ -64,8 +94,9 @@ sp<IServiceManager> defaultServiceManager() { { AutoMutex _l(gDefaultServiceManagerLock); AutoMutex _l(gDefaultServiceManagerLock); while (gDefaultServiceManager == nullptr) { while (gDefaultServiceManager == nullptr) { gDefaultServiceManager = interface_cast<IServiceManager>( gDefaultServiceManager = new ServiceManagerShim( ProcessState::self()->getContextObject(nullptr)); interface_cast<AidlServiceManager>( ProcessState::self()->getContextObject(nullptr))); if (gDefaultServiceManager == nullptr) if (gDefaultServiceManager == nullptr) sleep(1); sleep(1); } } Loading Loading @@ -158,16 +189,11 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- class BpServiceManager : public BpInterface<IServiceManager> ServiceManagerShim::ServiceManagerShim(const sp<AidlServiceManager>& impl) { : mTheRealServiceManager(impl) public: {} explicit BpServiceManager(const sp<IBinder>& impl) : BpInterface<IServiceManager>(impl), mTheRealServiceManager(interface_cast<AidlServiceManager>(impl)) { } sp<IBinder> getService(const String16& name) const override sp<IBinder> ServiceManagerShim::getService(const String16& name) const { { static bool gSystemBootCompleted = false; static bool gSystemBootCompleted = false; Loading Loading @@ -204,7 +230,8 @@ public: return nullptr; return nullptr; } } sp<IBinder> checkService(const String16& name) const override { sp<IBinder> ServiceManagerShim::checkService(const String16& name) const { sp<IBinder> ret; sp<IBinder> ret; if (!mTheRealServiceManager->checkService(String8(name).c_str(), &ret).isOk()) { if (!mTheRealServiceManager->checkService(String8(name).c_str(), &ret).isOk()) { return nullptr; return nullptr; Loading @@ -212,13 +239,16 @@ public: return ret; return ret; } } status_t addService(const String16& name, const sp<IBinder>& service, status_t ServiceManagerShim::addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) override { bool allowIsolated, int dumpsysPriority) Status status = mTheRealServiceManager->addService(String8(name).c_str(), service, allowIsolated, dumpsysPriority); { Status status = mTheRealServiceManager->addService( String8(name).c_str(), service, allowIsolated, dumpsysPriority); return status.exceptionCode(); return status.exceptionCode(); } } virtual Vector<String16> listServices(int dumpsysPriority) { Vector<String16> ServiceManagerShim::listServices(int dumpsysPriority) { std::vector<std::string> ret; std::vector<std::string> ret; if (!mTheRealServiceManager->listServices(dumpsysPriority, &ret).isOk()) { if (!mTheRealServiceManager->listServices(dumpsysPriority, &ret).isOk()) { return {}; return {}; Loading @@ -232,7 +262,8 @@ public: return res; return res; } } sp<IBinder> waitForService(const String16& name16) override { sp<IBinder> ServiceManagerShim::waitForService(const String16& name16) { class Waiter : public android::os::BnServiceCallback { class Waiter : public android::os::BnServiceCallback { Status onRegistration(const std::string& /*name*/, Status onRegistration(const std::string& /*name*/, const sp<IBinder>& binder) override { const sp<IBinder>& binder) override { Loading Loading @@ -290,10 +321,4 @@ public: } } } } private: sp<AidlServiceManager> mTheRealServiceManager; }; IMPLEMENT_META_INTERFACE(ServiceManager, "android.os.IServiceManager"); } // namespace android } // namespace android libs/binder/include/binder/IServiceManager.h +11 −1 Original line number Original line Diff line number Diff line Loading @@ -26,10 +26,20 @@ namespace android { // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- /** * Service manager for C++ services. * * IInterface is only for legacy ABI compatibility */ class IServiceManager : public IInterface class IServiceManager : public IInterface { { public: public: DECLARE_META_INTERFACE(ServiceManager) // for ABI compatibility virtual const String16& getInterfaceDescriptor() const; IServiceManager(); virtual ~IServiceManager(); /** /** * Must match values in IServiceManager.aidl * Must match values in IServiceManager.aidl */ */ Loading Loading
libs/binder/IServiceManager.cpp +138 −113 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,36 @@ static_assert(AidlServiceManager::DUMP_FLAG_PRIORITY_DEFAULT == IServiceManager: static_assert(AidlServiceManager::DUMP_FLAG_PRIORITY_ALL == IServiceManager::DUMP_FLAG_PRIORITY_ALL); static_assert(AidlServiceManager::DUMP_FLAG_PRIORITY_ALL == IServiceManager::DUMP_FLAG_PRIORITY_ALL); static_assert(AidlServiceManager::DUMP_FLAG_PROTO == IServiceManager::DUMP_FLAG_PROTO); static_assert(AidlServiceManager::DUMP_FLAG_PROTO == IServiceManager::DUMP_FLAG_PROTO); const String16& IServiceManager::getInterfaceDescriptor() const { return AidlServiceManager::descriptor; } IServiceManager::IServiceManager() {} IServiceManager::~IServiceManager() {} // From the old libbinder IServiceManager interface to IServiceManager. class ServiceManagerShim : public IServiceManager { public: explicit ServiceManagerShim (const sp<AidlServiceManager>& impl); sp<IBinder> getService(const String16& name) const override; sp<IBinder> checkService(const String16& name) const override; status_t addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) override; Vector<String16> listServices(int dumpsysPriority) override; sp<IBinder> waitForService(const String16& name16) override; // for legacy ABI const String16& getInterfaceDescriptor() const override { return mTheRealServiceManager->getInterfaceDescriptor(); } IBinder* onAsBinder() override { return IInterface::asBinder(mTheRealServiceManager).get(); } private: sp<AidlServiceManager> mTheRealServiceManager; }; sp<IServiceManager> defaultServiceManager() sp<IServiceManager> defaultServiceManager() { { static Mutex gDefaultServiceManagerLock; static Mutex gDefaultServiceManagerLock; Loading @@ -64,8 +94,9 @@ sp<IServiceManager> defaultServiceManager() { { AutoMutex _l(gDefaultServiceManagerLock); AutoMutex _l(gDefaultServiceManagerLock); while (gDefaultServiceManager == nullptr) { while (gDefaultServiceManager == nullptr) { gDefaultServiceManager = interface_cast<IServiceManager>( gDefaultServiceManager = new ServiceManagerShim( ProcessState::self()->getContextObject(nullptr)); interface_cast<AidlServiceManager>( ProcessState::self()->getContextObject(nullptr))); if (gDefaultServiceManager == nullptr) if (gDefaultServiceManager == nullptr) sleep(1); sleep(1); } } Loading Loading @@ -158,16 +189,11 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- class BpServiceManager : public BpInterface<IServiceManager> ServiceManagerShim::ServiceManagerShim(const sp<AidlServiceManager>& impl) { : mTheRealServiceManager(impl) public: {} explicit BpServiceManager(const sp<IBinder>& impl) : BpInterface<IServiceManager>(impl), mTheRealServiceManager(interface_cast<AidlServiceManager>(impl)) { } sp<IBinder> getService(const String16& name) const override sp<IBinder> ServiceManagerShim::getService(const String16& name) const { { static bool gSystemBootCompleted = false; static bool gSystemBootCompleted = false; Loading Loading @@ -204,7 +230,8 @@ public: return nullptr; return nullptr; } } sp<IBinder> checkService(const String16& name) const override { sp<IBinder> ServiceManagerShim::checkService(const String16& name) const { sp<IBinder> ret; sp<IBinder> ret; if (!mTheRealServiceManager->checkService(String8(name).c_str(), &ret).isOk()) { if (!mTheRealServiceManager->checkService(String8(name).c_str(), &ret).isOk()) { return nullptr; return nullptr; Loading @@ -212,13 +239,16 @@ public: return ret; return ret; } } status_t addService(const String16& name, const sp<IBinder>& service, status_t ServiceManagerShim::addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) override { bool allowIsolated, int dumpsysPriority) Status status = mTheRealServiceManager->addService(String8(name).c_str(), service, allowIsolated, dumpsysPriority); { Status status = mTheRealServiceManager->addService( String8(name).c_str(), service, allowIsolated, dumpsysPriority); return status.exceptionCode(); return status.exceptionCode(); } } virtual Vector<String16> listServices(int dumpsysPriority) { Vector<String16> ServiceManagerShim::listServices(int dumpsysPriority) { std::vector<std::string> ret; std::vector<std::string> ret; if (!mTheRealServiceManager->listServices(dumpsysPriority, &ret).isOk()) { if (!mTheRealServiceManager->listServices(dumpsysPriority, &ret).isOk()) { return {}; return {}; Loading @@ -232,7 +262,8 @@ public: return res; return res; } } sp<IBinder> waitForService(const String16& name16) override { sp<IBinder> ServiceManagerShim::waitForService(const String16& name16) { class Waiter : public android::os::BnServiceCallback { class Waiter : public android::os::BnServiceCallback { Status onRegistration(const std::string& /*name*/, Status onRegistration(const std::string& /*name*/, const sp<IBinder>& binder) override { const sp<IBinder>& binder) override { Loading Loading @@ -290,10 +321,4 @@ public: } } } } private: sp<AidlServiceManager> mTheRealServiceManager; }; IMPLEMENT_META_INTERFACE(ServiceManager, "android.os.IServiceManager"); } // namespace android } // namespace android
libs/binder/include/binder/IServiceManager.h +11 −1 Original line number Original line Diff line number Diff line Loading @@ -26,10 +26,20 @@ namespace android { // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- /** * Service manager for C++ services. * * IInterface is only for legacy ABI compatibility */ class IServiceManager : public IInterface class IServiceManager : public IInterface { { public: public: DECLARE_META_INTERFACE(ServiceManager) // for ABI compatibility virtual const String16& getInterfaceDescriptor() const; IServiceManager(); virtual ~IServiceManager(); /** /** * Must match values in IServiceManager.aidl * Must match values in IServiceManager.aidl */ */ Loading