1 /*
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 "BroadcastRadioDefault.VirtualRadio"
17 //#define LOG_NDEBUG 0
18
19 #include "VirtualRadio.h"
20
21 #include <broadcastradio-utils-1x/Utils.h>
22 #include <log/log.h>
23
24 namespace android {
25 namespace hardware {
26 namespace broadcastradio {
27 namespace V1_1 {
28 namespace implementation {
29
30 using V1_0::Band;
31 using V1_0::Class;
32 using V1_1::ProgramSelector;
33
34 using std::lock_guard;
35 using std::move;
36 using std::mutex;
37 using std::vector;
38
39 using utils::make_selector;
40
41 static const vector<VirtualProgram> gInitialFmPrograms{
42 {make_selector(Band::FM, 94900), "Wild 94.9", "Drake ft. Rihanna", "Too Good"},
43 {make_selector(Band::FM, 96500), "KOIT", "Celine Dion", "All By Myself"},
44 {make_selector(Band::FM, 97300), "Alice@97.3", "Drops of Jupiter", "Train"},
45 {make_selector(Band::FM, 99700), "99.7 Now!", "The Chainsmokers", "Closer"},
46 {make_selector(Band::FM, 101300), "101-3 KISS-FM", "Justin Timberlake", "Rock Your Body"},
47 {make_selector(Band::FM, 103700), "iHeart80s @ 103.7", "Michael Jackson", "Billie Jean"},
48 {make_selector(Band::FM, 106100), "106 KMEL", "Drake", "Marvins Room"},
49 };
50
51 static VirtualRadio gEmptyRadio({});
52 static VirtualRadio gFmRadio(gInitialFmPrograms);
53
VirtualRadio(const vector<VirtualProgram> initialList)54 VirtualRadio::VirtualRadio(const vector<VirtualProgram> initialList) : mPrograms(initialList) {}
55
getProgramList()56 vector<VirtualProgram> VirtualRadio::getProgramList() {
57 lock_guard<mutex> lk(mMut);
58 return mPrograms;
59 }
60
getProgram(const ProgramSelector & selector,VirtualProgram & programOut)61 bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram& programOut) {
62 lock_guard<mutex> lk(mMut);
63 for (auto&& program : mPrograms) {
64 if (utils::tunesTo(selector, program.selector)) {
65 programOut = program;
66 return true;
67 }
68 }
69 return false;
70 }
71
getRadio(V1_0::Class classId)72 VirtualRadio& getRadio(V1_0::Class classId) {
73 switch (classId) {
74 case Class::AM_FM:
75 return getFmRadio();
76 case Class::SAT:
77 return getSatRadio();
78 case Class::DT:
79 return getDigitalRadio();
80 default:
81 ALOGE("Invalid class ID");
82 return gEmptyRadio;
83 }
84 }
85
getAmRadio()86 VirtualRadio& getAmRadio() {
87 return gEmptyRadio;
88 }
89
getFmRadio()90 VirtualRadio& getFmRadio() {
91 return gFmRadio;
92 }
93
getSatRadio()94 VirtualRadio& getSatRadio() {
95 return gEmptyRadio;
96 }
97
getDigitalRadio()98 VirtualRadio& getDigitalRadio() {
99 return gEmptyRadio;
100 }
101
102 } // namespace implementation
103 } // namespace V1_1
104 } // namespace broadcastradio
105 } // namespace hardware
106 } // namespace android
107