/* * Copyright (C) 2022 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_AIDL_INCLUDE_ENUMERATOR_H #define CPP_EVS_MANAGER_AIDL_INCLUDE_ENUMERATOR_H #include "HalCamera.h" #include "VirtualCamera.h" #include "stats/include/StatsCollector.h" #include #include #include #include #include #include #include #include namespace aidl::android::automotive::evs::implementation { namespace aidlevs = ::aidl::android::hardware::automotive::evs; class Enumerator final : public ::aidl::android::hardware::automotive::evs::BnEvsEnumerator { public: // Methods from ::aidl::android::hardware::automotive::evs::IEvsEnumerator ::ndk::ScopedAStatus isHardware(bool* flag) override; ::ndk::ScopedAStatus openCamera(const std::string& cameraId, const aidlevs::Stream& streamConfig, std::shared_ptr* obj) override; ::ndk::ScopedAStatus closeCamera(const std::shared_ptr& obj) override; ::ndk::ScopedAStatus getCameraList(std::vector* _aidl_return) override; ::ndk::ScopedAStatus getStreamList(const aidlevs::CameraDesc& desc, std::vector* _aidl_return) override; ::ndk::ScopedAStatus openDisplay(int32_t displayId, std::shared_ptr* obj) override; ::ndk::ScopedAStatus closeDisplay(const std::shared_ptr& obj) override; ::ndk::ScopedAStatus getDisplayIdList(std::vector* list) override; ::ndk::ScopedAStatus getDisplayState(aidlevs::DisplayState* state) override; ::ndk::ScopedAStatus getDisplayStateById(int32_t displayId, aidlevs::DisplayState* state) override; ::ndk::ScopedAStatus registerStatusCallback( const std::shared_ptr& callback) override; ::ndk::ScopedAStatus openUltrasonicsArray( const std::string& id, std::shared_ptr* obj) override; ::ndk::ScopedAStatus closeUltrasonicsArray( const std::shared_ptr& obj) override; ::ndk::ScopedAStatus getUltrasonicsArrayList( std::vector* list) override; // Method from ::ndk::ICInterface binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; // Implementation details bool init(const std::string_view& hardwareServiceName); void broadcastDeviceStatusChange(const std::vector& list); // Destructor virtual ~Enumerator(); // TODO(b/235110887): We may eventually want to remove below two methods and // replace their functionality with other methods more // elegant. bool init(std::shared_ptr& hwEnumerator, bool enableMonitor = false); void enablePermissionCheck(bool enable); private: class EvsDeviceStatusCallbackImpl : public aidlevs::BnEvsEnumeratorStatusCallback { public: EvsDeviceStatusCallbackImpl(const std::shared_ptr& enumerator) : mEnumerator(enumerator) {} ::ndk::ScopedAStatus deviceStatusChanged( const std::vector& status) override; private: std::shared_ptr mEnumerator; }; bool checkPermission() const; bool isLogicalCamera(const camera_metadata_t* metadata) const; std::unordered_set getPhysicalCameraIds(const std::string& id); std::shared_ptr connectToAidlHal( const std::string_view& hardwareServiceName, bool blocking); std::shared_ptr connectToHidlHal( const std::string_view& hardwareServiceName); void cmdDump(int fd, const char** args, uint32_t numArgs); void cmdHelp(int fd); void cmdList(int fd, const char** args, uint32_t numArgs); void cmdDumpDevice(int fd, const char** args, uint32_t numArgs); // Hardware enumerator std::shared_ptr mHwEnumerator; // Display proxy object warpping hw display std::weak_ptr 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::vector mDisplayPorts; // Display port the internal display is connected to. int32_t mInternalDisplayPort; // Collecting camera usage statistics from clients ::android::sp mClientsMonitor; // Boolean flag to tell whether the camera usages are being monitored or not bool mMonitorEnabled; // Boolean flag to tell whether EvsDisplay is owned exclusively or not bool mDisplayOwnedExclusively; // Callback to listen to device status changes std::shared_ptr mDeviceStatusCallback; // Mutex to protect resources related with a device status callback mutable std::shared_mutex mLock; // Clients to forward device status callback messages std::set> mDeviceStatusCallbacks; bool mDisablePermissionCheck = false; std::list> mActiveCameraClients; }; } // namespace aidl::android::automotive::evs::implementation #endif // CPP_EVS_MANAGER_AIDL_INCLUDE_ENUMERATOR_H