Venkatarama Avadhani | 90373fe | 2022-11-11 16:54:53 +0530 | [diff] [blame^] | 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 | #define LOG_TAG "android.hardware.tv.earc" |
| 18 | #include <android-base/logging.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include "EArcMock.h" |
| 23 | |
| 24 | using ndk::ScopedAStatus; |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace tv { |
| 29 | namespace earc { |
| 30 | namespace implementation { |
| 31 | |
| 32 | void EArcMock::serviceDied(void* cookie) { |
| 33 | ALOGE("EArcMock died"); |
| 34 | auto eArc = static_cast<EArcMock*>(cookie); |
| 35 | eArc->mEArcEnabled = false; |
| 36 | } |
| 37 | |
| 38 | ScopedAStatus EArcMock::setEArcEnabled(bool in_enabled) { |
| 39 | mEArcEnabled = in_enabled; |
| 40 | if (mEArcEnabled != in_enabled) { |
| 41 | return ScopedAStatus::fromServiceSpecificError( |
| 42 | static_cast<int32_t>(Result::FAILURE_UNKNOWN)); |
| 43 | } else { |
| 44 | return ScopedAStatus::ok(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | ScopedAStatus EArcMock::isEArcEnabled(bool* _aidl_return) { |
| 49 | *_aidl_return = mEArcEnabled; |
| 50 | return ScopedAStatus::ok(); |
| 51 | } |
| 52 | |
| 53 | ScopedAStatus EArcMock::getState(int32_t portId, IEArcStatus* _aidl_return) { |
| 54 | // Maintain port connection status and update on hotplug event |
| 55 | if (portId <= mTotalPorts && portId >= 1) { |
| 56 | *_aidl_return = mPortStatus[portId]; |
| 57 | } else { |
| 58 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 59 | } |
| 60 | |
| 61 | return ScopedAStatus::ok(); |
| 62 | } |
| 63 | |
| 64 | ScopedAStatus EArcMock::getLastReportedAudioCapabilities(int32_t portId, |
| 65 | std::vector<uint8_t>* _aidl_return) { |
| 66 | if (portId <= mTotalPorts && portId >= 1) { |
| 67 | *_aidl_return = mCapabilities[portId]; |
| 68 | } else { |
| 69 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 70 | } |
| 71 | |
| 72 | return ScopedAStatus::ok(); |
| 73 | } |
| 74 | |
| 75 | ScopedAStatus EArcMock::setCallback(const std::shared_ptr<IEArcCallback>& callback) { |
| 76 | if (mCallback != nullptr) { |
| 77 | mCallback = nullptr; |
| 78 | } |
| 79 | |
| 80 | if (callback != nullptr) { |
| 81 | mCallback = callback; |
| 82 | AIBinder_linkToDeath(this->asBinder().get(), mDeathRecipient.get(), 0 /* cookie */); |
| 83 | } |
| 84 | return ScopedAStatus::ok(); |
| 85 | } |
| 86 | |
| 87 | ScopedAStatus EArcMock::reportCapabilities(const std::vector<uint8_t> capabilities, |
| 88 | int32_t portId) { |
| 89 | if (mCallback != nullptr) { |
| 90 | mCallback->onCapabilitiesReported(capabilities, portId); |
| 91 | return ScopedAStatus::ok(); |
| 92 | } else { |
| 93 | return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | ScopedAStatus EArcMock::changeState(const IEArcStatus status, int32_t portId) { |
| 98 | if (mCallback != nullptr) { |
| 99 | mCallback->onStateChange(status, portId); |
| 100 | return ScopedAStatus::ok(); |
| 101 | } else { |
| 102 | return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | EArcMock::EArcMock() { |
| 107 | ALOGE("[halimp_aidl] Opening a virtual eARC HAL for testing and virtual machine."); |
| 108 | mCallback = nullptr; |
| 109 | mCapabilities.resize(mTotalPorts); |
| 110 | mPortStatus.resize(mTotalPorts); |
| 111 | mPortStatus[0] = IEArcStatus::STATUS_IDLE; |
| 112 | mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied)); |
| 113 | } |
| 114 | |
| 115 | } // namespace implementation |
| 116 | } // namespace earc |
| 117 | } // namespace tv |
| 118 | } // namespace hardware |
| 119 | } // namespace android |