1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_HIDLPROVIDERINFOH
18 #define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_HIDLPROVIDERINFOH
19 
20 #include "common/CameraProviderManager.h"
21 
22 namespace android {
23 
24 struct HidlProviderInfo : public CameraProviderManager::ProviderInfo,
25             virtual public hardware::camera::provider::V2_6::ICameraProviderCallback,
26             virtual public hardware::hidl_death_recipient {
27     // Current overall Android device physical status
28     hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState;
29 
30     // This pointer is used to keep a reference to the ICameraProvider that was last accessed.
31     wp<hardware::camera::provider::V2_4::ICameraProvider> mActiveInterface;
32 
33     sp<hardware::camera::provider::V2_4::ICameraProvider> mSavedInterface;
HidlProviderInfoHidlProviderInfo34     HidlProviderInfo(
35             const std::string &providerName,
36             const std::string &providerInstance,
37             CameraProviderManager *manager) :
38             CameraProviderManager::ProviderInfo(providerName, providerInstance, manager) {}
39 
~HidlProviderInfoHidlProviderInfo40     virtual ~HidlProviderInfo() {}
41 
42     static status_t mapToStatusT(const hardware::camera::common::V1_0::Status &status);
43 
44     status_t initializeHidlProvider(
45             sp<hardware::camera::provider::V2_4::ICameraProvider>& interface,
46             int64_t currentDeviceState);
47 
getIPCTransportHidlProviderInfo48     IPCTransport getIPCTransport() const override {return IPCTransport::HIDL;}
49 
50     const sp<hardware::camera::provider::V2_4::ICameraProvider> startProviderInterface();
51 
52     virtual bool successfullyStartedProviderInterface() override;
53 
getDeviceStateHidlProviderInfo54     virtual int64_t getDeviceState() override {return mDeviceState;};
55 
56     virtual status_t setUpVendorTags() override;
57     virtual status_t notifyDeviceStateChange(int64_t) override;
58 
59     /**
60      * Query the camera provider for concurrent stream configuration support
61      */
62     virtual status_t isConcurrentSessionConfigurationSupported(
63         const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
64         const std::set<std::string>& perfClassPrimaryCameraIds,
65         int targetSdkVersion, bool *isSupported) override;
66 
67     // Helper for initializeDeviceInfo to use the right CameraProvider get method.
68     sp<hardware::camera::device::V3_2::ICameraDevice>
69             startDeviceInterface(const std::string &deviceName);
70 
71     // ICameraProviderCallbacks interface - these lock the parent mInterfaceMutex
72     hardware::Return<void> cameraDeviceStatusChange(
73             const hardware::hidl_string& ,
74             hardware::camera::common::V1_0::CameraDeviceStatus ) override;
75     hardware::Return<void> torchModeStatusChange(
76             const hardware::hidl_string& ,
77             hardware::camera::common::V1_0::TorchModeStatus ) override;
78     hardware::Return<void> physicalCameraDeviceStatusChange(
79             const hardware::hidl_string& ,
80             const hardware::hidl_string& ,
81             hardware::camera::common::V1_0::CameraDeviceStatus ) override;
82 
83     // hidl_death_recipient interface - this locks the parent mInterfaceMutex
84     virtual void serviceDied(uint64_t , const wp<hidl::base::V1_0::IBase>& ) override;
85 
86     struct HidlDeviceInfo3 : public CameraProviderManager::ProviderInfo::DeviceInfo3 {
87 
88         const hardware::hidl_version mVersion = hardware::hidl_version{3, 2};
89         sp<IBase> mSavedInterface = nullptr;
90 
91         HidlDeviceInfo3(const std::string& , const metadata_vendor_id_t ,
92                 const std::string &, uint16_t ,
93                 const CameraResourceCost& ,
94                 sp<ProviderInfo> ,
95                 const std::vector<std::string>& ,
96                 sp<hardware::camera::device::V3_2::ICameraDevice>);
97 
~HidlDeviceInfo3HidlProviderInfo::HidlDeviceInfo398         ~HidlDeviceInfo3() {}
99 
100         virtual status_t setTorchMode(bool enabled) override;
101         virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) override;
102         virtual status_t getTorchStrengthLevel(int32_t *torchStrength) override;
103 
104         virtual status_t dumpState(int fd) override;
105 
106         virtual status_t isSessionConfigurationSupported(
107                 const SessionConfiguration &/*configuration*/,
108                 bool overrideForPerfClass, camera3::metadataGetter /*getMetadata*/,
109                 bool checkSessionParams, bool *status/*status*/);
110 
111         sp<hardware::camera::device::V3_2::ICameraDevice> startDeviceInterface();
112     };
113 
114  private:
115 
116     virtual std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &,
117             const metadata_vendor_id_t , const std::string &,
118             uint16_t ) override;
119     virtual status_t reCacheConcurrentStreamingCameraIdsLocked() override;
120 
121     //Expects to have mLock locked
122     status_t getConcurrentCameraIdsInternalLocked(
123             sp<hardware::camera::provider::V2_6::ICameraProvider> &);
124 
125     //expects to have mManager->mInterfaceMutex locked
126     status_t convertToHALStreamCombinationAndCameraIdsLocked(
127         const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>&
128                 cameraIdsAndSessionConfigs,
129         const std::set<std::string>& perfClassPrimaryCameraIds,
130         int targetSdkVersion,
131         hardware::hidl_vec<hardware::camera::provider::V2_7::CameraIdAndStreamCombination>*
132                 halCameraIdsAndStreamCombinations,
133         bool *earlyExit);
134 }; // HidlProviderInfo
135 
136 } // namespace android
137 #endif
138