1 /** 2 * Copyright (C) 2018 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 17 package com.android.car.broadcastradio.support.platform; 18 19 import android.annotation.NonNull; 20 import android.hardware.radio.RadioMetadata; 21 22 /** 23 * Proposed extensions to android.hardware.radio.RadioMetadata. 24 * 25 * They might eventually get pushed to the framework. 26 */ 27 public class RadioMetadataExt { 28 private static int sModuleId; 29 30 /** 31 * A hack to inject module ID for getGlobalBitmapId. When pushed to the framework, 32 * it will be set with RadioMetadata object creation or just separate int field. 33 * @hide 34 */ setModuleId(int id)35 public static void setModuleId(int id) { 36 sModuleId = id; 37 } 38 39 /** 40 * Proposed redefinition of {@link RadioMetadata#getBitmapId}. 41 * 42 * {@link RadioMetadata#getBitmapId} isn't part of the system API yet, so we can skip 43 * deprecation here and jump straight to the correct solution. 44 */ getGlobalBitmapId(@onNull RadioMetadata meta, @NonNull String key)45 public static long getGlobalBitmapId(@NonNull RadioMetadata meta, @NonNull String key) { 46 int localId = meta.getBitmapId(key); 47 if (localId == 0) return 0; 48 49 /* When generating global bitmap ID, we want them to remain stable between sessions 50 * (radio app might cache images to disk between sessions). 51 * 52 * Local IDs are already stable, but module ID is not guaranteed to be stable (i.e. some 53 * module might be not available at each boot, due to HW failure). 54 * 55 * When we push this to the framework, we will need persistence mechanism at the radio 56 * service to permanently match modules to their IDs. 57 */ 58 return ((long) sModuleId << 32) | localId; 59 } 60 } 61