Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 android.bluetooth; |
| 18 | |
| 19 | import android.util.Log; |
| 20 | |
| 21 | /** @hide */ |
| 22 | public abstract class BluetoothHidDeviceCallback { |
| 23 | |
| 24 | private static final String TAG = BluetoothHidDeviceCallback.class.getSimpleName(); |
| 25 | |
| 26 | /** |
| 27 | * Callback called when application registration state changes. Usually it's |
| 28 | * called due to either |
| 29 | * {@link BluetoothHidDevice#registerApp(String, String, String, byte, byte[], |
| 30 | * BluetoothHidDeviceCallback)} |
| 31 | * or |
| 32 | * {@link BluetoothHidDevice#unregisterApp(BluetoothHidDeviceAppConfiguration)} |
| 33 | * , but can be also unsolicited in case e.g. Bluetooth was turned off in |
| 34 | * which case application is unregistered automatically. |
| 35 | * |
| 36 | * @param pluggedDevice {@link BluetoothDevice} object which represents host |
| 37 | * that currently has Virtual Cable established with device. Only |
| 38 | * valid when application is registered, can be <code>null</code> |
| 39 | * . |
| 40 | * @param config {@link BluetoothHidDeviceAppConfiguration} object which |
| 41 | * represents token required to unregister application using |
| 42 | * {@link BluetoothHidDevice#unregisterApp(BluetoothHidDeviceAppConfiguration)} |
| 43 | * . |
| 44 | * @param registered <code>true</code> if application is registered, |
| 45 | * <code>false</code> otherwise. |
| 46 | */ |
| 47 | public void onAppStatusChanged(BluetoothDevice pluggedDevice, |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 48 | BluetoothHidDeviceAppConfiguration config, boolean registered) { |
| 49 | Log.d(TAG, "onAppStatusChanged: pluggedDevice=" + pluggedDevice + " registered=" |
| 50 | + registered); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Callback called when connection state with remote host was changed. |
| 55 | * Application can assume than Virtual Cable is established when called with |
| 56 | * {@link BluetoothProfile#STATE_CONNECTED} <code>state</code>. |
| 57 | * |
| 58 | * @param device {@link BluetoothDevice} object representing host device |
| 59 | * which connection state was changed. |
| 60 | * @param state Connection state as defined in {@link BluetoothProfile}. |
| 61 | */ |
| 62 | public void onConnectionStateChanged(BluetoothDevice device, int state) { |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 63 | Log.d(TAG, "onConnectionStateChanged: device=" + device + " state=" + state); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Callback called when GET_REPORT is received from remote host. Should be |
| 68 | * replied by application using |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 69 | * {@link BluetoothHidDevice#replyReport(BluetoothDevice, byte, byte, byte[])}. |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 70 | * |
| 71 | * @param type Requested Report Type. |
| 72 | * @param id Requested Report Id, can be 0 if no Report Id are defined in |
| 73 | * descriptor. |
| 74 | * @param bufferSize Requested buffer size, application shall respond with |
| 75 | * at least given number of bytes. |
| 76 | */ |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 77 | public void onGetReport(BluetoothDevice device, byte type, byte id, int bufferSize) { |
| 78 | Log.d(TAG, "onGetReport: device=" + device + " type=" + type + " id=" + id + " bufferSize=" |
| 79 | + bufferSize); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Callback called when SET_REPORT is received from remote host. In case |
| 84 | * received data are invalid, application shall respond with |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 85 | * {@link BluetoothHidDevice#reportError(BluetoothDevice)}. |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 86 | * |
| 87 | * @param type Report Type. |
| 88 | * @param id Report Id. |
| 89 | * @param data Report data. |
| 90 | */ |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 91 | public void onSetReport(BluetoothDevice device, byte type, byte id, byte[] data) { |
| 92 | Log.d(TAG, "onSetReport: device=" + device + " type=" + type + " id=" + id); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Callback called when SET_PROTOCOL is received from remote host. |
| 97 | * Application shall use this information to send only reports valid for |
| 98 | * given protocol mode. By default, |
| 99 | * {@link BluetoothHidDevice#PROTOCOL_REPORT_MODE} shall be assumed. |
| 100 | * |
| 101 | * @param protocol Protocol Mode. |
| 102 | */ |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 103 | public void onSetProtocol(BluetoothDevice device, byte protocol) { |
| 104 | Log.d(TAG, "onSetProtocol: device=" + device + " protocol=" + protocol); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Callback called when report data is received over interrupt channel. |
| 109 | * Report Type is assumed to be |
| 110 | * {@link BluetoothHidDevice#REPORT_TYPE_OUTPUT}. |
| 111 | * |
| 112 | * @param reportId Report Id. |
| 113 | * @param data Report data. |
| 114 | */ |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 115 | public void onIntrData(BluetoothDevice device, byte reportId, byte[] data) { |
| 116 | Log.d(TAG, "onIntrData: device=" + device + " reportId=" + reportId); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Callback called when Virtual Cable is removed. This can be either due to |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 121 | * {@link BluetoothHidDevice#unplug(BluetoothDevice)} or request from remote |
| 122 | * side. After this callback is received connection will be disconnected |
| 123 | * automatically. |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 124 | */ |
Ivan Podogov | dd87cd3 | 2016-12-30 14:43:29 +0000 | [diff] [blame] | 125 | public void onVirtualCableUnplug(BluetoothDevice device) { |
| 126 | Log.d(TAG, "onVirtualCableUnplug: device=" + device); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 127 | } |
| 128 | } |