VirtualProgram.cpp revision 2834b95b12edb0b234594b21bcb4b44cc797fc90
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#include "VirtualProgram.h"
17
18#include <Utils.h>
19
20namespace android {
21namespace hardware {
22namespace broadcastradio {
23namespace V1_1 {
24namespace implementation {
25
26using V1_0::MetaData;
27using V1_0::MetadataKey;
28using V1_0::MetadataType;
29
30VirtualProgram::operator ProgramInfo() const {
31    ProgramInfo info11 = {};
32    auto& info10 = info11.base;
33
34    utils::getLegacyChannel(selector, &info10.channel, &info10.subChannel);
35    info11.selector = selector;
36    info10.tuned = true;
37    info10.stereo = true;
38    info10.digital = utils::isDigital(selector);
39    info10.signalStrength = info10.digital ? 100 : 80;
40
41    info10.metadata = hidl_vec<MetaData>({
42        {MetadataType::TEXT, MetadataKey::RDS_PS, {}, {}, programName, {}},
43        {MetadataType::TEXT, MetadataKey::TITLE, {}, {}, songTitle, {}},
44        {MetadataType::TEXT, MetadataKey::ARTIST, {}, {}, songArtist, {}},
45    });
46
47    return info11;
48}
49
50// Defining order on virtual programs, how they appear on band.
51// It's mostly for default implementation purposes, may not be complete or correct.
52bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) {
53    auto& l = lhs.selector;
54    auto& r = rhs.selector;
55
56    // Two programs with the same primaryId is considered the same.
57    if (l.programType != r.programType) return l.programType < r.programType;
58    if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type;
59    if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value;
60
61    // A little exception for HD Radio subchannel - we check secondary ID too.
62    if (utils::hasId(l, IdentifierType::HD_SUBCHANNEL) &&
63        utils::hasId(r, IdentifierType::HD_SUBCHANNEL)) {
64        return utils::getId(l, IdentifierType::HD_SUBCHANNEL) <
65               utils::getId(r, IdentifierType::HD_SUBCHANNEL);
66    }
67
68    return false;
69}
70
71}  // namespace implementation
72}  // namespace V1_1
73}  // namespace broadcastradio
74}  // namespace hardware
75}  // namespace android
76