diff options
| author | 2019-10-29 09:26:52 -0700 | |
|---|---|---|
| committer | 2019-10-29 09:26:52 -0700 | |
| commit | 3900da85d671a618596b4de5846fd3ecc7997dcd (patch) | |
| tree | b61bcb46a6fbd75e8646463f58e806417e264c45 /libs | |
| parent | be0e1c782653855c4719b87e459f755c8a0083ad (diff) | |
| parent | 4a44bce7ff121cc2da6a8a8cf4ee6d8a30a37630 (diff) | |
Merge "ServiceManager: add isDeclared" am: c9c2f0c858
am: 4a44bce7ff
Change-Id: I79631a4f48f0c77d7e6be0e333c397bc92bb75e9
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/binder/IServiceManager.cpp | 9 | ||||
| -rw-r--r-- | libs/binder/aidl/android/os/IServiceManager.aidl | 7 | ||||
| -rw-r--r-- | libs/binder/include/binder/IServiceManager.h | 15 | ||||
| -rw-r--r-- | libs/binder/tests/binderStabilityTest.cpp | 21 |
4 files changed, 40 insertions, 12 deletions
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index a30df14bd6..4f47db199e 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -72,6 +72,7 @@ public: bool allowIsolated, int dumpsysPriority) override; Vector<String16> listServices(int dumpsysPriority) override; sp<IBinder> waitForService(const String16& name16) override; + bool isDeclared(const String16& name) override; // for legacy ABI const String16& getInterfaceDescriptor() const override { @@ -321,4 +322,12 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16) } } +bool ServiceManagerShim::isDeclared(const String16& name) { + bool declared; + if (!mTheRealServiceManager->isDeclared(String8(name).c_str(), &declared).isOk()) { + return false; + } + return declared; +} + } // namespace android diff --git a/libs/binder/aidl/android/os/IServiceManager.aidl b/libs/binder/aidl/android/os/IServiceManager.aidl index 471b63fb5e..8c7ebbaf36 100644 --- a/libs/binder/aidl/android/os/IServiceManager.aidl +++ b/libs/binder/aidl/android/os/IServiceManager.aidl @@ -89,4 +89,11 @@ interface IServiceManager { * Unregisters all requests for notifications for a specific callback. */ void unregisterForNotifications(@utf8InCpp String name, IServiceCallback callback); + + /** + * Returns whether a given interface is declared on the device, even if it + * is not started yet. For instance, this could be a service declared in the VINTF + * manifest. + */ + boolean isDeclared(@utf8InCpp String name); } diff --git a/libs/binder/include/binder/IServiceManager.h b/libs/binder/include/binder/IServiceManager.h index a675513793..4a44c5a7da 100644 --- a/libs/binder/include/binder/IServiceManager.h +++ b/libs/binder/include/binder/IServiceManager.h @@ -88,6 +88,14 @@ public: * Returns nullptr only for permission problem or fatal error. */ virtual sp<IBinder> waitForService(const String16& name) = 0; + + /** + * Check if a service is declared (e.g. VINTF manifest). + * + * If this returns true, waitForService should always be able to return the + * service. + */ + virtual bool isDeclared(const String16& name) = 0; }; sp<IServiceManager> defaultServiceManager(); @@ -99,6 +107,13 @@ sp<INTERFACE> waitForService(const String16& name) { } template<typename INTERFACE> +sp<INTERFACE> waitForDeclaredService(const String16& name) { + const sp<IServiceManager> sm = defaultServiceManager(); + if (!sm->isDeclared(name)) return nullptr; + return interface_cast<INTERFACE>(sm->waitForService(name)); +} + +template<typename INTERFACE> status_t getService(const String16& name, sp<INTERFACE>* outService) { const sp<IServiceManager> sm = defaultServiceManager(); diff --git a/libs/binder/tests/binderStabilityTest.cpp b/libs/binder/tests/binderStabilityTest.cpp index 0bee56c943..1f2779abf0 100644 --- a/libs/binder/tests/binderStabilityTest.cpp +++ b/libs/binder/tests/binderStabilityTest.cpp @@ -134,18 +134,15 @@ TEST(BinderStability, OnlyVintfStabilityBinderNeedsVintfDeclaration) { TEST(BinderStability, VintfStabilityServerMustBeDeclaredInManifest) { sp<IBinder> vintfServer = BadStableBinder::vintf(); - EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, - android::defaultServiceManager()->addService(String16("."), vintfServer)); - EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, - android::defaultServiceManager()->addService(String16("/"), vintfServer)); - EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, - android::defaultServiceManager()->addService(String16("/."), vintfServer)); - EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, - android::defaultServiceManager()->addService(String16("a.d.IFoo"), vintfServer)); - EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, - android::defaultServiceManager()->addService(String16("foo"), vintfServer)); - EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, - android::defaultServiceManager()->addService(String16("a.d.IFoo/foo"), vintfServer)); + for (const char* instance8 : { + ".", "/", "/.", "a.d.IFoo", "foo", "a.d.IFoo/foo" + }) { + String16 instance (instance8); + + EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, + android::defaultServiceManager()->addService(String16("."), vintfServer)) << instance8; + EXPECT_FALSE(android::defaultServiceManager()->isDeclared(instance)) << instance8; + } } TEST(BinderStability, CantCallVendorBinderInSystemContext) { |