blob: 092776f62d65c7f9abd8f37e1a1dc8d005bc2a76 [file] [log] [blame]
Weilin Xub2a6ca62022-05-08 23:47:04 +00001/*
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
36namespace aidl::android::hardware::broadcastradio {
37
38class BroadcastRadio final : public BnBroadcastRadio {
39 public:
40 explicit BroadcastRadio(const VirtualRadio& virtualRadio);
41 ~BroadcastRadio();
42 ndk::ScopedAStatus getAmFmRegionConfig(bool full, AmFmRegionConfig* returnConfigs) override;
43 ndk::ScopedAStatus getDabRegionConfig(std::vector<DabTableEntry>* returnConfigs) override;
44 ndk::ScopedAStatus getImage(int32_t id, std::vector<uint8_t>* returnImage) override;
45 ndk::ScopedAStatus getProperties(Properties* returnProperties) override;
46
47 ndk::ScopedAStatus setTunerCallback(const std::shared_ptr<ITunerCallback>& callback) override;
48 ndk::ScopedAStatus unsetTunerCallback() override;
49 ndk::ScopedAStatus tune(const ProgramSelector& program) override;
50 ndk::ScopedAStatus seek(bool directionUp, bool skipSubChannel) override;
51 ndk::ScopedAStatus step(bool directionUp) override;
52 ndk::ScopedAStatus cancel() override;
53 ndk::ScopedAStatus startProgramListUpdates(const ProgramFilter& filter) override;
54 ndk::ScopedAStatus stopProgramListUpdates() override;
55 ndk::ScopedAStatus isConfigFlagSet(ConfigFlag flag, bool* returnIsSet) override;
56 ndk::ScopedAStatus setConfigFlag(ConfigFlag flag, bool in_value) override;
57 ndk::ScopedAStatus setParameters(const std::vector<VendorKeyValue>& parameters,
58 std::vector<VendorKeyValue>* returnParameters) override;
59 ndk::ScopedAStatus getParameters(const std::vector<std::string>& keys,
60 std::vector<VendorKeyValue>* returnParameters) override;
61 ndk::ScopedAStatus registerAnnouncementListener(
62 const std::shared_ptr<IAnnouncementListener>& listener,
63 const std::vector<AnnouncementType>& enabled,
64 std::shared_ptr<ICloseHandle>* returnCloseHandle) override;
Weilin Xu97203b02022-06-23 00:19:03 +000065 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
Weilin Xub2a6ca62022-05-08 23:47:04 +000066
67 private:
68 const VirtualRadio& mVirtualRadio;
69 std::mutex mMutex;
70 AmFmRegionConfig mAmFmConfig GUARDED_BY(mMutex);
71 std::unique_ptr<::android::WorkerThread> mThread GUARDED_BY(mMutex) =
72 std::unique_ptr<::android::WorkerThread>(new ::android::WorkerThread());
73 bool mIsTuneCompleted GUARDED_BY(mMutex) = true;
74 Properties mProperties GUARDED_BY(mMutex);
75 ProgramSelector mCurrentProgram GUARDED_BY(mMutex) = {};
76 std::shared_ptr<ITunerCallback> mCallback GUARDED_BY(mMutex);
77
Weilin Xu3bd4d9b2023-07-19 00:38:57 +000078 // Bitmap for all ConfigFlag values
79 int mConfigFlagValues GUARDED_BY(mMutex) = 0;
80
Weilin Xub2a6ca62022-05-08 23:47:04 +000081 std::optional<AmFmBandRange> getAmFmRangeLocked() const;
82 void cancelLocked();
83 ProgramInfo tuneInternalLocked(const ProgramSelector& sel);
Weilin Xu97203b02022-06-23 00:19:03 +000084
85 binder_status_t cmdHelp(int fd) const;
86 binder_status_t cmdTune(int fd, const char** args, uint32_t numArgs);
87 binder_status_t cmdSeek(int fd, const char** args, uint32_t numArgs);
88 binder_status_t cmdStep(int fd, const char** args, uint32_t numArgs);
89 binder_status_t cmdCancel(int fd, uint32_t numArgs);
90 binder_status_t cmdStartProgramListUpdates(int fd, const char** args, uint32_t numArgs);
91 binder_status_t cmdStopProgramListUpdates(int fd, uint32_t numArgs);
92
93 binder_status_t dumpsys(int fd);
Weilin Xub2a6ca62022-05-08 23:47:04 +000094};
95
96} // namespace aidl::android::hardware::broadcastradio