1 /* 2 * Copyright (C) 2019 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 HARDWARE_GOOGLE_CAMERA_HAL_TESTS_MOCK_PROVIDER_HWL_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_TESTS_MOCK_PROVIDER_HWL_H_ 19 20 #include <camera_buffer_allocator_hwl.h> 21 #include <camera_id_manager.h> 22 #include <camera_provider_hwl.h> 23 #include <hal_types.h> 24 25 namespace android { 26 namespace google_camera_hal { 27 28 class MockProviderHwl : public CameraProviderHwl { 29 public: Create()30 static std::unique_ptr<MockProviderHwl> Create() { 31 return std::unique_ptr<MockProviderHwl>(new MockProviderHwl()); 32 } 33 34 virtual ~MockProviderHwl() = default; 35 36 // Override functions in CameraProviderHwl. SetCallback(const HwlCameraProviderCallback & callback)37 status_t SetCallback(const HwlCameraProviderCallback& callback) override { 38 const HwlCameraProviderCallback* hwl_camera_provider_callback = &callback; 39 if (hwl_camera_provider_callback == nullptr) { 40 return BAD_VALUE; 41 } 42 43 hwl_camera_provider_callback->camera_device_status_change( 44 /*camera_id=*/0, camera_device_status_); 45 hwl_camera_provider_callback->torch_mode_status_change( 46 /*camera_id=*/0, torch_status_); 47 return OK; 48 }; 49 TriggerDeferredCallbacks()50 status_t TriggerDeferredCallbacks() override { 51 return OK; 52 }; 53 GetVendorTags(std::vector<VendorTagSection> * vendor_tag_sections)54 status_t GetVendorTags( 55 std::vector<VendorTagSection>* vendor_tag_sections) override { 56 if (vendor_tag_sections == nullptr) { 57 return BAD_VALUE; 58 } 59 60 *vendor_tag_sections = vendor_tag_sections_; 61 return OK; 62 } 63 GetVisibleCameraIds(std::vector<uint32_t> * cameras_ids)64 status_t GetVisibleCameraIds(std::vector<uint32_t>* cameras_ids) override { 65 if (cameras_ids == nullptr) { 66 return BAD_VALUE; 67 } 68 69 cameras_ids->clear(); 70 for (auto camera : cameras_) { 71 if (camera.visible_to_framework) { 72 cameras_ids->push_back(camera.id); 73 } 74 } 75 return OK; 76 } 77 IsSetTorchModeSupported()78 bool IsSetTorchModeSupported() override { 79 return is_torch_supported_; 80 } 81 IsConcurrentStreamCombinationSupported(const std::vector<CameraIdAndStreamConfiguration> &,bool * is_supported)82 status_t IsConcurrentStreamCombinationSupported( 83 const std::vector<CameraIdAndStreamConfiguration>&, 84 bool* is_supported) override { 85 if (is_supported == nullptr) { 86 return BAD_VALUE; 87 } 88 *is_supported = false; 89 return OK; 90 } 91 GetConcurrentStreamingCameraIds(std::vector<std::unordered_set<uint32_t>> *)92 status_t GetConcurrentStreamingCameraIds( 93 std::vector<std::unordered_set<uint32_t>>*) override { 94 return OK; 95 } 96 CreateCameraDeviceHwl(uint32_t,std::unique_ptr<CameraDeviceHwl> *)97 status_t CreateCameraDeviceHwl( 98 uint32_t /*cameraId*/, 99 std::unique_ptr<CameraDeviceHwl>* /*camera_device_hwl*/) override { 100 // TODO(b/138960498): support mock device HWL. 101 return INVALID_OPERATION; 102 } 103 CreateBufferAllocatorHwl(std::unique_ptr<CameraBufferAllocatorHwl> * camera_buffer_allocator_hwl)104 status_t CreateBufferAllocatorHwl(std::unique_ptr<CameraBufferAllocatorHwl>* 105 camera_buffer_allocator_hwl) override { 106 if (camera_buffer_allocator_hwl == nullptr) { 107 ALOGE("%s: camera_buffer_allocator_hwl is nullptr.", __FUNCTION__); 108 return BAD_VALUE; 109 } 110 111 return OK; 112 } 113 // End of override functions in CameraProviderHwl. 114 115 // The following members are public so the test can change the values easily. 116 std::vector<VendorTagSection> vendor_tag_sections_; 117 std::vector<CameraIdMap> cameras_; 118 bool is_torch_supported_ = false; 119 CameraDeviceStatus camera_device_status_ = CameraDeviceStatus::kNotPresent; 120 TorchModeStatus torch_status_ = TorchModeStatus::kAvailableOff; 121 122 private: 123 MockProviderHwl() = default; 124 }; 125 } // namespace google_camera_hal 126 } // namespace android 127 128 #endif // HARDWARE_GOOGLE_CAMERA_HAL_TESTS_MOCK_PROVIDER_HWL_H_ 129