Loading libs/binder/IServiceManager.cpp +138 −113 Original line number 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_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() { static Mutex gDefaultServiceManagerLock; Loading @@ -64,8 +94,9 @@ sp<IServiceManager> defaultServiceManager() { AutoMutex _l(gDefaultServiceManagerLock); while (gDefaultServiceManager == nullptr) { gDefaultServiceManager = interface_cast<IServiceManager>( ProcessState::self()->getContextObject(nullptr)); gDefaultServiceManager = new ServiceManagerShim( interface_cast<AidlServiceManager>( ProcessState::self()->getContextObject(nullptr))); if (gDefaultServiceManager == nullptr) sleep(1); } Loading Loading @@ -158,16 +189,11 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) // ---------------------------------------------------------------------- class BpServiceManager : public BpInterface<IServiceManager> { public: explicit BpServiceManager(const sp<IBinder>& impl) : BpInterface<IServiceManager>(impl), mTheRealServiceManager(interface_cast<AidlServiceManager>(impl)) { } ServiceManagerShim::ServiceManagerShim(const sp<AidlServiceManager>& impl) : mTheRealServiceManager(impl) {} sp<IBinder> getService(const String16& name) const override sp<IBinder> ServiceManagerShim::getService(const String16& name) const { static bool gSystemBootCompleted = false; Loading Loading @@ -204,7 +230,8 @@ public: return nullptr; } sp<IBinder> checkService(const String16& name) const override { sp<IBinder> ServiceManagerShim::checkService(const String16& name) const { sp<IBinder> ret; if (!mTheRealServiceManager->checkService(String8(name).c_str(), &ret).isOk()) { return nullptr; Loading @@ -212,13 +239,16 @@ public: return ret; } status_t addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) override { Status status = mTheRealServiceManager->addService(String8(name).c_str(), service, allowIsolated, dumpsysPriority); status_t ServiceManagerShim::addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) { Status status = mTheRealServiceManager->addService( String8(name).c_str(), service, allowIsolated, dumpsysPriority); return status.exceptionCode(); } virtual Vector<String16> listServices(int dumpsysPriority) { Vector<String16> ServiceManagerShim::listServices(int dumpsysPriority) { std::vector<std::string> ret; if (!mTheRealServiceManager->listServices(dumpsysPriority, &ret).isOk()) { return {}; Loading @@ -232,7 +262,8 @@ public: return res; } sp<IBinder> waitForService(const String16& name16) override { sp<IBinder> ServiceManagerShim::waitForService(const String16& name16) { class Waiter : public android::os::BnServiceCallback { Status onRegistration(const std::string& /*name*/, 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 libs/binder/include/binder/IServiceManager.h +11 −1 Original line number 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 { public: DECLARE_META_INTERFACE(ServiceManager) // for ABI compatibility virtual const String16& getInterfaceDescriptor() const; IServiceManager(); virtual ~IServiceManager(); /** * Must match values in IServiceManager.aidl */ Loading Loading
libs/binder/IServiceManager.cpp +138 −113 Original line number 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_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() { static Mutex gDefaultServiceManagerLock; Loading @@ -64,8 +94,9 @@ sp<IServiceManager> defaultServiceManager() { AutoMutex _l(gDefaultServiceManagerLock); while (gDefaultServiceManager == nullptr) { gDefaultServiceManager = interface_cast<IServiceManager>( ProcessState::self()->getContextObject(nullptr)); gDefaultServiceManager = new ServiceManagerShim( interface_cast<AidlServiceManager>( ProcessState::self()->getContextObject(nullptr))); if (gDefaultServiceManager == nullptr) sleep(1); } Loading Loading @@ -158,16 +189,11 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) // ---------------------------------------------------------------------- class BpServiceManager : public BpInterface<IServiceManager> { public: explicit BpServiceManager(const sp<IBinder>& impl) : BpInterface<IServiceManager>(impl), mTheRealServiceManager(interface_cast<AidlServiceManager>(impl)) { } ServiceManagerShim::ServiceManagerShim(const sp<AidlServiceManager>& impl) : mTheRealServiceManager(impl) {} sp<IBinder> getService(const String16& name) const override sp<IBinder> ServiceManagerShim::getService(const String16& name) const { static bool gSystemBootCompleted = false; Loading Loading @@ -204,7 +230,8 @@ public: return nullptr; } sp<IBinder> checkService(const String16& name) const override { sp<IBinder> ServiceManagerShim::checkService(const String16& name) const { sp<IBinder> ret; if (!mTheRealServiceManager->checkService(String8(name).c_str(), &ret).isOk()) { return nullptr; Loading @@ -212,13 +239,16 @@ public: return ret; } status_t addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) override { Status status = mTheRealServiceManager->addService(String8(name).c_str(), service, allowIsolated, dumpsysPriority); status_t ServiceManagerShim::addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) { Status status = mTheRealServiceManager->addService( String8(name).c_str(), service, allowIsolated, dumpsysPriority); return status.exceptionCode(); } virtual Vector<String16> listServices(int dumpsysPriority) { Vector<String16> ServiceManagerShim::listServices(int dumpsysPriority) { std::vector<std::string> ret; if (!mTheRealServiceManager->listServices(dumpsysPriority, &ret).isOk()) { return {}; Loading @@ -232,7 +262,8 @@ public: return res; } sp<IBinder> waitForService(const String16& name16) override { sp<IBinder> ServiceManagerShim::waitForService(const String16& name16) { class Waiter : public android::os::BnServiceCallback { Status onRegistration(const std::string& /*name*/, 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
libs/binder/include/binder/IServiceManager.h +11 −1 Original line number 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 { public: DECLARE_META_INTERFACE(ServiceManager) // for ABI compatibility virtual const String16& getInterfaceDescriptor() const; IServiceManager(); virtual ~IServiceManager(); /** * Must match values in IServiceManager.aidl */ Loading