Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa04b3ba authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

Camera: Add default 2.5 provider for legacy and external webcam HALs

Add 2.5 implementations, which do not support passthrough mode and
therefore doesn't need the HIDL_Fetch methods or a specially-named
-impl library in the /hw directory.  Instead, the service directly
instantiates the necessary service.

Also add VTS tests for the new notification

Test: Verify device state changes are logged by HAL
Test: Camera starts as usual with both 2.4 and 2.5 providers on
      walleye.  Camera CTS completes.
Test: New VTS tests pass
Bug: 121379978
Change-Id: I0fc99379eb7e01c5b2efb20afb5753bb6ce8b627
parent 29518041
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ cc_test {
        "android.hardware.camera.device@3.5",
	"android.hardware.camera.metadata@3.4",
        "android.hardware.camera.provider@2.4",
        "android.hardware.camera.provider@2.5",
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.common@1.0",
        "android.hardware.graphics.mapper@2.0",
+35 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <android/hardware/camera/device/3.4/ICameraDeviceCallback.h>
#include <android/hardware/camera/device/3.5/ICameraDeviceCallback.h>
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
#include <android/hardware/camera/metadata/3.4/types.h>
#include <android/hidl/manager/1.0/IServiceManager.h>
#include <binder/MemoryHeapBase.h>
@@ -65,6 +66,7 @@
using namespace ::android::hardware::camera::device;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_bitfield;
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
@@ -543,6 +545,9 @@ public:

     uint32_t id;
     ASSERT_TRUE(parseProviderName(service_name, &mProviderType, &id));

     castProvider(mProvider, &mProvider2_5);
     notifyDeviceState(provider::V2_5::DeviceState::NORMAL);
 }
 virtual void TearDown() override {}

@@ -680,6 +685,8 @@ public:
        CameraHidlTest *mParent;               // Parent object
    };

    void notifyDeviceState(::android::hardware::camera::provider::V2_5::DeviceState newState);

    void openCameraDevice(const std::string &name, sp<ICameraProvider> provider,
            sp<::android::hardware::camera::device::V1_0::ICameraDevice> *device /*out*/);
    void setupPreviewWindow(
@@ -709,6 +716,8 @@ public:
            sp<ICameraDeviceSession> *session /*out*/,
            camera_metadata_t **staticMeta /*out*/,
            ::android::sp<ICameraDevice> *device = nullptr/*out*/);
    void castProvider(const sp<provider::V2_4::ICameraProvider> &provider,
            sp<provider::V2_5::ICameraProvider> *provider2_5 /*out*/);
    void castSession(const sp<ICameraDeviceSession> &session, int32_t deviceVersion,
            sp<device::V3_3::ICameraDeviceSession> *session3_3 /*out*/,
            sp<device::V3_4::ICameraDeviceSession> *session3_4 /*out*/,
@@ -898,6 +907,8 @@ protected:

    // Camera provider service
    sp<ICameraProvider> mProvider;
    sp<::android::hardware::camera::provider::V2_5::ICameraProvider> mProvider2_5;

    // Camera provider type.
    std::string mProviderType;
};
@@ -4681,6 +4692,13 @@ TEST_F(CameraHidlTest, flushEmpty) {
    }
}

// Test camera provider@2.5 notify method
TEST_F(CameraHidlTest, providerDeviceStateNotification) {

    notifyDeviceState(provider::V2_5::DeviceState::BACK_COVERED);
    notifyDeviceState(provider::V2_5::DeviceState::NORMAL);
}

// Retrieve all valid output stream resolutions from the camera
// static characteristics.
Status CameraHidlTest::getAvailableOutputStreams(camera_metadata_t *staticMeta,
@@ -5362,6 +5380,16 @@ void CameraHidlTest::castDevice(const sp<device::V3_2::ICameraDevice> &device,
    }
}

//Cast camera provider to corresponding version if available
void CameraHidlTest::castProvider(const sp<ICameraProvider> &provider,
        sp<provider::V2_5::ICameraProvider> *provider2_5 /*out*/) {
    ASSERT_NE(nullptr, provider2_5);
    auto castResult = provider::V2_5::ICameraProvider::castFrom(provider);
    if (castResult.isOk()) {
        *provider2_5 = castResult;
    }
}

