Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 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 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 18 | #include <Utils.h> |
| 19 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 20 | namespace android { |
| 21 | namespace hardware { |
| 22 | namespace broadcastradio { |
| 23 | namespace V1_1 { |
| 24 | namespace implementation { |
| 25 | |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 26 | using V1_0::MetaData; |
| 27 | using V1_0::MetadataKey; |
| 28 | using V1_0::MetadataType; |
| 29 | |
| 30 | VirtualProgram::operator ProgramInfo() const { |
| 31 | ProgramInfo info11 = {}; |
| 32 | auto& info10 = info11.base; |
| 33 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 34 | utils::getLegacyChannel(selector, info10.channel, info10.subChannel); |
| 35 | info11.selector = selector; |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 36 | info10.tuned = true; |
| 37 | info10.stereo = true; |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 38 | info10.digital = utils::isDigital(selector); |
| 39 | info10.signalStrength = info10.digital ? 100 : 80; |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 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 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 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. |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 52 | bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) { |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 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; |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | } // namespace implementation |
| 72 | } // namespace V1_1 |
| 73 | } // namespace broadcastradio |
| 74 | } // namespace hardware |
| 75 | } // namespace android |