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

Commit a04055f5 authored by Jayant Chowdhary's avatar Jayant Chowdhary
Browse files

Add AidlProviderInfo to handle aidl hal providers.



Bug: 196432585

Test: GCA; Record videos and take pictures (Basic validity)
Test: Camera CTS with AIDL provider
Test: Use Camera VNDK

Change-Id: I8c2bf49100c45d5f09f6ef97a0d5739ebc2199d7
Signed-off-by: default avatarJayant Chowdhary <jchowdhary@google.com>
parent 3eeeda39
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ cc_binary {
        "android.hardware.camera.provider@2.5",
        "android.hardware.camera.provider@2.6",
        "android.hardware.camera.provider@2.7",
        "android.hardware.camera.provider-V1-ndk",
        "android.hardware.camera.device@1.0",
        "android.hardware.camera.device@3.2",
        "android.hardware.camera.device@3.4",
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ cc_library_shared {
        "common/CameraProviderManager.cpp",
        "common/FrameProcessorBase.cpp",
        "common/hidl/HidlProviderInfo.cpp",
        "common/aidl/AidlProviderInfo.cpp",
        "api1/Camera2Client.cpp",
        "api1/client2/Parameters.cpp",
        "api1/client2/FrameProcessor.cpp",
@@ -115,6 +116,7 @@ cc_library_shared {
        "libutilscallstack",
        "libutils",
        "libbinder",
        "libbinder_ndk",
        "libactivitymanager_aidl",
        "libpermission",
        "libcutils",
@@ -148,6 +150,7 @@ cc_library_shared {
        "android.hardware.camera.provider@2.5",
        "android.hardware.camera.provider@2.6",
        "android.hardware.camera.provider@2.7",
        "android.hardware.camera.provider-V1-ndk",
        "android.hardware.camera.device@3.2",
        "android.hardware.camera.device@3.3",
        "android.hardware.camera.device@3.4",
@@ -159,6 +162,7 @@ cc_library_shared {
    ],

    static_libs: [
        "libaidlcommonsupport",
        "libprocessinfoservice_aidl",
        "libbinderthreadstateutils",
        "media_permission-aidl-cpp",
+112 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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_SERVERS_CAMERA_CAMERAPROVIDERINFO_TEMPLATEDH
#define ANDROID_SERVERS_CAMERA_CAMERAPROVIDERINFO_TEMPLATEDH

#include "common/CameraProviderManager.h"

namespace android {

template <class VendorTagSectionVectorType, class VendorTagSectionType>
status_t IdlVendorTagDescriptor::createDescriptorFromIdl(
        const VendorTagSectionVectorType& vts,
        sp<VendorTagDescriptor>& descriptor) {

    int tagCount = 0;

    for (size_t s = 0; s < vts.size(); s++) {
        tagCount += vts[s].tags.size();
    }

    if (tagCount < 0 || tagCount > INT32_MAX) {
        ALOGE("%s: tag count %d from vendor tag sections is invalid.", __FUNCTION__, tagCount);
        return BAD_VALUE;
    }

    Vector<uint32_t> tagArray;
    LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount,
            "%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount);
    sp<IdlVendorTagDescriptor> desc = new IdlVendorTagDescriptor();
    desc->mTagCount = tagCount;

    SortedVector<String8> sections;
    KeyedVector<uint32_t, String8> tagToSectionMap;

    int idx = 0;
    for (size_t s = 0; s < vts.size(); s++) {
        const VendorTagSectionType& section = vts[s];
        const char *sectionName = section.sectionName.c_str();
        if (sectionName == NULL) {
            ALOGE("%s: no section name defined for vendor tag section %zu.", __FUNCTION__, s);
            return BAD_VALUE;
        }
        String8 sectionString(sectionName);
        sections.add(sectionString);

        for (size_t j = 0; j < section.tags.size(); j++) {
            uint32_t tag = section.tags[j].tagId;
            if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) {
                ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag);
                return BAD_VALUE;
            }

            tagArray.editItemAt(idx++) = section.tags[j].tagId;

            const char *tagName = section.tags[j].tagName.c_str();
            if (tagName == NULL) {
                ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag);
                return BAD_VALUE;
            }
            desc->mTagToNameMap.add(tag, String8(tagName));
            tagToSectionMap.add(tag, sectionString);

            int tagType = (int) section.tags[j].tagType;
            if (tagType < 0 || tagType >= NUM_TYPES) {
                ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType);
                return BAD_VALUE;
            }
            desc->mTagToTypeMap.add(tag, tagType);
        }
    }

    desc->mSections = sections;

    for (size_t i = 0; i < tagArray.size(); ++i) {
        uint32_t tag = tagArray[i];
        String8 sectionString = tagToSectionMap.valueFor(tag);

        // Set up tag to section index map
        ssize_t index = sections.indexOf(sectionString);
        LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index);
        desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index));

        // Set up reverse mapping
        ssize_t reverseIndex = -1;
        if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
            KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
            reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
        }
        desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
    }

    descriptor = std::move(desc);
    return OK;
}


} // namespace android