//Cast camera device session to corresponding version
void CameraHidlTest::castSession(const sp<ICameraDeviceSession> &session, int32_t deviceVersion,
        sp<device::V3_3::ICameraDeviceSession> *session3_3 /*out*/,
@@ -5774,6 +5802,13 @@ void CameraHidlTest::openEmptyDeviceSession(const std::string &name, sp<ICameraP
    ASSERT_TRUE(ret.isOk());
}

void CameraHidlTest::notifyDeviceState(provider::V2_5::DeviceState newState) {
    if (mProvider2_5.get() == nullptr) return;

    mProvider2_5->notifyDeviceStateChange(
            static_cast<hidl_bitfield<provider::V2_5::DeviceState>>(newState));
}

// Open a particular camera device.
void CameraHidlTest::openCameraDevice(const std::string &name,
        sp<ICameraProvider> provider,
+187 −0
Original line number Diff line number Diff line
cc_library_shared {
    name: "android.hardware.camera.provider@2.5-legacy",
    proprietary: true,
    srcs: ["LegacyCameraProviderImpl_2_5.cpp"],
    shared_libs: [
        "android.hardware.camera.common@1.0",
        "android.hardware.camera.device@1.0",
        "android.hardware.camera.device@3.2",
        "android.hardware.camera.device@3.3",
        "android.hardware.camera.device@3.4",
        "android.hardware.camera.device@3.5",
        "android.hardware.camera.provider@2.4",
        "android.hardware.camera.provider@2.4-legacy",
        "android.hardware.camera.provider@2.5",
        "android.hardware.graphics.mapper@2.0",
        "android.hidl.allocator@1.0",
        "android.hidl.memory@1.0",
        "camera.device@1.0-impl",
        "camera.device@3.2-impl",
        "camera.device@3.3-impl",
        "camera.device@3.4-impl",
        "camera.device@3.5-impl",
        "libcamera_metadata",
        "libcutils",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "liblog",
        "libutils",
    ],
    static_libs: [
        "android.hardware.camera.common@1.0-helper",
    ],
    header_libs: [
        "camera.device@3.4-impl_headers",
        "camera.device@3.5-impl_headers",
    ],
    export_include_dirs: ["."],
}

cc_library_shared {
    name: "android.hardware.camera.provider@2.5-external",
    proprietary: true,
    srcs: ["ExternalCameraProviderImpl_2_5.cpp"],
    shared_libs: [
        "android.hardware.camera.common@1.0",
        "android.hardware.camera.device@1.0",
        "android.hardware.camera.device@3.2",
        "android.hardware.camera.device@3.3",
        "android.hardware.camera.device@3.4",
        "android.hardware.camera.device@3.5",
        "android.hardware.camera.provider@2.4",
        "android.hardware.camera.provider@2.4-external",
        "android.hardware.camera.provider@2.5",
        "android.hardware.graphics.mapper@2.0",
        "android.hidl.allocator@1.0",
        "android.hidl.memory@1.0",
        "camera.device@3.3-impl",
        "camera.device@3.4-external-impl",
        "camera.device@3.4-impl",
        "camera.device@3.5-external-impl",
        "camera.device@3.5-impl",
        "libcamera_metadata",
        "libcutils",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "liblog",
        "libtinyxml2",
        "libutils",
    ],
    static_libs: [
        "android.hardware.camera.common@1.0-helper",
    ],
    header_libs: [
        "camera.device@3.4-external-impl_headers",
        "camera.device@3.5-external-impl_headers"
    ],
    export_include_dirs: ["."],
}

cc_defaults {
    name: "camera_service_2_5_defaults",
    defaults: ["hidl_defaults"],
    proprietary: true,
    relative_install_path: "hw",
    srcs: ["service.cpp"],
    shared_libs: [
        "android.hardware.camera.common@1.0",
        "android.hardware.camera.device@1.0",
        "android.hardware.camera.device@3.2",
        "android.hardware.camera.device@3.3",
        "android.hardware.camera.device@3.4",
        "android.hardware.camera.device@3.5",
        "android.hardware.camera.provider@2.4",
        "android.hardware.camera.provider@2.4-legacy",
        "android.hardware.camera.provider@2.5",
        "android.hardware.camera.provider@2.5-legacy",
        "android.hardware.graphics.mapper@2.0",
        "android.hidl.allocator@1.0",
        "android.hidl.memory@1.0",
        "libbinder",
        "libcamera_metadata",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "liblog",
        "libutils",
    ],
    static_libs: [
        "android.hardware.camera.common@1.0-helper",
    ],
    header_libs: [
        "camera.device@3.4-impl_headers",
        "camera.device@3.5-impl_headers"
    ],
}

cc_binary {
    name: "android.hardware.camera.provider@2.5-service",
    defaults: ["camera_service_2_5_defaults"],
    compile_multilib: "32",
    init_rc: ["android.hardware.camera.provider@2.5-service.rc"],
}

cc_binary {
    name: "android.hardware.camera.provider@2.5-service_64",
    defaults: ["camera_service_2_5_defaults"],
    compile_multilib: "64",
    init_rc: ["android.hardware.camera.provider@2.5-service_64.rc"],
}

cc_binary {
    name: "android.hardware.camera.provider@2.5-service-lazy",
    overrides: ["android.hardware.camera.provider@2.5-service"],
    defaults: ["camera_service_2_5_defaults"],
    compile_multilib: "32",
    init_rc: ["android.hardware.camera.provider@2.5-service-lazy.rc"],
    cflags: ["-DLAZY_SERVICE"],
}

cc_binary {
    name: "android.hardware.camera.provider@2.5-service-lazy_64",
    overrides: ["android.hardware.camera.provider@2.5-service_64"],
    defaults: ["camera_service_2_5_defaults"],
    compile_multilib: "64",
    init_rc: ["android.hardware.camera.provider@2.5-service-lazy_64.rc"],
    cflags: ["-DLAZY_SERVICE"],
}

cc_binary {
    name: "android.hardware.camera.provider@2.5-external-service",
    defaults: ["hidl_defaults"],
    proprietary: true,
    relative_install_path: "hw",
    srcs: ["external-service.cpp"],
    compile_multilib: "32",
    init_rc: ["android.hardware.camera.provider@2.5-external-service.rc"],
    shared_libs: [
        "android.hardware.camera.common@1.0",
        "android.hardware.camera.device@1.0",
        "android.hardware.camera.device@3.2",
        "android.hardware.camera.device@3.3",
        "android.hardware.camera.device@3.4",
        "android.hardware.camera.device@3.5",
        "android.hardware.camera.provider@2.4",
        "android.hardware.camera.provider@2.4-external",
        "android.hardware.camera.provider@2.5",
        "android.hardware.camera.provider@2.5-external",
        "android.hardware.graphics.mapper@2.0",
        "libbinder",
        "libhidlbase",
        "libhidltransport",
        "liblog",
        "libtinyxml2",
        "libutils",
    ],
    static_libs: [
        "android.hardware.camera.common@1.0-helper",
    ],
    header_libs: [
        "camera.device@3.4-external-impl_headers",
        "camera.device@3.4-impl_headers",
        "camera.device@3.5-external-impl_headers",
        "camera.device@3.5-impl_headers",
    ],
}
+94 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

#ifndef ANDROID_HARDWARE_CAMERA_PROVIDER_V2_5_CAMERAPROVIDER_H
#define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_5_CAMERAPROVIDER_H

#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
#include <hidl/Status.h>
#include <hidl/MQDescriptor.h>

namespace android {
namespace hardware {
namespace camera {
namespace provider {
namespace V2_5 {
namespace implementation {

using ::android::hardware::camera::common::V1_0::Status;
using ::android::hardware::camera::provider::V2_5::ICameraProvider;
using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
using ::android::hardware::Return;
using ::android::hardware::hidl_string;
using ::android::sp;

// Default recommended RPC thread count for camera provider implementations
const int HWBINDER_THREAD_COUNT = 6;

template<typename IMPL>
struct CameraProvider : public ICameraProvider {
    CameraProvider() : impl() {}
    ~CameraProvider() {}

    // Caller must use this method to check if CameraProvider ctor failed
    bool isInitFailed() { return impl.isInitFailed(); }

    // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
    Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override {
        return impl.setCallback(callback);
    }

    Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override {
        return impl.getVendorTags(_hidl_cb);
    }

    Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override {
        return impl.getCameraIdList(_hidl_cb);
    }

    Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override {
        return impl.isSetTorchModeSupported(_hidl_cb);
    }

    Return<void> getCameraDeviceInterface_V1_x(
            const hidl_string& cameraDeviceName,
            getCameraDeviceInterface_V1_x_cb _hidl_cb) override {
        return impl.getCameraDeviceInterface_V1_x(cameraDeviceName, _hidl_cb);
    }

    Return<void> getCameraDeviceInterface_V3_x(
            const hidl_string& cameraDeviceName,
            getCameraDeviceInterface_V3_x_cb _hidl_cb) override {
        return impl.getCameraDeviceInterface_V3_x(cameraDeviceName, _hidl_cb);
    }

    // Methods from ::android::hardware::camera::provider::V2_5::ICameraProvider follow.
    Return<void> notifyDeviceStateChange(hardware::hidl_bitfield<DeviceState> newState) override {
        return impl.notifyDeviceStateChange(newState);
    }

private:
    IMPL impl;
};

}  // namespace implementation
}  // namespace V2_5
}  // namespace provider
}  // namespace camera
}  // namespace hardware
}  // namespace android

#endif  // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_5_CAMERAPROVIDER_H
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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_TAG "CamPrvdr@2.5-external"
//#define LOG_NDEBUG 0
#include <log/log.h>

#include "ExternalCameraProviderImpl_2_5.h"

namespace android {
namespace hardware {
namespace camera {
namespace provider {
namespace V2_5 {
namespace implementation {

ExternalCameraProviderImpl_2_5::ExternalCameraProviderImpl_2_5() :
        ExternalCameraProviderImpl_2_4() {
}

ExternalCameraProviderImpl_2_5::~ExternalCameraProviderImpl_2_5() {
}

Return<void> ExternalCameraProviderImpl_2_5::notifyDeviceStateChange(
        hidl_bitfield<DeviceState> /*newState*/) {
    return Void();
}

}  // namespace implementation
}  // namespace V2_5
}  // namespace provider
}  // namespace camera
}  // namespace hardware
}  // namespace android
Loading