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