• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 #include "VirtualRadio.h"
18 #include <broadcastradio-utils-aidl/Utils.h>
19 
20 namespace aidl::android::hardware::broadcastradio {
21 
22 using ::aidl::android::hardware::broadcastradio::utils::makeSelectorAmfm;
23 using ::aidl::android::hardware::broadcastradio::utils::makeSelectorDab;
24 using ::std::string;
25 using ::std::vector;
26 
VirtualRadio(const string & name,const vector<VirtualProgram> & initialList)27 VirtualRadio::VirtualRadio(const string& name, const vector<VirtualProgram>& initialList)
28     : mName(name), mPrograms(initialList) {
29     sort(mPrograms.begin(), mPrograms.end());
30 }
31 
getName() const32 string VirtualRadio::getName() const {
33     return mName;
34 }
35 
getProgramList() const36 const vector<VirtualProgram>& VirtualRadio::getProgramList() const {
37     return mPrograms;
38 }
39 
getProgram(const ProgramSelector & selector,VirtualProgram * programOut) const40 bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram* programOut) const {
41     for (const auto& program : mPrograms) {
42         if (utils::tunesTo(selector, program.selector)) {
43             *programOut = program;
44             return true;
45         }
46     }
47     return false;
48 }
49 
50 // get singleton of AMFM Virtual Radio
getAmFmRadio()51 const VirtualRadio& VirtualRadio::getAmFmRadio() {
52     // clang-format off
53     static VirtualRadio amFmRadioMock(
54         "AM/FM radio mock",
55         {
56             {makeSelectorAmfm(/* frequency= */ 94900u), "Wild 94.9", "Drake ft. Rihanna",
57                 "Too Good"},
58             {makeSelectorAmfm(/* frequency= */ 96500u), "KOIT", "Celine Dion", "All By Myself"},
59             {makeSelectorAmfm(/* frequency= */ 97300u), "Alice@97.3", "Drops of Jupiter", "Train"},
60             {makeSelectorAmfm(/* frequency= */ 99700u), "99.7 Now!", "The Chainsmokers", "Closer"},
61             {makeSelectorAmfm(/* frequency= */ 101300u), "101-3 KISS-FM", "Justin Timberlake",
62                 "Rock Your Body"},
63             {makeSelectorAmfm(/* frequency= */ 103700u), "iHeart80s @ 103.7", "Michael Jackson",
64                 "Billie Jean"},
65             {makeSelectorAmfm(/* frequency= */ 106100u), "106 KMEL", "Drake", "Marvins Room"},
66             {makeSelectorAmfm(/* frequency= */ 700u), "700 AM", "Artist700", "Title700"},
67             {makeSelectorAmfm(/* frequency= */ 1700u), "1700 AM", "Artist1700", "Title1700"},
68         });
69     // clang-format on
70     return amFmRadioMock;
71 }
72 
73 // get singleton of DAB Virtual Radio
getDabRadio()74 const VirtualRadio& VirtualRadio::getDabRadio() {
75     // clang-format off
76     static VirtualRadio dabRadioMock(
77         "DAB radio mock",
78         {
79             {makeSelectorDab(/* sidExt= */ 0xA000000001u, /* ensemble= */ 0x0001u,
80                 /* freq= */ 225648u), "BBC Radio 1", "Khalid", "Talk"},
81             {makeSelectorDab(/* sidExt= */ 0xB000000001u, /* ensemble= */ 0x1001u,
82                 /* freq= */ 222064u), "Classic FM", "Jean Sibelius", "Andante Festivo"},
83             {makeSelectorDab(/* sidExt= */ 0xB000000002u, /* ensemble= */ 0x1002u,
84                 /* freq= */ 227360u), "Absolute Radio", "Coldplay", "Clocks"},
85             {makeSelectorDab(/* sidExt= */ 0xB000000002u, /* ensemble= */ 0x1002u,
86                 /* freq= */ 222064u), "Absolute Radio", "Coldplay", "Clocks"},
87         });
88     // clang-format on
89     return dabRadioMock;
90 }
91 
92 }  // namespace aidl::android::hardware::broadcastradio
93