blob: 5ab517d17f5b743283124eeec820ca3305bc348c [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 */
16#define LOG_TAG "BcRadioDef.module"
17#define LOG_NDEBUG 0
18
19#include "BroadcastRadio.h"
20
21#include <log/log.h>
22
23#include "resources.h"
24
25namespace android {
26namespace hardware {
27namespace broadcastradio {
28namespace V2_0 {
29namespace implementation {
30
31using std::lock_guard;
32using std::map;
33using std::mutex;
34using std::vector;
35
36static Properties initProperties(const VirtualRadio& virtualRadio) {
37 Properties prop = {};
38
39 prop.maker = "Google";
40 prop.product = virtualRadio.getName();
41 prop.supportedIdentifierTypes = hidl_vec<uint32_t>({
42 static_cast<uint32_t>(IdentifierType::AMFM_FREQUENCY),
43 static_cast<uint32_t>(IdentifierType::RDS_PI),
44 static_cast<uint32_t>(IdentifierType::HD_STATION_ID_EXT),
45 });
46 prop.vendorInfo = hidl_vec<VendorKeyValue>({
47 {"com.google.dummy", "dummy"},
48 });
49
50 return prop;
51}
52
53BroadcastRadio::BroadcastRadio(const VirtualRadio& virtualRadio)
54 : mVirtualRadio(virtualRadio), mProperties(initProperties(virtualRadio)) {}
55
56Return<void> BroadcastRadio::getProperties(getProperties_cb _hidl_cb) {
57 ALOGV("%s", __func__);
58 _hidl_cb(mProperties);
59 return {};
60}
61
62Return<void> BroadcastRadio::openSession(const sp<ITunerCallback>& callback,
63 openSession_cb _hidl_cb) {
64 ALOGV("%s", __func__);
65 lock_guard<mutex> lk(mMut);
66
67 auto oldSession = mSession.promote();
68 if (oldSession != nullptr) {
69 ALOGI("Closing previously opened tuner");
70 oldSession->close();
71 mSession = nullptr;
72 }
73
74 sp<TunerSession> newSession = new TunerSession(*this, callback);
75 mSession = newSession;
76
77 _hidl_cb(Result::OK, newSession);
78 return {};
79}
80
81Return<void> BroadcastRadio::getImage(uint32_t id, getImage_cb _hidl_cb) {
82 ALOGV("%s(%x)", __func__, id);
83
84 if (id == resources::demoPngId) {
85 _hidl_cb(std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng)));
86 return {};
87 }
88
89 ALOGI("Image %x doesn't exists", id);
90 _hidl_cb({});
91 return {};
92}
93
94} // namespace implementation
95} // namespace V2_0
96} // namespace broadcastradio
97} // namespace hardware
98} // namespace android