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