/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CPP_EVS_MANAGER_1_1_ENUMERATOR_H_ #define CPP_EVS_MANAGER_1_1_ENUMERATOR_H_ #include "HalCamera.h" #include "IEnumeratorManager.h" #include "IPermissionsChecker.h" #include "ServiceFactory.h" #include "VirtualCamera.h" #include "emul/EvsEmulatedCamera.h" #include "stats/IStatsCollector.h" #include "stats/StatsCollector.h" #include #include #include #include #include #include #include #include namespace android::automotive::evs::V1_1::implementation { // Passthrough to remove static cling and allow for mocking. class ProdServiceFactory : public ServiceFactory { public: explicit ProdServiceFactory(const char* hardwareServiceName) : mService(IEvsEnumerator::getService(hardwareServiceName)) {} virtual ~ProdServiceFactory() = default; ::android::hardware::automotive::evs::V1_1::IEvsEnumerator* getService() override { return mService.get(); } private: sp<::android::hardware::automotive::evs::V1_1::IEvsEnumerator> mService; }; class Enumerator : public IEvsEnumerator { public: // For testing. explicit Enumerator(std::unique_ptr serviceFactory, std::unique_ptr statsCollector, std::unique_ptr permissionChecker); static std::unique_ptr build(const char* hardwareServiceName); static std::unique_ptr build( std::unique_ptr serviceFactory, std::unique_ptr statsCollector, std::unique_ptr permissionChecker); virtual ~Enumerator() = default; // Methods from hardware::automotive::evs::V1_0::IEvsEnumerator follow. hardware::Return getCameraList(getCameraList_cb _hidl_cb) override; hardware::Return> openCamera( const hardware::hidl_string& cameraId) override; hardware::Return closeCamera( const ::android::sp& virtualCamera) override; hardware::Return> openDisplay() override; hardware::Return closeDisplay( const ::android::sp& display) override; hardware::Return getDisplayState() override; // Methods from hardware::automotive::evs::V1_1::IEvsEnumerator follow. hardware::Return getCameraList_1_1(getCameraList_1_1_cb _hidl_cb) override; hardware::Return> openCamera_1_1( const hardware::hidl_string& cameraId, const hardware::camera::device::V3_2::Stream& streamCfg) override; hardware::Return isHardware() override { return false; } hardware::Return getDisplayIdList(getDisplayIdList_cb _list_cb) override; hardware::Return> openDisplay_1_1( uint8_t id) override; hardware::Return getUltrasonicsArrayList(getUltrasonicsArrayList_cb _hidl_cb) override; hardware::Return> openUltrasonicsArray( const hardware::hidl_string& ultrasonicsArrayId) override; hardware::Return closeUltrasonicsArray( const ::android::sp& evsUltrasonicsArray) override; // Methods from ::android.hidl.base::V1_0::IBase follow. hardware::Return debug(const hardware::hidl_handle& fd, const hidl_vec& options) override; private: bool isLogicalCamera(const camera_metadata_t* metadata); std::unordered_set getPhysicalCameraIds(const std::string& id); const std::unique_ptr mServiceFactory; const std::unique_ptr mStatsCollector; const std::unique_ptr mPermissionChecker; wp mActiveDisplay; // List of active camera proxy objects that wrap hw cameras std::unordered_map> mActiveCameras; // List of camera descriptors of enumerated hw cameras std::unordered_map mCameraDevices; // List of available physical display devices std::list mDisplayPorts; // Display port the internal display is connected to. uint8_t mInternalDisplayPort; // Boolean flag to tell whether the camera usages are being monitored or not. bool mMonitorEnabled = false; // Boolean flag to tell whether EvsDisplay is owned exclusively or not. bool mDisplayOwnedExclusively = false; // LSHAL dump void cmdDump(int fd, const hidl_vec& options); void cmdHelp(int fd); void cmdList(int fd, const hidl_vec& options); void cmdDumpDevice(int fd, const hidl_vec& options); // List of emulated camera devices std::unordered_map mEmulatedCameraDevices; // LSHAL command to use emulated camera device void cmdConfigureEmulatedCamera(int fd, const hidl_vec& options); }; } // namespace android::automotive::evs::V1_1::implementation #endif // CPP_EVS_MANAGER_1_1_ENUMERATOR_H_