Default implementation for BroadcastRadio AIDL HAL
Default implementation for BroadcastRadio AIDL HAL is based on
default implementation for HIDL 2.0, with necessary data type
conversion. The callback for IBroadcastRadio interface is
initialized as nullptr.
Bug: 170336130
Test: m -j
Change-Id: Id521573116c565c42af16333cad73c5dd0583420
diff --git a/broadcastradio/aidl/default/BroadcastRadio.h b/broadcastradio/aidl/default/BroadcastRadio.h
new file mode 100644
index 0000000..52d394e
--- /dev/null
+++ b/broadcastradio/aidl/default/BroadcastRadio.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "VirtualRadio.h"
+
+#include <aidl/android/hardware/broadcastradio/AmFmBandRange.h>
+#include <aidl/android/hardware/broadcastradio/AmFmRegionConfig.h>
+#include <aidl/android/hardware/broadcastradio/AnnouncementType.h>
+#include <aidl/android/hardware/broadcastradio/BnBroadcastRadio.h>
+#include <aidl/android/hardware/broadcastradio/DabTableEntry.h>
+#include <aidl/android/hardware/broadcastradio/IAnnouncementListener.h>
+#include <aidl/android/hardware/broadcastradio/ICloseHandle.h>
+#include <aidl/android/hardware/broadcastradio/ITunerCallback.h>
+#include <aidl/android/hardware/broadcastradio/Properties.h>
+#include <broadcastradio-utils/WorkerThread.h>
+
+#include <android-base/thread_annotations.h>
+
+#include <optional>
+
+namespace aidl::android::hardware::broadcastradio {
+
+class BroadcastRadio final : public BnBroadcastRadio {
+ public:
+ explicit BroadcastRadio(const VirtualRadio& virtualRadio);
+ ~BroadcastRadio();
+ ndk::ScopedAStatus getAmFmRegionConfig(bool full, AmFmRegionConfig* returnConfigs) override;
+ ndk::ScopedAStatus getDabRegionConfig(std::vector<DabTableEntry>* returnConfigs) override;
+ ndk::ScopedAStatus getImage(int32_t id, std::vector<uint8_t>* returnImage) override;
+ ndk::ScopedAStatus getProperties(Properties* returnProperties) override;
+
+ ndk::ScopedAStatus setTunerCallback(const std::shared_ptr<ITunerCallback>& callback) override;
+ ndk::ScopedAStatus unsetTunerCallback() override;
+ ndk::ScopedAStatus tune(const ProgramSelector& program) override;
+ ndk::ScopedAStatus seek(bool directionUp, bool skipSubChannel) override;
+ ndk::ScopedAStatus step(bool directionUp) override;
+ ndk::ScopedAStatus cancel() override;
+ ndk::ScopedAStatus startProgramListUpdates(const ProgramFilter& filter) override;
+ ndk::ScopedAStatus stopProgramListUpdates() override;
+ ndk::ScopedAStatus isConfigFlagSet(ConfigFlag flag, bool* returnIsSet) override;
+ ndk::ScopedAStatus setConfigFlag(ConfigFlag flag, bool in_value) override;
+ ndk::ScopedAStatus setParameters(const std::vector<VendorKeyValue>& parameters,
+ std::vector<VendorKeyValue>* returnParameters) override;
+ ndk::ScopedAStatus getParameters(const std::vector<std::string>& keys,
+ std::vector<VendorKeyValue>* returnParameters) override;
+ ndk::ScopedAStatus registerAnnouncementListener(
+ const std::shared_ptr<IAnnouncementListener>& listener,
+ const std::vector<AnnouncementType>& enabled,
+ std::shared_ptr<ICloseHandle>* returnCloseHandle) override;
+
+ private:
+ const VirtualRadio& mVirtualRadio;
+ std::mutex mMutex;
+ AmFmRegionConfig mAmFmConfig GUARDED_BY(mMutex);
+ std::unique_ptr<::android::WorkerThread> mThread GUARDED_BY(mMutex) =
+ std::unique_ptr<::android::WorkerThread>(new ::android::WorkerThread());
+ bool mIsTuneCompleted GUARDED_BY(mMutex) = true;
+ Properties mProperties GUARDED_BY(mMutex);
+ ProgramSelector mCurrentProgram GUARDED_BY(mMutex) = {};
+ std::shared_ptr<ITunerCallback> mCallback GUARDED_BY(mMutex);
+
+ std::optional<AmFmBandRange> getAmFmRangeLocked() const;
+ void cancelLocked();
+ ProgramInfo tuneInternalLocked(const ProgramSelector& sel);
+};
+
+} // namespace aidl::android::hardware::broadcastradio