Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 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 | |
| 27 | VirtualRadio::VirtualRadio(const string& name, const vector<VirtualProgram>& initialList) |
| 28 | : mName(name), mPrograms(initialList) { |
| 29 | sort(mPrograms.begin(), mPrograms.end()); |
| 30 | } |
| 31 | |
| 32 | string VirtualRadio::getName() const { |
| 33 | return mName; |
| 34 | } |
| 35 | |
| 36 | const vector<VirtualProgram>& VirtualRadio::getProgramList() const { |
| 37 | return mPrograms; |
| 38 | } |
| 39 | |
| 40 | 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 |
| 51 | const VirtualRadio& VirtualRadio::getAmFmRadio() { |
| 52 | // clang-format off |
| 53 | static VirtualRadio amFmRadioMock( |
| 54 | "AM/FM radio mock", |
| 55 | { |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 56 | {makeSelectorAmfm(/* frequency= */ 94900u), "Wild 94.9", "Drake ft. Rihanna", |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 57 | "Too Good"}, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 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", |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 62 | "Rock Your Body"}, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 63 | {makeSelectorAmfm(/* frequency= */ 103700u), "iHeart80s @ 103.7", "Michael Jackson", |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 64 | "Billie Jean"}, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 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"}, |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 68 | }); |
| 69 | // clang-format on |
| 70 | return amFmRadioMock; |
| 71 | } |
| 72 | |
| 73 | // get singleton of DAB Virtual Radio |
| 74 | const VirtualRadio& VirtualRadio::getDabRadio() { |
| 75 | // clang-format off |
| 76 | static VirtualRadio dabRadioMock( |
| 77 | "DAB radio mock", |
| 78 | { |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 79 | {makeSelectorDab(/* sidExt= */ 0xA000000001u, /* ensemble= */ 0x0001u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 80 | /* freq= */ 225648u), "BBC Radio 1", "Khalid", "Talk"}, |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 81 | {makeSelectorDab(/* sidExt= */ 0xB000000001u, /* ensemble= */ 0x1001u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 82 | /* freq= */ 222064u), "Classic FM", "Jean Sibelius", "Andante Festivo"}, |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 83 | {makeSelectorDab(/* sidExt= */ 0xB000000002u, /* ensemble= */ 0x1002u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 84 | /* freq= */ 227360u), "Absolute Radio", "Coldplay", "Clocks"}, |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 85 | {makeSelectorDab(/* sidExt= */ 0xB000000002u, /* ensemble= */ 0x1002u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 86 | /* freq= */ 222064u), "Absolute Radio", "Coldplay", "Clocks"}, |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 87 | }); |
| 88 | // clang-format on |
| 89 | return dabRadioMock; |
| 90 | } |
| 91 | |
| 92 | } // namespace aidl::android::hardware::broadcastradio |