1 /* 2 * Copyright 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 package com.android.settingslib.media; 17 18 import android.bluetooth.BluetoothDevice; 19 import android.media.MediaRoute2Info; 20 21 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 22 23 /** 24 * MediaDeviceUtils provides utility function for MediaDevice 25 */ 26 public class MediaDeviceUtils { 27 /** 28 * Use CachedBluetoothDevice address to represent unique id 29 * 30 * @param cachedDevice the CachedBluetoothDevice 31 * @return CachedBluetoothDevice address 32 */ getId(CachedBluetoothDevice cachedDevice)33 public static String getId(CachedBluetoothDevice cachedDevice) { 34 if (cachedDevice.isHearingAidDevice()) { 35 return Long.toString(cachedDevice.getHiSyncId()); 36 } 37 return cachedDevice.getAddress(); 38 } 39 40 /** 41 * Use BluetoothDevice address to represent unique id 42 * 43 * @param bluetoothDevice the BluetoothDevice 44 * @return BluetoothDevice address 45 */ getId(BluetoothDevice bluetoothDevice)46 public static String getId(BluetoothDevice bluetoothDevice) { 47 return bluetoothDevice.getAddress(); 48 } 49 50 /** 51 * Use MediaRoute2Info id to represent unique id 52 * 53 * @param route the MediaRoute2Info 54 * @return MediaRoute2Info id 55 */ getId(MediaRoute2Info route)56 public static String getId(MediaRoute2Info route) { 57 return route.getId(); 58 } 59 } 60