blob: 851543b0aae9a7ac53884b6c1953e78749b38e26 [file] [log] [blame]
Weilin Xub2a6ca62022-05-08 23:47:04 +00001/*
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
20namespace aidl::android::hardware::broadcastradio {
21
22using ::aidl::android::hardware::broadcastradio::utils::makeSelectorAmfm;
23using ::aidl::android::hardware::broadcastradio::utils::makeSelectorDab;
24using ::std::string;
25using ::std::vector;
26
27VirtualRadio::VirtualRadio(const string& name, const vector<VirtualProgram>& initialList)
28 : mName(name), mPrograms(initialList) {
29 sort(mPrograms.begin(), mPrograms.end());
30}
31
32string VirtualRadio::getName() const {
33 return mName;
34}
35
36const vector<VirtualProgram>& VirtualRadio::getProgramList() const {
37 return mPrograms;
38}
39
40bool 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
51const VirtualRadio& VirtualRadio::getAmFmRadio() {
52 // clang-format off
53 static VirtualRadio amFmRadioMock(
54 "AM/FM radio mock",
55 {
56 {makeSelectorAmfm(94900), "Wild 94.9", "Drake ft. Rihanna", "Too Good"},
57 {makeSelectorAmfm(96500), "KOIT", "Celine Dion", "All By Myself"},
58 {makeSelectorAmfm(97300), "Alice@97.3", "Drops of Jupiter", "Train"},
59 {makeSelectorAmfm(99700), "99.7 Now!", "The Chainsmokers", "Closer"},
60 {makeSelectorAmfm(101300), "101-3 KISS-FM", "Justin Timberlake", "Rock Your Body"},
61 {makeSelectorAmfm(103700), "iHeart80s @ 103.7", "Michael Jackson", "Billie Jean"},
62 {makeSelectorAmfm(106100), "106 KMEL", "Drake", "Marvins Room"},
63 {makeSelectorAmfm(700), "700 AM", "Artist700", "Title700"},
64 {makeSelectorAmfm(1700), "1700 AM", "Artist1700", "Title1700"},
65 });
66 // clang-format on
67 return amFmRadioMock;
68}
69
70// get singleton of DAB Virtual Radio
71const VirtualRadio& VirtualRadio::getDabRadio() {
72 // clang-format off
73 static VirtualRadio dabRadioMock(
74 "DAB radio mock",
75 {
76 {makeSelectorDab(0xA00001u, 0x0001u), "BBC Radio 1", "Khalid", "Talk"},
77 {makeSelectorDab(0xB00001u, 0x1001u), "Classic FM", "Jean Sibelius", "Andante Festivo"},
78 {makeSelectorDab(0xB00002u, 0x1001u), "Absolute Radio", "Coldplay", "Clocks"},
79 });
80 // clang-format on
81 return dabRadioMock;
82}
83
84} // namespace aidl::android::hardware::broadcastradio