blob: 4568209743c2dc163b84c50829f7c804b8754e34 [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>
Shuzhen Wang394ad702020-07-23 13:01:54 -070026#include <future>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080027
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080028#include <camera/camera2/ConcurrentCamera.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080029#include <camera/CameraParameters2.h>
30#include <camera/CameraMetadata.h>
31#include <camera/CameraBase.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020032#include <utils/Condition.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080033#include <utils/Errors.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020034#include <android/hardware/ICameraService.h>
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070035#include <utils/IPCTransport.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080036#include <android/hardware/camera/common/1.0/types.h>
Eino-Ville Talvala63f36112018-12-06 14:57:03 -080037#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
Shuzhen Wang43858162020-01-10 13:42:15 -080038#include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080039#include <android/hardware/camera/provider/2.6/ICameraProvider.h>
Shuzhen Wang83bff122020-11-20 15:51:39 -080040#include <android/hardware/camera/provider/2.7/ICameraProvider.h>
41#include <android/hardware/camera/device/3.7/types.h>
Emilian Peev2295df72021-11-12 18:14:10 -080042#include <android/hardware/camera/device/3.8/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)
89#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
90#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
91#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
92#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
93#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
94#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
95#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
96#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
Shuzhen Wang90708ea2021-11-04 11:40:49 -070097#define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8)
Shuzhen Wang83bff122020-11-20 15:51:39 -080098
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080099/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800100 * A manager for all camera providers available on an Android device.
101 *
102 * Responsible for enumerating providers and the individual camera devices
103 * they export, both at startup and as providers and devices are added/removed.
104 *
105 * Provides methods for requesting information about individual devices and for
106 * opening them for active use.
107 *
108 */
109class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification {
110public:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700111 // needs to be made friend strict since HidlProviderInfo needs to inherit
112 // from CameraProviderManager::ProviderInfo which isn't a public member.
113 friend struct HidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800114 ~CameraProviderManager();
115
116 // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
117 // service manager, to be replacable in unit tests with a fake.
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700118 struct HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800119 virtual bool registerForNotifications(
120 const std::string &serviceName,
121 const sp<hidl::manager::V1_0::IServiceNotification>
122 &notification) = 0;
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700123 // Will not wait for service to start if it's not already running
124 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
125 const std::string &serviceName) = 0;
126 // Will block for service if it exists but isn't running
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800127 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
128 const std::string &serviceName) = 0;
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700129 virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700130 virtual ~HidlServiceInteractionProxy() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800131 };
132
133 // Standard use case - call into the normal generated static methods which invoke
134 // the real hardware service manager
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700135 struct HidlServiceInteractionProxyImpl : public HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800136 virtual bool registerForNotifications(
137 const std::string &serviceName,
138 const sp<hidl::manager::V1_0::IServiceNotification>
139 &notification) override {
140 return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications(
141 serviceName, notification);
142 }
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700143 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
144 const std::string &serviceName) override {
145 return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName);
146 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800147 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
148 const std::string &serviceName) override {
149 return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName);
150 }
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700151
152 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800153 };
154
155 /**
156 * Listener interface for device/torch status changes
157 */
158 struct StatusListener : virtual public RefBase {
159 ~StatusListener() {}
160
161 virtual void onDeviceStatusChanged(const String8 &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700162 CameraDeviceStatus newStatus) = 0;
Shuzhen Wang43858162020-01-10 13:42:15 -0800163 virtual void onDeviceStatusChanged(const String8 &cameraId,
164 const String8 &physicalCameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700165 CameraDeviceStatus newStatus) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800166 virtual void onTorchStatusChanged(const String8 &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700167 TorchModeStatus newStatus,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700168 SystemCameraKind kind) = 0;
169 virtual void onTorchStatusChanged(const String8 &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700170 TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100171 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800172 };
173
174 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700175 * Represents the mode a camera device is currently in
176 */
177 enum class DeviceMode {
178 TORCH,
179 CAMERA
180 };
181
182 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800183 * Initialize the manager and give it a status listener; optionally accepts a service
184 * interaction proxy.
185 *
186 * The default proxy communicates via the hardware service manager; alternate proxies can be
187 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
188 */
189 status_t initialize(wp<StatusListener> listener,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700190 HidlServiceInteractionProxy *hidlProxy = &sHidlServiceInteractionProxy);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800191
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800192 status_t getCameraIdIPCTransport(const std::string &id,
193 IPCTransport *providerTransport) const;
194
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800195 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700196 * Retrieve the total number of available cameras.
197 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800198 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700199 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800200
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800201 std::vector<std::string> getCameraDeviceIds() const;
202
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800203 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100204 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800205 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800206 * accessible via the old camera API.
207 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800208 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100209 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700210
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800211 /**
212 * Return true if a device with a given ID and major version exists
213 */
214 bool isValidDevice(const std::string &id, uint16_t majorVersion) const;
215
216 /**
217 * Return true if a device with a given ID has a flash unit. Returns false
218 * for devices that are unknown.
219 */
220 bool hasFlashUnit(const std::string &id) const;
221
222 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800223 * Return true if the camera device has native zoom ratio support.
224 */
225 bool supportNativeZoomRatio(const std::string &id) const;
226
227 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800228 * Return the resource cost of this camera device
229 */
230 status_t getResourceCost(const std::string &id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700231 CameraResourceCost* cost) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800232
233 /**
234 * Return the old camera API camera info
235 */
236 status_t getCameraInfo(const std::string &id,
237 hardware::CameraInfo* info) const;
238
239 /**
240 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
241 * not have a v3 or newer HAL version.
242 */
243 status_t getCameraCharacteristics(const std::string &id,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700244 bool overrideForPerfClass, CameraMetadata* characteristics) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800245
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800246 status_t isConcurrentSessionConfigurationSupported(
247 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
248 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700249 const std::set<std::string>& perfClassPrimaryCameraIds,
250 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800251
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700252 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800253 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000254 * Check for device support of specific stream combination.
255 */
256 status_t isSessionConfigurationSupported(const std::string& id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700257 const SessionConfiguration &configuration,
258 bool overrideForPerfClass,
Emilian Peev35ae8262018-11-08 13:11:32 +0000259 bool *status /*out*/) const;
260
261 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800262 * Return the highest supported device interface version for this ID
263 */
264 status_t getHighestSupportedVersion(const std::string &id,
265 hardware::hidl_version *v);
266
267 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700268 * Check if a given camera device support setTorchMode API.
269 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700270 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700271
272 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800273 * Check if torch strength update should be skipped or not.
274 */
275 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
276
277 /**
278 * Return the default torch strength level if the torch strength control
279 * feature is supported.
280 */
281 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
282
283 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800284 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700285 * May fail if the device does not support this API, is in active use, or if the device
286 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800287 */
288 status_t setTorchMode(const std::string &id, bool enabled);
289
290 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800291 * Change the brightness level of the flash unit associated with the cameraId and
292 * set it to the value in torchStrength.
293 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
294 * specified strength level. If the torch is ON, only the brightness level will be
295 * changed.
296 *
297 * This operation will fail if the device does not have flash unit, has flash unit
298 * but does not support this API, torchStrength is invalid or if the device doesn't
299 * exist etc.
300 */
301 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
302
303 /**
304 * Return the torch strength level of this camera device.
305 */
306 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
307
308 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800309 * Setup vendor tags for all registered providers
310 */
311 status_t setUpVendorTags();
312
313 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800314 * Inform registered providers about a device state change, such as folding or unfolding
315 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700316 status_t notifyDeviceStateChange(int64_t newState);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800317
318 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800319 * Open an active session to a camera device.
320 *
321 * This fully powers on the camera device hardware, and returns a handle to a
322 * session to be used for hardware configuration and operation.
323 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700324 status_t openHidlSession(const std::string &id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800325 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
326 /*out*/
327 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
328
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800329 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700330 * Notify that the camera or torch is no longer being used by a camera client
331 */
332 void removeRef(DeviceMode usageType, const std::string &cameraId);
333
334 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800335 * IServiceNotification::onRegistration
336 * Invoked by the hardware service manager when a new camera provider is registered
337 */
338 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
339 const hardware::hidl_string& name,
340 bool preexisting) override;
341
342 /**
343 * Dump out information about available providers and devices
344 */
345 status_t dump(int fd, const Vector<String16>& args);
346
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800347 /**
348 * Conversion methods between HAL Status and status_t and strings
349 */
350 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
351 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
352
Emilian Peev71c73a22017-03-21 16:35:51 +0000353 /*
354 * Return provider type for a specific device.
355 */
356 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id,
357 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
358 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
359
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700360 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700361 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700362 * the physical camera ids.
363 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700364 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700365
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700366 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
367 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000368
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700369 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700370
Valentin Iftime29e2e152021-08-13 15:17:33 +0200371 status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId);
372
Emilian Peev538c90e2018-12-17 18:03:19 +0000373 static const float kDepthARTolerance;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800374private:
375 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
376 mutable std::mutex mInterfaceMutex;
377
378 wp<StatusListener> mListener;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700379 HidlServiceInteractionProxy* mHidlServiceProxy;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800380
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800381 // Current overall Android device physical status
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700382 int64_t mDeviceState;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800383
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700384 // mProviderLifecycleLock is locked during onRegistration and removeProvider
385 mutable std::mutex mProviderLifecycleLock;
386
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700387 static HidlServiceInteractionProxyImpl sHidlServiceInteractionProxy;
388
389 struct HalCameraProvider {
390 // Empty parent struct for storing either aidl / hidl camera provider reference
391 HalCameraProvider(const char *descriptor) : mDescriptor(descriptor) { };
392 virtual ~HalCameraProvider() {};
393 std::string mDescriptor;
394 };
395
396 struct HidlHalCameraProvider : public HalCameraProvider {
397 HidlHalCameraProvider(
398 const sp<hardware::camera::provider::V2_4::ICameraProvider> &provider,
399 const char *descriptor) :
400 HalCameraProvider(descriptor), mCameraProvider(provider) { };
401 private:
402 sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider;
403 };
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800404
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700405 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
406 // ICameraProvider alive while it is in use by the camera with the given ID for camera
407 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700408 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700409 mCameraProviderByCameraId;
410
411 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
412 // ICameraProvider alive while it is in use by the camera with the given ID for torch
413 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700414 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700415 mTorchProviderByCameraId;
416
417 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
418 std::mutex mProviderInterfaceMapLock;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700419 struct ProviderInfo : public virtual RefBase {
420 friend struct HidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800421 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700422 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000423 const metadata_vendor_id_t mProviderTagid;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800424 int mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800425 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700426 bool mSetTorchModeSupported;
427 bool mIsRemote;
428
Emilian Peevc93cac22020-08-17 16:00:10 -0700429 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800430 CameraProviderManager *manager);
431 ~ProviderInfo();
432
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700433 virtual IPCTransport getIPCTransport() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800434
435 const std::string& getType() const;
436
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800437 status_t dump(int fd, const Vector<String16>& args) const;
438
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800439 /**
440 * Setup vendor tags for this provider
441 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700442 virtual status_t setUpVendorTags() = 0;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800443
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800444 /**
445 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700446 *
447 * Note that 'mInterfaceMutex' should not be held when calling this method.
448 * It is possible for camera providers to add/remove devices and try to
449 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800450 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700451 virtual status_t notifyDeviceStateChange(int64_t newDeviceState) = 0;
452
453 virtual bool successfullyStartedProviderInterface() = 0;
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800454
455 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
456
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800457 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700458 * Notify 'DeviceInfo' instanced about top-level device physical state changes
459 *
460 * Note that 'mInterfaceMutex' should be held when calling this method.
461 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700462 void notifyDeviceInfoStateChangeLocked(int64_t newDeviceState);
Emilian Peevb50402e2021-09-24 17:41:57 -0700463
464 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800465 * Query the camera provider for concurrent stream configuration support
466 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700467 virtual status_t isConcurrentSessionConfigurationSupported(
468 const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
469 const std::set<std::string>& perfClassPrimaryCameraIds,
470 int targetSdkVersion, bool *isSupported) = 0;
471
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800472
Valentin Iftime29e2e152021-08-13 15:17:33 +0200473 /**
474 * Remove all devices associated with this provider and notify listeners
475 * with NOT_PRESENT state.
476 */
477 void removeAllDevices();
478
479 /**
480 * Provider is an external lazy HAL
481 */
482 bool isExternalLazyHAL() const;
483
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800484 // Basic device information, common to all camera devices
485 struct DeviceInfo {
486 const std::string mName; // Full instance name
487 const std::string mId; // ID section of full name
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700488 //Both hidl and aidl DeviceInfos. Aidl deviceInfos get {3, 8} to
489 //start off.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800490 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000491 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700492 bool mIsLogicalCamera;
493 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700494 hardware::CameraInfo mInfo;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700495 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800496
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700497 const CameraResourceCost mResourceCost;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800498
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700499 CameraDeviceStatus mStatus;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800500
Shuzhen Wang79680432020-03-05 11:53:46 -0800501 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800502 // Torch strength default, maximum levels if the torch strength control
503 // feature is supported.
504 int32_t mTorchStrengthLevel;
505 int32_t mTorchMaximumStrengthLevel;
506 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700507
Valentin Iftime29e2e152021-08-13 15:17:33 +0200508 // Wait for lazy HALs to confirm device availability
509 static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms
510 Mutex mDeviceAvailableLock;
511 Condition mDeviceAvailableSignal;
512 bool mIsDeviceAvailable = true;
513
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800514 bool hasFlashUnit() const { return mHasFlashUnit; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800515 bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800516 virtual status_t setTorchMode(bool enabled) = 0;
Rucha Katakwar38284522021-11-10 11:25:21 -0800517 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
518 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800519 virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100520 virtual bool isAPI1Compatible() const = 0;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700521 virtual status_t dumpState(int fd) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700522 virtual status_t getCameraCharacteristics(bool overrideForPerfClass,
523 CameraMetadata *characteristics) const {
524 (void) overrideForPerfClass;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800525 (void) characteristics;
526 return INVALID_OPERATION;
527 }
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700528 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
529 CameraMetadata *characteristics) const {
530 (void) physicalCameraId;
531 (void) characteristics;
532 return INVALID_OPERATION;
533 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800534
Emilian Peev35ae8262018-11-08 13:11:32 +0000535 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700536 const SessionConfiguration &/*configuration*/,
537 bool /*overrideForPerfClass*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700538 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000539 return INVALID_OPERATION;
540 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700541 virtual status_t filterSmallJpegSizes() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700542 virtual void notifyDeviceStateChange(int64_t /*newState*/) {}
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700543
Emilian Peev71c73a22017-03-21 16:35:51 +0000544 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
545 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700546 const std::vector<std::string>& publicCameraIds,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700547 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700548 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000549 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700550 mIsLogicalCamera(false), mResourceCost(resourceCost),
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700551 mStatus(CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800552 mParentProvider(parentProvider), mTorchStrengthLevel(0),
553 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
554 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
555 mPublicCameraIds(publicCameraIds) {}
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700556 virtual ~DeviceInfo() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800557 protected:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700558
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800559 bool mHasFlashUnit; // const after constructor
560 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700561 const std::vector<std::string>& mPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800562 };
563 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800564 std::unordered_set<std::string> mUniqueCameraIds;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700565 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700566 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700567 // The initial public camera IDs published by the camera provider.
568 // Currently logical multi-camera is not supported for hot-plug camera.
569 // And we use this list to keep track of initial public camera IDs
570 // advertised by the provider, and to distinguish against "hidden"
571 // physical camera IDs.
572 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800573
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800574 // HALv3-specific camera fields, including the actual device interface
575 struct DeviceInfo3 : public DeviceInfo {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800576
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700577 virtual status_t setTorchMode(bool enabled) = 0;
578 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
579 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800580 virtual status_t getCameraInfo(hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100581 virtual bool isAPI1Compatible() const override;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700582 virtual status_t dumpState(int fd) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800583 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700584 bool overrideForPerfClass,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800585 CameraMetadata *characteristics) const override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700586 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
587 CameraMetadata *characteristics) const override;
Emilian Peev35ae8262018-11-08 13:11:32 +0000588 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700589 const SessionConfiguration &configuration, bool /*overrideForPerfClass*/,
590 bool *status /*out*/) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700591 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700592 virtual void notifyDeviceStateChange(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700593 int64_t newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800594
Emilian Peev71c73a22017-03-21 16:35:51 +0000595 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
596 const std::string &id, uint16_t minorVersion,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700597 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700598 sp<ProviderInfo> parentProvider,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700599 const std::vector<std::string>& publicCameraIds);
600 virtual ~DeviceInfo3() {};
601 protected:
602 // Modified by derived transport specific (hidl / aidl) class
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800603 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700604 // Map device states to sensor orientations
605 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700606 // A copy of mCameraCharacteristics without performance class
607 // override
608 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700609 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700610 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700611 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700612 status_t fixupMonochromeTags();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800613 status_t addDynamicDepthTags(bool maxResolution = false);
614 status_t deriveHeicTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800615 status_t addRotateCropTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700616 status_t addPreCorrectionActiveArraySize();
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800617
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000618 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
619 android_pixel_format_t format,
620 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700621 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000622 android_pixel_format_t format,
623 const std::vector<std::tuple<size_t, size_t>>& sizes,
624 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700625 static void getSupportedDynamicDepthDurations(
626 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000627 const std::vector<int64_t>& blobDurations,
628 std::vector<int64_t> *dynamicDepthDurations /*out*/);
629 static void getSupportedDynamicDepthSizes(
630 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
631 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
632 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
633 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700634 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
635 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800636 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
637 std::vector<int64_t>* durations,
638 std::vector<int64_t>* stallDurations,
639 const camera_metadata_entry& halStreamConfigs,
640 const camera_metadata_entry& halStreamDurations);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800641 };
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700642 protected:
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800643 std::string mType;
644 uint32_t mId;
645
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700646 std::mutex mLock;
647
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800648 CameraProviderManager *mManager;
649
Shuzhen Wang394ad702020-07-23 13:01:54 -0700650 struct CameraStatusInfoT {
651 bool isPhysicalCameraStatus = false;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700652 std::string cameraId;
653 std::string physicalCameraId;
654 CameraDeviceStatus status;
655 CameraStatusInfoT(bool isForPhysicalCamera, const std::string& id,
656 const std::string& physicalId,
657 CameraDeviceStatus s) :
Shuzhen Wang394ad702020-07-23 13:01:54 -0700658 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
659 physicalCameraId(physicalId), status(s) {}
660 };
661
662 // Lock to synchronize between initialize() and camera status callbacks
663 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800664 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700665 std::vector<CameraStatusInfoT> mCachedStatus;
666 // End of scope for mInitLock
667
668 std::future<void> mInitialStatusCallbackFuture;
669 void notifyInitialStatusChange(sp<StatusListener> listener,
670 std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus);
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800671
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800672 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
673
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800674 // Parse provider instance name for type and id
675 static status_t parseProviderName(const std::string& name,
676 std::string *type, uint32_t *id);
677
678 // Parse device instance name for device version, type, and id.
679 static status_t parseDeviceName(const std::string& name,
680 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000681
682 // Generate vendor tag id
683 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100684
685 void removeDevice(std::string id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800686
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800687 };
688
Emilian Peev7fe6c422021-09-08 13:43:20 -0700689 /**
690 * Save the ICameraProvider while it is being used by a camera or torch client
691 */
692 void saveRef(DeviceMode usageType, const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700693 std::shared_ptr<HalCameraProvider> provider);
Emilian Peev7fe6c422021-09-08 13:43:20 -0700694
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800695 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
696 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800697 // Finds the first device of the given ID that falls within the requested version range
698 // minVersion <= deviceVersion < maxVersion
699 // No guarantees on the order of traversal
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800700 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800701 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
702 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800703
Valentin Iftime29e2e152021-08-13 15:17:33 +0200704 // Map external providers to USB devices in order to handle USB hotplug
705 // events for lazy HALs
706 std::pair<std::vector<std::string>, sp<ProviderInfo>>
707 mExternalUsbDevicesForProvider;
708 sp<ProviderInfo> startExternalLazyProvider() const;
709
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700710 status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false);
Emilian Peevc93cac22020-08-17 16:00:10 -0700711
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700712 status_t tryToInitializeHidlProviderLocked(const std::string& providerName,
Emilian Peevc93cac22020-08-17 16:00:10 -0700713 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700714
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800715 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
716
Jayant Chowdharye8c4b232022-02-04 18:18:04 +0000717 // No method corresponding to the same provider / member belonging to the
718 // same provider should be used after this method is called since it'll lead
719 // to invalid memory access (especially since this is called by ProviderInfo methods on hal
720 // service death).
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800721 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700722 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800723
724 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const;
725
Emilian Peevc93cac22020-08-17 16:00:10 -0700726 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800727 std::vector<sp<ProviderInfo>> mProviders;
728
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800729 static const char* deviceStatusToString(
730 const hardware::camera::common::V1_0::CameraDeviceStatus&);
731 static const char* torchStatusToString(
732 const hardware::camera::common::V1_0::TorchModeStatus&);
733
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700734 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700735 CameraMetadata* characteristics) const;
736 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700737
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700738 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700739 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(
740 const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700741
742 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
743 std::vector<std::string>& normalDeviceIds,
744 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800745
Valentin Iftime29e2e152021-08-13 15:17:33 +0200746 status_t usbDeviceDetached(const std::string &usbDeviceId);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800747};
748
749} // namespace android
750
751#endif