blob: 28a0dd504aa5bf37beda6e9dd936e743da57240f [file] [log] [blame]
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -08001/*
2 * Copyright (C) 2017 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 */
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080016#include "BroadcastRadio.h"
17
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080018#include "resources.h"
19
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -080020#include <android-base/logging.h>
21
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080022namespace android {
23namespace hardware {
24namespace broadcastradio {
25namespace V2_0 {
26namespace implementation {
27
28using std::lock_guard;
29using std::map;
30using std::mutex;
31using std::vector;
32
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080033static const AmFmRegionConfig gDefaultAmFmConfig = { //
34 {
35 {87500, 108000, 100, 100}, // FM
36 {153, 282, 3, 9}, // AM LW
37 {531, 1620, 9, 9}, // AM MW
38 {1600, 30000, 1, 5}, // AM SW
39 },
40 static_cast<uint32_t>(Deemphasis::D50),
41 static_cast<uint32_t>(Rds::RDS)};
42
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080043static Properties initProperties(const VirtualRadio& virtualRadio) {
44 Properties prop = {};
45
46 prop.maker = "Google";
47 prop.product = virtualRadio.getName();
48 prop.supportedIdentifierTypes = hidl_vec<uint32_t>({
49 static_cast<uint32_t>(IdentifierType::AMFM_FREQUENCY),
50 static_cast<uint32_t>(IdentifierType::RDS_PI),
51 static_cast<uint32_t>(IdentifierType::HD_STATION_ID_EXT),
52 });
53 prop.vendorInfo = hidl_vec<VendorKeyValue>({
54 {"com.google.dummy", "dummy"},
55 });
56
57 return prop;
58}
59
60BroadcastRadio::BroadcastRadio(const VirtualRadio& virtualRadio)
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080061 : mVirtualRadio(virtualRadio),
62 mProperties(initProperties(virtualRadio)),
63 mAmFmConfig(gDefaultAmFmConfig) {}
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080064
65Return<void> BroadcastRadio::getProperties(getProperties_cb _hidl_cb) {
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080066 _hidl_cb(mProperties);
67 return {};
68}
69
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080070AmFmRegionConfig BroadcastRadio::getAmFmConfig() const {
71 lock_guard<mutex> lk(mMut);
72 return mAmFmConfig;
73}
74
75Return<void> BroadcastRadio::getAmFmRegionConfig(bool full, getAmFmRegionConfig_cb _hidl_cb) {
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080076 if (full) {
77 AmFmRegionConfig config = {};
78 config.ranges = hidl_vec<AmFmBandRange>({
79 {65000, 108000, 10, 0}, // FM
80 {150, 30000, 1, 0}, // AM
81 });
82 config.fmDeemphasis = Deemphasis::D50 | Deemphasis::D75;
83 config.fmRds = Rds::RDS | Rds::RBDS;
84 _hidl_cb(Result::OK, config);
85 return {};
86 } else {
87 _hidl_cb(Result::OK, getAmFmConfig());
88 return {};
89 }
90}
91
92Return<void> BroadcastRadio::getDabRegionConfig(getDabRegionConfig_cb _hidl_cb) {
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080093 hidl_vec<DabTableEntry> config = {
94 {"5A", 174928}, {"7D", 194064}, {"8A", 195936}, {"8B", 197648}, {"9A", 202928},
95 {"9B", 204640}, {"9C", 206352}, {"10B", 211648}, {"10C", 213360}, {"10D", 215072},
96 {"11A", 216928}, {"11B", 218640}, {"11C", 220352}, {"11D", 222064}, {"12A", 223936},
97 {"12B", 225648}, {"12C", 227360}, {"12D", 229072},
98 };
99
100 _hidl_cb(Result::OK, config);
101 return {};
102}
103
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800104Return<void> BroadcastRadio::openSession(const sp<ITunerCallback>& callback,
105 openSession_cb _hidl_cb) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800106 LOG(DEBUG) << "opening new session...";
Tomasz Wasilczykdb902862018-01-14 17:22:03 -0800107
108 /* For the needs of default implementation it's fine to instantiate new session object
109 * out of the lock scope. If your implementation needs it, use reentrant lock.
110 */
111 sp<TunerSession> newSession = new TunerSession(*this, callback);
112
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800113 lock_guard<mutex> lk(mMut);
114
115 auto oldSession = mSession.promote();
116 if (oldSession != nullptr) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800117 LOG(INFO) << "closing previously opened tuner";
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800118 oldSession->close();
119 mSession = nullptr;
120 }
121
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800122 mSession = newSession;
123
124 _hidl_cb(Result::OK, newSession);
125 return {};
126}
127
128Return<void> BroadcastRadio::getImage(uint32_t id, getImage_cb _hidl_cb) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800129 LOG(DEBUG) << "fetching image " << std::hex << id;
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800130
131 if (id == resources::demoPngId) {
132 _hidl_cb(std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng)));
133 return {};
134 }
135
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800136 LOG(INFO) << "image " << std::hex << id << " doesn't exists";
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800137 _hidl_cb({});
138 return {};
139}
140
Tomasz Wasilczyk0d5ef5d2018-01-10 10:58:20 -0800141Return<void> BroadcastRadio::registerAnnouncementListener(
142 const hidl_vec<AnnouncementType>& enabled, const sp<IAnnouncementListener>& /* listener */,
143 registerAnnouncementListener_cb _hidl_cb) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800144 LOG(DEBUG) << "registering announcement listener for " << toString(enabled);
Tomasz Wasilczyk6a9f8562017-12-27 09:46:43 -0800145
146 _hidl_cb(Result::NOT_SUPPORTED, nullptr);
147 return {};
148}
149
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800150} // namespace implementation
151} // namespace V2_0
152} // namespace broadcastradio
153} // namespace hardware
154} // namespace android