Home | History | Annotate | Download | only in default
      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 <broadcastradio-utils/Utils.h>
     19 
     20 #include "resources.h"
     21 
     22 namespace android {
     23 namespace hardware {
     24 namespace broadcastradio {
     25 namespace V1_1 {
     26 namespace implementation {
     27 
     28 using std::vector;
     29 
     30 using V1_0::MetaData;
     31 using V1_0::MetadataKey;
     32 using V1_0::MetadataType;
     33 using utils::HalRevision;
     34 
     35 static MetaData createDemoBitmap(MetadataKey key, HalRevision halRev) {
     36     MetaData bmp = {MetadataType::INT, key, resources::demoPngId, {}, {}, {}};
     37     if (halRev < HalRevision::V1_1) {
     38         bmp.type = MetadataType::RAW;
     39         bmp.intValue = 0;
     40         bmp.rawValue = hidl_vec<uint8_t>(resources::demoPng, std::end(resources::demoPng));
     41     }
     42     return bmp;
     43 }
     44 
     45 ProgramInfo VirtualProgram::getProgramInfo(HalRevision halRev) const {
     46     ProgramInfo info11 = {};
     47     auto& info10 = info11.base;
     48 
     49     utils::getLegacyChannel(selector, &info10.channel, &info10.subChannel);
     50     info11.selector = selector;
     51     info10.tuned = true;
     52     info10.stereo = true;
     53     info10.digital = utils::isDigital(selector);
     54     info10.signalStrength = info10.digital ? 100 : 80;
     55 
     56     info10.metadata = hidl_vec<MetaData>({
     57         {MetadataType::TEXT, MetadataKey::RDS_PS, {}, {}, programName, {}},
     58         {MetadataType::TEXT, MetadataKey::TITLE, {}, {}, songTitle, {}},
     59         {MetadataType::TEXT, MetadataKey::ARTIST, {}, {}, songArtist, {}},
     60         createDemoBitmap(MetadataKey::ICON, halRev),
     61         createDemoBitmap(MetadataKey::ART, halRev),
     62     });
     63 
     64     info11.vendorInfo = hidl_vec<VendorKeyValue>({
     65         {"com.google.dummy", "dummy"},
     66         {"com.google.dummy.VirtualProgram", std::to_string(reinterpret_cast<uintptr_t>(this))},
     67     });
     68 
     69     return info11;
     70 }
     71 
     72 // Defining order on virtual programs, how they appear on band.
     73 // It's mostly for default implementation purposes, may not be complete or correct.
     74 bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) {
     75     auto& l = lhs.selector;
     76     auto& r = rhs.selector;
     77 
     78     // Two programs with the same primaryId is considered the same.
     79     if (l.programType != r.programType) return l.programType < r.programType;
     80     if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type;
     81     if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value;
     82 
     83     // A little exception for HD Radio subchannel - we check secondary ID too.
     84     if (utils::hasId(l, IdentifierType::HD_SUBCHANNEL) &&
     85         utils::hasId(r, IdentifierType::HD_SUBCHANNEL)) {
     86         return utils::getId(l, IdentifierType::HD_SUBCHANNEL) <
     87                utils::getId(r, IdentifierType::HD_SUBCHANNEL);
     88     }
     89 
     90     return false;
     91 }
     92 
     93 vector<ProgramInfo> getProgramInfoVector(const vector<VirtualProgram>& vec, HalRevision halRev) {
     94     vector<ProgramInfo> out;
     95     out.reserve(vec.size());
     96     for (auto&& program : vec) {
     97         out.push_back(program.getProgramInfo(halRev));
     98     }
     99     return out;
    100 }
    101 
    102 }  // namespace implementation
    103 }  // namespace V1_1
    104 }  // namespace broadcastradio
    105 }  // namespace hardware
    106 }  // namespace android
    107