From ce94b75b68df3e07e9c73d42eaa59cfce0929e53 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Mon, 14 Nov 2022 18:55:06 +0900 Subject: servicemanager: add tests for updatable-via-apex This is a follow-up of 76944fee1a642cdfbabaa72ef7d29e53af1d50db. With an example vendor apex installed on a cuttlefish device, the added tests test two new APIs regarding updatable-via-apex. - ServiceManager.updatableViaApex(instance) - ServiceManager.getUpdatableNames(apexName) This also fixes both methods - (minor) updatableViaApex returns early when the match found - getUpdatableNames iterates over all instances to find updatable instances. Bug: 254201177 Test: atest servicemanager_test Change-Id: I165c5532b40a4f9d520bef55864708b1629e24c7 --- cmds/servicemanager/ServiceManager.cpp | 3 +- cmds/servicemanager/test_sm.cpp | 54 ++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index 2ae61b9603..cc038ae0d4 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -136,6 +136,7 @@ static std::optional getVintfUpdatableApex(const std::string& name) updatableViaApex = manifestInstance.updatableViaApex(); return false; // break (libvintf uses opposite convention) }); + if (updatableViaApex.has_value()) return true; // break (found match) return false; // continue }); @@ -154,7 +155,7 @@ static std::vector getVintfUpdatableInstances(const std::string& ap manifestInstance.interface() + "/" + manifestInstance.instance(); instances.push_back(aname); } - return false; // continue + return true; // continue (libvintf uses opposite convention) }); return false; // continue }); diff --git a/cmds/servicemanager/test_sm.cpp b/cmds/servicemanager/test_sm.cpp index 5d5a75e174..0fd8d8ee2a 100644 --- a/cmds/servicemanager/test_sm.cpp +++ b/cmds/servicemanager/test_sm.cpp @@ -14,13 +14,15 @@ * limitations under the License. */ +#include +#include #include #include -#include #include +#include #include -#include #include +#include #include "Access.h" #include "ServiceManager.h" @@ -75,6 +77,11 @@ static sp getPermissiveServiceManager() { return sm; } +static bool isCuttlefish() { + return android::base::StartsWith(android::base::GetProperty("ro.product.vendor.device", ""), + "vsoc_"); +} + TEST(AddService, HappyHappy) { auto sm = getPermissiveServiceManager(); EXPECT_TRUE(sm->addService("foo", getBinder(), false /*allowIsolated*/, @@ -306,6 +313,49 @@ TEST(ListServices, CriticalServices) { EXPECT_THAT(out, ElementsAre("sa")); } +TEST(Vintf, UpdatableViaApex) { + if (!isCuttlefish()) GTEST_SKIP() << "Skipping non-Cuttlefish devices"; + + auto sm = getPermissiveServiceManager(); + std::optional updatableViaApex; + EXPECT_TRUE(sm->updatableViaApex("android.hardware.camera.provider.ICameraProvider/internal/0", + &updatableViaApex) + .isOk()); + EXPECT_EQ(std::make_optional("com.google.emulated.camera.provider.hal"), + updatableViaApex); +} + +TEST(Vintf, UpdatableViaApex_InvalidNameReturnsNullOpt) { + if (!isCuttlefish()) GTEST_SKIP() << "Skipping non-Cuttlefish devices"; + + auto sm = getPermissiveServiceManager(); + std::optional updatableViaApex; + EXPECT_TRUE(sm->updatableViaApex("android.hardware.camera.provider.ICameraProvider", + &updatableViaApex) + .isOk()); // missing instance name + EXPECT_EQ(std::nullopt, updatableViaApex); +} + +TEST(Vintf, GetUpdatableNames) { + if (!isCuttlefish()) GTEST_SKIP() << "Skipping non-Cuttlefish devices"; + + auto sm = getPermissiveServiceManager(); + std::vector names; + EXPECT_TRUE(sm->getUpdatableNames("com.google.emulated.camera.provider.hal", &names).isOk()); + EXPECT_EQ(std::vector< + std::string>{"android.hardware.camera.provider.ICameraProvider/internal/0"}, + names); +} + +TEST(Vintf, GetUpdatableNames_InvalidApexNameReturnsEmpty) { + if (!isCuttlefish()) GTEST_SKIP() << "Skipping non-Cuttlefish devices"; + + auto sm = getPermissiveServiceManager(); + std::vector names; + EXPECT_TRUE(sm->getUpdatableNames("non.existing.apex.name", &names).isOk()); + EXPECT_EQ(std::vector{}, names); +} + class CallbackHistorian : public BnServiceCallback { Status onRegistration(const std::string& name, const sp& binder) override { registrations.push_back(name); -- cgit v1.2.3-59-g8ed1b