1 /*
2  * Copyright (C) 2014 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.tv.settings.accessories;
18 
19 import android.bluetooth.BluetoothClass;
20 import android.bluetooth.BluetoothDevice;
21 
22 import androidx.annotation.DrawableRes;
23 import androidx.annotation.NonNull;
24 
25 import com.android.tv.settings.R;
26 
27 /*
28  * Provide utilities for Remote & Accessories.
29  */
30 public class AccessoryUtils {
getImageIdForDevice(@onNull BluetoothDevice dev)31     public static @DrawableRes int getImageIdForDevice(@NonNull BluetoothDevice dev) {
32         final BluetoothClass bluetoothClass = dev.getBluetoothClass();
33         if (bluetoothClass == null) {
34             return R.drawable.ic_bluetooth;
35         }
36 
37         final int devClass = bluetoothClass.getDeviceClass();
38 
39         if (devClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) {
40             return R.drawable.ic_headset_mic;
41         } else if (devClass == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES ||
42                 devClass == BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER ||
43                 devClass == BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO ||
44                 devClass == BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO) {
45             return R.drawable.ic_headset;
46         } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_POINTING) != 0) {
47             return R.drawable.ic_mouse;
48         } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_JOYSTICK) != 0) {
49             return R.drawable.ic_games;
50         } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_GAMEPAD) != 0) {
51             return R.drawable.ic_games;
52         } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_KEYBOARD) != 0) {
53             return R.drawable.ic_keyboard;
54         }
55 
56         // Default for now
57         return R.drawable.ic_bluetooth;
58     }
59 
AccessoryUtils()60     private AccessoryUtils() {
61         // do not allow instantiation
62     }
63 }
64