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