1 /* 2 * Copyright (C) 2013 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 /** 20 * This abstract class is used to implement {@link BluetoothGatt} callbacks. 21 */ 22 public abstract class BluetoothGattCallback { 23 24 /** 25 * Callback indicating when GATT client has connected/disconnected to/from a remote 26 * GATT server. 27 * 28 * @param gatt GATT client 29 * @param status Status of the connect or disconnect operation. 30 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 31 * @param newState Returns the new connection state. Can be one of 32 * {@link BluetoothProfile#STATE_DISCONNECTED} or 33 * {@link BluetoothProfile#STATE_CONNECTED} 34 */ 35 public void onConnectionStateChange(BluetoothGatt gatt, int status, 36 int newState) { 37 } 38 39 /** 40 * Callback invoked when the list of remote services, characteristics and descriptors 41 * for the remote device have been updated, ie new services have been discovered. 42 * 43 * @param gatt GATT client invoked {@link BluetoothGatt#discoverServices} 44 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device 45 * has been explored successfully. 46 */ 47 public void onServicesDiscovered(BluetoothGatt gatt, int status) { 48 } 49 50 /** 51 * Callback reporting the result of a characteristic read operation. 52 * 53 * @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic} 54 * @param characteristic Characteristic that was read from the associated 55 * remote device. 56 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation 57 * was completed successfully. 58 */ 59 public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, 60 int status) { 61 } 62 63 /** 64 * Callback indicating the result of a characteristic write operation. 65 * 66 * <p>If this callback is invoked while a reliable write transaction is 67 * in progress, the value of the characteristic represents the value 68 * reported by the remote device. An application should compare this 69 * value to the desired value to be written. If the values don't match, 70 * the application must abort the reliable write transaction. 71 * 72 * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic} 73 * @param characteristic Characteristic that was written to the associated 74 * remote device. 75 * @param status The result of the write operation 76 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 77 */ 78 public void onCharacteristicWrite(BluetoothGatt gatt, 79 BluetoothGattCharacteristic characteristic, int status) { 80 } 81 82 /** 83 * Callback triggered as a result of a remote characteristic notification. 84 * 85 * @param gatt GATT client the characteristic is associated with 86 * @param characteristic Characteristic that has been updated as a result 87 * of a remote notification event. 88 */ 89 public void onCharacteristicChanged(BluetoothGatt gatt, 90 BluetoothGattCharacteristic characteristic) { 91 } 92 93 /** 94 * Callback reporting the result of a descriptor read operation. 95 * 96 * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor} 97 * @param descriptor Descriptor that was read from the associated 98 * remote device. 99 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation 100 * was completed successfully 101 */ 102 public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, 103 int status) { 104 } 105 106 /** 107 * Callback indicating the result of a descriptor write operation. 108 * 109 * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor} 110 * @param descriptor Descriptor that was writte to the associated 111 * remote device. 112 * @param status The result of the write operation 113 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 114 */ 115 public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, 116 int status) { 117 } 118 119 /** 120 * Callback invoked when a reliable write transaction has been completed. 121 * 122 * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite} 123 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write 124 * transaction was executed successfully 125 */ 126 public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { 127 } 128 129 /** 130 * Callback reporting the RSSI for a remote device connection. 131 * 132 * This callback is triggered in response to the 133 * {@link BluetoothGatt#readRemoteRssi} function. 134 * 135 * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi} 136 * @param rssi The RSSI value for the remote device 137 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully 138 */ 139 public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { 140 } 141 142 /** 143 * Callback indicating the MTU for a given device connection has changed. 144 * 145 * This callback is triggered in response to the 146 * {@link BluetoothGatt#requestMtu} function, or in response to a connection 147 * event. 148 * 149 * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu} 150 * @param mtu The new MTU size 151 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully 152 */ 153 public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { 154 } 155 } 156