1 /* 2 * Copyright (C) 2024 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 "MockBroadcastRadioCallback.h" 18 19 #include <android-base/logging.h> 20 21 namespace aidl::android::hardware::broadcastradio { 22 23 namespace { 24 using std::vector; 25 } 26 MockBroadcastRadioCallback()27MockBroadcastRadioCallback::MockBroadcastRadioCallback() { 28 mAntennaConnectionState = true; 29 } 30 onTuneFailed(Result result,const ProgramSelector & selector)31ScopedAStatus MockBroadcastRadioCallback::onTuneFailed(Result result, 32 const ProgramSelector& selector) { 33 LOG(DEBUG) << "onTuneFailed with result with " << selector.toString().c_str(); 34 if (result != Result::CANCELED) { 35 std::lock_guard<std::mutex> lk(mLock); 36 tunerFailed = true; 37 } 38 return ndk::ScopedAStatus::ok(); 39 } 40 onCurrentProgramInfoChanged(const ProgramInfo & info)41ScopedAStatus MockBroadcastRadioCallback::onCurrentProgramInfoChanged(const ProgramInfo& info) { 42 LOG(DEBUG) << "onCurrentProgramInfoChanged with " << info.toString().c_str(); 43 { 44 std::lock_guard<std::mutex> lk(mLock); 45 mCurrentProgramInfo = info; 46 } 47 48 mOnCurrentProgramInfoChangedFlag.notify(); 49 return ndk::ScopedAStatus::ok(); 50 } 51 onProgramListUpdated(const ProgramListChunk & chunk)52ScopedAStatus MockBroadcastRadioCallback::onProgramListUpdated(const ProgramListChunk& chunk) { 53 { 54 std::lock_guard<std::mutex> lk(mLock); 55 updateProgramList(chunk, &mProgramList); 56 } 57 58 if (chunk.complete) { 59 mOnProgramListReadyFlag.notify(); 60 } 61 62 return ndk::ScopedAStatus::ok(); 63 } 64 onParametersUpdated(const vector<VendorKeyValue> & parameters)65ScopedAStatus MockBroadcastRadioCallback::onParametersUpdated( 66 [[maybe_unused]] const vector<VendorKeyValue>& parameters) { 67 return ndk::ScopedAStatus::ok(); 68 } 69 onAntennaStateChange(bool connected)70ScopedAStatus MockBroadcastRadioCallback::onAntennaStateChange(bool connected) { 71 if (!connected) { 72 std::lock_guard<std::mutex> lk(mLock); 73 mAntennaConnectionState = false; 74 } 75 return ndk::ScopedAStatus::ok(); 76 } 77 onConfigFlagUpdated(ConfigFlag in_flag,bool in_value)78ScopedAStatus MockBroadcastRadioCallback::onConfigFlagUpdated([[maybe_unused]] ConfigFlag in_flag, 79 [[maybe_unused]] bool in_value) { 80 return ndk::ScopedAStatus::ok(); 81 } 82 waitOnCurrentProgramInfoChangedCallback()83bool MockBroadcastRadioCallback::waitOnCurrentProgramInfoChangedCallback() { 84 return mOnCurrentProgramInfoChangedFlag.wait(); 85 } 86 waitProgramReady()87bool MockBroadcastRadioCallback::waitProgramReady() { 88 return mOnProgramListReadyFlag.wait(); 89 } 90 reset()91void MockBroadcastRadioCallback::reset() { 92 mOnCurrentProgramInfoChangedFlag.reset(); 93 mOnProgramListReadyFlag.reset(); 94 } 95 isTunerFailed()96bool MockBroadcastRadioCallback::isTunerFailed() { 97 std::lock_guard<std::mutex> lk(mLock); 98 return tunerFailed; 99 } 100 getCurrentProgramInfo()101ProgramInfo MockBroadcastRadioCallback::getCurrentProgramInfo() { 102 std::lock_guard<std::mutex> lk(mLock); 103 return mCurrentProgramInfo; 104 } 105 getProgramList()106utils::ProgramInfoSet MockBroadcastRadioCallback::getProgramList() { 107 std::lock_guard<std::mutex> lk(mLock); 108 return mProgramList; 109 } 110 111 } // namespace aidl::android::hardware::broadcastradio 112