blob: 891c8b1cb78a7a21c17b41a0db69b7abb6ddea6c [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>
32#include <utils/Errors.h>
33#include <android/hardware/camera/common/1.0/types.h>
Eino-Ville Talvala63f36112018-12-06 14:57:03 -080034#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
Shuzhen Wang43858162020-01-10 13:42:15 -080035#include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080036#include <android/hardware/camera/provider/2.6/ICameraProvider.h>
Shuzhen Wang83bff122020-11-20 15:51:39 -080037#include <android/hardware/camera/provider/2.7/ICameraProvider.h>
38#include <android/hardware/camera/device/3.7/types.h>
Emilian Peev2295df72021-11-12 18:14:10 -080039#include <android/hardware/camera/device/3.8/types.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080040#include <android/hidl/manager/1.0/IServiceNotification.h>
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080041#include <camera/VendorTagDescriptor.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080042
43namespace android {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080044/**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080045 * The vendor tag descriptor class that takes HIDL vendor tag information as
46 * input. Not part of VendorTagDescriptor class because that class is used
47 * in AIDL generated sources which don't have access to HIDL headers.
48 */
49class HidlVendorTagDescriptor : public VendorTagDescriptor {
50public:
51 /**
52 * Create a VendorTagDescriptor object from the HIDL VendorTagSection
53 * vector.
54 *
55 * Returns OK on success, or a negative error code.
56 */
57 static status_t createDescriptorFromHidl(
58 const hardware::hidl_vec<hardware::camera::common::V1_0::VendorTagSection>& vts,
59 /*out*/
60 sp<VendorTagDescriptor>& descriptor);
61};
62
Jayant Chowdhary5216b212019-07-17 09:26:23 -070063enum SystemCameraKind {
64 /**
65 * These camera devices are visible to all apps and system components alike
66 */
67 PUBLIC = 0,
68
69 /**
70 * These camera devices are visible only to processes having the
71 * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P
72 * apps.
73 */
74 SYSTEM_ONLY_CAMERA,
75
76 /**
77 * These camera devices are visible only to HAL clients (that try to connect
78 * on a hwbinder thread).
79 */
80 HIDDEN_SECURE_CAMERA
81};
82
Shuzhen Wang83bff122020-11-20 15:51:39 -080083#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
84#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
85#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
86#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
87#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
88#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
89#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
90#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
91#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
Shuzhen Wang90708ea2021-11-04 11:40:49 -070092#define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8)
Shuzhen Wang83bff122020-11-20 15:51:39 -080093
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080094/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080095 * A manager for all camera providers available on an Android device.
96 *
97 * Responsible for enumerating providers and the individual camera devices
98 * they export, both at startup and as providers and devices are added/removed.
99 *
100 * Provides methods for requesting information about individual devices and for
101 * opening them for active use.
102 *
103 */
104class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification {
105public:
106
107 ~CameraProviderManager();
108
109 // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
110 // service manager, to be replacable in unit tests with a fake.
111 struct ServiceInteractionProxy {
112 virtual bool registerForNotifications(
113 const std::string &serviceName,
114 const sp<hidl::manager::V1_0::IServiceNotification>
115 &notification) = 0;
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700116 // Will not wait for service to start if it's not already running
117 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
118 const std::string &serviceName) = 0;
119 // Will block for service if it exists but isn't running
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800120 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
121 const std::string &serviceName) = 0;
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700122 virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800123 virtual ~ServiceInteractionProxy() {}
124 };
125
126 // Standard use case - call into the normal generated static methods which invoke
127 // the real hardware service manager
128 struct HardwareServiceInteractionProxy : public ServiceInteractionProxy {
129 virtual bool registerForNotifications(
130 const std::string &serviceName,
131 const sp<hidl::manager::V1_0::IServiceNotification>
132 &notification) override {
133 return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications(
134 serviceName, notification);
135 }
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700136 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
137 const std::string &serviceName) override {
138 return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName);
139 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800140 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
141 const std::string &serviceName) override {
142 return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName);
143 }
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700144
145 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800146 };
147
148 /**
149 * Listener interface for device/torch status changes
150 */
151 struct StatusListener : virtual public RefBase {
152 ~StatusListener() {}
153
154 virtual void onDeviceStatusChanged(const String8 &cameraId,
155 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0;
Shuzhen Wang43858162020-01-10 13:42:15 -0800156 virtual void onDeviceStatusChanged(const String8 &cameraId,
157 const String8 &physicalCameraId,
158 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800159 virtual void onTorchStatusChanged(const String8 &cameraId,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700160 hardware::camera::common::V1_0::TorchModeStatus newStatus,
161 SystemCameraKind kind) = 0;
162 virtual void onTorchStatusChanged(const String8 &cameraId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800163 hardware::camera::common::V1_0::TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100164 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800165 };
166
167 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700168 * Represents the mode a camera device is currently in
169 */
170 enum class DeviceMode {
171 TORCH,
172 CAMERA
173 };
174
175 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800176 * Initialize the manager and give it a status listener; optionally accepts a service
177 * interaction proxy.
178 *
179 * The default proxy communicates via the hardware service manager; alternate proxies can be
180 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
181 */
182 status_t initialize(wp<StatusListener> listener,
183 ServiceInteractionProxy *proxy = &sHardwareServiceInteractionProxy);
184
185 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700186 * Retrieve the total number of available cameras.
187 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800188 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700189 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800190
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800191 std::vector<std::string> getCameraDeviceIds() const;
192
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800193 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100194 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800195 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800196 * accessible via the old camera API.
197 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800198 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100199 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700200
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800201 /**
202 * Return true if a device with a given ID and major version exists
203 */
204 bool isValidDevice(const std::string &id, uint16_t majorVersion) const;
205
206 /**
207 * Return true if a device with a given ID has a flash unit. Returns false
208 * for devices that are unknown.
209 */
210 bool hasFlashUnit(const std::string &id) const;
211
212 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800213 * Return true if the camera device has native zoom ratio support.
214 */
215 bool supportNativeZoomRatio(const std::string &id) const;
216
217 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800218 * Return the resource cost of this camera device
219 */
220 status_t getResourceCost(const std::string &id,
221 hardware::camera::common::V1_0::CameraResourceCost* cost) const;
222
223 /**
224 * Return the old camera API camera info
225 */
226 status_t getCameraInfo(const std::string &id,
227 hardware::CameraInfo* info) const;
228
229 /**
230 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
231 * not have a v3 or newer HAL version.
232 */
233 status_t getCameraCharacteristics(const std::string &id,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700234 bool overrideForPerfClass, CameraMetadata* characteristics) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800235
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800236 status_t isConcurrentSessionConfigurationSupported(
237 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
238 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700239 const std::set<std::string>& perfClassPrimaryCameraIds,
240 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800241
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700242 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800243 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000244 * Check for device support of specific stream combination.
245 */
246 status_t isSessionConfigurationSupported(const std::string& id,
Emilian Peev2295df72021-11-12 18:14:10 -0800247 const hardware::camera::device::V3_8::StreamConfiguration &configuration,
Emilian Peev35ae8262018-11-08 13:11:32 +0000248 bool *status /*out*/) const;
249
250 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800251 * Return the highest supported device interface version for this ID
252 */
253 status_t getHighestSupportedVersion(const std::string &id,
254 hardware::hidl_version *v);
255
256 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700257 * Check if a given camera device support setTorchMode API.
258 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700259 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700260
261 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800262 * Check if torch strength update should be skipped or not.
263 */
264 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
265
266 /**
267 * Return the default torch strength level if the torch strength control
268 * feature is supported.
269 */
270 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
271
272 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800273 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700274 * May fail if the device does not support this API, is in active use, or if the device
275 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800276 */
277 status_t setTorchMode(const std::string &id, bool enabled);
278
279 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800280 * Change the brightness level of the flash unit associated with the cameraId and
281 * set it to the value in torchStrength.
282 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
283 * specified strength level. If the torch is ON, only the brightness level will be
284 * changed.
285 *
286 * This operation will fail if the device does not have flash unit, has flash unit
287 * but does not support this API, torchStrength is invalid or if the device doesn't
288 * exist etc.
289 */
290 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
291
292 /**
293 * Return the torch strength level of this camera device.
294 */
295 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
296
297 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800298 * Setup vendor tags for all registered providers
299 */
300 status_t setUpVendorTags();
301
302 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800303 * Inform registered providers about a device state change, such as folding or unfolding
304 */
305 status_t notifyDeviceStateChange(
306 android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> newState);
307
308 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800309 * Open an active session to a camera device.
310 *
311 * This fully powers on the camera device hardware, and returns a handle to a
312 * session to be used for hardware configuration and operation.
313 */
314 status_t openSession(const std::string &id,
315 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
316 /*out*/
317 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
318
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800319 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700320 * Notify that the camera or torch is no longer being used by a camera client
321 */
322 void removeRef(DeviceMode usageType, const std::string &cameraId);
323
324 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800325 * IServiceNotification::onRegistration
326 * Invoked by the hardware service manager when a new camera provider is registered
327 */
328 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
329 const hardware::hidl_string& name,
330 bool preexisting) override;
331
332 /**
333 * Dump out information about available providers and devices
334 */
335 status_t dump(int fd, const Vector<String16>& args);
336
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800337 /**
338 * Conversion methods between HAL Status and status_t and strings
339 */
340 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
341 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
342
Emilian Peev71c73a22017-03-21 16:35:51 +0000343 /*
344 * Return provider type for a specific device.
345 */
346 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id,
347 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
348 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
349
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700350 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700351 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700352 * the physical camera ids.
353 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700354 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700355
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700356 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
357 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000358
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700359 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700360
Emilian Peev538c90e2018-12-17 18:03:19 +0000361 static const float kDepthARTolerance;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800362private:
363 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
364 mutable std::mutex mInterfaceMutex;
365
366 wp<StatusListener> mListener;
367 ServiceInteractionProxy* mServiceProxy;
368
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800369 // Current overall Android device physical status
370 android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState;
371
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700372 // mProviderLifecycleLock is locked during onRegistration and removeProvider
373 mutable std::mutex mProviderLifecycleLock;
374
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800375 static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy;
376
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700377 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
378 // ICameraProvider alive while it is in use by the camera with the given ID for camera
379 // capabilities
380 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>>
381 mCameraProviderByCameraId;
382
383 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
384 // ICameraProvider alive while it is in use by the camera with the given ID for torch
385 // capabilities
386 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>>
387 mTorchProviderByCameraId;
388
389 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
390 std::mutex mProviderInterfaceMapLock;
391
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700392 struct ProviderInfo :
Shuzhen Wang43858162020-01-10 13:42:15 -0800393 virtual public hardware::camera::provider::V2_6::ICameraProviderCallback,
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700394 virtual public hardware::hidl_death_recipient
395 {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800396 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700397 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000398 const metadata_vendor_id_t mProviderTagid;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800399 int mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800400 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700401 bool mSetTorchModeSupported;
402 bool mIsRemote;
403
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800404 // Current overall Android device physical status
405 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState;
406
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700407 // This pointer is used to keep a reference to the ICameraProvider that was last accessed.
408 wp<hardware::camera::provider::V2_4::ICameraProvider> mActiveInterface;
409
410 sp<hardware::camera::provider::V2_4::ICameraProvider> mSavedInterface;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800411
Emilian Peevc93cac22020-08-17 16:00:10 -0700412 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800413 CameraProviderManager *manager);
414 ~ProviderInfo();
415
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800416 status_t initialize(sp<hardware::camera::provider::V2_4::ICameraProvider>& interface,
417 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
418 currentDeviceState);
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700419
420 const sp<hardware::camera::provider::V2_4::ICameraProvider> startProviderInterface();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800421
422 const std::string& getType() const;
423
424 status_t addDevice(const std::string& name,
425 hardware::camera::common::V1_0::CameraDeviceStatus initialStatus =
426 hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT,
427 /*out*/ std::string *parsedId = nullptr);
428
429 status_t dump(int fd, const Vector<String16>& args) const;
430
431 // ICameraProviderCallbacks interface - these lock the parent mInterfaceMutex
Shuzhen Wang43858162020-01-10 13:42:15 -0800432 hardware::Return<void> cameraDeviceStatusChange(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800433 const hardware::hidl_string& cameraDeviceName,
434 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override;
Shuzhen Wang43858162020-01-10 13:42:15 -0800435 hardware::Return<void> torchModeStatusChange(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800436 const hardware::hidl_string& cameraDeviceName,
437 hardware::camera::common::V1_0::TorchModeStatus newStatus) override;
Shuzhen Wang43858162020-01-10 13:42:15 -0800438 hardware::Return<void> physicalCameraDeviceStatusChange(
439 const hardware::hidl_string& cameraDeviceName,
440 const hardware::hidl_string& physicalCameraDeviceName,
441 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800442
Shuzhen Wang394ad702020-07-23 13:01:54 -0700443 status_t cameraDeviceStatusChangeLocked(
444 std::string* id, const hardware::hidl_string& cameraDeviceName,
445 hardware::camera::common::V1_0::CameraDeviceStatus newStatus);
446 status_t physicalCameraDeviceStatusChangeLocked(
447 std::string* id, std::string* physicalId,
448 const hardware::hidl_string& cameraDeviceName,
449 const hardware::hidl_string& physicalCameraDeviceName,
450 hardware::camera::common::V1_0::CameraDeviceStatus newStatus);
451
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700452 // hidl_death_recipient interface - this locks the parent mInterfaceMutex
453 virtual void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override;
454
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800455 /**
456 * Setup vendor tags for this provider
457 */
458 status_t setUpVendorTags();
459
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800460 /**
461 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700462 *
463 * Note that 'mInterfaceMutex' should not be held when calling this method.
464 * It is possible for camera providers to add/remove devices and try to
465 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800466 */
467 status_t notifyDeviceStateChange(
468 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
469 newDeviceState);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800470
471 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
472
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800473 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700474 * Notify 'DeviceInfo' instanced about top-level device physical state changes
475 *
476 * Note that 'mInterfaceMutex' should be held when calling this method.
477 */
478 void notifyDeviceInfoStateChangeLocked(
479 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
480 newDeviceState);
481
482 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800483 * Query the camera provider for concurrent stream configuration support
484 */
485 status_t isConcurrentSessionConfigurationSupported(
486 const hardware::hidl_vec<
Shuzhen Wang83bff122020-11-20 15:51:39 -0800487 hardware::camera::provider::V2_7::CameraIdAndStreamCombination>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800488 &halCameraIdsAndStreamCombinations,
489 bool *isSupported);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800490
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800491 // Basic device information, common to all camera devices
492 struct DeviceInfo {
493 const std::string mName; // Full instance name
494 const std::string mId; // ID section of full name
495 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000496 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700497 bool mIsLogicalCamera;
498 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700499 hardware::CameraInfo mInfo;
500 sp<IBase> mSavedInterface;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700501 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800502
503 const hardware::camera::common::V1_0::CameraResourceCost mResourceCost;
504
505 hardware::camera::common::V1_0::CameraDeviceStatus mStatus;
506
Shuzhen Wang79680432020-03-05 11:53:46 -0800507 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800508 // Torch strength default, maximum levels if the torch strength control
509 // feature is supported.
510 int32_t mTorchStrengthLevel;
511 int32_t mTorchMaximumStrengthLevel;
512 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700513
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(
Emilian Peev2295df72021-11-12 18:14:10 -0800536 const hardware::camera::device::V3_8::StreamConfiguration &/*configuration*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700537 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000538 return INVALID_OPERATION;
539 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700540 virtual status_t filterSmallJpegSizes() = 0;
Emilian Peevb50402e2021-09-24 17:41:57 -0700541 virtual void notifyDeviceStateChange(
542 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
543 /*newState*/) {}
Emilian Peev35ae8262018-11-08 13:11:32 +0000544
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700545 template<class InterfaceT>
546 sp<InterfaceT> startDeviceInterface();
547
Emilian Peev71c73a22017-03-21 16:35:51 +0000548 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
549 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700550 const std::vector<std::string>& publicCameraIds,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700551 const hardware::camera::common::V1_0::CameraResourceCost& resourceCost,
552 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000553 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700554 mIsLogicalCamera(false), mResourceCost(resourceCost),
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800555 mStatus(hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800556 mParentProvider(parentProvider), mTorchStrengthLevel(0),
557 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
558 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
559 mPublicCameraIds(publicCameraIds) {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800560 virtual ~DeviceInfo();
561 protected:
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800562 bool mHasFlashUnit; // const after constructor
563 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700564 const std::vector<std::string>& mPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800565
566 template<class InterfaceT>
567 static status_t setTorchMode(InterfaceT& interface, bool enabled);
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700568
569 template<class InterfaceT>
570 status_t setTorchModeForDevice(bool enabled) {
571 // Don't save the ICameraProvider interface here because we assume that this was
572 // called from CameraProviderManager::setTorchMode(), which does save it.
573 const sp<InterfaceT> interface = startDeviceInterface<InterfaceT>();
574 return DeviceInfo::setTorchMode(interface, enabled);
575 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800576 };
577 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800578 std::unordered_set<std::string> mUniqueCameraIds;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700579 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700580 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700581 // The initial public camera IDs published by the camera provider.
582 // Currently logical multi-camera is not supported for hot-plug camera.
583 // And we use this list to keep track of initial public camera IDs
584 // advertised by the provider, and to distinguish against "hidden"
585 // physical camera IDs.
586 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800587
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800588 // HALv3-specific camera fields, including the actual device interface
589 struct DeviceInfo3 : public DeviceInfo {
590 typedef hardware::camera::device::V3_2::ICameraDevice InterfaceT;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800591
592 virtual status_t setTorchMode(bool enabled) override;
Rucha Katakwar38284522021-11-10 11:25:21 -0800593 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) override;
594 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) override;
595
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800596 virtual status_t getCameraInfo(hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100597 virtual bool isAPI1Compatible() const override;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700598 virtual status_t dumpState(int fd) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800599 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700600 bool overrideForPerfClass,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800601 CameraMetadata *characteristics) const override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700602 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
603 CameraMetadata *characteristics) const override;
Emilian Peev35ae8262018-11-08 13:11:32 +0000604 virtual status_t isSessionConfigurationSupported(
Emilian Peev2295df72021-11-12 18:14:10 -0800605 const hardware::camera::device::V3_8::StreamConfiguration &configuration,
Emilian Peev35ae8262018-11-08 13:11:32 +0000606 bool *status /*out*/)
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700607 override;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700608 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700609 virtual void notifyDeviceStateChange(
610 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
611 newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800612
Emilian Peev71c73a22017-03-21 16:35:51 +0000613 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
614 const std::string &id, uint16_t minorVersion,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800615 const hardware::camera::common::V1_0::CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700616 sp<ProviderInfo> parentProvider,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700617 const std::vector<std::string>& publicCameraIds, sp<InterfaceT> interface);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800618 virtual ~DeviceInfo3();
619 private:
620 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700621 // Map device states to sensor orientations
622 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700623 // A copy of mCameraCharacteristics without performance class
624 // override
625 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700626 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700627 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700628 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700629 status_t fixupMonochromeTags();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800630 status_t addDynamicDepthTags(bool maxResolution = false);
631 status_t deriveHeicTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800632 status_t addRotateCropTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700633 status_t addPreCorrectionActiveArraySize();
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800634
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000635 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
636 android_pixel_format_t format,
637 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700638 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000639 android_pixel_format_t format,
640 const std::vector<std::tuple<size_t, size_t>>& sizes,
641 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700642 static void getSupportedDynamicDepthDurations(
643 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000644 const std::vector<int64_t>& blobDurations,
645 std::vector<int64_t> *dynamicDepthDurations /*out*/);
646 static void getSupportedDynamicDepthSizes(
647 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
648 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
649 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
650 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700651 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
652 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800653 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
654 std::vector<int64_t>* durations,
655 std::vector<int64_t>* stallDurations,
656 const camera_metadata_entry& halStreamConfigs,
657 const camera_metadata_entry& halStreamDurations);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800658 };
659
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800660 private:
661 std::string mType;
662 uint32_t mId;
663
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700664 std::mutex mLock;
665
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800666 CameraProviderManager *mManager;
667
Shuzhen Wang394ad702020-07-23 13:01:54 -0700668 struct CameraStatusInfoT {
669 bool isPhysicalCameraStatus = false;
670 hardware::hidl_string cameraId;
671 hardware::hidl_string physicalCameraId;
672 hardware::camera::common::V1_0::CameraDeviceStatus status;
673 CameraStatusInfoT(bool isForPhysicalCamera, const hardware::hidl_string& id,
674 const hardware::hidl_string& physicalId,
675 hardware::camera::common::V1_0::CameraDeviceStatus s) :
676 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
677 physicalCameraId(physicalId), status(s) {}
678 };
679
680 // Lock to synchronize between initialize() and camera status callbacks
681 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800682 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700683 std::vector<CameraStatusInfoT> mCachedStatus;
684 // End of scope for mInitLock
685
686 std::future<void> mInitialStatusCallbackFuture;
687 void notifyInitialStatusChange(sp<StatusListener> listener,
688 std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus);
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800689
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800690 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
691
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800692 // Templated method to instantiate the right kind of DeviceInfo and call the
693 // right CameraProvider getCameraDeviceInterface_* method.
694 template<class DeviceInfoT>
695 std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &name,
Emilian Peev71c73a22017-03-21 16:35:51 +0000696 const metadata_vendor_id_t tagId, const std::string &id,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700697 uint16_t minorVersion);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800698
699 // Helper for initializeDeviceInfo to use the right CameraProvider get method.
700 template<class InterfaceT>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700701 sp<InterfaceT> startDeviceInterface(const std::string &name);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800702
703 // Parse provider instance name for type and id
704 static status_t parseProviderName(const std::string& name,
705 std::string *type, uint32_t *id);
706
707 // Parse device instance name for device version, type, and id.
708 static status_t parseDeviceName(const std::string& name,
709 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000710
711 // Generate vendor tag id
712 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100713
714 void removeDevice(std::string id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800715
716 // Expects to have mLock locked
717 status_t reCacheConcurrentStreamingCameraIdsLocked();
718 // Expects to have mLock locked
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700719 status_t getConcurrentCameraIdsInternalLocked(
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800720 sp<hardware::camera::provider::V2_6::ICameraProvider> &interface2_6);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800721 };
722
Emilian Peev7fe6c422021-09-08 13:43:20 -0700723 /**
724 * Save the ICameraProvider while it is being used by a camera or torch client
725 */
726 void saveRef(DeviceMode usageType, const std::string &cameraId,
727 sp<hardware::camera::provider::V2_4::ICameraProvider> provider);
728
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800729 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
730 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800731 // Finds the first device of the given ID that falls within the requested version range
732 // minVersion <= deviceVersion < maxVersion
733 // No guarantees on the order of traversal
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800734 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800735 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
736 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800737
Emilian Peevc93cac22020-08-17 16:00:10 -0700738 status_t addProviderLocked(const std::string& newProvider, bool preexisting = false);
739
740 status_t tryToInitializeProviderLocked(const std::string& providerName,
741 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700742
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800743 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
744
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800745 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700746 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800747
748 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const;
749
Emilian Peevc93cac22020-08-17 16:00:10 -0700750 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800751 std::vector<sp<ProviderInfo>> mProviders;
752
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700753 void addProviderToMap(
754 const std::string &cameraId,
755 sp<hardware::camera::provider::V2_4::ICameraProvider> provider,
756 bool isTorchUsage);
757 void removeCameraIdFromMap(
758 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>> &map,
759 const std::string &cameraId);
760
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800761 static const char* deviceStatusToString(
762 const hardware::camera::common::V1_0::CameraDeviceStatus&);
763 static const char* torchStatusToString(
764 const hardware::camera::common::V1_0::TorchModeStatus&);
765
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700766 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700767 CameraMetadata* characteristics) const;
768 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700769
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700770 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
771 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700772
773 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
774 std::vector<std::string>& normalDeviceIds,
775 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800776
777 status_t convertToHALStreamCombinationAndCameraIdsLocked(
778 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
779 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700780 const std::set<std::string>& perfClassPrimaryCameraIds,
781 int targetSdkVersion,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800782 hardware::hidl_vec<hardware::camera::provider::V2_7::CameraIdAndStreamCombination>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800783 *halCameraIdsAndStreamCombinations,
784 bool *earlyExit);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800785};
786
787} // namespace android
788
789#endif