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 CPP_EVS_MANAGER_1_1_ENUMERATOR_H_ 18 #define CPP_EVS_MANAGER_1_1_ENUMERATOR_H_ 19 20 #include "HalCamera.h" 21 #include "IEnumeratorManager.h" 22 #include "IPermissionsChecker.h" 23 #include "ServiceFactory.h" 24 #include "VirtualCamera.h" 25 #include "emul/EvsEmulatedCamera.h" 26 #include "stats/IStatsCollector.h" 27 #include "stats/StatsCollector.h" 28 29 #include <android/hardware/automotive/evs/1.1/IEvsDisplay.h> 30 #include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h> 31 #include <android/hardware/camera/device/3.2/ICameraDevice.h> 32 #include <system/camera_metadata.h> 33 34 #include <list> 35 #include <memory> 36 #include <unordered_map> 37 #include <unordered_set> 38 39 namespace android::automotive::evs::V1_1::implementation { 40 41 // Passthrough to remove static cling and allow for mocking. 42 class ProdServiceFactory : public ServiceFactory { 43 public: ProdServiceFactory(const char * hardwareServiceName)44 explicit ProdServiceFactory(const char* hardwareServiceName) : 45 mService(IEvsEnumerator::getService(hardwareServiceName)) {} 46 virtual ~ProdServiceFactory() = default; 47 getService()48 ::android::hardware::automotive::evs::V1_1::IEvsEnumerator* getService() override { 49 return mService.get(); 50 } 51 52 private: 53 sp<::android::hardware::automotive::evs::V1_1::IEvsEnumerator> mService; 54 }; 55 56 class Enumerator : public IEvsEnumerator { 57 public: 58 // For testing. 59 explicit Enumerator(std::unique_ptr<ServiceFactory> serviceFactory, 60 std::unique_ptr<IStatsCollector> statsCollector, 61 std::unique_ptr<IPermissionsChecker> permissionChecker); 62 63 static std::unique_ptr<Enumerator> build(const char* hardwareServiceName); 64 static std::unique_ptr<Enumerator> build( 65 std::unique_ptr<ServiceFactory> serviceFactory, 66 std::unique_ptr<IStatsCollector> statsCollector, 67 std::unique_ptr<IPermissionsChecker> permissionChecker); 68 69 virtual ~Enumerator() = default; 70 71 // Methods from hardware::automotive::evs::V1_0::IEvsEnumerator follow. 72 hardware::Return<void> getCameraList(getCameraList_cb _hidl_cb) override; 73 hardware::Return<sp<hardware::automotive::evs::V1_0::IEvsCamera>> openCamera( 74 const hardware::hidl_string& cameraId) override; 75 hardware::Return<void> closeCamera( 76 const ::android::sp<hardware::automotive::evs::V1_0::IEvsCamera>& virtualCamera) 77 override; 78 hardware::Return<sp<hardware::automotive::evs::V1_0::IEvsDisplay>> openDisplay() override; 79 hardware::Return<void> closeDisplay( 80 const ::android::sp<hardware::automotive::evs::V1_0::IEvsDisplay>& display) override; 81 hardware::Return<hardware::automotive::evs::V1_0::DisplayState> getDisplayState() override; 82 83 // Methods from hardware::automotive::evs::V1_1::IEvsEnumerator follow. 84 hardware::Return<void> getCameraList_1_1(getCameraList_1_1_cb _hidl_cb) override; 85 hardware::Return<sp<hardware::automotive::evs::V1_1::IEvsCamera>> openCamera_1_1( 86 const hardware::hidl_string& cameraId, 87 const hardware::camera::device::V3_2::Stream& streamCfg) override; isHardware()88 hardware::Return<bool> isHardware() override { return false; } 89 hardware::Return<void> getDisplayIdList(getDisplayIdList_cb _list_cb) override; 90 hardware::Return<sp<hardware::automotive::evs::V1_1::IEvsDisplay>> openDisplay_1_1( 91 uint8_t id) override; 92 hardware::Return<void> getUltrasonicsArrayList(getUltrasonicsArrayList_cb _hidl_cb) override; 93 hardware::Return<sp<IEvsUltrasonicsArray>> openUltrasonicsArray( 94 const hardware::hidl_string& ultrasonicsArrayId) override; 95 hardware::Return<void> closeUltrasonicsArray( 96 const ::android::sp<IEvsUltrasonicsArray>& evsUltrasonicsArray) override; 97 98 // Methods from ::android.hidl.base::V1_0::IBase follow. 99 hardware::Return<void> debug(const hardware::hidl_handle& fd, 100 const hidl_vec<hardware::hidl_string>& options) override; 101 102 private: 103 bool isLogicalCamera(const camera_metadata_t* metadata); 104 std::unordered_set<std::string> getPhysicalCameraIds(const std::string& id); 105 106 const std::unique_ptr<ServiceFactory> mServiceFactory; 107 const std::unique_ptr<IStatsCollector> mStatsCollector; 108 const std::unique_ptr<IPermissionsChecker> mPermissionChecker; 109 110 wp<hardware::automotive::evs::V1_0::IEvsDisplay> mActiveDisplay; 111 112 // List of active camera proxy objects that wrap hw cameras 113 std::unordered_map<std::string, sp<HalCamera>> mActiveCameras; 114 115 // List of camera descriptors of enumerated hw cameras 116 std::unordered_map<std::string, CameraDesc> mCameraDevices; 117 118 // List of available physical display devices 119 std::list<uint8_t> mDisplayPorts; 120 121 // Display port the internal display is connected to. 122 uint8_t mInternalDisplayPort; 123 124 // Boolean flag to tell whether the camera usages are being monitored or not. 125 bool mMonitorEnabled = false; 126 127 // Boolean flag to tell whether EvsDisplay is owned exclusively or not. 128 bool mDisplayOwnedExclusively = false; 129 130 // LSHAL dump 131 void cmdDump(int fd, const hidl_vec<hardware::hidl_string>& options); 132 void cmdHelp(int fd); 133 void cmdList(int fd, const hidl_vec<hardware::hidl_string>& options); 134 void cmdDumpDevice(int fd, const hidl_vec<hardware::hidl_string>& options); 135 136 // List of emulated camera devices 137 std::unordered_map<std::string, EmulatedCameraDesc> mEmulatedCameraDevices; 138 139 // LSHAL command to use emulated camera device 140 void cmdConfigureEmulatedCamera(int fd, const hidl_vec<hardware::hidl_string>& options); 141 }; 142 143 } // namespace android::automotive::evs::V1_1::implementation 144 145 #endif // CPP_EVS_MANAGER_1_1_ENUMERATOR_H_ 146