Camera: Update camera service to use new HIDL HALs, part 1
- Add CameraProviderManager
- Enumerates individual camera provider HAL instances, as well
as the devices they provide
- Handles dynamic provider and device appearance/disappearance
- Maps device names to public API namespace
- Add unit tests for CameraProviderManager
- Add logic to enable new HIDL path
- Switch various bits of service internals to use string camera IDs,
though leaving most camera1-facing bits using int IDs, since that's
what the old API uses.
- Update CameraService to use CameraProviderManager instead of
the legacy camera HAL
- Update clients to pass through provider manager to devices instead
of just camera module
- Still TODO:
- Update Camera3Device to use new HIDL interface
- Update CameraHardwareInterface to use new HIDL interface
- Update dump()
- Update vendor tag handling
Test: New unit tests pass, camera CTS passes with Treble disabled
Bug: 30985004
Bug: 32991422
Change-Id: I7ac41f13b9501d5e53256e28c0465ec70aa3980e
diff --git a/services/camera/libcameraservice/tests/Android.mk b/services/camera/libcameraservice/tests/Android.mk
new file mode 100644
index 0000000..179643b
--- /dev/null
+++ b/services/camera/libcameraservice/tests/Android.mk
@@ -0,0 +1,38 @@
+# Copyright 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= $(call all-cpp-files-under, .)
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ libcameraservice \
+ libhidlbase \
+ liblog \
+ libutils \
+ android.hardware.camera.common@1.0 \
+ android.hardware.camera.provider@2.4 \
+ android.hardware.camera.device@1.0 \
+ android.hardware.camera.device@3.2
+
+LOCAL_C_INCLUDES += \
+
+LOCAL_CFLAGS += -Wall -Wextra -Werror
+
+LOCAL_MODULE:= cameraservice_test
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_NATIVE_TEST)
diff --git a/services/camera/libcameraservice/tests/CameraProviderManagerTest.cpp b/services/camera/libcameraservice/tests/CameraProviderManagerTest.cpp
new file mode 100644
index 0000000..eb934ba
--- /dev/null
+++ b/services/camera/libcameraservice/tests/CameraProviderManagerTest.cpp
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "CameraProviderManagerTest"
+
+#include "../common/CameraProviderManager.h"
+#include <android/hidl/manager/1.0/IServiceManager.h>
+#include <android/hidl/manager/1.0/IServiceNotification.h>
+
+#include <gtest/gtest.h>
+
+using namespace android;
+using namespace android::hardware::camera;
+using android::hardware::camera::common::V1_0::Status;
+
+/**
+ * Basic test implementation of a camera provider
+ */
+struct TestICameraProvider : virtual public provider::V2_4::ICameraProvider {
+ sp<provider::V2_4::ICameraProviderCallbacks> mCallbacks;
+
+ std::vector<hardware::hidl_string> mDeviceNames;
+
+ TestICameraProvider() {
+ mDeviceNames.push_back("device@3.2/test/0");
+ mDeviceNames.push_back("device@1.0/test/0");
+ mDeviceNames.push_back("device@3.2/test/1");
+ }
+
+ virtual hardware::Return<Status> setCallbacks(
+ const sp<provider::V2_4::ICameraProviderCallbacks>& callbacks) override {
+ mCallbacks = callbacks;
+ return hardware::Return<Status>(Status::OK);
+ }
+
+ using getVendorTags_cb = std::function<void(Status status,
+ const hardware::hidl_vec<common::V1_0::VendorTagSection>& sections)>;
+ virtual hardware::Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override {
+ hardware::hidl_vec<common::V1_0::VendorTagSection> sections;
+ _hidl_cb(Status::OK, sections);
+ return hardware::Void();
+ }
+
+ using getCameraIdList_cb = std::function<void(Status status,
+ const hardware::hidl_vec<hardware::hidl_string>& cameraDeviceNames)>;
+ virtual hardware::Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override {
+ _hidl_cb(Status::OK, mDeviceNames);
+ return hardware::Void();
+ }
+
+ using getCameraDeviceInterface_V1_x_cb = std::function<void(Status status,
+ const sp<device::V1_0::ICameraDevice>& device)>;
+ virtual hardware::Return<void> getCameraDeviceInterface_V1_x(
+ const hardware::hidl_string& cameraDeviceName,
+ getCameraDeviceInterface_V1_x_cb _hidl_cb) override {
+ (void) cameraDeviceName;
+ _hidl_cb(Status::OK, nullptr);
+ return hardware::Void();
+ }
+
+ using getCameraDeviceInterface_V3_x_cb = std::function<void(Status status,
+ const sp<device::V3_2::ICameraDevice>& device)>;
+ virtual hardware::Return<void> getCameraDeviceInterface_V3_x(
+ const hardware::hidl_string& cameraDeviceName,
+ getCameraDeviceInterface_V3_x_cb _hidl_cb) override {
+ (void) cameraDeviceName;
+ _hidl_cb(Status::OK, nullptr);
+ return hardware::Void();
+ }
+
+};
+
+/**
+ * Simple test version of the interaction proxy, to use to inject onRegistered calls to the
+ * CameraProviderManager
+ */
+struct TestInteractionProxy : public CameraProviderManager::ServiceInteractionProxy {
+ sp<hidl::manager::V1_0::IServiceNotification> mManagerNotificationInterface;
+ const sp<TestICameraProvider> mTestCameraProvider;
+
+ TestInteractionProxy() :
+ mTestCameraProvider(new TestICameraProvider()) {
+
+ }
+ std::string mLastRequestedServiceName;
+
+ virtual ~TestInteractionProxy() {}
+
+ virtual bool registerForNotifications(
+ const std::string &serviceName,
+ const sp<hidl::manager::V1_0::IServiceNotification> ¬ification) override {
+ (void) serviceName;
+ mManagerNotificationInterface = notification;
+ return true;
+ }
+
+ virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
+ const std::string &serviceName) override {
+ mLastRequestedServiceName = serviceName;
+ return mTestCameraProvider;
+ }
+
+};
+
+TEST(CameraProviderManagerTest, InitializeTest) {
+
+ status_t res;
+ sp<CameraProviderManager> providerManager = new CameraProviderManager();
+ TestInteractionProxy serviceProxy{};
+
+ res = providerManager->initialize(&serviceProxy);
+ ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
+
+ hardware::hidl_string legacyInstanceName = "legacy/0";
+ ASSERT_EQ(serviceProxy.mLastRequestedServiceName, legacyInstanceName) <<
+ "Legacy instance not requested from service manager";
+
+ hardware::hidl_string testProviderFqInterfaceName =
+ "android.hardware.camera.provider@2.4::ICameraProvider";
+ hardware::hidl_string testProviderInstanceName = "test/0";
+ serviceProxy.mManagerNotificationInterface->onRegistration(
+ testProviderFqInterfaceName,
+ testProviderInstanceName, false);
+
+ ASSERT_EQ(serviceProxy.mLastRequestedServiceName, testProviderInstanceName) <<
+ "Incorrect instance requested from service manager";
+}