1 /* 2 * Copyright (C) 2022 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 #include <aidl/android/hardware/tv/hdmi/earc/BnEArc.h> 18 #include <aidl/android/hardware/tv/hdmi/earc/Result.h> 19 #include <algorithm> 20 #include <vector> 21 22 using namespace std; 23 24 namespace android { 25 namespace hardware { 26 namespace tv { 27 namespace hdmi { 28 namespace earc { 29 namespace implementation { 30 31 using ::aidl::android::hardware::tv::hdmi::earc::BnEArc; 32 using ::aidl::android::hardware::tv::hdmi::earc::IEArc; 33 using ::aidl::android::hardware::tv::hdmi::earc::IEArcCallback; 34 using ::aidl::android::hardware::tv::hdmi::earc::IEArcStatus; 35 using ::aidl::android::hardware::tv::hdmi::earc::Result; 36 37 struct EArcMock : public BnEArc { 38 EArcMock(); 39 40 ::ndk::ScopedAStatus setEArcEnabled(bool in_enabled) override; 41 ::ndk::ScopedAStatus isEArcEnabled(bool* _aidl_return) override; 42 ::ndk::ScopedAStatus setCallback(const std::shared_ptr<IEArcCallback>& in_callback) override; 43 ::ndk::ScopedAStatus getState(int32_t in_portId, IEArcStatus* _aidl_return) override; 44 ::ndk::ScopedAStatus getLastReportedAudioCapabilities( 45 int32_t in_portId, std::vector<uint8_t>* _aidl_return) override; 46 ::ndk::ScopedAStatus reportCapabilities(const std::vector<uint8_t>& capabilities, 47 int32_t portId); 48 ::ndk::ScopedAStatus changeState(const IEArcStatus status, int32_t portId); 49 50 private: 51 static void* __threadLoop(void* data); 52 void threadLoop(); 53 54 private: 55 static void serviceDied(void* cookie); 56 std::shared_ptr<IEArcCallback> mCallback; 57 58 // Variables for the virtual EARC hal impl 59 std::vector<std::vector<uint8_t>> mCapabilities; 60 std::vector<IEArcStatus> mPortStatus; 61 bool mEArcEnabled = true; 62 63 // Port configuration 64 int mTotalPorts = 1; 65 66 // Testing variables 67 pthread_t mThreadId = 0; 68 69 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; 70 }; 71 } // namespace implementation 72 } // namespace earc 73 } // Namespace hdmi 74 } // Namespace tv 75 } // namespace hardware 76 } // namespace android 77