blob: 3d108bd227a930a1f9ca2ab4c35863f6af477b63 [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>
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>
Emilian Peev2295df72021-11-12 18:14:10 -080043#include <android/hardware/camera/device/3.8/types.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080044#include <android/hidl/manager/1.0/IServiceNotification.h>
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070045#include <binder/IServiceManager.h>
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080046#include <camera/VendorTagDescriptor.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080047
48namespace android {
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070049
50using hardware::camera2::utils::CameraIdAndSessionConfiguration;
51
52enum class CameraDeviceStatus : uint32_t {
53 NOT_PRESENT = 0,
54 PRESENT = 1,
55 ENUMERATING = 2
56};
57
58enum class TorchModeStatus : uint32_t {
59 NOT_AVAILABLE = 0,
60 AVAILABLE_OFF = 1,
61 AVAILABLE_ON = 2
62};
63
64struct CameraResourceCost {
65 uint32_t resourceCost;
66 std::vector<std::string> conflictingDevices;
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080067};
68
Jayant Chowdhary5216b212019-07-17 09:26:23 -070069enum SystemCameraKind {
70 /**
71 * These camera devices are visible to all apps and system components alike
72 */
73 PUBLIC = 0,
74
75 /**
76 * These camera devices are visible only to processes having the
77 * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P
78 * apps.
79 */
80 SYSTEM_ONLY_CAMERA,
81
82 /**
83 * These camera devices are visible only to HAL clients (that try to connect
84 * on a hwbinder thread).
85 */
86 HIDDEN_SECURE_CAMERA
87};
88
Shuzhen Wang83bff122020-11-20 15:51:39 -080089#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
90#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
91#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
92#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
93#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
94#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
95#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
96#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
97#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
Shuzhen Wang90708ea2021-11-04 11:40:49 -070098#define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8)
Shuzhen Wang83bff122020-11-20 15:51:39 -080099
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
178 /**
179 * Listener interface for device/torch status changes
180 */
181 struct StatusListener : virtual public RefBase {
182 ~StatusListener() {}
183
184 virtual void onDeviceStatusChanged(const String8 &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700185 CameraDeviceStatus newStatus) = 0;
Shuzhen Wang43858162020-01-10 13:42:15 -0800186 virtual void onDeviceStatusChanged(const String8 &cameraId,
187 const String8 &physicalCameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700188 CameraDeviceStatus newStatus) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800189 virtual void onTorchStatusChanged(const String8 &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700190 TorchModeStatus newStatus,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700191 SystemCameraKind kind) = 0;
192 virtual void onTorchStatusChanged(const String8 &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700193 TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100194 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800195 };
196
197 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700198 * Represents the mode a camera device is currently in
199 */
200 enum class DeviceMode {
201 TORCH,
202 CAMERA
203 };
204
205 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800206 * Initialize the manager and give it a status listener; optionally accepts a service
207 * interaction proxy.
208 *
209 * The default proxy communicates via the hardware service manager; alternate proxies can be
210 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
211 */
212 status_t initialize(wp<StatusListener> listener,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700213 HidlServiceInteractionProxy *hidlProxy = &sHidlServiceInteractionProxy);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800214
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800215 status_t getCameraIdIPCTransport(const std::string &id,
216 IPCTransport *providerTransport) const;
217
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800218 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700219 * Retrieve the total number of available cameras.
220 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800221 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700222 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800223
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800224 std::vector<std::string> getCameraDeviceIds() const;
225
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800226 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100227 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800228 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800229 * accessible via the old camera API.
230 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800231 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100232 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700233
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800234 /**
235 * Return true if a device with a given ID and major version exists
236 */
237 bool isValidDevice(const std::string &id, uint16_t majorVersion) const;
238
239 /**
240 * Return true if a device with a given ID has a flash unit. Returns false
241 * for devices that are unknown.
242 */
243 bool hasFlashUnit(const std::string &id) const;
244
245 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800246 * Return true if the camera device has native zoom ratio support.
247 */
248 bool supportNativeZoomRatio(const std::string &id) const;
249
250 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800251 * Return the resource cost of this camera device
252 */
253 status_t getResourceCost(const std::string &id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700254 CameraResourceCost* cost) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800255
256 /**
257 * Return the old camera API camera info
258 */
259 status_t getCameraInfo(const std::string &id,
260 hardware::CameraInfo* info) const;
261
262 /**
263 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
264 * not have a v3 or newer HAL version.
265 */
266 status_t getCameraCharacteristics(const std::string &id,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700267 bool overrideForPerfClass, CameraMetadata* characteristics) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800268
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800269 status_t isConcurrentSessionConfigurationSupported(
270 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
271 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700272 const std::set<std::string>& perfClassPrimaryCameraIds,
273 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800274
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700275 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800276 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000277 * Check for device support of specific stream combination.
278 */
279 status_t isSessionConfigurationSupported(const std::string& id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700280 const SessionConfiguration &configuration,
281 bool overrideForPerfClass,
Emilian Peev35ae8262018-11-08 13:11:32 +0000282 bool *status /*out*/) const;
283
284 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800285 * Return the highest supported device interface version for this ID
286 */
287 status_t getHighestSupportedVersion(const std::string &id,
288 hardware::hidl_version *v);
289
290 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700291 * Check if a given camera device support setTorchMode API.
292 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700293 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700294
295 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800296 * Check if torch strength update should be skipped or not.
297 */
298 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
299
300 /**
301 * Return the default torch strength level if the torch strength control
302 * feature is supported.
303 */
304 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
305
306 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800307 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700308 * May fail if the device does not support this API, is in active use, or if the device
309 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800310 */
311 status_t setTorchMode(const std::string &id, bool enabled);
312
313 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800314 * Change the brightness level of the flash unit associated with the cameraId and
315 * set it to the value in torchStrength.
316 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
317 * specified strength level. If the torch is ON, only the brightness level will be
318 * changed.
319 *
320 * This operation will fail if the device does not have flash unit, has flash unit
321 * but does not support this API, torchStrength is invalid or if the device doesn't
322 * exist etc.
323 */
324 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
325
326 /**
327 * Return the torch strength level of this camera device.
328 */
329 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
330
331 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800332 * Setup vendor tags for all registered providers
333 */
334 status_t setUpVendorTags();
335
336 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800337 * Inform registered providers about a device state change, such as folding or unfolding
338 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700339 status_t notifyDeviceStateChange(int64_t newState);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800340
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000341 status_t openAidlSession(const std::string &id,
342 const std::shared_ptr<
343 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
344 /*out*/
345 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceSession> *session);
346
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000347 status_t openAidlInjectionSession(const std::string &id,
348 const std::shared_ptr<
349 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
350 /*out*/
351 std::shared_ptr<aidl::android::hardware::camera::device::ICameraInjectionSession> *session);
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000352
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800353 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800354 * Open an active session to a camera device.
355 *
356 * This fully powers on the camera device hardware, and returns a handle to a
357 * session to be used for hardware configuration and operation.
358 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700359 status_t openHidlSession(const std::string &id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800360 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
361 /*out*/
362 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
363
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800364 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700365 * Notify that the camera or torch is no longer being used by a camera client
366 */
367 void removeRef(DeviceMode usageType, const std::string &cameraId);
368
369 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800370 * IServiceNotification::onRegistration
371 * Invoked by the hardware service manager when a new camera provider is registered
372 */
373 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
374 const hardware::hidl_string& name,
375 bool preexisting) override;
376
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000377 // LocalRegistrationCallback::onServiceRegistration
378 virtual void onServiceRegistration(const String16& name, const sp<IBinder> &binder) override;
379
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800380 /**
381 * Dump out information about available providers and devices
382 */
383 status_t dump(int fd, const Vector<String16>& args);
384
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800385 /**
386 * Conversion methods between HAL Status and status_t and strings
387 */
388 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
389 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
390
Emilian Peev71c73a22017-03-21 16:35:51 +0000391 /*
392 * Return provider type for a specific device.
393 */
394 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id,
395 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
396 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
397
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700398 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700399 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700400 * the physical camera ids.
401 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700402 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700403
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700404 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
405 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000406
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700407 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700408
Valentin Iftime29e2e152021-08-13 15:17:33 +0200409 status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId);
410
Emilian Peev538c90e2018-12-17 18:03:19 +0000411 static const float kDepthARTolerance;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800412private:
413 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
414 mutable std::mutex mInterfaceMutex;
415
416 wp<StatusListener> mListener;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700417 HidlServiceInteractionProxy* mHidlServiceProxy;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800418
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800419 // Current overall Android device physical status
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700420 int64_t mDeviceState;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800421
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700422 // mProviderLifecycleLock is locked during onRegistration and removeProvider
423 mutable std::mutex mProviderLifecycleLock;
424
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700425 static HidlServiceInteractionProxyImpl sHidlServiceInteractionProxy;
426
427 struct HalCameraProvider {
428 // Empty parent struct for storing either aidl / hidl camera provider reference
429 HalCameraProvider(const char *descriptor) : mDescriptor(descriptor) { };
430 virtual ~HalCameraProvider() {};
431 std::string mDescriptor;
432 };
433
434 struct HidlHalCameraProvider : public HalCameraProvider {
435 HidlHalCameraProvider(
436 const sp<hardware::camera::provider::V2_4::ICameraProvider> &provider,
437 const char *descriptor) :
438 HalCameraProvider(descriptor), mCameraProvider(provider) { };
439 private:
440 sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider;
441 };
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800442
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000443 struct AidlHalCameraProvider : public HalCameraProvider {
444 AidlHalCameraProvider(
445 const std::shared_ptr<
446 aidl::android::hardware::camera::provider::ICameraProvider> &provider,
447 const char *descriptor) :
448 HalCameraProvider(descriptor), mCameraProvider(provider) { };
449 private:
450 std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mCameraProvider;
451 };
452
453
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700454 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
455 // ICameraProvider alive while it is in use by the camera with the given ID for camera
456 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700457 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700458 mCameraProviderByCameraId;
459
460 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
461 // ICameraProvider alive while it is in use by the camera with the given ID for torch
462 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700463 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700464 mTorchProviderByCameraId;
465
466 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
467 std::mutex mProviderInterfaceMapLock;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700468 struct ProviderInfo : public virtual RefBase {
469 friend struct HidlProviderInfo;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000470 friend struct AidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800471 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700472 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000473 const metadata_vendor_id_t mProviderTagid;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000474 int32_t mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800475 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700476 bool mSetTorchModeSupported;
477 bool mIsRemote;
478
Emilian Peevc93cac22020-08-17 16:00:10 -0700479 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800480 CameraProviderManager *manager);
481 ~ProviderInfo();
482
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700483 virtual IPCTransport getIPCTransport() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800484
485 const std::string& getType() const;
486
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800487 status_t dump(int fd, const Vector<String16>& args) const;
488
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000489 void initializeProviderInfoCommon(const std::vector<std::string> &devices);
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800490 /**
491 * Setup vendor tags for this provider
492 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700493 virtual status_t setUpVendorTags() = 0;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800494
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800495 /**
496 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700497 *
498 * Note that 'mInterfaceMutex' should not be held when calling this method.
499 * It is possible for camera providers to add/remove devices and try to
500 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800501 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700502 virtual status_t notifyDeviceStateChange(int64_t newDeviceState) = 0;
503
504 virtual bool successfullyStartedProviderInterface() = 0;
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800505
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000506 virtual int64_t getDeviceState() = 0;
507
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800508 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
509
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800510 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700511 * Notify 'DeviceInfo' instanced about top-level device physical state changes
512 *
513 * Note that 'mInterfaceMutex' should be held when calling this method.
514 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700515 void notifyDeviceInfoStateChangeLocked(int64_t newDeviceState);
Emilian Peevb50402e2021-09-24 17:41:57 -0700516
517 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800518 * Query the camera provider for concurrent stream configuration support
519 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700520 virtual status_t isConcurrentSessionConfigurationSupported(
521 const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
522 const std::set<std::string>& perfClassPrimaryCameraIds,
523 int targetSdkVersion, bool *isSupported) = 0;
524
Valentin Iftime29e2e152021-08-13 15:17:33 +0200525 /**
526 * Remove all devices associated with this provider and notify listeners
527 * with NOT_PRESENT state.
528 */
529 void removeAllDevices();
530
531 /**
532 * Provider is an external lazy HAL
533 */
534 bool isExternalLazyHAL() const;
535
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800536 // Basic device information, common to all camera devices
537 struct DeviceInfo {
538 const std::string mName; // Full instance name
539 const std::string mId; // ID section of full name
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700540 //Both hidl and aidl DeviceInfos. Aidl deviceInfos get {3, 8} to
541 //start off.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800542 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000543 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700544 bool mIsLogicalCamera;
545 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700546 hardware::CameraInfo mInfo;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700547 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800548
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700549 const CameraResourceCost mResourceCost;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800550
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700551 CameraDeviceStatus mStatus;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800552
Shuzhen Wang79680432020-03-05 11:53:46 -0800553 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800554 // Torch strength default, maximum levels if the torch strength control
555 // feature is supported.
556 int32_t mTorchStrengthLevel;
557 int32_t mTorchMaximumStrengthLevel;
558 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700559
Valentin Iftime29e2e152021-08-13 15:17:33 +0200560 // Wait for lazy HALs to confirm device availability
561 static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms
562 Mutex mDeviceAvailableLock;
563 Condition mDeviceAvailableSignal;
564 bool mIsDeviceAvailable = true;
565
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800566 bool hasFlashUnit() const { return mHasFlashUnit; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800567 bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800568 virtual status_t setTorchMode(bool enabled) = 0;
Rucha Katakwar38284522021-11-10 11:25:21 -0800569 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
570 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800571 virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100572 virtual bool isAPI1Compatible() const = 0;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700573 virtual status_t dumpState(int fd) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700574 virtual status_t getCameraCharacteristics(bool overrideForPerfClass,
575 CameraMetadata *characteristics) const {
576 (void) overrideForPerfClass;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800577 (void) characteristics;
578 return INVALID_OPERATION;
579 }
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700580 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
581 CameraMetadata *characteristics) const {
582 (void) physicalCameraId;
583 (void) characteristics;
584 return INVALID_OPERATION;
585 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800586
Emilian Peev35ae8262018-11-08 13:11:32 +0000587 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700588 const SessionConfiguration &/*configuration*/,
589 bool /*overrideForPerfClass*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700590 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000591 return INVALID_OPERATION;
592 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700593 virtual status_t filterSmallJpegSizes() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700594 virtual void notifyDeviceStateChange(int64_t /*newState*/) {}
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700595
Emilian Peev71c73a22017-03-21 16:35:51 +0000596 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
597 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700598 const std::vector<std::string>& publicCameraIds,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700599 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700600 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000601 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700602 mIsLogicalCamera(false), mResourceCost(resourceCost),
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700603 mStatus(CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800604 mParentProvider(parentProvider), mTorchStrengthLevel(0),
605 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
606 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
607 mPublicCameraIds(publicCameraIds) {}
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700608 virtual ~DeviceInfo() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800609 protected:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700610
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800611 bool mHasFlashUnit; // const after constructor
612 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700613 const std::vector<std::string>& mPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800614 };
615 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800616 std::unordered_set<std::string> mUniqueCameraIds;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700617 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700618 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700619 // The initial public camera IDs published by the camera provider.
620 // Currently logical multi-camera is not supported for hot-plug camera.
621 // And we use this list to keep track of initial public camera IDs
622 // advertised by the provider, and to distinguish against "hidden"
623 // physical camera IDs.
624 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800625
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800626 // HALv3-specific camera fields, including the actual device interface
627 struct DeviceInfo3 : public DeviceInfo {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800628
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700629 virtual status_t setTorchMode(bool enabled) = 0;
630 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
631 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800632 virtual status_t getCameraInfo(hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100633 virtual bool isAPI1Compatible() const override;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700634 virtual status_t dumpState(int fd) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800635 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700636 bool overrideForPerfClass,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800637 CameraMetadata *characteristics) const override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700638 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
639 CameraMetadata *characteristics) const override;
Emilian Peev35ae8262018-11-08 13:11:32 +0000640 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700641 const SessionConfiguration &configuration, bool /*overrideForPerfClass*/,
642 bool *status /*out*/) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700643 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700644 virtual void notifyDeviceStateChange(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700645 int64_t newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800646
Emilian Peev71c73a22017-03-21 16:35:51 +0000647 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
648 const std::string &id, uint16_t minorVersion,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700649 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700650 sp<ProviderInfo> parentProvider,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700651 const std::vector<std::string>& publicCameraIds);
652 virtual ~DeviceInfo3() {};
653 protected:
654 // Modified by derived transport specific (hidl / aidl) class
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800655 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700656 // Map device states to sensor orientations
657 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700658 // A copy of mCameraCharacteristics without performance class
659 // override
660 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700661 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700662 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700663 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700664 status_t fixupMonochromeTags();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800665 status_t addDynamicDepthTags(bool maxResolution = false);
666 status_t deriveHeicTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800667 status_t addRotateCropTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700668 status_t addPreCorrectionActiveArraySize();
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800669
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000670 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
671 android_pixel_format_t format,
672 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700673 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000674 android_pixel_format_t format,
675 const std::vector<std::tuple<size_t, size_t>>& sizes,
676 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700677 static void getSupportedDynamicDepthDurations(
678 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000679 const std::vector<int64_t>& blobDurations,
680 std::vector<int64_t> *dynamicDepthDurations /*out*/);
681 static void getSupportedDynamicDepthSizes(
682 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
683 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
684 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
685 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700686 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
687 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800688 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
689 std::vector<int64_t>* durations,
690 std::vector<int64_t>* stallDurations,
691 const camera_metadata_entry& halStreamConfigs,
692 const camera_metadata_entry& halStreamDurations);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800693 };
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700694 protected:
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800695 std::string mType;
696 uint32_t mId;
697
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700698 std::mutex mLock;
699
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800700 CameraProviderManager *mManager;
701
Shuzhen Wang394ad702020-07-23 13:01:54 -0700702 struct CameraStatusInfoT {
703 bool isPhysicalCameraStatus = false;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700704 std::string cameraId;
705 std::string physicalCameraId;
706 CameraDeviceStatus status;
707 CameraStatusInfoT(bool isForPhysicalCamera, const std::string& id,
708 const std::string& physicalId,
709 CameraDeviceStatus s) :
Shuzhen Wang394ad702020-07-23 13:01:54 -0700710 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
711 physicalCameraId(physicalId), status(s) {}
712 };
713
714 // Lock to synchronize between initialize() and camera status callbacks
715 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800716 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700717 std::vector<CameraStatusInfoT> mCachedStatus;
718 // End of scope for mInitLock
719
720 std::future<void> mInitialStatusCallbackFuture;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000721
722 std::unique_ptr<ProviderInfo::DeviceInfo>
723 virtual initializeDeviceInfo(
724 const std::string &name, const metadata_vendor_id_t tagId,
725 const std::string &id, uint16_t minorVersion) = 0;
726
727 virtual status_t reCacheConcurrentStreamingCameraIdsLocked() = 0;
728
Shuzhen Wang394ad702020-07-23 13:01:54 -0700729 void notifyInitialStatusChange(sp<StatusListener> listener,
730 std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus);
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800731
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800732 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
733
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800734 // Parse provider instance name for type and id
735 static status_t parseProviderName(const std::string& name,
736 std::string *type, uint32_t *id);
737
738 // Parse device instance name for device version, type, and id.
739 static status_t parseDeviceName(const std::string& name,
740 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000741
742 // Generate vendor tag id
743 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100744
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000745 status_t addDevice(
746 const std::string& name, CameraDeviceStatus initialStatus,
747 /*out*/ std::string* parsedId);
748
749 void cameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
750 CameraDeviceStatus newStatus);
751
752 status_t cameraDeviceStatusChangeLocked(
753 std::string* id, const std::string& cameraDeviceName,
754 CameraDeviceStatus newStatus);
755
756 void physicalCameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
757 const std::string& physicalCameraDeviceName,
758 CameraDeviceStatus newStatus);
759
760 status_t physicalCameraDeviceStatusChangeLocked(
761 std::string* id, std::string* physicalId,
762 const std::string& cameraDeviceName,
763 const std::string& physicalCameraDeviceName,
764 CameraDeviceStatus newStatus);
765
766 void torchModeStatusChangeInternal(const std::string& cameraDeviceName,
767 TorchModeStatus newStatus);
768
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100769 void removeDevice(std::string id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800770
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800771 };
772
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000773 template <class ProviderInfoType, class HalCameraProviderType>
774 status_t setTorchModeT(sp<ProviderInfo> &parentProvider,
775 std::shared_ptr<HalCameraProvider> *halCameraProvider);
776
777 // Try to get hidl provider services declared. Expects mInterfaceMutex to be
778 // locked. Also registers for hidl provider service notifications.
779 status_t tryToInitAndAddHidlProvidersLocked(HidlServiceInteractionProxy *hidlProxy);
780
781 // Try to get aidl provider services declared. Expects mInterfaceMutex to be
782 // locked. Also registers for aidl provider service notifications.
783 status_t tryToAddAidlProvidersLocked();
784
Emilian Peev7fe6c422021-09-08 13:43:20 -0700785 /**
786 * Save the ICameraProvider while it is being used by a camera or torch client
787 */
788 void saveRef(DeviceMode usageType, const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700789 std::shared_ptr<HalCameraProvider> provider);
Emilian Peev7fe6c422021-09-08 13:43:20 -0700790
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800791 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
792 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800793 // Finds the first device of the given ID that falls within the requested version range
794 // minVersion <= deviceVersion < maxVersion
795 // No guarantees on the order of traversal
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800796 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800797 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
798 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800799
Valentin Iftime29e2e152021-08-13 15:17:33 +0200800 // Map external providers to USB devices in order to handle USB hotplug
801 // events for lazy HALs
802 std::pair<std::vector<std::string>, sp<ProviderInfo>>
803 mExternalUsbDevicesForProvider;
804 sp<ProviderInfo> startExternalLazyProvider() const;
805
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700806 status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false);
Emilian Peevc93cac22020-08-17 16:00:10 -0700807
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000808 status_t addAidlProviderLocked(const std::string& newProvider);
809
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700810 status_t tryToInitializeHidlProviderLocked(const std::string& providerName,
Emilian Peevc93cac22020-08-17 16:00:10 -0700811 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700812
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000813 status_t tryToInitializeAidlProviderLocked(const std::string& providerName,
814 const sp<ProviderInfo>& providerInfo);
815
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800816 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
817
Jayant Chowdharye8c4b232022-02-04 18:18:04 +0000818 // No method corresponding to the same provider / member belonging to the
819 // same provider should be used after this method is called since it'll lead
820 // to invalid memory access (especially since this is called by ProviderInfo methods on hal
821 // service death).
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800822 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700823 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800824
825 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const;
826
Emilian Peevc93cac22020-08-17 16:00:10 -0700827 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800828 std::vector<sp<ProviderInfo>> mProviders;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000829 // Provider names of AIDL providers with retrieved binders.
830 std::set<std::string> mAidlProviderWithBinders;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800831
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800832 static const char* deviceStatusToString(
833 const hardware::camera::common::V1_0::CameraDeviceStatus&);
834 static const char* torchStatusToString(
835 const hardware::camera::common::V1_0::TorchModeStatus&);
836
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700837 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700838 CameraMetadata* characteristics) const;
839 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700840
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700841 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700842 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(
843 const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700844
845 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
846 std::vector<std::string>& normalDeviceIds,
847 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800848
Valentin Iftime29e2e152021-08-13 15:17:33 +0200849 status_t usbDeviceDetached(const std::string &usbDeviceId);
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000850 ndk::ScopedAStatus onAidlRegistration(const std::string& in_name,
851 const ::ndk::SpAIBinder& in_binder);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800852};
853
854} // namespace android
855
856#endif