1 /*
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 #define LOG_NDEBUG 0
18 #define LOG_TAG "CameraProviderManagerTest"
19
20 #include "../common/CameraProviderManager.h"
21 #include <aidl/android/hardware/camera/device/BnCameraDevice.h>
22 #include <aidl/android/hardware/camera/provider/BnCameraProvider.h>
23 #include <android_companion_virtualdevice_flags.h>
24 #include <android/binder_auto_utils.h>
25 #include <android/binder_ibinder.h>
26 #include <android/binder_interface_utils.h>
27 #include <android/binder_libbinder.h>
28 #include <android/binder_manager.h>
29 #include <android/binder_parcel.h>
30 #include <android/hardware/camera/device/3.2/ICameraDeviceCallback.h>
31 #include <android/hardware/camera/device/3.2/ICameraDeviceSession.h>
32 #include <android/hidl/manager/1.0/IServiceManager.h>
33 #include <android/hidl/manager/1.0/IServiceNotification.h>
34 #include <binder/IServiceManager.h>
35 #include <camera_metadata_hidden.h>
36 #include <com_android_internal_camera_flags.h>
37 #include <flag_macros.h>
38 #include <gmock/gmock.h>
39 #include <gtest/gtest.h>
40 #include <hidl/HidlBinderSupport.h>
41 #include <utility>
42
43 using namespace android;
44 using namespace android::hardware::camera;
45 using ::aidl::android::hardware::camera::provider::ICameraProviderCallback;
46 using android::hardware::camera::common::V1_0::CameraMetadataType;
47 using android::hardware::camera::common::V1_0::Status;
48 using android::hardware::camera::common::V1_0::VendorTag;
49 using android::hardware::camera::common::V1_0::VendorTagSection;
50 using android::hardware::camera::device::V3_2::ICameraDeviceCallback;
51 using android::hardware::camera::device::V3_2::ICameraDeviceSession;
52 using android::hardware::camera::provider::V2_5::DeviceState;
53 using ::testing::ElementsAre;
54
55 namespace flags = com::android::internal::camera::flags;
56 namespace vd_flags = android::companion::virtualdevice::flags;
57
58 /**
59 * Basic test implementation of a camera ver. 3.2 device interface
60 */
61 struct TestDeviceInterface : public device::V3_2::ICameraDevice {
62 std::vector<hardware::hidl_string> mDeviceNames;
63 android::hardware::hidl_vec<uint8_t> mCharacteristics;
64
TestDeviceInterfaceTestDeviceInterface65 TestDeviceInterface(std::vector<hardware::hidl_string> deviceNames,
66 android::hardware::hidl_vec<uint8_t> chars) :
67 mDeviceNames(deviceNames), mCharacteristics(chars) {}
68
TestDeviceInterfaceTestDeviceInterface69 TestDeviceInterface(std::vector<hardware::hidl_string> deviceNames) :
70 mDeviceNames(deviceNames) {}
71
72 using getResourceCost_cb = std::function<void(
73 hardware::camera::common::V1_0::Status status,
74 const hardware::camera::common::V1_0::CameraResourceCost& resourceCost)>;
getResourceCostTestDeviceInterface75 virtual ::android::hardware::Return<void> getResourceCost(
76 getResourceCost_cb _hidl_cb) override {
77 hardware::camera::common::V1_0::CameraResourceCost resourceCost = {100,
78 mDeviceNames};
79 _hidl_cb(Status::OK, resourceCost);
80 return hardware::Void();
81 }
82
83 using getCameraCharacteristics_cb = std::function<void(
84 hardware::camera::common::V1_0::Status status,
85 const hardware::hidl_vec<uint8_t>& cameraCharacteristics)>;
getCameraCharacteristicsTestDeviceInterface86 hardware::Return<void> getCameraCharacteristics(
87 getCameraCharacteristics_cb _hidl_cb) override {
88 _hidl_cb(Status::OK, mCharacteristics);
89 return hardware::Void();
90 }
91
setTorchModeTestDeviceInterface92 hardware::Return<hardware::camera::common::V1_0::Status> setTorchMode(
93 ::android::hardware::camera::common::V1_0::TorchMode) override {
94 return Status::OK;
95 }
96
97 using open_cb = std::function<void(
98 ::android::hardware::camera::common::V1_0::Status status,
99 const ::android::sp<ICameraDeviceSession>& session)>;
openTestDeviceInterface100 hardware::Return<void> open(
101 const ::android::sp<ICameraDeviceCallback>&,
102 open_cb _hidl_cb) override {
103 sp<ICameraDeviceSession> deviceSession = nullptr;
104 _hidl_cb(Status::OK, deviceSession);
105 return hardware::Void();
106 }
107
dumpStateTestDeviceInterface108 hardware::Return<void> dumpState(
109 const ::android::hardware::hidl_handle&) override {
110 return hardware::Void();
111 }
112 };
113
114 /**
115 * Basic test implementation of a camera provider
116 */
117 struct TestICameraProvider : virtual public provider::V2_5::ICameraProvider {
118 sp<provider::V2_4::ICameraProviderCallback> mCallbacks;
119 std::vector<hardware::hidl_string> mDeviceNames;
120 sp<device::V3_2::ICameraDevice> mDeviceInterface;
121 hardware::hidl_vec<common::V1_0::VendorTagSection> mVendorTagSections;
122
123 // Whether to call a physical camera unavailable callback upon setCallback
124 bool mHasPhysicalCameraUnavailableCallback;
125 hardware::hidl_string mLogicalCameraId;
126 hardware::hidl_string mUnavailablePhysicalCameraId;
127
TestICameraProviderTestICameraProvider128 TestICameraProvider(const std::vector<hardware::hidl_string> &devices,
129 const hardware::hidl_vec<common::V1_0::VendorTagSection> &vendorSection) :
130 mDeviceNames(devices),
131 mDeviceInterface(new TestDeviceInterface(devices)),
132 mVendorTagSections (vendorSection),
133 mHasPhysicalCameraUnavailableCallback(false) {}
134
TestICameraProviderTestICameraProvider135 TestICameraProvider(const std::vector<hardware::hidl_string> &devices,
136 const hardware::hidl_vec<common::V1_0::VendorTagSection> &vendorSection,
137 android::hardware::hidl_vec<uint8_t> chars) :
138 mDeviceNames(devices),
139 mDeviceInterface(new TestDeviceInterface(devices, chars)),
140 mVendorTagSections (vendorSection),
141 mHasPhysicalCameraUnavailableCallback(false) {}
142
TestICameraProviderTestICameraProvider143 TestICameraProvider(const std::vector<hardware::hidl_string> &devices,
144 const hardware::hidl_vec<common::V1_0::VendorTagSection> &vendorSection,
145 android::hardware::hidl_vec<uint8_t> chars,
146 const hardware::hidl_string& logicalCameraId,
147 const hardware::hidl_string& unavailablePhysicalCameraId) :
148 mDeviceNames(devices),
149 mDeviceInterface(new TestDeviceInterface(devices, chars)),
150 mVendorTagSections (vendorSection),
151 mHasPhysicalCameraUnavailableCallback(true),
152 mLogicalCameraId(logicalCameraId),
153 mUnavailablePhysicalCameraId(unavailablePhysicalCameraId) {}
154
setCallbackTestICameraProvider155 virtual hardware::Return<Status> setCallback(
156 const sp<provider::V2_4::ICameraProviderCallback>& callbacks) override {
157 mCalledCounter[SET_CALLBACK]++;
158 mCallbacks = callbacks;
159 if (mHasPhysicalCameraUnavailableCallback) {
160 auto cast26 = provider::V2_6::ICameraProviderCallback::castFrom(callbacks);
161 if (!cast26.isOk()) {
162 ADD_FAILURE() << "Failed to cast ICameraProviderCallback to V2_6";
163 } else {
164 sp<provider::V2_6::ICameraProviderCallback> callback26 = cast26;
165 if (callback26 == nullptr) {
166 ADD_FAILURE() << "V2_6::ICameraProviderCallback is null after conversion";
167 } else {
168 callback26->physicalCameraDeviceStatusChange(mLogicalCameraId,
169 mUnavailablePhysicalCameraId,
170 android::hardware::camera::common::V1_0::CameraDeviceStatus::NOT_PRESENT);
171 }
172 }
173 }
174 return hardware::Return<Status>(Status::OK);
175 }
176
177 using getVendorTags_cb = std::function<void(Status status,
178 const hardware::hidl_vec<common::V1_0::VendorTagSection>& sections)>;
getVendorTagsTestICameraProvider179 hardware::Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override {
180 mCalledCounter[GET_VENDOR_TAGS]++;
181 _hidl_cb(Status::OK, mVendorTagSections);
182 return hardware::Void();
183 }
184
185 using isSetTorchModeSupported_cb = std::function<void(
186 ::android::hardware::camera::common::V1_0::Status status,
187 bool support)>;
isSetTorchModeSupportedTestICameraProvider188 virtual ::hardware::Return<void> isSetTorchModeSupported(
189 isSetTorchModeSupported_cb _hidl_cb) override {
190 mCalledCounter[IS_SET_TORCH_MODE_SUPPORTED]++;
191 _hidl_cb(Status::OK, false);
192 return hardware::Void();
193 }
194
195 using getCameraIdList_cb = std::function<void(Status status,
196 const hardware::hidl_vec<hardware::hidl_string>& cameraDeviceNames)>;
getCameraIdListTestICameraProvider197 virtual hardware::Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override {
198 mCalledCounter[GET_CAMERA_ID_LIST]++;
199 _hidl_cb(Status::OK, mDeviceNames);
200 return hardware::Void();
201 }
202
203 using getCameraDeviceInterface_V1_x_cb = std::function<void(Status status,
204 const sp<device::V1_0::ICameraDevice>& device)>;
getCameraDeviceInterface_V1_xTestICameraProvider205 virtual hardware::Return<void> getCameraDeviceInterface_V1_x(
206 [[maybe_unused]] const hardware::hidl_string& cameraDeviceName,
207 getCameraDeviceInterface_V1_x_cb _hidl_cb) override {
208 _hidl_cb(Status::OK, nullptr); //TODO: impl. of ver. 1.0 device interface
209 // otherwise enumeration will fail.
210 return hardware::Void();
211 }
212
213 using getCameraDeviceInterface_V3_x_cb = std::function<void(Status status,
214 const sp<device::V3_2::ICameraDevice>& device)>;
getCameraDeviceInterface_V3_xTestICameraProvider215 virtual hardware::Return<void> getCameraDeviceInterface_V3_x(
216 const hardware::hidl_string&,
217 getCameraDeviceInterface_V3_x_cb _hidl_cb) override {
218 _hidl_cb(Status::OK, mDeviceInterface);
219 return hardware::Void();
220 }
221
notifyDeviceStateChangeTestICameraProvider222 virtual hardware::Return<void> notifyDeviceStateChange(
223 hardware::hidl_bitfield<DeviceState> newState) override {
224 mCalledCounter[NOTIFY_DEVICE_STATE]++;
225 mCurrentState = newState;
226 return hardware::Void();
227 }
228
linkToDeathTestICameraProvider229 virtual ::android::hardware::Return<bool> linkToDeath(
230 const ::android::sp<::android::hardware::hidl_death_recipient>& recipient,
231 uint64_t cookie) {
232 if (mInitialDeathRecipient.get() == nullptr) {
233 mInitialDeathRecipient =
234 std::make_unique<::android::hardware::hidl_binder_death_recipient>(recipient,
235 cookie, this);
236 }
237 return true;
238 }
239
signalInitialBinderDeathRecipientTestICameraProvider240 void signalInitialBinderDeathRecipient() {
241 if (mInitialDeathRecipient.get() != nullptr) {
242 mInitialDeathRecipient->binderDied(nullptr /*who*/);
243 }
244 }
245
246 std::unique_ptr<::android::hardware::hidl_binder_death_recipient> mInitialDeathRecipient;
247
248 enum MethodNames {
249 SET_CALLBACK,
250 GET_VENDOR_TAGS,
251 IS_SET_TORCH_MODE_SUPPORTED,
252 NOTIFY_DEVICE_STATE,
253 GET_CAMERA_ID_LIST,
254
255 METHOD_NAME_COUNT
256 };
257 int mCalledCounter[METHOD_NAME_COUNT] {0};
258
259 hardware::hidl_bitfield<DeviceState> mCurrentState = 0xFFFFFFFF; // Unlikely to be a real state
260 };
261
262 struct TestAidlCameraDevice : public aidl::android::hardware::camera::device::BnCameraDevice {
getCameraCharacteristicsTestAidlCameraDevice263 ::ndk::ScopedAStatus getCameraCharacteristics(
264 ::aidl::android::hardware::camera::device::CameraMetadata*) override {
265 return ndk::ScopedAStatus::ok();
266 }
getPhysicalCameraCharacteristicsTestAidlCameraDevice267 ::ndk::ScopedAStatus getPhysicalCameraCharacteristics(
268 const std::string&,
269 ::aidl::android::hardware::camera::device::CameraMetadata*) override {
270 return ndk::ScopedAStatus::ok();
271 }
getResourceCostTestAidlCameraDevice272 ::ndk::ScopedAStatus getResourceCost(
273 ::aidl::android::hardware::camera::common::CameraResourceCost* aidl_return) override {
274 auto cost = ::aidl::android::hardware::camera::common::CameraResourceCost();
275 aidl_return->resourceCost = 100;
276 return ndk::ScopedAStatus::ok();
277 }
isStreamCombinationSupportedTestAidlCameraDevice278 ::ndk::ScopedAStatus isStreamCombinationSupported(
279 const ::aidl::android::hardware::camera::device::StreamConfiguration&, bool*) override {
280 return ndk::ScopedAStatus::ok();
281 }
282 ::ndk::ScopedAStatus
openTestAidlCameraDevice283 open(const std::shared_ptr<::aidl::android::hardware::camera::device::ICameraDeviceCallback>&,
284 std::shared_ptr<::aidl::android::hardware::camera::device::ICameraDeviceSession>*)
285 override {
286 return ndk::ScopedAStatus::ok();
287 }
openInjectionSessionTestAidlCameraDevice288 ::ndk::ScopedAStatus openInjectionSession(
289 const std::shared_ptr<
290 ::aidl::android::hardware::camera::device::ICameraDeviceCallback>&,
291 std::shared_ptr<::aidl::android::hardware::camera::device::ICameraInjectionSession>*)
292 override {
293 return ndk::ScopedAStatus::ok();
294 }
setTorchModeTestAidlCameraDevice295 ::ndk::ScopedAStatus setTorchMode(bool) override { return ndk::ScopedAStatus::ok(); }
turnOnTorchWithStrengthLevelTestAidlCameraDevice296 ::ndk::ScopedAStatus turnOnTorchWithStrengthLevel(int32_t) override {
297 return ndk::ScopedAStatus::ok();
298 }
getTorchStrengthLevelTestAidlCameraDevice299 ::ndk::ScopedAStatus getTorchStrengthLevel(int32_t*) override {
300 return ndk::ScopedAStatus::ok();
301 }
constructDefaultRequestSettingsTestAidlCameraDevice302 ::ndk::ScopedAStatus constructDefaultRequestSettings(
303 ::aidl::android::hardware::camera::device::RequestTemplate,
304 ::aidl::android::hardware::camera::device::CameraMetadata*) override {
305 return ndk::ScopedAStatus::ok();
306 }
isStreamCombinationWithSettingsSupportedTestAidlCameraDevice307 ::ndk::ScopedAStatus isStreamCombinationWithSettingsSupported(
308 const ::aidl::android::hardware::camera::device::StreamConfiguration&,
309 bool*) override {
310 return ndk::ScopedAStatus::ok();
311 }
312
getSessionCharacteristicsTestAidlCameraDevice313 ::ndk::ScopedAStatus getSessionCharacteristics(
314 const ::aidl::android::hardware::camera::device::StreamConfiguration&,
315 ::aidl::android::hardware::camera::device::CameraMetadata*) override {
316 return ndk::ScopedAStatus::ok();
317 }
318 };
319
320 /**
321 * Basic test implementation of a AIDL camera provider
322 */
323 class TestAidlICameraProvider : public aidl::android::hardware::camera::provider::BnCameraProvider {
324 public:
325 std::shared_ptr<ICameraProviderCallback> mCallback;
326 std::vector<std::string> mDeviceNames;
327
TestAidlICameraProvider(const std::vector<std::string> & deviceNames)328 TestAidlICameraProvider(const std::vector<std::string>& deviceNames) {
329 mDeviceNames = deviceNames;
330 }
331
setCallback(const std::shared_ptr<::aidl::android::hardware::camera::provider::ICameraProviderCallback> & callback)332 ::ndk::ScopedAStatus setCallback(
333 const std::shared_ptr<
334 ::aidl::android::hardware::camera::provider::ICameraProviderCallback>& callback)
335 override {
336 mCallback = callback;
337 return ndk::ScopedAStatus::ok();
338 }
getVendorTags(std::vector<::aidl::android::hardware::camera::common::VendorTagSection> *)339 ::ndk::ScopedAStatus getVendorTags(
340 std::vector<::aidl::android::hardware::camera::common::VendorTagSection>*) override {
341 return ndk::ScopedAStatus::ok();
342 }
getCameraIdList(std::vector<std::string> * camera_list)343 ::ndk::ScopedAStatus getCameraIdList(std::vector<std::string>* camera_list) override {
344 ALOGW("getCameraIdList");
345 for (size_t i = 0; i < mDeviceNames.size(); i++) {
346 camera_list->push_back(mDeviceNames.at(i));
347 }
348 return ndk::ScopedAStatus::ok();
349 }
getCameraDeviceInterface(const std::string &,std::shared_ptr<::aidl::android::hardware::camera::device::ICameraDevice> * device)350 ::ndk::ScopedAStatus getCameraDeviceInterface(
351 const std::string&,
352 std::shared_ptr<::aidl::android::hardware::camera::device::ICameraDevice>* device)
353 override {
354 *device = ndk::SharedRefBase::make<TestAidlCameraDevice>();
355 return ndk::ScopedAStatus::ok();
356 }
notifyDeviceStateChange(int64_t)357 ::ndk::ScopedAStatus notifyDeviceStateChange(int64_t) override {
358 return ndk::ScopedAStatus::ok();
359 }
getConcurrentCameraIds(std::vector<::aidl::android::hardware::camera::provider::ConcurrentCameraIdCombination> *)360 ::ndk::ScopedAStatus getConcurrentCameraIds(
361 std::vector<
362 ::aidl::android::hardware::camera::provider::ConcurrentCameraIdCombination>*)
363 override {
364 return ndk::ScopedAStatus::ok();
365 }
isConcurrentStreamCombinationSupported(const std::vector<::aidl::android::hardware::camera::provider::CameraIdAndStreamCombination> &,bool *)366 ::ndk::ScopedAStatus isConcurrentStreamCombinationSupported(
367 const std::vector<
368 ::aidl::android::hardware::camera::provider::CameraIdAndStreamCombination>&,
369 bool*) override {
370 return ndk::ScopedAStatus::ok();
371 }
372 };
373
374 /**
375 * Simple test version of HidlServiceInteractionProxy, to use to inject onRegistered calls to the
376 * CameraProviderManager
377 */
378 struct TestHidlInteractionProxy : public CameraProviderManager::HidlServiceInteractionProxy {
379 sp<hidl::manager::V1_0::IServiceNotification> mManagerNotificationInterface;
380 sp<TestICameraProvider> mTestCameraProvider;
381
TestHidlInteractionProxyTestHidlInteractionProxy382 TestHidlInteractionProxy() {}
383
setProviderTestHidlInteractionProxy384 void setProvider(sp<TestICameraProvider> provider) {
385 mTestCameraProvider = provider;
386 }
387
388 std::vector<std::string> mLastRequestedServiceNames;
389
~TestHidlInteractionProxyTestHidlInteractionProxy390 virtual ~TestHidlInteractionProxy() {}
391
registerForNotificationsTestHidlInteractionProxy392 virtual bool registerForNotifications(
393 [[maybe_unused]] const std::string &serviceName,
394 const sp<hidl::manager::V1_0::IServiceNotification> ¬ification) override {
395 mManagerNotificationInterface = notification;
396 return true;
397 }
398
tryGetServiceTestHidlInteractionProxy399 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
400 const std::string &serviceName) override {
401 // If no provider has been given, act like the HAL isn't available and return null.
402 if (mTestCameraProvider == nullptr) return nullptr;
403 return getService(serviceName);
404 }
405
getServiceTestHidlInteractionProxy406 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
407 const std::string &serviceName) override {
408 // If no provider has been given, fail; in reality, getService would
409 // block for HALs that don't start correctly, so we should never use
410 // getService when we don't have a valid HAL running
411 if (mTestCameraProvider == nullptr) {
412 ADD_FAILURE() << "getService called with no valid provider; would block indefinitely";
413 // Real getService would block, but that's bad in unit tests. So
414 // just record an error and return nullptr
415 return nullptr;
416 }
417 mLastRequestedServiceNames.push_back(serviceName);
418 return mTestCameraProvider;
419 }
420
listServicesTestHidlInteractionProxy421 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override {
422 // Always provide a list even if there's no actual provider yet, to
423 // simulate stuck HAL situations as well
424 hardware::hidl_vec<hardware::hidl_string> ret = {"test/0"};
425 return ret;
426 }
427 };
428
429 /**
430 * Simple test version of AidlServiceInteractionProxy, to use to inject onRegistered calls to the
431 * CameraProviderManager
432 */
433 struct TestAidlInteractionProxy : public CameraProviderManager::AidlServiceInteractionProxy {
434 std::shared_ptr<TestAidlICameraProvider> mTestAidlCameraProvider;
435
TestAidlInteractionProxyTestAidlInteractionProxy436 TestAidlInteractionProxy() {}
437
setProviderTestAidlInteractionProxy438 void setProvider(std::shared_ptr<TestAidlICameraProvider> provider) {
439 mTestAidlCameraProvider = provider;
440 }
441
442 std::vector<std::string> mLastRequestedServiceNames;
443
~TestAidlInteractionProxyTestAidlInteractionProxy444 virtual ~TestAidlInteractionProxy() {}
445
446 virtual std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider>
getServiceTestAidlInteractionProxy447 getService(const std::string& serviceName) override {
448 if (!flags::delay_lazy_hal_instantiation()) {
449 return mTestAidlCameraProvider;
450 }
451
452 // If no provider has been given, fail; in reality, getService would
453 // block for HALs that don't start correctly, so we should never use
454 // getService when we don't have a valid HAL running
455 if (mTestAidlCameraProvider == nullptr) {
456 ADD_FAILURE() << __FUNCTION__ << "called with no valid provider;"
457 << " would block indefinitely";
458 // Real getService would block, but that's bad in unit tests. So
459 // just record an error and return nullptr
460 return nullptr;
461 }
462 mLastRequestedServiceNames.push_back(serviceName);
463 return mTestAidlCameraProvider;
464 }
465
466 virtual std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider>
tryGetServiceTestAidlInteractionProxy467 tryGetService(const std::string&) override {
468 return mTestAidlCameraProvider;
469 }
470 };
471
472 struct TestStatusListener : public CameraProviderManager::StatusListener {
473 int mPhysicalCameraStatusChangeCount = 0;
474
~TestStatusListenerTestStatusListener475 ~TestStatusListener() {}
476
onDeviceStatusChangedTestStatusListener477 void onDeviceStatusChanged(const std::string &,
478 CameraDeviceStatus) override {}
onDeviceStatusChangedTestStatusListener479 void onDeviceStatusChanged(const std::string &, const std::string &,
480 CameraDeviceStatus) override {
481 mPhysicalCameraStatusChangeCount++;
482 }
onTorchStatusChangedTestStatusListener483 void onTorchStatusChanged(const std::string &,
484 TorchModeStatus) override {}
onTorchStatusChangedTestStatusListener485 void onTorchStatusChanged(const std::string &,
486 TorchModeStatus, SystemCameraKind) override {}
onNewProviderRegisteredTestStatusListener487 void onNewProviderRegistered() override {}
488 };
489
TEST(CameraProviderManagerTest,InitializeDynamicDepthTest)490 TEST(CameraProviderManagerTest, InitializeDynamicDepthTest) {
491 std::vector<hardware::hidl_string> deviceNames;
492 deviceNames.push_back("device@3.2/test/0");
493 hardware::hidl_vec<common::V1_0::VendorTagSection> vendorSection;
494 status_t res;
495 sp<CameraProviderManager> providerManager = new CameraProviderManager();
496 sp<TestStatusListener> statusListener = new TestStatusListener();
497 TestHidlInteractionProxy serviceProxy;
498
499 android::hardware::hidl_vec<uint8_t> chars;
500 CameraMetadata meta;
501 int32_t charKeys[] = { ANDROID_DEPTH_DEPTH_IS_EXCLUSIVE,
502 ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS };
503 meta.update(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, charKeys,
504 sizeof(charKeys) / sizeof(charKeys[0]));
505 uint8_t depthIsExclusive = ANDROID_DEPTH_DEPTH_IS_EXCLUSIVE_FALSE;
506 meta.update(ANDROID_DEPTH_DEPTH_IS_EXCLUSIVE, &depthIsExclusive, 1);
507 int32_t sizes[] = { HAL_PIXEL_FORMAT_BLOB,
508 640, 480, ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT };
509 meta.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, sizes,
510 sizeof(sizes) / sizeof(sizes[0]));
511 sizes[0] = HAL_PIXEL_FORMAT_Y16;
512 meta.update(ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS, sizes,
513 sizeof(sizes) / sizeof(sizes[0]));
514 int64_t durations[] = { HAL_PIXEL_FORMAT_BLOB, 640, 480, 0 };
515 meta.update(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, durations,
516 sizeof(durations) / sizeof(durations[0]));
517 meta.update(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, durations,
518 sizeof(durations) / sizeof(durations[0]));
519 durations[0]= HAL_PIXEL_FORMAT_Y16;
520 meta.update(ANDROID_DEPTH_AVAILABLE_DEPTH_MIN_FRAME_DURATIONS, durations,
521 sizeof(durations) / sizeof(durations[0]));
522 meta.update(ANDROID_DEPTH_AVAILABLE_DEPTH_STALL_DURATIONS, durations,
523 sizeof(durations) / sizeof(durations[0]));
524 camera_metadata_t* metaBuffer = const_cast<camera_metadata_t*>(meta.getAndLock());
525 chars.setToExternal(reinterpret_cast<uint8_t*>(metaBuffer),
526 get_camera_metadata_size(metaBuffer));
527
528 sp<TestICameraProvider> provider = new TestICameraProvider(deviceNames,
529 vendorSection, chars);
530 serviceProxy.setProvider(provider);
531
532 res = providerManager->initialize(statusListener, &serviceProxy);
533 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
534 }
535
TEST(CameraProviderManagerTest,InitializeTest)536 TEST(CameraProviderManagerTest, InitializeTest) {
537 std::vector<hardware::hidl_string> deviceNames;
538 deviceNames.push_back("device@3.2/test/0");
539 deviceNames.push_back("device@1.0/test/0");
540 deviceNames.push_back("device@3.2/test/1");
541 hardware::hidl_vec<common::V1_0::VendorTagSection> vendorSection;
542 status_t res;
543 sp<CameraProviderManager> providerManager = new CameraProviderManager();
544 sp<TestStatusListener> statusListener = new TestStatusListener();
545 TestHidlInteractionProxy serviceProxy;
546 sp<TestICameraProvider> provider = new TestICameraProvider(deviceNames,
547 vendorSection);
548 serviceProxy.setProvider(provider);
549
550 int numProviders = static_cast<int>(serviceProxy.listServices().size());
551
552 res = providerManager->initialize(statusListener, &serviceProxy);
553 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
554 // Check that both "legacy" and "external" providers (really the same object) are called
555 // once for all the init methods
556 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::SET_CALLBACK], numProviders) <<
557 "Only one call to setCallback per provider expected during init";
558 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_VENDOR_TAGS], numProviders) <<
559 "Only one call to getVendorTags per provider expected during init";
560 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::IS_SET_TORCH_MODE_SUPPORTED],
561 numProviders) <<
562 "Only one call to isSetTorchModeSupported per provider expected during init";
563 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_CAMERA_ID_LIST], numProviders) <<
564 "Only one call to getCameraIdList per provider expected during init";
565 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::NOTIFY_DEVICE_STATE], numProviders) <<
566 "Only one call to notifyDeviceState per provider expected during init";
567
568 hardware::hidl_string testProviderFqInterfaceName =
569 "android.hardware.camera.provider@2.4::ICameraProvider";
570 hardware::hidl_string testProviderInstanceName = "test/0";
571 serviceProxy.mManagerNotificationInterface->onRegistration(
572 testProviderFqInterfaceName,
573 testProviderInstanceName, false);
574
575 ASSERT_EQ(serviceProxy.mLastRequestedServiceNames.back(), testProviderInstanceName) <<
576 "Incorrect instance requested from service manager";
577 }
578
TEST(CameraProviderManagerTest,MultipleVendorTagTest)579 TEST(CameraProviderManagerTest, MultipleVendorTagTest) {
580 hardware::hidl_string sectionName = "VendorTestSection";
581 hardware::hidl_string tagName = "VendorTestTag";
582 uint32_t tagId = VENDOR_SECTION << 16;
583 hardware::hidl_vec<common::V1_0::VendorTagSection> vendorSection;
584 CameraMetadataType tagType = CameraMetadataType::BYTE;
585 vendorSection.resize(1);
586 vendorSection[0].sectionName = sectionName;
587 vendorSection[0].tags.resize(1);
588 vendorSection[0].tags[0].tagId = tagId;
589 vendorSection[0].tags[0].tagName = tagName;
590 vendorSection[0].tags[0].tagType = tagType;
591 std::vector<hardware::hidl_string> deviceNames = {"device@3.2/test/0"};
592
593 sp<CameraProviderManager> providerManager = new CameraProviderManager();
594 sp<TestStatusListener> statusListener = new TestStatusListener();
595 TestHidlInteractionProxy serviceProxy;
596
597 sp<TestICameraProvider> provider = new TestICameraProvider(deviceNames,
598 vendorSection);
599 serviceProxy.setProvider(provider);
600
601 auto res = providerManager->initialize(statusListener, &serviceProxy);
602 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
603
604 hardware::hidl_string testProviderInstanceName = "test/0";
605 hardware::hidl_string testProviderFqInterfaceName =
606 "android.hardware.camera.provider@2.4::ICameraProvider";
607 serviceProxy.mManagerNotificationInterface->onRegistration(
608 testProviderFqInterfaceName, testProviderInstanceName, false);
609 ASSERT_EQ(serviceProxy.mLastRequestedServiceNames.back(), testProviderInstanceName) <<
610 "Incorrect instance requested from service manager";
611
612 hardware::hidl_string sectionNameSecond = "SecondVendorTestSection";
613 hardware::hidl_string secondTagName = "SecondVendorTestTag";
614 CameraMetadataType secondTagType = CameraMetadataType::DOUBLE;
615 vendorSection[0].sectionName = sectionNameSecond;
616 vendorSection[0].tags[0].tagId = tagId;
617 vendorSection[0].tags[0].tagName = secondTagName;
618 vendorSection[0].tags[0].tagType = secondTagType;
619 deviceNames = {"device@3.2/test2/1"};
620
621 sp<TestICameraProvider> secondProvider = new TestICameraProvider(
622 deviceNames, vendorSection);
623 serviceProxy.setProvider(secondProvider);
624 hardware::hidl_string testProviderSecondInstanceName = "test2/0";
625 serviceProxy.mManagerNotificationInterface->onRegistration(
626 testProviderFqInterfaceName, testProviderSecondInstanceName, false);
627 ASSERT_EQ(serviceProxy.mLastRequestedServiceNames.back(),
628 testProviderSecondInstanceName) <<
629 "Incorrect instance requested from service manager";
630
631 ASSERT_EQ(NO_ERROR , providerManager->setUpVendorTags());
632 sp<VendorTagDescriptorCache> vendorCache =
633 VendorTagDescriptorCache::getGlobalVendorTagCache();
634 ASSERT_NE(nullptr, vendorCache.get());
635
636 metadata_vendor_id_t vendorId = std::hash<std::string> {} (
637 testProviderInstanceName.c_str());
638 metadata_vendor_id_t vendorIdSecond = std::hash<std::string> {} (
639 testProviderSecondInstanceName.c_str());
640
641 hardware::hidl_string resultTag = vendorCache->getTagName(tagId, vendorId);
642 ASSERT_EQ(resultTag, tagName);
643
644 resultTag = vendorCache->getTagName(tagId, vendorIdSecond);
645 ASSERT_EQ(resultTag, secondTagName);
646
647 // Check whether we can create two separate CameraMetadata instances
648 // using different tag vendor vendors.
649 camera_metadata *metaBuffer = allocate_camera_metadata(10, 20);
650 ASSERT_NE(nullptr, metaBuffer);
651 set_camera_metadata_vendor_id(metaBuffer, vendorId);
652 CameraMetadata metadata(metaBuffer);
653
654 uint8_t byteVal = 10;
655 ASSERT_TRUE(metadata.isEmpty());
656 ASSERT_EQ(OK, metadata.update(tagId, &byteVal, 1));
657 ASSERT_FALSE(metadata.isEmpty());
658 ASSERT_TRUE(metadata.exists(tagId));
659
660 metaBuffer = allocate_camera_metadata(10, 20);
661 ASSERT_NE(nullptr, metaBuffer);
662 set_camera_metadata_vendor_id(metaBuffer, vendorIdSecond);
663 CameraMetadata secondMetadata(metaBuffer);
664
665 ASSERT_TRUE(secondMetadata.isEmpty());
666 double doubleVal = 1.0f;
667 ASSERT_EQ(OK, secondMetadata.update(tagId, &doubleVal, 1));
668 ASSERT_FALSE(secondMetadata.isEmpty());
669 ASSERT_TRUE(secondMetadata.exists(tagId));
670
671 // Check whether CameraMetadata copying works as expected
672 CameraMetadata metadataCopy(metadata);
673 ASSERT_FALSE(metadataCopy.isEmpty());
674 ASSERT_TRUE(metadataCopy.exists(tagId));
675 ASSERT_EQ(OK, metadataCopy.update(tagId, &byteVal, 1));
676 ASSERT_TRUE(metadataCopy.exists(tagId));
677
678 // Check whether values are as expected
679 camera_metadata_entry_t entry = metadata.find(tagId);
680 ASSERT_EQ(1u, entry.count);
681 ASSERT_EQ(byteVal, entry.data.u8[0]);
682 entry = secondMetadata.find(tagId);
683 ASSERT_EQ(1u, entry.count);
684 ASSERT_EQ(doubleVal, entry.data.d[0]);
685
686 // Swap and erase
687 secondMetadata.swap(metadataCopy);
688 ASSERT_TRUE(metadataCopy.exists(tagId));
689 ASSERT_TRUE(secondMetadata.exists(tagId));
690 ASSERT_EQ(OK, secondMetadata.erase(tagId));
691 ASSERT_TRUE(secondMetadata.isEmpty());
692 doubleVal = 0.0f;
693 ASSERT_EQ(OK, metadataCopy.update(tagId, &doubleVal, 1));
694 entry = metadataCopy.find(tagId);
695 ASSERT_EQ(1u, entry.count);
696 ASSERT_EQ(doubleVal, entry.data.d[0]);
697
698 // Append
699 uint8_t sceneMode = ANDROID_CONTROL_SCENE_MODE_ACTION;
700 secondMetadata.update(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1);
701 // Append from two different vendor tag providers is not supported!
702 ASSERT_NE(OK, metadataCopy.append(secondMetadata));
703 ASSERT_EQ(OK, metadataCopy.erase(tagId));
704 metadataCopy.update(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1);
705 // However appending from same vendor tag provider should be fine
706 ASSERT_EQ(OK, metadata.append(secondMetadata));
707 // Append from a metadata without vendor tag provider should be supported
708 CameraMetadata regularMetadata(10, 20);
709 uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO;
710 regularMetadata.update(ANDROID_CONTROL_MODE, &controlMode, 1);
711 ASSERT_EQ(OK, secondMetadata.append(regularMetadata));
712 ASSERT_EQ(2u, secondMetadata.entryCount());
713 ASSERT_EQ(2u, metadata.entryCount());
714
715 // Dump
716 metadata.dump(1, 2);
717 metadataCopy.dump(1, 2);
718 secondMetadata.dump(1, 2);
719 }
720
TEST(CameraProviderManagerTest,NotifyStateChangeTest)721 TEST(CameraProviderManagerTest, NotifyStateChangeTest) {
722 std::vector<hardware::hidl_string> deviceNames {
723 "device@3.2/test/0",
724 "device@1.0/test/0",
725 "device@3.2/test/1"};
726
727 hardware::hidl_vec<common::V1_0::VendorTagSection> vendorSection;
728 status_t res;
729 sp<CameraProviderManager> providerManager = new CameraProviderManager();
730 sp<TestStatusListener> statusListener = new TestStatusListener();
731 TestHidlInteractionProxy serviceProxy;
732 sp<TestICameraProvider> provider = new TestICameraProvider(deviceNames,
733 vendorSection);
734 serviceProxy.setProvider(provider);
735
736 res = providerManager->initialize(statusListener, &serviceProxy);
737 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
738
739 ASSERT_EQ(provider->mCurrentState,
740 static_cast<hardware::hidl_bitfield<DeviceState>>(DeviceState::NORMAL))
741 << "Initial device state not set";
742
743 res = providerManager->notifyDeviceStateChange(
744 static_cast<hardware::hidl_bitfield<DeviceState>>(DeviceState::FOLDED));
745
746 ASSERT_EQ(res, OK) << "Unable to call notifyDeviceStateChange";
747 ASSERT_EQ(provider->mCurrentState,
748 static_cast<hardware::hidl_bitfield<DeviceState>>(DeviceState::FOLDED))
749 << "Unable to change device state";
750
751 }
752
753 // Test that CameraProviderManager doesn't get stuck when the camera HAL isn't really working
TEST(CameraProviderManagerTest,BadHalStartupTest)754 TEST(CameraProviderManagerTest, BadHalStartupTest) {
755
756 std::vector<hardware::hidl_string> deviceNames;
757 deviceNames.push_back("device@3.2/test/0");
758 deviceNames.push_back("device@1.0/test/0");
759 deviceNames.push_back("device@3.2/test/1");
760 hardware::hidl_vec<common::V1_0::VendorTagSection> vendorSection;
761 status_t res;
762
763 sp<CameraProviderManager> providerManager = new CameraProviderManager();
764 sp<TestStatusListener> statusListener = new TestStatusListener();
765 TestHidlInteractionProxy serviceProxy;
766 sp<TestICameraProvider> provider = new TestICameraProvider(deviceNames,
767 vendorSection);
768
769 // Not setting up provider in the service proxy yet, to test cases where a
770 // HAL isn't starting right
771 res = providerManager->initialize(statusListener, &serviceProxy);
772 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
773
774 // Now set up provider and trigger a registration
775 serviceProxy.setProvider(provider);
776 int numProviders = static_cast<int>(serviceProxy.listServices().size());
777
778 hardware::hidl_string testProviderFqInterfaceName =
779 "android.hardware.camera.provider@2.4::ICameraProvider";
780 hardware::hidl_string testProviderInstanceName = "test/0";
781 serviceProxy.mManagerNotificationInterface->onRegistration(
782 testProviderFqInterfaceName,
783 testProviderInstanceName, false);
784
785 // Check that new provider is called once for all the init methods
786 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::SET_CALLBACK], numProviders) <<
787 "Only one call to setCallback per provider expected during register";
788 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_VENDOR_TAGS], numProviders) <<
789 "Only one call to getVendorTags per provider expected during register";
790 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::IS_SET_TORCH_MODE_SUPPORTED],
791 numProviders) <<
792 "Only one call to isSetTorchModeSupported per provider expected during init";
793 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::GET_CAMERA_ID_LIST], numProviders) <<
794 "Only one call to getCameraIdList per provider expected during init";
795 EXPECT_EQ(provider->mCalledCounter[TestICameraProvider::NOTIFY_DEVICE_STATE], numProviders) <<
796 "Only one call to notifyDeviceState per provider expected during init";
797
798 ASSERT_EQ(serviceProxy.mLastRequestedServiceNames.back(), testProviderInstanceName) <<
799 "Incorrect instance requested from service manager";
800 }
801
802 // Test that CameraProviderManager can handle races between provider death notifications and
803 // provider registration callbacks
TEST(CameraProviderManagerTest,BinderDeathRegistrationRaceTest)804 TEST(CameraProviderManagerTest, BinderDeathRegistrationRaceTest) {
805
806 std::vector<hardware::hidl_string> deviceNames;
807 deviceNames.push_back("device@3.2/test/0");
808 deviceNames.push_back("device@3.2/test/1");
809 hardware::hidl_vec<common::V1_0::VendorTagSection> vendorSection;
810 status_t res;
811
812 sp<CameraProviderManager> providerManager = new CameraProviderManager();
813 sp<TestStatusListener> statusListener = new TestStatusListener();
814 TestHidlInteractionProxy serviceProxy;
815 sp<TestICameraProvider> provider = new TestICameraProvider(deviceNames,
816 vendorSection);
817
818 // Not setting up provider in the service proxy yet, to test cases where a
819 // HAL isn't starting right
820 res = providerManager->initialize(statusListener, &serviceProxy);
821 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
822
823 // Now set up provider and trigger a registration
824 serviceProxy.setProvider(provider);
825
826 hardware::hidl_string testProviderFqInterfaceName =
827 "android.hardware.camera.provider@2.4::ICameraProvider";
828 hardware::hidl_string testProviderInstanceName = "test/0";
829 serviceProxy.mManagerNotificationInterface->onRegistration(
830 testProviderFqInterfaceName,
831 testProviderInstanceName, false);
832
833 // Simulate artificial delay of the registration callback which arrives before the
834 // death notification
835 serviceProxy.mManagerNotificationInterface->onRegistration(
836 testProviderFqInterfaceName,
837 testProviderInstanceName, false);
838
839 provider->signalInitialBinderDeathRecipient();
840
841 auto deviceCount = static_cast<unsigned> (providerManager->getCameraCount().second);
842 ASSERT_EQ(deviceCount, deviceNames.size()) <<
843 "Unexpected amount of camera devices";
844 }
845
846 // Test that CameraProviderManager does not trigger
847 // onDeviceStatusChanged(NOT_PRESENT) for physical camera before initialize()
848 // returns.
TEST(CameraProviderManagerTest,PhysicalCameraAvailabilityCallbackRaceTest)849 TEST(CameraProviderManagerTest, PhysicalCameraAvailabilityCallbackRaceTest) {
850 std::vector<hardware::hidl_string> deviceNames;
851 deviceNames.push_back("device@3.2/test/0");
852 hardware::hidl_vec<common::V1_0::VendorTagSection> vendorSection;
853
854 sp<CameraProviderManager> providerManager = new CameraProviderManager();
855 sp<TestStatusListener> statusListener = new TestStatusListener();
856 TestHidlInteractionProxy serviceProxy;
857
858 android::hardware::hidl_vec<uint8_t> chars;
859 CameraMetadata meta;
860 int32_t charKeys[] = { ANDROID_REQUEST_AVAILABLE_CAPABILITIES };
861 meta.update(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, charKeys,
862 sizeof(charKeys) / sizeof(charKeys[0]));
863 uint8_t capabilities[] = { ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA };
864 meta.update(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, capabilities,
865 sizeof(capabilities)/sizeof(capabilities[0]));
866 uint8_t physicalCameraIds[] = { '2', '\0', '3', '\0' };
867 meta.update(ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS, physicalCameraIds,
868 sizeof(physicalCameraIds)/sizeof(physicalCameraIds[0]));
869 camera_metadata_t* metaBuffer = const_cast<camera_metadata_t*>(meta.getAndLock());
870 chars.setToExternal(reinterpret_cast<uint8_t*>(metaBuffer),
871 get_camera_metadata_size(metaBuffer));
872
873 sp<TestICameraProvider> provider = new TestICameraProvider(deviceNames,
874 vendorSection, chars, "device@3.2/test/0", "2");
875 serviceProxy.setProvider(provider);
876
877 status_t res = providerManager->initialize(statusListener, &serviceProxy);
878 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
879
880 ASSERT_EQ(statusListener->mPhysicalCameraStatusChangeCount, 0)
881 << "Unexpected physical camera status change callback upon provider init.";
882
883 std::unordered_map<std::string, std::set<std::string>> unavailablePhysicalIds;
884 auto cameraIds = providerManager->getCameraDeviceIds(&unavailablePhysicalIds);
885 ASSERT_TRUE(unavailablePhysicalIds.count("0") > 0 && unavailablePhysicalIds["0"].count("2") > 0)
886 << "Unavailable physical camera Ids not set properly.";
887 }
TEST_WITH_FLAGS(CameraProviderManagerTest,AidlVirtualCameraProviderDiscovered,REQUIRES_FLAGS_ENABLED (ACONFIG_FLAG (vd_flags,virtual_camera_service_discovery)))888 TEST_WITH_FLAGS(CameraProviderManagerTest, AidlVirtualCameraProviderDiscovered,
889 REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(vd_flags, virtual_camera_service_discovery))) {
890 sp<CameraProviderManager> providerManager = new CameraProviderManager();
891 sp<TestStatusListener> statusListener = new TestStatusListener();
892 TestAidlInteractionProxy aidlServiceProxy;
893 TestHidlInteractionProxy hidlServiceProxy;
894
895 status_t res = providerManager->initialize(statusListener,
896 &hidlServiceProxy, &aidlServiceProxy);
897 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
898
899 std::vector<std::string> cameraList = {"device@1.1/virtual/123"};
900
901 std::shared_ptr<TestAidlICameraProvider> aidlProvider =
902 ndk::SharedRefBase::make<TestAidlICameraProvider>(cameraList);
903 ndk::SpAIBinder spBinder = aidlProvider->asBinder();
904 AIBinder* aiBinder = spBinder.get();
905 aidlServiceProxy.setProvider(aidlProvider);
906 providerManager->onServiceRegistration(
907 String16("android.hardware.camera.provider.ICameraProvider/virtual/0"),
908 AIBinder_toPlatformBinder(aiBinder));
909
910 std::unordered_map<std::string, std::set<std::string>> unavailableDeviceIds;
911 auto cameraIds = providerManager->getCameraDeviceIds(&unavailableDeviceIds);
912
913 EXPECT_THAT(cameraIds, ElementsAre("123"));
914 }
915
TEST_WITH_FLAGS(CameraProviderManagerTest,AidlVirtualCameraProviderDiscoveredOnInit,REQUIRES_FLAGS_ENABLED (ACONFIG_FLAG (vd_flags,virtual_camera_service_discovery)))916 TEST_WITH_FLAGS(CameraProviderManagerTest, AidlVirtualCameraProviderDiscoveredOnInit,
917 REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(vd_flags, virtual_camera_service_discovery))) {
918 sp<CameraProviderManager> providerManager = new CameraProviderManager();
919 sp<TestStatusListener> statusListener = new TestStatusListener();
920 TestAidlInteractionProxy aidlServiceProxy;
921 TestHidlInteractionProxy hidlServiceProxy;
922
923 std::vector<std::string> cameraList = {"device@1.1/virtual/123"};
924
925 std::shared_ptr<TestAidlICameraProvider> aidlProvider =
926 ndk::SharedRefBase::make<TestAidlICameraProvider>(cameraList);
927 aidlServiceProxy.setProvider(aidlProvider);
928
929 status_t res = providerManager->initialize(statusListener,
930 &hidlServiceProxy, &aidlServiceProxy);
931 ASSERT_EQ(res, OK) << "Unable to initialize provider manager";
932
933 std::unordered_map<std::string, std::set<std::string>> unavailableDeviceIds;
934 std::vector<std::string> cameraIds = providerManager->getCameraDeviceIds(&unavailableDeviceIds);
935
936 EXPECT_THAT(cameraIds, ElementsAre("123"));
937 }
938