Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [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 | |
| 18 | #include "resources.h" |
| 19 | |
| 20 | #include <broadcastradio-utils-2x/Utils.h> |
| 21 | |
| 22 | namespace android { |
| 23 | namespace hardware { |
| 24 | namespace broadcastradio { |
| 25 | namespace V2_0 { |
| 26 | namespace implementation { |
| 27 | |
| 28 | using utils::getType; |
| 29 | using utils::make_metadata; |
| 30 | |
| 31 | using std::vector; |
| 32 | |
| 33 | VirtualProgram::operator ProgramInfo() const { |
| 34 | ProgramInfo info = {}; |
| 35 | |
| 36 | info.selector = selector; |
| 37 | |
| 38 | auto pType = getType(selector.primaryId); |
| 39 | auto isDigital = (pType != IdentifierType::AMFM_FREQUENCY && pType != IdentifierType::RDS_PI); |
| 40 | |
| 41 | info.infoFlags |= ProgramInfoFlags::TUNED; |
| 42 | info.infoFlags |= ProgramInfoFlags::STEREO; |
| 43 | info.signalQuality = isDigital ? 100 : 80; |
| 44 | |
| 45 | info.metadata = hidl_vec<Metadata>({ |
| 46 | make_metadata(MetadataKey::RDS_PS, programName), |
| 47 | make_metadata(MetadataKey::SONG_TITLE, songTitle), |
| 48 | make_metadata(MetadataKey::SONG_ARTIST, songArtist), |
| 49 | make_metadata(MetadataKey::STATION_ICON, resources::demoPngId), |
| 50 | make_metadata(MetadataKey::ALBUM_ART, resources::demoPngId), |
| 51 | }); |
| 52 | |
| 53 | info.vendorInfo = hidl_vec<VendorKeyValue>({ |
| 54 | {"com.google.dummy", "dummy"}, |
| 55 | {"com.google.dummy.VirtualProgram", std::to_string(reinterpret_cast<uintptr_t>(this))}, |
| 56 | }); |
| 57 | |
| 58 | return info; |
| 59 | } |
| 60 | |
| 61 | bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) { |
| 62 | auto& l = lhs.selector; |
| 63 | auto& r = rhs.selector; |
| 64 | |
| 65 | // Two programs with the same primaryId are considered the same. |
| 66 | if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type; |
| 67 | if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value; |
| 68 | |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | } // namespace implementation |
| 73 | } // namespace V2_0 |
| 74 | } // namespace broadcastradio |
| 75 | } // namespace hardware |
| 76 | } // namespace android |