blob: 7f3130e3976980fcf516f093ca2ef4d9c5e966fa [file] [log] [blame]
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001/*
2 * Copyright (C) 2016 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_H
18#define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H
19
20#include <vector>
Peter Kalauskasa29c1352018-10-10 12:05:42 -070021#include <unordered_map>
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080022#include <unordered_set>
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070023#include <set>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080024#include <string>
25#include <mutex>
26
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080027#include <camera/camera2/ConcurrentCamera.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080028#include <camera/CameraParameters2.h>
29#include <camera/CameraMetadata.h>
30#include <camera/CameraBase.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020031#include <utils/Condition.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080032#include <utils/Errors.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020033#include <android/hardware/ICameraService.h>
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070034#include <utils/IPCTransport.h>
Shuzhen Wanga79a64d2022-04-24 19:56:30 -070035#include <utils/SessionConfigurationUtils.h>
Jayant Chowdharya04055f2022-01-03 02:07:49 +000036#include <aidl/android/hardware/camera/provider/ICameraProvider.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080037#include <android/hardware/camera/common/1.0/types.h>
Eino-Ville Talvala63f36112018-12-06 14:57:03 -080038#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
Shuzhen Wang43858162020-01-10 13:42:15 -080039#include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080040#include <android/hardware/camera/provider/2.6/ICameraProvider.h>
Shuzhen Wang83bff122020-11-20 15:51:39 -080041#include <android/hardware/camera/provider/2.7/ICameraProvider.h>
42#include <android/hardware/camera/device/3.7/types.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080043#include <android/hidl/manager/1.0/IServiceNotification.h>
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070044#include <binder/IServiceManager.h>
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080045#include <camera/VendorTagDescriptor.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080046
47namespace android {
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070048
49using hardware::camera2::utils::CameraIdAndSessionConfiguration;
50
51enum class CameraDeviceStatus : uint32_t {
52 NOT_PRESENT = 0,
53 PRESENT = 1,
54 ENUMERATING = 2
55};
56
57enum class TorchModeStatus : uint32_t {
58 NOT_AVAILABLE = 0,
59 AVAILABLE_OFF = 1,
60 AVAILABLE_ON = 2
61};
62
63struct CameraResourceCost {
64 uint32_t resourceCost;
65 std::vector<std::string> conflictingDevices;
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080066};
67
Jayant Chowdhary5216b212019-07-17 09:26:23 -070068enum SystemCameraKind {
69 /**
70 * These camera devices are visible to all apps and system components alike
71 */
72 PUBLIC = 0,
73
74 /**
75 * These camera devices are visible only to processes having the
76 * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P
77 * apps.
78 */
79 SYSTEM_ONLY_CAMERA,
80
81 /**
82 * These camera devices are visible only to HAL clients (that try to connect
83 * on a hwbinder thread).
84 */
85 HIDDEN_SECURE_CAMERA
86};
87
Shuzhen Wang83bff122020-11-20 15:51:39 -080088#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
Kwangkyu Park91f4a9b2023-03-17 17:28:39 +090089#define CAMERA_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION(1, 2)
Shuzhen Wang83bff122020-11-20 15:51:39 -080090#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
91#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
92#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
93#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
94#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
95#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
96#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
97#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
98
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080099/**
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000100 * The vendor tag descriptor class that takes HIDL/AIDL vendor tag information as
101 * input. Not part of VendorTagDescriptor class because that class is used
102 * in AIDL generated sources which don't have access to AIDL / HIDL headers.
103 */
104class IdlVendorTagDescriptor : public VendorTagDescriptor {
105public:
106 /**
107 * Create a VendorTagDescriptor object from the HIDL/AIDL VendorTagSection
108 * vector.
109 *
110 * Returns OK on success, or a negative error code.
111 */
112 template <class VendorTagSectionVectorType, class VendorTagSectionType>
113 static status_t createDescriptorFromIdl(
114 const VendorTagSectionVectorType& vts,
115 /*out*/
116 sp<VendorTagDescriptor>& descriptor);
117};
118
119/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800120 * A manager for all camera providers available on an Android device.
121 *
122 * Responsible for enumerating providers and the individual camera devices
123 * they export, both at startup and as providers and devices are added/removed.
124 *
125 * Provides methods for requesting information about individual devices and for
126 * opening them for active use.
127 *
128 */
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000129class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification,
130 public virtual IServiceManager::LocalRegistrationCallback {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800131public:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700132 // needs to be made friend strict since HidlProviderInfo needs to inherit
133 // from CameraProviderManager::ProviderInfo which isn't a public member.
134 friend struct HidlProviderInfo;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000135 friend struct AidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800136 ~CameraProviderManager();
137
138 // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
139 // service manager, to be replacable in unit tests with a fake.
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700140 struct HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800141 virtual bool registerForNotifications(
142 const std::string &serviceName,
143 const sp<hidl::manager::V1_0::IServiceNotification>
144 &notification) = 0;
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700145 // Will not wait for service to start if it's not already running
146 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
147 const std::string &serviceName) = 0;
148 // Will block for service if it exists but isn't running
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800149 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
150 const std::string &serviceName) = 0;
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700151 virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700152 virtual ~HidlServiceInteractionProxy() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800153 };
154
155 // Standard use case - call into the normal generated static methods which invoke
156 // the real hardware service manager
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700157 struct HidlServiceInteractionProxyImpl : public HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800158 virtual bool registerForNotifications(
159 const std::string &serviceName,
160 const sp<hidl::manager::V1_0::IServiceNotification>
161 &notification) override {
162 return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications(
163 serviceName, notification);
164 }
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700165 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
166 const std::string &serviceName) override {
167 return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName);
168 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800169 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
170 const std::string &serviceName) override {
171 return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName);
172 }
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700173
174 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800175 };
176
177 /**
178 * Listener interface for device/torch status changes
179 */
180 struct StatusListener : virtual public RefBase {
181 ~StatusListener() {}
182
Austin Borger0fb3ad92023-06-01 16:51:35 -0700183 virtual void onDeviceStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700184 CameraDeviceStatus newStatus) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700185 virtual void onDeviceStatusChanged(const std::string &cameraId,
186 const std::string &physicalCameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700187 CameraDeviceStatus newStatus) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700188 virtual void onTorchStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700189 TorchModeStatus newStatus,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700190 SystemCameraKind kind) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700191 virtual void onTorchStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700192 TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100193 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800194 };
195
196 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700197 * Represents the mode a camera device is currently in
198 */
199 enum class DeviceMode {
200 TORCH,
201 CAMERA
202 };
203
204 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800205 * Initialize the manager and give it a status listener; optionally accepts a service
206 * interaction proxy.
207 *
208 * The default proxy communicates via the hardware service manager; alternate proxies can be
209 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
210 */
211 status_t initialize(wp<StatusListener> listener,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700212 HidlServiceInteractionProxy *hidlProxy = &sHidlServiceInteractionProxy);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800213
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800214 status_t getCameraIdIPCTransport(const std::string &id,
215 IPCTransport *providerTransport) const;
216
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800217 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700218 * Retrieve the total number of available cameras.
219 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800220 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700221 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800222
Shuzhen Wang3d316f32022-10-25 20:33:34 +0000223 /**
224 * Upon the function return, if unavailablePhysicalIds is not nullptr, it
225 * will contain all of the unavailable physical camera Ids represented in
226 * the form of:
227 * {[logicalCamera, {physicalCamera1, physicalCamera2, ...}], ...}.
228 */
229 std::vector<std::string> getCameraDeviceIds(std::unordered_map<
230 std::string, std::set<std::string>>* unavailablePhysicalIds = nullptr) const;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800231
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800232 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100233 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800234 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800235 * accessible via the old camera API.
236 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800237 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100238 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700239
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800240 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800241 * Return true if a device with a given ID has a flash unit. Returns false
242 * for devices that are unknown.
243 */
244 bool hasFlashUnit(const std::string &id) const;
245
246 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800247 * Return true if the camera device has native zoom ratio support.
248 */
249 bool supportNativeZoomRatio(const std::string &id) const;
250
251 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800252 * Return the resource cost of this camera device
253 */
254 status_t getResourceCost(const std::string &id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700255 CameraResourceCost* cost) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800256
257 /**
258 * Return the old camera API camera info
259 */
260 status_t getCameraInfo(const std::string &id,
Austin Borger3560b7e2022-10-27 12:20:29 -0700261 bool overrideToPortrait, int *portraitRotation, hardware::CameraInfo* info) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800262
263 /**
264 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
265 * not have a v3 or newer HAL version.
266 */
267 status_t getCameraCharacteristics(const std::string &id,
Austin Borger3560b7e2022-10-27 12:20:29 -0700268 bool overrideForPerfClass, CameraMetadata* characteristics,
269 bool overrideToPortrait) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800270
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800271 status_t isConcurrentSessionConfigurationSupported(
272 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
273 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700274 const std::set<std::string>& perfClassPrimaryCameraIds,
275 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800276
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700277 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800278 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000279 * Check for device support of specific stream combination.
280 */
281 status_t isSessionConfigurationSupported(const std::string& id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700282 const SessionConfiguration &configuration,
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700283 bool overrideForPerfClass, camera3::metadataGetter getMetadata,
Emilian Peev35ae8262018-11-08 13:11:32 +0000284 bool *status /*out*/) const;
285
286 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800287 * Return the highest supported device interface version for this ID
288 */
289 status_t getHighestSupportedVersion(const std::string &id,
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000290 hardware::hidl_version *v, IPCTransport *transport);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800291
292 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700293 * Check if a given camera device support setTorchMode API.
294 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700295 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700296
297 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800298 * Check if torch strength update should be skipped or not.
299 */
300 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
301
302 /**
303 * Return the default torch strength level if the torch strength control
304 * feature is supported.
305 */
306 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
307
308 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800309 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700310 * May fail if the device does not support this API, is in active use, or if the device
311 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800312 */
313 status_t setTorchMode(const std::string &id, bool enabled);
314
315 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800316 * Change the brightness level of the flash unit associated with the cameraId and
317 * set it to the value in torchStrength.
318 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
319 * specified strength level. If the torch is ON, only the brightness level will be
320 * changed.
321 *
322 * This operation will fail if the device does not have flash unit, has flash unit
323 * but does not support this API, torchStrength is invalid or if the device doesn't
324 * exist etc.
325 */
326 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
327
328 /**
329 * Return the torch strength level of this camera device.
330 */
331 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
332
333 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800334 * Setup vendor tags for all registered providers
335 */
336 status_t setUpVendorTags();
337
338 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800339 * Inform registered providers about a device state change, such as folding or unfolding
340 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700341 status_t notifyDeviceStateChange(int64_t newState);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800342
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000343 status_t openAidlSession(const std::string &id,
344 const std::shared_ptr<
345 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
346 /*out*/
347 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceSession> *session);
348
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000349 status_t openAidlInjectionSession(const std::string &id,
350 const std::shared_ptr<
351 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
352 /*out*/
353 std::shared_ptr<aidl::android::hardware::camera::device::ICameraInjectionSession> *session);
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000354
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800355 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800356 * Open an active session to a camera device.
357 *
358 * This fully powers on the camera device hardware, and returns a handle to a
359 * session to be used for hardware configuration and operation.
360 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700361 status_t openHidlSession(const std::string &id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800362 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
363 /*out*/
364 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
365
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800366 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700367 * Notify that the camera or torch is no longer being used by a camera client
368 */
369 void removeRef(DeviceMode usageType, const std::string &cameraId);
370
371 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800372 * IServiceNotification::onRegistration
373 * Invoked by the hardware service manager when a new camera provider is registered
374 */
375 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
376 const hardware::hidl_string& name,
377 bool preexisting) override;
378
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000379 // LocalRegistrationCallback::onServiceRegistration
380 virtual void onServiceRegistration(const String16& name, const sp<IBinder> &binder) override;
381
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800382 /**
383 * Dump out information about available providers and devices
384 */
385 status_t dump(int fd, const Vector<String16>& args);
386
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800387 /**
388 * Conversion methods between HAL Status and status_t and strings
389 */
390 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
391 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
392
Emilian Peev71c73a22017-03-21 16:35:51 +0000393 /*
394 * Return provider type for a specific device.
395 */
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000396 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id) const;
Emilian Peev71c73a22017-03-21 16:35:51 +0000397
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700398 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700399 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700400 * the physical camera ids.
401 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700402 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700403
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700404 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
405 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000406
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700407 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700408
Valentin Iftime29e2e152021-08-13 15:17:33 +0200409 status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId);
410
Emilian Peev538c90e2018-12-17 18:03:19 +0000411 static const float kDepthARTolerance;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800412private:
413 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
414 mutable std::mutex mInterfaceMutex;
415
416 wp<StatusListener> mListener;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700417 HidlServiceInteractionProxy* mHidlServiceProxy;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800418
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800419 // Current overall Android device physical status
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700420 int64_t mDeviceState;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800421
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700422 // mProviderLifecycleLock is locked during onRegistration and removeProvider
423 mutable std::mutex mProviderLifecycleLock;
424
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700425 static HidlServiceInteractionProxyImpl sHidlServiceInteractionProxy;
426
427 struct HalCameraProvider {
428 // Empty parent struct for storing either aidl / hidl camera provider reference
429 HalCameraProvider(const char *descriptor) : mDescriptor(descriptor) { };
430 virtual ~HalCameraProvider() {};
431 std::string mDescriptor;
432 };
433
434 struct HidlHalCameraProvider : public HalCameraProvider {
435 HidlHalCameraProvider(
436 const sp<hardware::camera::provider::V2_4::ICameraProvider> &provider,
437 const char *descriptor) :
438 HalCameraProvider(descriptor), mCameraProvider(provider) { };
439 private:
440 sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider;
441 };
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800442
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000443 struct AidlHalCameraProvider : public HalCameraProvider {
444 AidlHalCameraProvider(
445 const std::shared_ptr<
446 aidl::android::hardware::camera::provider::ICameraProvider> &provider,
447 const char *descriptor) :
448 HalCameraProvider(descriptor), mCameraProvider(provider) { };
449 private:
450 std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mCameraProvider;
451 };
452
453
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700454 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
455 // ICameraProvider alive while it is in use by the camera with the given ID for camera
456 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700457 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700458 mCameraProviderByCameraId;
459
460 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
461 // ICameraProvider alive while it is in use by the camera with the given ID for torch
462 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700463 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700464 mTorchProviderByCameraId;
465
466 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
467 std::mutex mProviderInterfaceMapLock;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700468 struct ProviderInfo : public virtual RefBase {
469 friend struct HidlProviderInfo;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000470 friend struct AidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800471 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700472 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000473 const metadata_vendor_id_t mProviderTagid;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000474 int32_t mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800475 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700476 bool mSetTorchModeSupported;
477 bool mIsRemote;
478
Emilian Peevc93cac22020-08-17 16:00:10 -0700479 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800480 CameraProviderManager *manager);
481 ~ProviderInfo();
482
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700483 virtual IPCTransport getIPCTransport() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800484
485 const std::string& getType() const;
486
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800487 status_t dump(int fd, const Vector<String16>& args) const;
488
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000489 void initializeProviderInfoCommon(const std::vector<std::string> &devices);
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800490 /**
491 * Setup vendor tags for this provider
492 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700493 virtual status_t setUpVendorTags() = 0;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800494
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800495 /**
496 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700497 *
498 * Note that 'mInterfaceMutex' should not be held when calling this method.
499 * It is possible for camera providers to add/remove devices and try to
500 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800501 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700502 virtual status_t notifyDeviceStateChange(int64_t newDeviceState) = 0;
503
504 virtual bool successfullyStartedProviderInterface() = 0;
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800505
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000506 virtual int64_t getDeviceState() = 0;
507
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800508 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
509
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800510 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700511 * Notify 'DeviceInfo' instanced about top-level device physical state changes
512 *
513 * Note that 'mInterfaceMutex' should be held when calling this method.
514 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700515 void notifyDeviceInfoStateChangeLocked(int64_t newDeviceState);
Emilian Peevb50402e2021-09-24 17:41:57 -0700516
517 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800518 * Query the camera provider for concurrent stream configuration support
519 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700520 virtual status_t isConcurrentSessionConfigurationSupported(
521 const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
522 const std::set<std::string>& perfClassPrimaryCameraIds,
523 int targetSdkVersion, bool *isSupported) = 0;
524
Valentin Iftime29e2e152021-08-13 15:17:33 +0200525 /**
526 * Remove all devices associated with this provider and notify listeners
527 * with NOT_PRESENT state.
528 */
529 void removeAllDevices();
530
531 /**
532 * Provider is an external lazy HAL
533 */
534 bool isExternalLazyHAL() const;
535
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800536 // Basic device information, common to all camera devices
537 struct DeviceInfo {
538 const std::string mName; // Full instance name
539 const std::string mId; // ID section of full name
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700540 //Both hidl and aidl DeviceInfos. Aidl deviceInfos get {3, 8} to
541 //start off.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800542 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000543 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700544 bool mIsLogicalCamera;
545 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700546 hardware::CameraInfo mInfo;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700547 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800548
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700549 const CameraResourceCost mResourceCost;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800550
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700551 CameraDeviceStatus mStatus;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800552
Shuzhen Wang79680432020-03-05 11:53:46 -0800553 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800554 // Torch strength default, maximum levels if the torch strength control
555 // feature is supported.
556 int32_t mTorchStrengthLevel;
557 int32_t mTorchMaximumStrengthLevel;
558 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700559
Valentin Iftime29e2e152021-08-13 15:17:33 +0200560 // Wait for lazy HALs to confirm device availability
561 static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms
562 Mutex mDeviceAvailableLock;
563 Condition mDeviceAvailableSignal;
564 bool mIsDeviceAvailable = true;
565
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800566 bool hasFlashUnit() const { return mHasFlashUnit; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800567 bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800568 virtual status_t setTorchMode(bool enabled) = 0;
Rucha Katakwar38284522021-11-10 11:25:21 -0800569 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
570 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Austin Borger3560b7e2022-10-27 12:20:29 -0700571 virtual status_t getCameraInfo(bool overrideToPortrait,
572 int *portraitRotation,
573 hardware::CameraInfo *info) const = 0;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100574 virtual bool isAPI1Compatible() const = 0;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700575 virtual status_t dumpState(int fd) = 0;
Jing Mikec7f9b132023-03-12 11:12:04 +0800576 virtual status_t getCameraCharacteristics(
577 [[maybe_unused]] bool overrideForPerfClass,
578 [[maybe_unused]] CameraMetadata *characteristics,
579 [[maybe_unused]] bool overrideToPortrait) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800580 return INVALID_OPERATION;
581 }
Jing Mikec7f9b132023-03-12 11:12:04 +0800582 virtual status_t getPhysicalCameraCharacteristics(
583 [[maybe_unused]] const std::string& physicalCameraId,
584 [[maybe_unused]] CameraMetadata *characteristics) const {
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700585 return INVALID_OPERATION;
586 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800587
Emilian Peev35ae8262018-11-08 13:11:32 +0000588 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700589 const SessionConfiguration &/*configuration*/,
590 bool /*overrideForPerfClass*/,
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700591 camera3::metadataGetter /*getMetadata*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700592 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000593 return INVALID_OPERATION;
594 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700595 virtual status_t filterSmallJpegSizes() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700596 virtual void notifyDeviceStateChange(int64_t /*newState*/) {}
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700597
Emilian Peev71c73a22017-03-21 16:35:51 +0000598 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
599 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700600 const std::vector<std::string>& publicCameraIds,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700601 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700602 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000603 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700604 mIsLogicalCamera(false), mResourceCost(resourceCost),
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700605 mStatus(CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800606 mParentProvider(parentProvider), mTorchStrengthLevel(0),
607 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
608 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
609 mPublicCameraIds(publicCameraIds) {}
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700610 virtual ~DeviceInfo() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800611 protected:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700612
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800613 bool mHasFlashUnit; // const after constructor
614 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700615 const std::vector<std::string>& mPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800616 };
617 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800618 std::unordered_set<std::string> mUniqueCameraIds;
Shuzhen Wang3d316f32022-10-25 20:33:34 +0000619 std::unordered_map<std::string, std::set<std::string>> mUnavailablePhysicalCameras;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700620 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700621 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700622 // The initial public camera IDs published by the camera provider.
623 // Currently logical multi-camera is not supported for hot-plug camera.
624 // And we use this list to keep track of initial public camera IDs
625 // advertised by the provider, and to distinguish against "hidden"
626 // physical camera IDs.
627 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800628
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800629 // HALv3-specific camera fields, including the actual device interface
630 struct DeviceInfo3 : public DeviceInfo {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800631
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700632 virtual status_t setTorchMode(bool enabled) = 0;
633 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
634 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Austin Borger3560b7e2022-10-27 12:20:29 -0700635 virtual status_t getCameraInfo(bool overrideToPortrait,
636 int *portraitRotation,
637 hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100638 virtual bool isAPI1Compatible() const override;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700639 virtual status_t dumpState(int fd) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800640 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700641 bool overrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700642 CameraMetadata *characteristics,
643 bool overrideToPortrait) override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700644 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
645 CameraMetadata *characteristics) const override;
Emilian Peev35ae8262018-11-08 13:11:32 +0000646 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700647 const SessionConfiguration &configuration, bool /*overrideForPerfClass*/,
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700648 camera3::metadataGetter /*getMetadata*/,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700649 bool *status /*out*/) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700650 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700651 virtual void notifyDeviceStateChange(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700652 int64_t newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800653
Emilian Peev71c73a22017-03-21 16:35:51 +0000654 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
655 const std::string &id, uint16_t minorVersion,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700656 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700657 sp<ProviderInfo> parentProvider,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700658 const std::vector<std::string>& publicCameraIds);
659 virtual ~DeviceInfo3() {};
660 protected:
661 // Modified by derived transport specific (hidl / aidl) class
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800662 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700663 // Map device states to sensor orientations
664 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700665 // A copy of mCameraCharacteristics without performance class
666 // override
667 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700668 // Only contains characteristics for hidden physical cameras,
669 // not for public physical cameras.
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700670 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700671 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700672 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700673 status_t fixupMonochromeTags();
Rucha Katakwar31fbf3a2022-05-02 13:23:56 -0700674 status_t fixupTorchStrengthTags();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800675 status_t addDynamicDepthTags(bool maxResolution = false);
676 status_t deriveHeicTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800677 status_t addRotateCropTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700678 status_t addPreCorrectionActiveArraySize();
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000679 status_t addReadoutTimestampTag(bool readoutTimestampSupported = true);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800680
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000681 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
682 android_pixel_format_t format,
683 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700684 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000685 android_pixel_format_t format,
686 const std::vector<std::tuple<size_t, size_t>>& sizes,
687 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700688 static void getSupportedDynamicDepthDurations(
689 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000690 const std::vector<int64_t>& blobDurations,
691 std::vector<int64_t> *dynamicDepthDurations /*out*/);
692 static void getSupportedDynamicDepthSizes(
693 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
694 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
695 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
696 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700697 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
698 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800699 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
700 std::vector<int64_t>* durations,
701 std::vector<int64_t>* stallDurations,
702 const camera_metadata_entry& halStreamConfigs,
703 const camera_metadata_entry& halStreamDurations);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800704 };
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700705 protected:
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800706 std::string mType;
707 uint32_t mId;
708
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700709 std::mutex mLock;
710
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800711 CameraProviderManager *mManager;
712
Shuzhen Wang394ad702020-07-23 13:01:54 -0700713 struct CameraStatusInfoT {
714 bool isPhysicalCameraStatus = false;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700715 std::string cameraId;
716 std::string physicalCameraId;
717 CameraDeviceStatus status;
718 CameraStatusInfoT(bool isForPhysicalCamera, const std::string& id,
719 const std::string& physicalId,
720 CameraDeviceStatus s) :
Shuzhen Wang394ad702020-07-23 13:01:54 -0700721 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
722 physicalCameraId(physicalId), status(s) {}
723 };
724
725 // Lock to synchronize between initialize() and camera status callbacks
726 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800727 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700728 std::vector<CameraStatusInfoT> mCachedStatus;
729 // End of scope for mInitLock
730
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000731 std::unique_ptr<ProviderInfo::DeviceInfo>
732 virtual initializeDeviceInfo(
733 const std::string &name, const metadata_vendor_id_t tagId,
734 const std::string &id, uint16_t minorVersion) = 0;
735
736 virtual status_t reCacheConcurrentStreamingCameraIdsLocked() = 0;
737
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800738 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
739
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800740 // Parse provider instance name for type and id
741 static status_t parseProviderName(const std::string& name,
742 std::string *type, uint32_t *id);
743
744 // Parse device instance name for device version, type, and id.
745 static status_t parseDeviceName(const std::string& name,
746 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000747
748 // Generate vendor tag id
749 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100750
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000751 status_t addDevice(
752 const std::string& name, CameraDeviceStatus initialStatus,
753 /*out*/ std::string* parsedId);
754
755 void cameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
756 CameraDeviceStatus newStatus);
757
758 status_t cameraDeviceStatusChangeLocked(
759 std::string* id, const std::string& cameraDeviceName,
760 CameraDeviceStatus newStatus);
761
762 void physicalCameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
763 const std::string& physicalCameraDeviceName,
764 CameraDeviceStatus newStatus);
765
766 status_t physicalCameraDeviceStatusChangeLocked(
767 std::string* id, std::string* physicalId,
768 const std::string& cameraDeviceName,
769 const std::string& physicalCameraDeviceName,
770 CameraDeviceStatus newStatus);
771
772 void torchModeStatusChangeInternal(const std::string& cameraDeviceName,
773 TorchModeStatus newStatus);
774
Austin Borger0fb3ad92023-06-01 16:51:35 -0700775 void removeDevice(const std::string &id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800776
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800777 };
778
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000779 template <class ProviderInfoType, class HalCameraProviderType>
780 status_t setTorchModeT(sp<ProviderInfo> &parentProvider,
781 std::shared_ptr<HalCameraProvider> *halCameraProvider);
782
783 // Try to get hidl provider services declared. Expects mInterfaceMutex to be
784 // locked. Also registers for hidl provider service notifications.
785 status_t tryToInitAndAddHidlProvidersLocked(HidlServiceInteractionProxy *hidlProxy);
786
787 // Try to get aidl provider services declared. Expects mInterfaceMutex to be
788 // locked. Also registers for aidl provider service notifications.
789 status_t tryToAddAidlProvidersLocked();
790
Emilian Peev7fe6c422021-09-08 13:43:20 -0700791 /**
792 * Save the ICameraProvider while it is being used by a camera or torch client
793 */
794 void saveRef(DeviceMode usageType, const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700795 std::shared_ptr<HalCameraProvider> provider);
Emilian Peev7fe6c422021-09-08 13:43:20 -0700796
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800797 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
798 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800799 // No guarantees on the order of traversal
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000800 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800801
Valentin Iftime29e2e152021-08-13 15:17:33 +0200802 // Map external providers to USB devices in order to handle USB hotplug
803 // events for lazy HALs
804 std::pair<std::vector<std::string>, sp<ProviderInfo>>
805 mExternalUsbDevicesForProvider;
806 sp<ProviderInfo> startExternalLazyProvider() const;
807
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700808 status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false);
Emilian Peevc93cac22020-08-17 16:00:10 -0700809
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000810 status_t addAidlProviderLocked(const std::string& newProvider);
811
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700812 status_t tryToInitializeHidlProviderLocked(const std::string& providerName,
Emilian Peevc93cac22020-08-17 16:00:10 -0700813 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700814
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000815 status_t tryToInitializeAidlProviderLocked(const std::string& providerName,
816 const sp<ProviderInfo>& providerInfo);
817
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800818 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
819
Jayant Chowdharye8c4b232022-02-04 18:18:04 +0000820 // No method corresponding to the same provider / member belonging to the
821 // same provider should be used after this method is called since it'll lead
822 // to invalid memory access (especially since this is called by ProviderInfo methods on hal
823 // service death).
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800824 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700825 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800826
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000827 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion,
828 IPCTransport transport) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800829
Emilian Peevc93cac22020-08-17 16:00:10 -0700830 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800831 std::vector<sp<ProviderInfo>> mProviders;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000832 // Provider names of AIDL providers with retrieved binders.
833 std::set<std::string> mAidlProviderWithBinders;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800834
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800835 static const char* deviceStatusToString(
836 const hardware::camera::common::V1_0::CameraDeviceStatus&);
837 static const char* torchStatusToString(
838 const hardware::camera::common::V1_0::TorchModeStatus&);
839
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700840 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700841 CameraMetadata* characteristics, bool overrideToPortrait) const;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700842 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700843
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700844 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700845 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(
846 const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700847
848 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
849 std::vector<std::string>& normalDeviceIds,
850 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800851
Valentin Iftime29e2e152021-08-13 15:17:33 +0200852 status_t usbDeviceDetached(const std::string &usbDeviceId);
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000853 ndk::ScopedAStatus onAidlRegistration(const std::string& in_name,
854 const ::ndk::SpAIBinder& in_binder);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800855};
856
857} // namespace android
858
859#endif