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 21 import com.android.tv.settings.util.bluetooth.BluetoothDeviceCriteria; 22 23 public class InputDeviceCriteria extends BluetoothDeviceCriteria { 24 25 public static final int MINOR_DEVICE_CLASS_POINTING = 26 Integer.parseInt("0000010000000", 2); 27 public static final int MINOR_DEVICE_CLASS_JOYSTICK = 28 Integer.parseInt("0000000000100", 2); 29 public static final int MINOR_DEVICE_CLASS_GAMEPAD = 30 Integer.parseInt("0000000001000", 2); 31 public static final int MINOR_DEVICE_CLASS_KEYBOARD = 32 Integer.parseInt("0000001000000", 2); 33 public static final int MINOR_DEVICE_CLASS_REMOTE = 34 Integer.parseInt("0000000001100", 2); 35 36 @Override isMatchingMajorDeviceClass(int majorDeviceClass)37 public boolean isMatchingMajorDeviceClass(int majorDeviceClass) { 38 return majorDeviceClass == BluetoothClass.Device.Major.PERIPHERAL; 39 } 40 41 @Override isMatchingDeviceClass(int majorMinorClass)42 public boolean isMatchingDeviceClass(int majorMinorClass) { 43 int acceptableDevicesMask = MINOR_DEVICE_CLASS_POINTING | MINOR_DEVICE_CLASS_JOYSTICK | 44 MINOR_DEVICE_CLASS_GAMEPAD | MINOR_DEVICE_CLASS_KEYBOARD | 45 MINOR_DEVICE_CLASS_REMOTE; 46 47 return (acceptableDevicesMask & majorMinorClass) != 0; 48 } 49 isInputDevice(BluetoothClass bluetoothClass)50 public boolean isInputDevice(BluetoothClass bluetoothClass) { 51 return isMatchingMajorDeviceClass(bluetoothClass.getMajorDeviceClass()) && 52 isMatchingDeviceClass(bluetoothClass.getDeviceClass()); 53 } 54 } 55