blob: 4c6b3b1b5912aa8445e7a7b0904a2d2ce9733cf7 [file] [log] [blame]
Tomasz Wasilczyk48377552017-06-22 10:45:33 -07001/*
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
Tomasz Wasilczykc1763a62017-07-25 10:01:17 -070018#include <broadcastradio-utils/Utils.h>
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070019
Tomasz Wasilczykba3e2542017-07-17 13:59:21 -070020#include "resources.h"
21
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070022namespace android {
23namespace hardware {
24namespace broadcastradio {
25namespace V1_1 {
26namespace implementation {
27
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070028using V1_0::MetaData;
29using V1_0::MetadataKey;
30using V1_0::MetadataType;
31
Tomasz Wasilczykba3e2542017-07-17 13:59:21 -070032// TODO (b/36864090): inject this data in a more elegant way
33static int gHalVersion = 2; // 1 = 1.0, 2 = 1.1
34
35void setCompatibilityLevel(int halversion) {
36 gHalVersion = halversion;
37}
38
39static MetaData createDemoBitmap(MetadataKey key) {
40 MetaData bmp = {MetadataType::INT, key, resources::demoPngId, {}, {}, {}};
41 if (gHalVersion < 2) {
42 bmp.type = MetadataType::RAW;
43 bmp.intValue = 0;
44 bmp.rawValue = std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng));
45 }
46 return bmp;
47}
48
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070049VirtualProgram::operator ProgramInfo() const {
50 ProgramInfo info11 = {};
51 auto& info10 = info11.base;
52
Tomasz Wasilczyk2834b952017-07-12 14:17:09 -070053 utils::getLegacyChannel(selector, &info10.channel, &info10.subChannel);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070054 info11.selector = selector;
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070055 info10.tuned = true;
56 info10.stereo = true;
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070057 info10.digital = utils::isDigital(selector);
58 info10.signalStrength = info10.digital ? 100 : 80;
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070059
60 info10.metadata = hidl_vec<MetaData>({
61 {MetadataType::TEXT, MetadataKey::RDS_PS, {}, {}, programName, {}},
62 {MetadataType::TEXT, MetadataKey::TITLE, {}, {}, songTitle, {}},
63 {MetadataType::TEXT, MetadataKey::ARTIST, {}, {}, songArtist, {}},
Tomasz Wasilczykba3e2542017-07-17 13:59:21 -070064 createDemoBitmap(MetadataKey::ICON),
65 createDemoBitmap(MetadataKey::ART),
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070066 });
67
68 return info11;
69}
70
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070071// Defining order on virtual programs, how they appear on band.
72// It's mostly for default implementation purposes, may not be complete or correct.
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070073bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) {
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070074 auto& l = lhs.selector;
75 auto& r = rhs.selector;
76
77 // Two programs with the same primaryId is considered the same.
78 if (l.programType != r.programType) return l.programType < r.programType;
79 if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type;
80 if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value;
81
82 // A little exception for HD Radio subchannel - we check secondary ID too.
83 if (utils::hasId(l, IdentifierType::HD_SUBCHANNEL) &&
84 utils::hasId(r, IdentifierType::HD_SUBCHANNEL)) {
85 return utils::getId(l, IdentifierType::HD_SUBCHANNEL) <
86 utils::getId(r, IdentifierType::HD_SUBCHANNEL);
87 }
88
89 return false;
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070090}
91
92} // namespace implementation
93} // namespace V1_1
94} // namespace broadcastradio
95} // namespace hardware
96} // namespace android