blob: 0df0a82fa418131cd74958c7cf9fe0804e9cfa89 [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 "VirtualProgram.h"
18
19#include <broadcastradio-utils-aidl/Utils.h>
20#include "resources.h"
21
22#include <android-base/logging.h>
23
24namespace aidl::android::hardware::broadcastradio {
25
26using ::std::vector;
27
28VirtualProgram::operator ProgramInfo() const {
29 ProgramInfo info = {};
30
31 info.selector = selector;
32
33 IdentifierType programType = selector.primaryId.type;
34 bool isDigital = (programType != IdentifierType::AMFM_FREQUENCY_KHZ &&
35 programType != IdentifierType::RDS_PI);
36
37 auto selectId = [&info](const IdentifierType& type) {
38 return utils::makeIdentifier(type, utils::getId(info.selector, type));
39 };
40
41 switch (programType) {
42 case IdentifierType::AMFM_FREQUENCY_KHZ:
43 info.logicallyTunedTo = info.physicallyTunedTo =
44 selectId(IdentifierType::AMFM_FREQUENCY_KHZ);
45 break;
46 case IdentifierType::RDS_PI:
47 info.logicallyTunedTo = selectId(IdentifierType::RDS_PI);
48 info.physicallyTunedTo = selectId(IdentifierType::AMFM_FREQUENCY_KHZ);
49 break;
50 case IdentifierType::HD_STATION_ID_EXT:
51 info.logicallyTunedTo = selectId(IdentifierType::HD_STATION_ID_EXT);
52 info.physicallyTunedTo = selectId(IdentifierType::AMFM_FREQUENCY_KHZ);
53 break;
54 case IdentifierType::DAB_SID_EXT:
55 info.logicallyTunedTo = selectId(IdentifierType::DAB_SID_EXT);
56 info.physicallyTunedTo = selectId(IdentifierType::DAB_ENSEMBLE);
57 break;
58 case IdentifierType::DRMO_SERVICE_ID:
59 info.logicallyTunedTo = selectId(IdentifierType::DRMO_SERVICE_ID);
60 info.physicallyTunedTo = selectId(IdentifierType::DRMO_FREQUENCY_KHZ);
61 break;
62 case IdentifierType::SXM_SERVICE_ID:
63 info.logicallyTunedTo = selectId(IdentifierType::SXM_SERVICE_ID);
64 info.physicallyTunedTo = selectId(IdentifierType::SXM_CHANNEL);
65 break;
66 default:
67 LOG(FATAL) << "unsupported program type: " << toString(programType);
68 return {};
69 }
70
71 info.infoFlags |= (ProgramInfo::FLAG_TUNABLE | ProgramInfo::FLAG_STEREO);
72 info.signalQuality = isDigital ? kSignalQualityDigital : kSignalQualityNonDigital;
73
74 info.metadata = vector<Metadata>({
75 Metadata::make<Metadata::rdsPs>(programName),
76 Metadata::make<Metadata::songTitle>(songTitle),
77 Metadata::make<Metadata::songArtist>(songArtist),
78 Metadata::make<Metadata::stationIcon>(resources::kDemoPngId),
79 Metadata::make<Metadata::albumArt>(resources::kDemoPngId),
80 });
81
82 info.vendorInfo = vector<VendorKeyValue>({
83 {"com.android.sample", "sample"},
84 {"com.android.sample.VirtualProgram", "VirtualProgram"},
85 });
86
87 return info;
88}
89
90bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) {
91 auto& l = lhs.selector;
92 auto& r = rhs.selector;
93
94 // Two programs with the same primaryId are considered the same.
95 if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type;
96
97 return l.primaryId.value < r.primaryId.value;
98}
99
100} // namespace aidl::android::hardware::broadcastradio