blob: 53a2102e97e7fa06f31d168c7bc74af9e4105d1d [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 Wang045be6c2023-10-12 10:01:10 -070090#define CAMERA_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION(1, 3)
Shuzhen Wang83bff122020-11-20 15:51:39 -080091#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
92#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
93#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
94#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
95#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
96#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
97#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
98#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
99
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800100/**
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000101 * The vendor tag descriptor class that takes HIDL/AIDL vendor tag information as
102 * input. Not part of VendorTagDescriptor class because that class is used
103 * in AIDL generated sources which don't have access to AIDL / HIDL headers.
104 */
105class IdlVendorTagDescriptor : public VendorTagDescriptor {
106public:
107 /**
108 * Create a VendorTagDescriptor object from the HIDL/AIDL VendorTagSection
109 * vector.
110 *
111 * Returns OK on success, or a negative error code.
112 */
113 template <class VendorTagSectionVectorType, class VendorTagSectionType>
114 static status_t createDescriptorFromIdl(
115 const VendorTagSectionVectorType& vts,
116 /*out*/
117 sp<VendorTagDescriptor>& descriptor);
118};
119
120/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800121 * A manager for all camera providers available on an Android device.
122 *
123 * Responsible for enumerating providers and the individual camera devices
124 * they export, both at startup and as providers and devices are added/removed.
125 *
126 * Provides methods for requesting information about individual devices and for
127 * opening them for active use.
128 *
129 */
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000130class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification,
131 public virtual IServiceManager::LocalRegistrationCallback {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800132public:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700133 // needs to be made friend strict since HidlProviderInfo needs to inherit
134 // from CameraProviderManager::ProviderInfo which isn't a public member.
135 friend struct HidlProviderInfo;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000136 friend struct AidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800137 ~CameraProviderManager();
138
139 // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
140 // service manager, to be replacable in unit tests with a fake.
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700141 struct HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800142 virtual bool registerForNotifications(
143 const std::string &serviceName,
144 const sp<hidl::manager::V1_0::IServiceNotification>
145 &notification) = 0;
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700146 // Will not wait for service to start if it's not already running
147 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
148 const std::string &serviceName) = 0;
149 // Will block for service if it exists but isn't running
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800150 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
151 const std::string &serviceName) = 0;
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700152 virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700153 virtual ~HidlServiceInteractionProxy() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800154 };
155
156 // Standard use case - call into the normal generated static methods which invoke
157 // the real hardware service manager
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700158 struct HidlServiceInteractionProxyImpl : public HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800159 virtual bool registerForNotifications(
160 const std::string &serviceName,
161 const sp<hidl::manager::V1_0::IServiceNotification>
162 &notification) override {
163 return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications(
164 serviceName, notification);
165 }
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700166 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
167 const std::string &serviceName) override {
168 return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName);
169 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800170 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
171 const std::string &serviceName) override {
172 return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName);
173 }
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700174
175 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800176 };
177
Vadim Caen7eccd7c2023-10-03 16:26:33 +0200178 // Proxy to inject fake services in test.
179 class AidlServiceInteractionProxy {
180 public:
181 // Returns the Aidl service with the given serviceName
182 virtual std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider>
183 getAidlService(const std::string& serviceName) = 0;
184
185 virtual ~AidlServiceInteractionProxy() = default;
186 };
187
188 // Standard use case - call into the normal static methods which invoke
189 // the real service manager
190 class AidlServiceInteractionProxyImpl : public AidlServiceInteractionProxy {
191 public:
192 virtual std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider>
193 getAidlService(const std::string& serviceName) override;
194 };
195
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800196 /**
197 * Listener interface for device/torch status changes
198 */
199 struct StatusListener : virtual public RefBase {
200 ~StatusListener() {}
201
Austin Borger0fb3ad92023-06-01 16:51:35 -0700202 virtual void onDeviceStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700203 CameraDeviceStatus newStatus) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700204 virtual void onDeviceStatusChanged(const std::string &cameraId,
205 const std::string &physicalCameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700206 CameraDeviceStatus newStatus) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700207 virtual void onTorchStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700208 TorchModeStatus newStatus,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700209 SystemCameraKind kind) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700210 virtual void onTorchStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700211 TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100212 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800213 };
214
215 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700216 * Represents the mode a camera device is currently in
217 */
218 enum class DeviceMode {
219 TORCH,
220 CAMERA
221 };
222
223 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800224 * Initialize the manager and give it a status listener; optionally accepts a service
225 * interaction proxy.
226 *
227 * The default proxy communicates via the hardware service manager; alternate proxies can be
228 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
229 */
230 status_t initialize(wp<StatusListener> listener,
Vadim Caen7eccd7c2023-10-03 16:26:33 +0200231 HidlServiceInteractionProxy* hidlProxy = &sHidlServiceInteractionProxy,
232 AidlServiceInteractionProxy* aidlProxy = &sAidlServiceInteractionProxy);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800233
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800234 status_t getCameraIdIPCTransport(const std::string &id,
235 IPCTransport *providerTransport) const;
236
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800237 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700238 * Retrieve the total number of available cameras.
239 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800240 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700241 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800242
Shuzhen Wang3d316f32022-10-25 20:33:34 +0000243 /**
244 * Upon the function return, if unavailablePhysicalIds is not nullptr, it
245 * will contain all of the unavailable physical camera Ids represented in
246 * the form of:
247 * {[logicalCamera, {physicalCamera1, physicalCamera2, ...}], ...}.
248 */
249 std::vector<std::string> getCameraDeviceIds(std::unordered_map<
250 std::string, std::set<std::string>>* unavailablePhysicalIds = nullptr) const;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800251
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800252 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100253 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800254 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800255 * accessible via the old camera API.
256 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800257 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100258 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700259
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800260 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800261 * Return true if a device with a given ID has a flash unit. Returns false
262 * for devices that are unknown.
263 */
264 bool hasFlashUnit(const std::string &id) const;
265
266 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800267 * Return true if the camera device has native zoom ratio support.
268 */
269 bool supportNativeZoomRatio(const std::string &id) const;
270
271 /**
Emilian Peev15230142023-04-27 20:22:54 +0000272 * Return true if the camera device has no composite Jpeg/R support.
Emilian Peeve579d8b2023-02-28 14:16:08 -0800273 */
Emilian Peev15230142023-04-27 20:22:54 +0000274 bool isCompositeJpegRDisabled(const std::string &id) const;
Emilian Peeve579d8b2023-02-28 14:16:08 -0800275
276 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800277 * Return the resource cost of this camera device
278 */
279 status_t getResourceCost(const std::string &id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700280 CameraResourceCost* cost) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800281
282 /**
283 * Return the old camera API camera info
284 */
285 status_t getCameraInfo(const std::string &id,
Austin Borger3560b7e2022-10-27 12:20:29 -0700286 bool overrideToPortrait, int *portraitRotation, hardware::CameraInfo* info) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800287
288 /**
289 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
290 * not have a v3 or newer HAL version.
291 */
292 status_t getCameraCharacteristics(const std::string &id,
Austin Borger3560b7e2022-10-27 12:20:29 -0700293 bool overrideForPerfClass, CameraMetadata* characteristics,
294 bool overrideToPortrait) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800295
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800296 status_t isConcurrentSessionConfigurationSupported(
297 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
298 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700299 const std::set<std::string>& perfClassPrimaryCameraIds,
300 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800301
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700302 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700303
304 /**
305 * Create a default capture request metadata for a camera and a specific
306 * template.
307 */
308 status_t createDefaultRequest(const std::string& id,
309 camera3::camera_request_template_t templateId,
310 hardware::camera2::impl::CameraMetadataNative* request) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800311 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000312 * Check for device support of specific stream combination.
313 */
314 status_t isSessionConfigurationSupported(const std::string& id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700315 const SessionConfiguration &configuration,
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700316 bool overrideForPerfClass, bool checkSessionParams,
Emilian Peev35ae8262018-11-08 13:11:32 +0000317 bool *status /*out*/) const;
318
319 /**
Bharatt Kukreja6dddeb72023-11-21 10:06:25 +0000320 * Get session characteristics for a particular session.
321 */
322 status_t getSessionCharacteristics(const std::string& id,
323 const SessionConfiguration &configuration,
324 bool overrideForPerfClass, camera3::metadataGetter getMetadata,
325 CameraMetadata* sessionCharacteristics /*out*/) const;
326
327 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800328 * Return the highest supported device interface version for this ID
329 */
330 status_t getHighestSupportedVersion(const std::string &id,
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000331 hardware::hidl_version *v, IPCTransport *transport);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800332
333 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700334 * Check if a given camera device support setTorchMode API.
335 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700336 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700337
338 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800339 * Check if torch strength update should be skipped or not.
340 */
341 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
342
343 /**
344 * Return the default torch strength level if the torch strength control
345 * feature is supported.
346 */
347 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
348
349 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800350 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700351 * May fail if the device does not support this API, is in active use, or if the device
352 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800353 */
354 status_t setTorchMode(const std::string &id, bool enabled);
355
356 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800357 * Change the brightness level of the flash unit associated with the cameraId and
358 * set it to the value in torchStrength.
359 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
360 * specified strength level. If the torch is ON, only the brightness level will be
361 * changed.
362 *
363 * This operation will fail if the device does not have flash unit, has flash unit
364 * but does not support this API, torchStrength is invalid or if the device doesn't
365 * exist etc.
366 */
367 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
368
369 /**
370 * Return the torch strength level of this camera device.
371 */
372 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
373
374 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800375 * Setup vendor tags for all registered providers
376 */
377 status_t setUpVendorTags();
378
379 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800380 * Inform registered providers about a device state change, such as folding or unfolding
381 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700382 status_t notifyDeviceStateChange(int64_t newState);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800383
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000384 status_t openAidlSession(const std::string &id,
385 const std::shared_ptr<
386 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
387 /*out*/
388 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceSession> *session);
389
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000390 status_t openAidlInjectionSession(const std::string &id,
391 const std::shared_ptr<
392 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
393 /*out*/
394 std::shared_ptr<aidl::android::hardware::camera::device::ICameraInjectionSession> *session);
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000395
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800396 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800397 * Open an active session to a camera device.
398 *
399 * This fully powers on the camera device hardware, and returns a handle to a
400 * session to be used for hardware configuration and operation.
401 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700402 status_t openHidlSession(const std::string &id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800403 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
404 /*out*/
405 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
406
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800407 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700408 * Notify that the camera or torch is no longer being used by a camera client
409 */
410 void removeRef(DeviceMode usageType, const std::string &cameraId);
411
412 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800413 * IServiceNotification::onRegistration
414 * Invoked by the hardware service manager when a new camera provider is registered
415 */
416 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
417 const hardware::hidl_string& name,
418 bool preexisting) override;
419
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000420 // LocalRegistrationCallback::onServiceRegistration
421 virtual void onServiceRegistration(const String16& name, const sp<IBinder> &binder) override;
422
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800423 /**
424 * Dump out information about available providers and devices
425 */
426 status_t dump(int fd, const Vector<String16>& args);
427
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800428 /**
429 * Conversion methods between HAL Status and status_t and strings
430 */
431 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
432 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
433
Emilian Peev71c73a22017-03-21 16:35:51 +0000434 /*
435 * Return provider type for a specific device.
436 */
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000437 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id) const;
Emilian Peev71c73a22017-03-21 16:35:51 +0000438
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700439 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700440 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700441 * the physical camera ids.
442 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700443 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700444
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700445 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
446 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000447
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700448 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700449
Valentin Iftime29e2e152021-08-13 15:17:33 +0200450 status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId);
451
Emilian Peev434248e2022-10-06 14:58:54 -0700452 static bool isConcurrentDynamicRangeCaptureSupported(const CameraMetadata& deviceInfo,
453 int64_t profile, int64_t concurrentProfile);
454
Emilian Peev538c90e2018-12-17 18:03:19 +0000455 static const float kDepthARTolerance;
Emilian Peev434248e2022-10-06 14:58:54 -0700456 static const bool kFrameworkJpegRDisabled;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800457private:
458 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
459 mutable std::mutex mInterfaceMutex;
460
461 wp<StatusListener> mListener;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700462 HidlServiceInteractionProxy* mHidlServiceProxy;
Vadim Caen7eccd7c2023-10-03 16:26:33 +0200463 AidlServiceInteractionProxy* mAidlServiceProxy;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800464
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800465 // Current overall Android device physical status
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700466 int64_t mDeviceState;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800467
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700468 // mProviderLifecycleLock is locked during onRegistration and removeProvider
469 mutable std::mutex mProviderLifecycleLock;
470
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700471 static HidlServiceInteractionProxyImpl sHidlServiceInteractionProxy;
Vadim Caen7eccd7c2023-10-03 16:26:33 +0200472 static AidlServiceInteractionProxyImpl sAidlServiceInteractionProxy;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700473
474 struct HalCameraProvider {
475 // Empty parent struct for storing either aidl / hidl camera provider reference
476 HalCameraProvider(const char *descriptor) : mDescriptor(descriptor) { };
477 virtual ~HalCameraProvider() {};
478 std::string mDescriptor;
479 };
480
481 struct HidlHalCameraProvider : public HalCameraProvider {
482 HidlHalCameraProvider(
483 const sp<hardware::camera::provider::V2_4::ICameraProvider> &provider,
484 const char *descriptor) :
485 HalCameraProvider(descriptor), mCameraProvider(provider) { };
486 private:
487 sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider;
488 };
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800489
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000490 struct AidlHalCameraProvider : public HalCameraProvider {
491 AidlHalCameraProvider(
492 const std::shared_ptr<
493 aidl::android::hardware::camera::provider::ICameraProvider> &provider,
494 const char *descriptor) :
495 HalCameraProvider(descriptor), mCameraProvider(provider) { };
496 private:
497 std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mCameraProvider;
498 };
499
500
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700501 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
502 // ICameraProvider alive while it is in use by the camera with the given ID for camera
503 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700504 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700505 mCameraProviderByCameraId;
506
507 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
508 // ICameraProvider alive while it is in use by the camera with the given ID for torch
509 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700510 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700511 mTorchProviderByCameraId;
512
513 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
514 std::mutex mProviderInterfaceMapLock;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700515 struct ProviderInfo : public virtual RefBase {
516 friend struct HidlProviderInfo;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000517 friend struct AidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800518 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700519 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000520 const metadata_vendor_id_t mProviderTagid;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000521 int32_t mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800522 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700523 bool mSetTorchModeSupported;
524 bool mIsRemote;
525
Emilian Peevc93cac22020-08-17 16:00:10 -0700526 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800527 CameraProviderManager *manager);
528 ~ProviderInfo();
529
Jayant Chowdharyd65d9442023-07-11 01:18:06 +0000530 virtual IPCTransport getIPCTransport() const = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800531
532 const std::string& getType() const;
533
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800534 status_t dump(int fd, const Vector<String16>& args) const;
535
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000536 void initializeProviderInfoCommon(const std::vector<std::string> &devices);
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800537 /**
538 * Setup vendor tags for this provider
539 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700540 virtual status_t setUpVendorTags() = 0;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800541
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800542 /**
543 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700544 *
545 * Note that 'mInterfaceMutex' should not be held when calling this method.
546 * It is possible for camera providers to add/remove devices and try to
547 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800548 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700549 virtual status_t notifyDeviceStateChange(int64_t newDeviceState) = 0;
550
551 virtual bool successfullyStartedProviderInterface() = 0;
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800552
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000553 virtual int64_t getDeviceState() = 0;
554
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800555 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
556
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800557 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700558 * Notify 'DeviceInfo' instanced about top-level device physical state changes
559 *
560 * Note that 'mInterfaceMutex' should be held when calling this method.
561 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700562 void notifyDeviceInfoStateChangeLocked(int64_t newDeviceState);
Emilian Peevb50402e2021-09-24 17:41:57 -0700563
564 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800565 * Query the camera provider for concurrent stream configuration support
566 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700567 virtual status_t isConcurrentSessionConfigurationSupported(
568 const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
569 const std::set<std::string>& perfClassPrimaryCameraIds,
570 int targetSdkVersion, bool *isSupported) = 0;
571
Valentin Iftime29e2e152021-08-13 15:17:33 +0200572 /**
573 * Remove all devices associated with this provider and notify listeners
574 * with NOT_PRESENT state.
575 */
576 void removeAllDevices();
577
578 /**
579 * Provider is an external lazy HAL
580 */
581 bool isExternalLazyHAL() const;
582
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800583 // Basic device information, common to all camera devices
584 struct DeviceInfo {
585 const std::string mName; // Full instance name
586 const std::string mId; // ID section of full name
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700587 //Both hidl and aidl DeviceInfos. Aidl deviceInfos get {3, 8} to
588 //start off.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800589 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000590 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700591 bool mIsLogicalCamera;
592 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700593 hardware::CameraInfo mInfo;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700594 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800595
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700596 const CameraResourceCost mResourceCost;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800597
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700598 CameraDeviceStatus mStatus;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800599
Shuzhen Wang79680432020-03-05 11:53:46 -0800600 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800601 // Torch strength default, maximum levels if the torch strength control
602 // feature is supported.
603 int32_t mTorchStrengthLevel;
604 int32_t mTorchMaximumStrengthLevel;
605 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700606
Valentin Iftime29e2e152021-08-13 15:17:33 +0200607 // Wait for lazy HALs to confirm device availability
608 static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms
609 Mutex mDeviceAvailableLock;
610 Condition mDeviceAvailableSignal;
611 bool mIsDeviceAvailable = true;
612
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800613 bool hasFlashUnit() const { return mHasFlashUnit; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800614 bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; }
Emilian Peev15230142023-04-27 20:22:54 +0000615 bool isCompositeJpegRDisabled() const { return mCompositeJpegRDisabled; }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800616 virtual status_t setTorchMode(bool enabled) = 0;
Rucha Katakwar38284522021-11-10 11:25:21 -0800617 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
618 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Austin Borger3560b7e2022-10-27 12:20:29 -0700619 virtual status_t getCameraInfo(bool overrideToPortrait,
620 int *portraitRotation,
621 hardware::CameraInfo *info) const = 0;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100622 virtual bool isAPI1Compatible() const = 0;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700623 virtual status_t dumpState(int fd) = 0;
Jing Mikec7f9b132023-03-12 11:12:04 +0800624 virtual status_t getCameraCharacteristics(
625 [[maybe_unused]] bool overrideForPerfClass,
626 [[maybe_unused]] CameraMetadata *characteristics,
627 [[maybe_unused]] bool overrideToPortrait) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800628 return INVALID_OPERATION;
629 }
Jing Mikec7f9b132023-03-12 11:12:04 +0800630 virtual status_t getPhysicalCameraCharacteristics(
631 [[maybe_unused]] const std::string& physicalCameraId,
632 [[maybe_unused]] CameraMetadata *characteristics) const {
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700633 return INVALID_OPERATION;
634 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800635
Emilian Peev35ae8262018-11-08 13:11:32 +0000636 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700637 const SessionConfiguration &/*configuration*/,
638 bool /*overrideForPerfClass*/,
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700639 bool /*checkSessionParams*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700640 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000641 return INVALID_OPERATION;
642 }
Bharatt Kukreja6dddeb72023-11-21 10:06:25 +0000643
644 virtual status_t getSessionCharacteristics(
645 const SessionConfiguration &/*configuration*/,
646 bool /*overrideForPerfClass*/,
647 camera3::metadataGetter /*getMetadata*/,
648 CameraMetadata* /*sessionCharacteristics*/) {
649 return INVALID_OPERATION;
650 }
651
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700652 virtual status_t filterSmallJpegSizes() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700653 virtual void notifyDeviceStateChange(int64_t /*newState*/) {}
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700654 virtual status_t createDefaultRequest(
655 camera3::camera_request_template_t /*templateId*/,
656 camera_metadata_t** /*metadata*/) {
657 return INVALID_OPERATION;
658 }
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700659
Emilian Peev71c73a22017-03-21 16:35:51 +0000660 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
661 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700662 const std::vector<std::string>& publicCameraIds,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700663 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700664 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000665 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700666 mIsLogicalCamera(false), mResourceCost(resourceCost),
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700667 mStatus(CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800668 mParentProvider(parentProvider), mTorchStrengthLevel(0),
669 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
670 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
Emilian Peev15230142023-04-27 20:22:54 +0000671 mPublicCameraIds(publicCameraIds), mCompositeJpegRDisabled(false) {}
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700672 virtual ~DeviceInfo() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800673 protected:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700674
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800675 bool mHasFlashUnit; // const after constructor
676 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700677 const std::vector<std::string>& mPublicCameraIds;
Emilian Peev15230142023-04-27 20:22:54 +0000678 bool mCompositeJpegRDisabled;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800679 };
680 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800681 std::unordered_set<std::string> mUniqueCameraIds;
Shuzhen Wang3d316f32022-10-25 20:33:34 +0000682 std::unordered_map<std::string, std::set<std::string>> mUnavailablePhysicalCameras;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700683 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700684 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700685 // The initial public camera IDs published by the camera provider.
686 // Currently logical multi-camera is not supported for hot-plug camera.
687 // And we use this list to keep track of initial public camera IDs
688 // advertised by the provider, and to distinguish against "hidden"
689 // physical camera IDs.
690 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800691
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800692 // HALv3-specific camera fields, including the actual device interface
693 struct DeviceInfo3 : public DeviceInfo {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800694
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700695 virtual status_t setTorchMode(bool enabled) = 0;
696 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
697 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Austin Borger3560b7e2022-10-27 12:20:29 -0700698 virtual status_t getCameraInfo(bool overrideToPortrait,
699 int *portraitRotation,
700 hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100701 virtual bool isAPI1Compatible() const override;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700702 virtual status_t dumpState(int fd) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800703 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700704 bool overrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700705 CameraMetadata *characteristics,
706 bool overrideToPortrait) override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700707 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
708 CameraMetadata *characteristics) const override;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700709 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700710 virtual void notifyDeviceStateChange(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700711 int64_t newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800712
Emilian Peev71c73a22017-03-21 16:35:51 +0000713 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
714 const std::string &id, uint16_t minorVersion,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700715 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700716 sp<ProviderInfo> parentProvider,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700717 const std::vector<std::string>& publicCameraIds);
718 virtual ~DeviceInfo3() {};
719 protected:
720 // Modified by derived transport specific (hidl / aidl) class
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800721 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700722 // Map device states to sensor orientations
723 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700724 // A copy of mCameraCharacteristics without performance class
725 // override
726 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700727 // Only contains characteristics for hidden physical cameras,
728 // not for public physical cameras.
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700729 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700730 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700731 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700732 status_t fixupMonochromeTags();
Rucha Katakwar31fbf3a2022-05-02 13:23:56 -0700733 status_t fixupTorchStrengthTags();
Rucha Katakware4d3e1f2023-11-06 13:46:45 -0800734 status_t fixupManualFlashStrengthControlTags(CameraMetadata& ch);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800735 status_t addDynamicDepthTags(bool maxResolution = false);
736 status_t deriveHeicTags(bool maxResolution = false);
Emilian Peev434248e2022-10-06 14:58:54 -0700737 status_t deriveJpegRTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800738 status_t addRotateCropTags();
Bharatt Kukrejad33fe9f2022-11-23 21:52:52 +0000739 status_t addAutoframingTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700740 status_t addPreCorrectionActiveArraySize();
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000741 status_t addReadoutTimestampTag(bool readoutTimestampSupported = true);
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700742 status_t addSessionConfigQueryVersionTag();
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800743
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000744 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
745 android_pixel_format_t format,
746 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700747 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000748 android_pixel_format_t format,
749 const std::vector<std::tuple<size_t, size_t>>& sizes,
750 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700751 static void getSupportedDynamicDepthDurations(
752 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000753 const std::vector<int64_t>& blobDurations,
754 std::vector<int64_t> *dynamicDepthDurations /*out*/);
755 static void getSupportedDynamicDepthSizes(
756 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
757 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
758 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
759 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700760 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
761 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800762 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
763 std::vector<int64_t>* durations,
764 std::vector<int64_t>* stallDurations,
765 const camera_metadata_entry& halStreamConfigs,
766 const camera_metadata_entry& halStreamDurations);
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700767
768 CameraMetadata deviceInfo(const std::string &id);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800769 };
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700770 protected:
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800771 std::string mType;
772 uint32_t mId;
773
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700774 std::mutex mLock;
775
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800776 CameraProviderManager *mManager;
777
Shuzhen Wang394ad702020-07-23 13:01:54 -0700778 struct CameraStatusInfoT {
779 bool isPhysicalCameraStatus = false;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700780 std::string cameraId;
781 std::string physicalCameraId;
782 CameraDeviceStatus status;
783 CameraStatusInfoT(bool isForPhysicalCamera, const std::string& id,
784 const std::string& physicalId,
785 CameraDeviceStatus s) :
Shuzhen Wang394ad702020-07-23 13:01:54 -0700786 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
787 physicalCameraId(physicalId), status(s) {}
788 };
789
790 // Lock to synchronize between initialize() and camera status callbacks
791 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800792 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700793 std::vector<CameraStatusInfoT> mCachedStatus;
794 // End of scope for mInitLock
795
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000796 std::unique_ptr<ProviderInfo::DeviceInfo>
797 virtual initializeDeviceInfo(
798 const std::string &name, const metadata_vendor_id_t tagId,
799 const std::string &id, uint16_t minorVersion) = 0;
800
801 virtual status_t reCacheConcurrentStreamingCameraIdsLocked() = 0;
802
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800803 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
804
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800805 // Parse provider instance name for type and id
806 static status_t parseProviderName(const std::string& name,
807 std::string *type, uint32_t *id);
808
809 // Parse device instance name for device version, type, and id.
810 static status_t parseDeviceName(const std::string& name,
811 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000812
813 // Generate vendor tag id
814 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100815
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000816 status_t addDevice(
817 const std::string& name, CameraDeviceStatus initialStatus,
818 /*out*/ std::string* parsedId);
819
820 void cameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
821 CameraDeviceStatus newStatus);
822
823 status_t cameraDeviceStatusChangeLocked(
824 std::string* id, const std::string& cameraDeviceName,
825 CameraDeviceStatus newStatus);
826
827 void physicalCameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
828 const std::string& physicalCameraDeviceName,
829 CameraDeviceStatus newStatus);
830
831 status_t physicalCameraDeviceStatusChangeLocked(
832 std::string* id, std::string* physicalId,
833 const std::string& cameraDeviceName,
834 const std::string& physicalCameraDeviceName,
835 CameraDeviceStatus newStatus);
836
837 void torchModeStatusChangeInternal(const std::string& cameraDeviceName,
838 TorchModeStatus newStatus);
839
Austin Borger0fb3ad92023-06-01 16:51:35 -0700840 void removeDevice(const std::string &id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800841
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800842 };
843
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000844 template <class ProviderInfoType, class HalCameraProviderType>
845 status_t setTorchModeT(sp<ProviderInfo> &parentProvider,
846 std::shared_ptr<HalCameraProvider> *halCameraProvider);
847
848 // Try to get hidl provider services declared. Expects mInterfaceMutex to be
849 // locked. Also registers for hidl provider service notifications.
850 status_t tryToInitAndAddHidlProvidersLocked(HidlServiceInteractionProxy *hidlProxy);
851
852 // Try to get aidl provider services declared. Expects mInterfaceMutex to be
853 // locked. Also registers for aidl provider service notifications.
854 status_t tryToAddAidlProvidersLocked();
855
Emilian Peev7fe6c422021-09-08 13:43:20 -0700856 /**
857 * Save the ICameraProvider while it is being used by a camera or torch client
858 */
859 void saveRef(DeviceMode usageType, const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700860 std::shared_ptr<HalCameraProvider> provider);
Emilian Peev7fe6c422021-09-08 13:43:20 -0700861
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800862 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
863 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800864 // No guarantees on the order of traversal
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000865 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800866
Emilian Peev15230142023-04-27 20:22:54 +0000867 bool isCompositeJpegRDisabledLocked(const std::string &id) const;
Emilian Peeve579d8b2023-02-28 14:16:08 -0800868
Valentin Iftime29e2e152021-08-13 15:17:33 +0200869 // Map external providers to USB devices in order to handle USB hotplug
870 // events for lazy HALs
871 std::pair<std::vector<std::string>, sp<ProviderInfo>>
872 mExternalUsbDevicesForProvider;
873 sp<ProviderInfo> startExternalLazyProvider() const;
874
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700875 status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false);
Emilian Peevc93cac22020-08-17 16:00:10 -0700876
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000877 status_t addAidlProviderLocked(const std::string& newProvider);
878
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700879 status_t tryToInitializeHidlProviderLocked(const std::string& providerName,
Emilian Peevc93cac22020-08-17 16:00:10 -0700880 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700881
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000882 status_t tryToInitializeAidlProviderLocked(const std::string& providerName,
883 const sp<ProviderInfo>& providerInfo);
884
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800885 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
886
Jayant Chowdharye8c4b232022-02-04 18:18:04 +0000887 // No method corresponding to the same provider / member belonging to the
888 // same provider should be used after this method is called since it'll lead
889 // to invalid memory access (especially since this is called by ProviderInfo methods on hal
890 // service death).
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800891 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700892 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800893
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000894 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion,
895 IPCTransport transport) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800896
Emilian Peevc93cac22020-08-17 16:00:10 -0700897 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800898 std::vector<sp<ProviderInfo>> mProviders;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000899 // Provider names of AIDL providers with retrieved binders.
900 std::set<std::string> mAidlProviderWithBinders;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800901
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800902 static const char* deviceStatusToString(
903 const hardware::camera::common::V1_0::CameraDeviceStatus&);
904 static const char* torchStatusToString(
905 const hardware::camera::common::V1_0::TorchModeStatus&);
906
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700907 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700908 CameraMetadata* characteristics, bool overrideToPortrait) const;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700909 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700910
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700911 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700912 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(
913 const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700914
915 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
916 std::vector<std::string>& normalDeviceIds,
917 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800918
Valentin Iftime29e2e152021-08-13 15:17:33 +0200919 status_t usbDeviceDetached(const std::string &usbDeviceId);
Vadim Caen7eccd7c2023-10-03 16:26:33 +0200920
921 static bool isVirtualCameraHalEnabled();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800922};
923
924} // namespace android
925
926#endif