Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [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 | #pragma once |
| 18 | |
| 19 | #include "VirtualRadio.h" |
| 20 | |
| 21 | #include <aidl/android/hardware/broadcastradio/AmFmBandRange.h> |
| 22 | #include <aidl/android/hardware/broadcastradio/AmFmRegionConfig.h> |
| 23 | #include <aidl/android/hardware/broadcastradio/AnnouncementType.h> |
| 24 | #include <aidl/android/hardware/broadcastradio/BnBroadcastRadio.h> |
| 25 | #include <aidl/android/hardware/broadcastradio/DabTableEntry.h> |
| 26 | #include <aidl/android/hardware/broadcastradio/IAnnouncementListener.h> |
| 27 | #include <aidl/android/hardware/broadcastradio/ICloseHandle.h> |
| 28 | #include <aidl/android/hardware/broadcastradio/ITunerCallback.h> |
| 29 | #include <aidl/android/hardware/broadcastradio/Properties.h> |
| 30 | #include <broadcastradio-utils/WorkerThread.h> |
| 31 | |
| 32 | #include <android-base/thread_annotations.h> |
| 33 | |
| 34 | #include <optional> |
| 35 | |
| 36 | namespace aidl::android::hardware::broadcastradio { |
| 37 | |
| 38 | class BroadcastRadio final : public BnBroadcastRadio { |
| 39 | public: |
| 40 | explicit BroadcastRadio(const VirtualRadio& virtualRadio); |
| 41 | ~BroadcastRadio(); |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 42 | ndk::ScopedAStatus getAmFmRegionConfig(bool full, AmFmRegionConfig* returnConfigs) |
| 43 | EXCLUDES(mMutex) override; |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 44 | ndk::ScopedAStatus getDabRegionConfig(std::vector<DabTableEntry>* returnConfigs) override; |
| 45 | ndk::ScopedAStatus getImage(int32_t id, std::vector<uint8_t>* returnImage) override; |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 46 | ndk::ScopedAStatus getProperties(Properties* returnProperties) EXCLUDES(mMutex) override; |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 47 | |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 48 | ndk::ScopedAStatus setTunerCallback(const std::shared_ptr<ITunerCallback>& callback) |
| 49 | EXCLUDES(mMutex) override; |
| 50 | ndk::ScopedAStatus unsetTunerCallback() EXCLUDES(mMutex) override; |
| 51 | ndk::ScopedAStatus tune(const ProgramSelector& program) EXCLUDES(mMutex) override; |
| 52 | ndk::ScopedAStatus seek(bool directionUp, bool skipSubChannel) EXCLUDES(mMutex) override; |
| 53 | ndk::ScopedAStatus step(bool directionUp) EXCLUDES(mMutex) override; |
| 54 | ndk::ScopedAStatus cancel() EXCLUDES(mMutex) override; |
| 55 | ndk::ScopedAStatus startProgramListUpdates(const ProgramFilter& filter) |
| 56 | EXCLUDES(mMutex) override; |
| 57 | ndk::ScopedAStatus stopProgramListUpdates() EXCLUDES(mMutex) override; |
| 58 | ndk::ScopedAStatus isConfigFlagSet(ConfigFlag flag, bool* returnIsSet) |
| 59 | EXCLUDES(mMutex) override; |
| 60 | ndk::ScopedAStatus setConfigFlag(ConfigFlag flag, bool in_value) EXCLUDES(mMutex) override; |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 61 | ndk::ScopedAStatus setParameters(const std::vector<VendorKeyValue>& parameters, |
| 62 | std::vector<VendorKeyValue>* returnParameters) override; |
| 63 | ndk::ScopedAStatus getParameters(const std::vector<std::string>& keys, |
| 64 | std::vector<VendorKeyValue>* returnParameters) override; |
| 65 | ndk::ScopedAStatus registerAnnouncementListener( |
| 66 | const std::shared_ptr<IAnnouncementListener>& listener, |
| 67 | const std::vector<AnnouncementType>& enabled, |
| 68 | std::shared_ptr<ICloseHandle>* returnCloseHandle) override; |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 69 | binder_status_t dump(int fd, const char** args, uint32_t numArgs) EXCLUDES(mMutex) override; |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 70 | |
| 71 | private: |
| 72 | const VirtualRadio& mVirtualRadio; |
| 73 | std::mutex mMutex; |
| 74 | AmFmRegionConfig mAmFmConfig GUARDED_BY(mMutex); |
Weilin Xu | 764fe0d | 2023-07-26 18:07:05 +0000 | [diff] [blame] | 75 | std::unique_ptr<::android::WorkerThread> mTuningThread GUARDED_BY(mMutex) = |
| 76 | std::unique_ptr<::android::WorkerThread>(new ::android::WorkerThread()); |
| 77 | std::unique_ptr<::android::WorkerThread> mProgramListThread GUARDED_BY(mMutex) = |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 78 | std::unique_ptr<::android::WorkerThread>(new ::android::WorkerThread()); |
| 79 | bool mIsTuneCompleted GUARDED_BY(mMutex) = true; |
| 80 | Properties mProperties GUARDED_BY(mMutex); |
Weilin Xu | 9d79f31 | 2024-10-18 10:37:05 -0700 | [diff] [blame] | 81 | ProgramSelector mCurrentProgramSelector GUARDED_BY(mMutex) = {}; |
| 82 | ProgramInfo mCurrentProgramInfo GUARDED_BY(mMutex) = {}; |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 83 | std::vector<VirtualProgram> mProgramList GUARDED_BY(mMutex) = {}; |
Weilin Xu | 4833896 | 2023-11-03 14:31:15 -0700 | [diff] [blame] | 84 | std::optional<AmFmBandRange> mCurrentAmFmBandRange GUARDED_BY(mMutex); |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 85 | std::shared_ptr<ITunerCallback> mCallback GUARDED_BY(mMutex); |
| 86 | |
Weilin Xu | 3bd4d9b | 2023-07-19 00:38:57 +0000 | [diff] [blame] | 87 | // Bitmap for all ConfigFlag values |
| 88 | int mConfigFlagValues GUARDED_BY(mMutex) = 0; |
| 89 | |
Weilin Xu | 4833896 | 2023-11-03 14:31:15 -0700 | [diff] [blame] | 90 | bool adjustAmFmRangeLocked() REQUIRES(mMutex); |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 91 | void cancelLocked() REQUIRES(mMutex); |
| 92 | ProgramInfo tuneInternalLocked(const ProgramSelector& sel) REQUIRES(mMutex); |
Weilin Xu | 4833896 | 2023-11-03 14:31:15 -0700 | [diff] [blame] | 93 | void startProgramListUpdatesLocked(const ProgramFilter& filter) REQUIRES(mMutex); |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 94 | void cancelProgramListUpdateLocked() REQUIRES(mMutex); |
Weilin Xu | 7991996 | 2023-11-06 19:11:02 -0800 | [diff] [blame] | 95 | void handleProgramInfoUpdateRadioCallback(ProgramInfo programInfo, |
| 96 | const std::shared_ptr<ITunerCallback>& callback) |
| 97 | EXCLUDES(mMutex); |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 98 | bool findNextLocked(const ProgramSelector& current, bool directionUp, bool skipSubChannel, |
| 99 | VirtualProgram* nextProgram) const REQUIRES(mMutex); |
| 100 | void jumpToFirstSubChannelLocked(std::vector<VirtualProgram>::const_iterator& it) const |
| 101 | REQUIRES(mMutex); |
Weilin Xu | 4833896 | 2023-11-03 14:31:15 -0700 | [diff] [blame] | 102 | bool isConfigFlagSetLocked(ConfigFlag flag) const REQUIRES(mMutex); |
Weilin Xu | 9d79f31 | 2024-10-18 10:37:05 -0700 | [diff] [blame] | 103 | void updateCurrentProgramInfoWithAlert(std::optional<Alert>& alert); |
Weilin Xu | 97203b0 | 2022-06-23 00:19:03 +0000 | [diff] [blame] | 104 | |
| 105 | binder_status_t cmdHelp(int fd) const; |
| 106 | binder_status_t cmdTune(int fd, const char** args, uint32_t numArgs); |
| 107 | binder_status_t cmdSeek(int fd, const char** args, uint32_t numArgs); |
| 108 | binder_status_t cmdStep(int fd, const char** args, uint32_t numArgs); |
| 109 | binder_status_t cmdCancel(int fd, uint32_t numArgs); |
| 110 | binder_status_t cmdStartProgramListUpdates(int fd, const char** args, uint32_t numArgs); |
| 111 | binder_status_t cmdStopProgramListUpdates(int fd, uint32_t numArgs); |
Weilin Xu | 9d79f31 | 2024-10-18 10:37:05 -0700 | [diff] [blame] | 112 | binder_status_t cmdSimulateAlert(int fd, const char** args, uint32_t numArgs); |
Weilin Xu | 97203b0 | 2022-06-23 00:19:03 +0000 | [diff] [blame] | 113 | |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 114 | binder_status_t dumpsys(int fd) EXCLUDES(mMutex); |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace aidl::android::hardware::broadcastradio |