Loading services/camera/libcameraservice/common/CameraProviderManager.cpp +22 −15 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include <future> #include <inttypes.h> #include <hardware/camera_common.h> #include <android/hidl/manager/1.2/IServiceManager.h> #include <hidl/ServiceManagement.h> #include <functional> #include <camera_metadata_hidden.h> Loading @@ -47,10 +48,6 @@ using namespace ::android::hardware::camera::common::V1_0; using std::literals::chrono_literals::operator""s; namespace { // Hardcoded name for the passthrough HAL implementation, since it can't be discovered via the // service manager const std::string kLegacyProviderName("legacy/0"); const std::string kExternalProviderName("external/0"); const bool kEnableLazyHal(property_get_bool("ro.camera.enableLazyHal", false)); } // anonymous namespace Loading @@ -62,6 +59,19 @@ CameraProviderManager::sHardwareServiceInteractionProxy{}; CameraProviderManager::~CameraProviderManager() { } hardware::hidl_vec<hardware::hidl_string> CameraProviderManager::HardwareServiceInteractionProxy::listServices() { hardware::hidl_vec<hardware::hidl_string> ret; auto manager = hardware::defaultServiceManager1_2(); if (manager != nullptr) { manager->listManifestByInterface(provider::V2_4::ICameraProvider::descriptor, [&ret](const hardware::hidl_vec<hardware::hidl_string> ®istered) { ret = registered; }); } return ret; } status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListener> listener, ServiceInteractionProxy* proxy) { std::lock_guard<std::mutex> lock(mInterfaceMutex); Loading @@ -84,9 +94,10 @@ status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListe return INVALID_OPERATION; } // See if there's a passthrough HAL, but let's not complain if there's not addProviderLocked(kLegacyProviderName, /*expected*/ false); addProviderLocked(kExternalProviderName, /*expected*/ false); for (const auto& instance : mServiceProxy->listServices()) { this->addProviderLocked(instance); } IPCThreadState::self()->flushCommands(); Loading Loading @@ -1087,7 +1098,7 @@ bool CameraProviderManager::isHiddenPhysicalCamera(const std::string& cameraId) return false; } status_t CameraProviderManager::addProviderLocked(const std::string& newProvider, bool expected) { status_t CameraProviderManager::addProviderLocked(const std::string& newProvider) { for (const auto& providerInfo : mProviders) { if (providerInfo->mProviderName == newProvider) { ALOGW("%s: Camera provider HAL with name '%s' already registered", __FUNCTION__, Loading @@ -1100,13 +1111,9 @@ status_t CameraProviderManager::addProviderLocked(const std::string& newProvider interface = mServiceProxy->getService(newProvider); if (interface == nullptr) { if (expected) { ALOGE("%s: Camera provider HAL '%s' is not actually available", __FUNCTION__, newProvider.c_str()); return BAD_VALUE; } else { return OK; } } sp<ProviderInfo> providerInfo = new ProviderInfo(newProvider, this); Loading services/camera/libcameraservice/common/CameraProviderManager.h +4 −1 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public: ¬ification) = 0; virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( const std::string &serviceName) = 0; virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0; virtual ~ServiceInteractionProxy() {} }; Loading @@ -95,6 +96,8 @@ public: const std::string &serviceName) override { return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName); } virtual hardware::hidl_vec<hardware::hidl_string> listServices() override; }; /** Loading Loading @@ -567,7 +570,7 @@ private: hardware::hidl_version minVersion = hardware::hidl_version{0,0}, hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; status_t addProviderLocked(const std::string& newProvider, bool expected = true); status_t addProviderLocked(const std::string& newProvider); status_t removeProvider(const std::string& provider); sp<StatusListener> getStatusListener() const; Loading services/camera/libcameraservice/tests/CameraProviderManagerTest.cpp +13 −21 Original line number Diff line number Diff line Loading @@ -205,6 +205,11 @@ struct TestInteractionProxy : public CameraProviderManager::ServiceInteractionPr return mTestCameraProvider; } virtual hardware::hidl_vec<hardware::hidl_string> listServices() override { hardware::hidl_vec<hardware::hidl_string> ret = {"test/0"}; return ret; } }; struct TestStatusListener : public CameraProviderManager::StatusListener { Loading @@ -231,37 +236,24 @@ TEST(CameraProviderManagerTest, InitializeTest) { vendorSection); serviceProxy.setProvider(provider); int numProviders = static_cast<int>(serviceProxy.listServices().size()); res = providerManager->initialize(statusListener, &serviceProxy); ASSERT_EQ(res, OK) << "Unable to initialize provider manager"; // Check that both "legacy" and "external" providers (really the same object) are called // once for all the init methods EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::SET_CALLBACK], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::SET_CALLBACK], numProviders) << "Only one call to setCallback per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_VENDOR_TAGS], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_VENDOR_TAGS], numProviders) << "Only one call to getVendorTags per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::IS_SET_TORCH_MODE_SUPPORTED], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::IS_SET_TORCH_MODE_SUPPORTED], numProviders) << "Only one call to isSetTorchModeSupported per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_CAMERA_ID_LIST], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_CAMERA_ID_LIST], numProviders) << "Only one call to getCameraIdList per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::NOTIFY_DEVICE_STATE], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::NOTIFY_DEVICE_STATE], numProviders) << "Only one call to notifyDeviceState per provider expected during init"; std::string legacyInstanceName = "legacy/0"; std::string externalInstanceName = "external/0"; bool gotLegacy = false; bool gotExternal = false; EXPECT_EQ(2u, serviceProxy.mLastRequestedServiceNames.size()) << "Only two service queries expected to be seen by hardware service manager"; for (auto& serviceName : serviceProxy.mLastRequestedServiceNames) { if (serviceName == legacyInstanceName) gotLegacy = true; if (serviceName == externalInstanceName) gotExternal = true; } ASSERT_TRUE(gotLegacy) << "Legacy instance not requested from service manager"; ASSERT_TRUE(gotExternal) << "External instance not requested from service manager"; hardware::hidl_string testProviderFqInterfaceName = "android.hardware.camera.provider@2.4::ICameraProvider"; hardware::hidl_string testProviderInstanceName = "test/0"; Loading Loading
services/camera/libcameraservice/common/CameraProviderManager.cpp +22 −15 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include <future> #include <inttypes.h> #include <hardware/camera_common.h> #include <android/hidl/manager/1.2/IServiceManager.h> #include <hidl/ServiceManagement.h> #include <functional> #include <camera_metadata_hidden.h> Loading @@ -47,10 +48,6 @@ using namespace ::android::hardware::camera::common::V1_0; using std::literals::chrono_literals::operator""s; namespace { // Hardcoded name for the passthrough HAL implementation, since it can't be discovered via the // service manager const std::string kLegacyProviderName("legacy/0"); const std::string kExternalProviderName("external/0"); const bool kEnableLazyHal(property_get_bool("ro.camera.enableLazyHal", false)); } // anonymous namespace Loading @@ -62,6 +59,19 @@ CameraProviderManager::sHardwareServiceInteractionProxy{}; CameraProviderManager::~CameraProviderManager() { } hardware::hidl_vec<hardware::hidl_string> CameraProviderManager::HardwareServiceInteractionProxy::listServices() { hardware::hidl_vec<hardware::hidl_string> ret; auto manager = hardware::defaultServiceManager1_2(); if (manager != nullptr) { manager->listManifestByInterface(provider::V2_4::ICameraProvider::descriptor, [&ret](const hardware::hidl_vec<hardware::hidl_string> ®istered) { ret = registered; }); } return ret; } status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListener> listener, ServiceInteractionProxy* proxy) { std::lock_guard<std::mutex> lock(mInterfaceMutex); Loading @@ -84,9 +94,10 @@ status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListe return INVALID_OPERATION; } // See if there's a passthrough HAL, but let's not complain if there's not addProviderLocked(kLegacyProviderName, /*expected*/ false); addProviderLocked(kExternalProviderName, /*expected*/ false); for (const auto& instance : mServiceProxy->listServices()) { this->addProviderLocked(instance); } IPCThreadState::self()->flushCommands(); Loading Loading @@ -1087,7 +1098,7 @@ bool CameraProviderManager::isHiddenPhysicalCamera(const std::string& cameraId) return false; } status_t CameraProviderManager::addProviderLocked(const std::string& newProvider, bool expected) { status_t CameraProviderManager::addProviderLocked(const std::string& newProvider) { for (const auto& providerInfo : mProviders) { if (providerInfo->mProviderName == newProvider) { ALOGW("%s: Camera provider HAL with name '%s' already registered", __FUNCTION__, Loading @@ -1100,13 +1111,9 @@ status_t CameraProviderManager::addProviderLocked(const std::string& newProvider interface = mServiceProxy->getService(newProvider); if (interface == nullptr) { if (expected) { ALOGE("%s: Camera provider HAL '%s' is not actually available", __FUNCTION__, newProvider.c_str()); return BAD_VALUE; } else { return OK; } } sp<ProviderInfo> providerInfo = new ProviderInfo(newProvider, this); Loading
services/camera/libcameraservice/common/CameraProviderManager.h +4 −1 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public: ¬ification) = 0; virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( const std::string &serviceName) = 0; virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0; virtual ~ServiceInteractionProxy() {} }; Loading @@ -95,6 +96,8 @@ public: const std::string &serviceName) override { return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName); } virtual hardware::hidl_vec<hardware::hidl_string> listServices() override; }; /** Loading Loading @@ -567,7 +570,7 @@ private: hardware::hidl_version minVersion = hardware::hidl_version{0,0}, hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; status_t addProviderLocked(const std::string& newProvider, bool expected = true); status_t addProviderLocked(const std::string& newProvider); status_t removeProvider(const std::string& provider); sp<StatusListener> getStatusListener() const; Loading
services/camera/libcameraservice/tests/CameraProviderManagerTest.cpp +13 −21 Original line number Diff line number Diff line Loading @@ -205,6 +205,11 @@ struct TestInteractionProxy : public CameraProviderManager::ServiceInteractionPr return mTestCameraProvider; } virtual hardware::hidl_vec<hardware::hidl_string> listServices() override { hardware::hidl_vec<hardware::hidl_string> ret = {"test/0"}; return ret; } }; struct TestStatusListener : public CameraProviderManager::StatusListener { Loading @@ -231,37 +236,24 @@ TEST(CameraProviderManagerTest, InitializeTest) { vendorSection); serviceProxy.setProvider(provider); int numProviders = static_cast<int>(serviceProxy.listServices().size()); res = providerManager->initialize(statusListener, &serviceProxy); ASSERT_EQ(res, OK) << "Unable to initialize provider manager"; // Check that both "legacy" and "external" providers (really the same object) are called // once for all the init methods EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::SET_CALLBACK], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::SET_CALLBACK], numProviders) << "Only one call to setCallback per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_VENDOR_TAGS], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_VENDOR_TAGS], numProviders) << "Only one call to getVendorTags per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::IS_SET_TORCH_MODE_SUPPORTED], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::IS_SET_TORCH_MODE_SUPPORTED], numProviders) << "Only one call to isSetTorchModeSupported per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_CAMERA_ID_LIST], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_CAMERA_ID_LIST], numProviders) << "Only one call to getCameraIdList per provider expected during init"; EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::NOTIFY_DEVICE_STATE], 2) << EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::NOTIFY_DEVICE_STATE], numProviders) << "Only one call to notifyDeviceState per provider expected during init"; std::string legacyInstanceName = "legacy/0"; std::string externalInstanceName = "external/0"; bool gotLegacy = false; bool gotExternal = false; EXPECT_EQ(2u, serviceProxy.mLastRequestedServiceNames.size()) << "Only two service queries expected to be seen by hardware service manager"; for (auto& serviceName : serviceProxy.mLastRequestedServiceNames) { if (serviceName == legacyInstanceName) gotLegacy = true; if (serviceName == externalInstanceName) gotExternal = true; } ASSERT_TRUE(gotLegacy) << "Legacy instance not requested from service manager"; ASSERT_TRUE(gotExternal) << "External instance not requested from service manager"; hardware::hidl_string testProviderFqInterfaceName = "android.hardware.camera.provider@2.4::ICameraProvider"; hardware::hidl_string testProviderInstanceName = "test/0"; Loading