#endif
+548 −22

File changed.

Preview size limit exceeded, changes collapsed.

+103 −3
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <utils/Errors.h>
#include <android/hardware/ICameraService.h>
#include <utils/IPCTransport.h>
#include <aidl/android/hardware/camera/provider/ICameraProvider.h>
#include <android/hardware/camera/common/1.0/types.h>
#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
#include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
@@ -96,6 +97,26 @@ enum SystemCameraKind {
#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
#define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8)

/**
 * The vendor tag descriptor class that takes HIDL/AIDL vendor tag information as
 * input. Not part of VendorTagDescriptor class because that class is used
 * in AIDL generated sources which don't have access to AIDL / HIDL headers.
 */
class IdlVendorTagDescriptor : public VendorTagDescriptor {
public:
    /**
     * Create a VendorTagDescriptor object from the HIDL/AIDL VendorTagSection
     * vector.
     *
     * Returns OK on success, or a negative error code.
     */
    template <class VendorTagSectionVectorType, class VendorTagSectionType>
    static status_t createDescriptorFromIdl(
            const VendorTagSectionVectorType& vts,
            /*out*/
            sp<VendorTagDescriptor>& descriptor);
};

/**
 * A manager for all camera providers available on an Android device.
 *
@@ -106,11 +127,13 @@ enum SystemCameraKind {
 * opening them for active use.
 *
 */
class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification {
class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification,
        public virtual IServiceManager::LocalRegistrationCallback {
public:
    // needs to be made friend strict since HidlProviderInfo needs to inherit
    // from CameraProviderManager::ProviderInfo which isn't a public member.
    friend struct HidlProviderInfo;
    friend struct AidlProviderInfo;
    ~CameraProviderManager();

    // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
@@ -315,6 +338,13 @@ public:
     */
    status_t notifyDeviceStateChange(int64_t newState);

    status_t openAidlSession(const std::string &id,
        const std::shared_ptr<
                aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
        /*out*/
        std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceSession> *session);


    /**
     * Open an active session to a camera device.
     *
@@ -339,6 +369,9 @@ public:
            const hardware::hidl_string& name,
            bool preexisting) override;

    // LocalRegistrationCallback::onServiceRegistration
    virtual void onServiceRegistration(const String16& name, const sp<IBinder> &binder) override;

    /**
     * Dump out information about available providers and devices
     */
@@ -402,6 +435,17 @@ private:
        sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider;
    };

    struct AidlHalCameraProvider : public HalCameraProvider {
        AidlHalCameraProvider(
                const std::shared_ptr<
                        aidl::android::hardware::camera::provider::ICameraProvider> &provider,
                const char *descriptor) :
                HalCameraProvider(descriptor), mCameraProvider(provider) { };
     private:
        std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mCameraProvider;
    };


    // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
    // ICameraProvider alive while it is in use by the camera with the given ID for camera
    // capabilities
@@ -418,10 +462,11 @@ private:
    std::mutex mProviderInterfaceMapLock;
    struct ProviderInfo : public virtual RefBase {
        friend struct HidlProviderInfo;
        friend struct AidlProviderInfo;
        const std::string mProviderName;
        const std::string mProviderInstance;
        const metadata_vendor_id_t mProviderTagid;
        int mMinorVersion;
        int32_t mMinorVersion;
        sp<VendorTagDescriptor> mVendorTagDescriptor;
        bool mSetTorchModeSupported;
        bool mIsRemote;
@@ -436,6 +481,7 @@ private:

        status_t dump(int fd, const Vector<String16>& args) const;

        void initializeProviderInfoCommon(const std::vector<std::string> &devices);
        /**
         * Setup vendor tags for this provider
         */
@@ -452,6 +498,8 @@ private:

        virtual bool successfullyStartedProviderInterface() = 0;

        virtual int64_t getDeviceState() = 0;

        std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();

        /**
@@ -469,7 +517,6 @@ private:
                    const std::set<std::string>& perfClassPrimaryCameraIds,
                    int targetSdkVersion, bool *isSupported) = 0;


        /**
         * Remove all devices associated with this provider and notify listeners
         * with NOT_PRESENT state.
@@ -666,6 +713,14 @@ private:
        // End of scope for mInitLock

        std::future<void> mInitialStatusCallbackFuture;

        std::unique_ptr<ProviderInfo::DeviceInfo>
        virtual initializeDeviceInfo(
                const std::string &name, const metadata_vendor_id_t tagId,
                const std::string &id, uint16_t minorVersion) = 0;

        virtual status_t reCacheConcurrentStreamingCameraIdsLocked() = 0;

        void notifyInitialStatusChange(sp<StatusListener> listener,
                std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus);

@@ -682,10 +737,46 @@ private:
        // Generate vendor tag id
        static metadata_vendor_id_t generateVendorTagId(const std::string &name);

        status_t addDevice(
                const std::string& name, CameraDeviceStatus initialStatus,
                /*out*/ std::string* parsedId);

        void cameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
                CameraDeviceStatus newStatus);

        status_t cameraDeviceStatusChangeLocked(
                std::string* id, const std::string& cameraDeviceName,
                CameraDeviceStatus newStatus);

        void physicalCameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
                const std::string& physicalCameraDeviceName,
                CameraDeviceStatus newStatus);

      status_t physicalCameraDeviceStatusChangeLocked(
            std::string* id, std::string* physicalId,
            const std::string& cameraDeviceName,
            const std::string& physicalCameraDeviceName,
            CameraDeviceStatus newStatus);

        void torchModeStatusChangeInternal(const std::string& cameraDeviceName,
                TorchModeStatus newStatus);

        void removeDevice(std::string id);

    };

    template <class ProviderInfoType, class HalCameraProviderType>
    status_t setTorchModeT(sp<ProviderInfo> &parentProvider,
            std::shared_ptr<HalCameraProvider> *halCameraProvider);

    // Try to get hidl provider services declared. Expects mInterfaceMutex to be
    // locked. Also registers for hidl provider service notifications.
    status_t tryToInitAndAddHidlProvidersLocked(HidlServiceInteractionProxy *hidlProxy);

    // Try to get aidl provider services declared. Expects mInterfaceMutex to be
    // locked. Also registers for aidl provider service notifications.
    status_t tryToAddAidlProvidersLocked();

    /**
     * Save the ICameraProvider while it is being used by a camera or torch client
     */
@@ -709,9 +800,14 @@ private:

    status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false);

    status_t addAidlProviderLocked(const std::string& newProvider);

    status_t tryToInitializeHidlProviderLocked(const std::string& providerName,
            const sp<ProviderInfo>& providerInfo);

    status_t tryToInitializeAidlProviderLocked(const std::string& providerName,
            const sp<ProviderInfo>& providerInfo);

    bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);

    // No method corresponding to the same provider / member belonging to the
@@ -725,6 +821,8 @@ private:

    size_t mProviderInstanceId = 0;
    std::vector<sp<ProviderInfo>> mProviders;
    // Provider names of AIDL providers with retrieved binders.
    std::set<std::string> mAidlProviderWithBinders;

    static const char* deviceStatusToString(
        const hardware::camera::common::V1_0::CameraDeviceStatus&);
@@ -744,6 +842,8 @@ private:
            std::vector<std::string>& systemCameraDeviceIds) const;

    status_t usbDeviceDetached(const std::string &usbDeviceId);
    ndk::ScopedAStatus onAidlRegistration(const std::string& in_name,
            const ::ndk::SpAIBinder& in_binder);
};

} // namespace android
Loading