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 "resources.h" 19 20 #include <android-base/logging.h> 21 #include <broadcastradio-utils-2x/Utils.h> 22 23 namespace android { 24 namespace hardware { 25 namespace broadcastradio { 26 namespace V2_0 { 27 namespace implementation { 28 29 using utils::getType; 30 using utils::make_metadata; 31 32 using std::vector; 33 34 VirtualProgram::operator ProgramInfo() const { 35 ProgramInfo info = {}; 36 37 info.selector = selector; 38 39 auto pType = getType(selector.primaryId); 40 auto isDigital = (pType != IdentifierType::AMFM_FREQUENCY && pType != IdentifierType::RDS_PI); 41 42 auto selectId = [&info](IdentifierType type) { 43 return utils::make_identifier(type, utils::getId(info.selector, type)); 44 }; 45 46 switch (pType) { 47 case IdentifierType::AMFM_FREQUENCY: 48 info.logicallyTunedTo = info.physicallyTunedTo = 49 selectId(IdentifierType::AMFM_FREQUENCY); 50 break; 51 case IdentifierType::RDS_PI: 52 info.logicallyTunedTo = selectId(IdentifierType::RDS_PI); 53 info.physicallyTunedTo = selectId(IdentifierType::AMFM_FREQUENCY); 54 break; 55 case IdentifierType::HD_STATION_ID_EXT: 56 info.logicallyTunedTo = selectId(IdentifierType::HD_STATION_ID_EXT); 57 info.physicallyTunedTo = selectId(IdentifierType::AMFM_FREQUENCY); 58 break; 59 case IdentifierType::DAB_SID_EXT: 60 info.logicallyTunedTo = selectId(IdentifierType::DAB_SID_EXT); 61 info.physicallyTunedTo = selectId(IdentifierType::DAB_ENSEMBLE); 62 break; 63 case IdentifierType::DRMO_SERVICE_ID: 64 info.logicallyTunedTo = selectId(IdentifierType::DRMO_SERVICE_ID); 65 info.physicallyTunedTo = selectId(IdentifierType::DRMO_FREQUENCY); 66 break; 67 case IdentifierType::SXM_SERVICE_ID: 68 info.logicallyTunedTo = selectId(IdentifierType::SXM_SERVICE_ID); 69 info.physicallyTunedTo = selectId(IdentifierType::SXM_CHANNEL); 70 break; 71 default: 72 LOG(FATAL) << "unsupported program type: " << toString(pType); 73 } 74 75 info.infoFlags |= ProgramInfoFlags::TUNED; 76 info.infoFlags |= ProgramInfoFlags::STEREO; 77 info.signalQuality = isDigital ? 100 : 80; 78 79 info.metadata = hidl_vec<Metadata>({ 80 make_metadata(MetadataKey::RDS_PS, programName), 81 make_metadata(MetadataKey::SONG_TITLE, songTitle), 82 make_metadata(MetadataKey::SONG_ARTIST, songArtist), 83 make_metadata(MetadataKey::STATION_ICON, resources::demoPngId), 84 make_metadata(MetadataKey::ALBUM_ART, resources::demoPngId), 85 }); 86 87 info.vendorInfo = hidl_vec<VendorKeyValue>({ 88 {"com.google.dummy", "dummy"}, 89 {"com.google.dummy.VirtualProgram", std::to_string(reinterpret_cast<uintptr_t>(this))}, 90 }); 91 92 return info; 93 } 94 95 bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) { 96 auto& l = lhs.selector; 97 auto& r = rhs.selector; 98 99 // Two programs with the same primaryId are considered the same. 100 if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type; 101 if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value; 102 103 return false; 104 } 105 106 } // namespace implementation 107 } // namespace V2_0 108 } // namespace broadcastradio 109 } // namespace hardware 110 } // namespace android 111