Merge "Bluetooth 5 PHY selection API"

This commit is contained in:
Jakub Pawlowski
2017-03-08 19:04:30 +00:00
committed by Gerrit Code Review
14 changed files with 775 additions and 302 deletions

View File

@@ -128,8 +128,8 @@ LOCAL_SRC_FILES += \
core/java/android/bluetooth/IBluetoothInputHost.aidl \
core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl \
core/java/android/bluetooth/IBluetoothGatt.aidl \
core/java/android/bluetooth/IBluetoothGattCallback.aidl \
core/java/android/bluetooth/IBluetoothGattServerCallback.aidl \
core/java/android/bluetooth/IBluetoothGattCallbackExt.aidl \
core/java/android/bluetooth/IBluetoothGattServerCallbackExt.aidl \
core/java/android/bluetooth/le/IAdvertiserCallback.aidl \
core/java/android/bluetooth/le/IPeriodicAdvertisingCallback.aidl \
core/java/android/bluetooth/le/IScannerCallback.aidl \

View File

@@ -7076,6 +7076,9 @@ package android.bluetooth {
public final class BluetoothDevice implements android.os.Parcelable {
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int, int);
method public boolean createBond();
method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
@@ -7119,6 +7122,13 @@ package android.bluetooth {
field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2
field public static final int PAIRING_VARIANT_PIN = 0; // 0x0
field public static final int PHY_LE_1M = 1; // 0x1
field public static final int PHY_LE_2M = 2; // 0x2
field public static final int PHY_LE_ANY = 7; // 0x7
field public static final int PHY_LE_CODED = 4; // 0x4
field public static final int PHY_OPTION_NO_PREFERRED = 0; // 0x0
field public static final int PHY_OPTION_S2 = 1; // 0x1
field public static final int PHY_OPTION_S8 = 2; // 0x2
field public static final int TRANSPORT_AUTO = 0; // 0x0
field public static final int TRANSPORT_BREDR = 1; // 0x1
field public static final int TRANSPORT_LE = 2; // 0x2
@@ -7141,10 +7151,12 @@ package android.bluetooth {
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean readCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean readDescriptor(android.bluetooth.BluetoothGattDescriptor);
method public void readPhy();
method public boolean readRemoteRssi();
method public boolean requestConnectionPriority(int);
method public boolean requestMtu(int);
method public boolean setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean);
method public void setPreferredPhy(int, int, int);
method public boolean writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean writeDescriptor(android.bluetooth.BluetoothGattDescriptor);
field public static final int CONNECTION_PRIORITY_BALANCED = 0; // 0x0
@@ -7162,8 +7174,12 @@ package android.bluetooth {
field public static final int GATT_WRITE_NOT_PERMITTED = 3; // 0x3
}
public abstract class BluetoothGattCallback {
public abstract deprecated class BluetoothGattCallback extends android.bluetooth.BluetoothGattCallbackExt {
ctor public BluetoothGattCallback();
}
public abstract class BluetoothGattCallbackExt {
ctor public BluetoothGattCallbackExt();
method public void onCharacteristicChanged(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
method public void onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
@@ -7171,6 +7187,8 @@ package android.bluetooth {
method public void onDescriptorRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onMtuChanged(android.bluetooth.BluetoothGatt, int, int);
method public void onPhyRead(android.bluetooth.BluetoothGatt, int, int, int);
method public void onPhyUpdate(android.bluetooth.BluetoothGatt, int, int, int);
method public void onReadRemoteRssi(android.bluetooth.BluetoothGatt, int, int);
method public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt, int);
method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
@@ -7264,12 +7282,18 @@ package android.bluetooth {
method public android.bluetooth.BluetoothGattService getService(java.util.UUID);
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean notifyCharacteristicChanged(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothGattCharacteristic, boolean);
method public void readPhy(android.bluetooth.BluetoothDevice);
method public boolean removeService(android.bluetooth.BluetoothGattService);
method public boolean sendResponse(android.bluetooth.BluetoothDevice, int, int, int, byte[]);
method public void setPreferredPhy(android.bluetooth.BluetoothDevice, int, int, int);
}
public abstract class BluetoothGattServerCallback {
public abstract deprecated class BluetoothGattServerCallback extends android.bluetooth.BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallback();
}
public abstract class BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallbackExt();
method public void onCharacteristicReadRequest(android.bluetooth.BluetoothDevice, int, int, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicWriteRequest(android.bluetooth.BluetoothDevice, int, android.bluetooth.BluetoothGattCharacteristic, boolean, boolean, int, byte[]);
method public void onConnectionStateChange(android.bluetooth.BluetoothDevice, int, int);
@@ -7278,6 +7302,8 @@ package android.bluetooth {
method public void onExecuteWrite(android.bluetooth.BluetoothDevice, int, boolean);
method public void onMtuChanged(android.bluetooth.BluetoothDevice, int);
method public void onNotificationSent(android.bluetooth.BluetoothDevice, int);
method public void onPhyRead(android.bluetooth.BluetoothDevice, int, int, int);
method public void onPhyUpdate(android.bluetooth.BluetoothDevice, int, int, int);
method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
}

View File

@@ -7378,6 +7378,9 @@ package android.bluetooth {
public final class BluetoothDevice implements android.os.Parcelable {
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int, int);
method public boolean createBond();
method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
@@ -7423,6 +7426,13 @@ package android.bluetooth {
field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2
field public static final int PAIRING_VARIANT_PIN = 0; // 0x0
field public static final int PHY_LE_1M = 1; // 0x1
field public static final int PHY_LE_2M = 2; // 0x2
field public static final int PHY_LE_ANY = 7; // 0x7
field public static final int PHY_LE_CODED = 4; // 0x4
field public static final int PHY_OPTION_NO_PREFERRED = 0; // 0x0
field public static final int PHY_OPTION_S2 = 1; // 0x1
field public static final int PHY_OPTION_S8 = 2; // 0x2
field public static final int TRANSPORT_AUTO = 0; // 0x0
field public static final int TRANSPORT_BREDR = 1; // 0x1
field public static final int TRANSPORT_LE = 2; // 0x2
@@ -7445,10 +7455,12 @@ package android.bluetooth {
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean readCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean readDescriptor(android.bluetooth.BluetoothGattDescriptor);
method public void readPhy();
method public boolean readRemoteRssi();
method public boolean requestConnectionPriority(int);
method public boolean requestMtu(int);
method public boolean setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean);
method public void setPreferredPhy(int, int, int);
method public boolean writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean writeDescriptor(android.bluetooth.BluetoothGattDescriptor);
field public static final int CONNECTION_PRIORITY_BALANCED = 0; // 0x0
@@ -7466,8 +7478,12 @@ package android.bluetooth {
field public static final int GATT_WRITE_NOT_PERMITTED = 3; // 0x3
}
public abstract class BluetoothGattCallback {
public abstract deprecated class BluetoothGattCallback extends android.bluetooth.BluetoothGattCallbackExt {
ctor public BluetoothGattCallback();
}
public abstract class BluetoothGattCallbackExt {
ctor public BluetoothGattCallbackExt();
method public void onCharacteristicChanged(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
method public void onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
@@ -7475,6 +7491,8 @@ package android.bluetooth {
method public void onDescriptorRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onMtuChanged(android.bluetooth.BluetoothGatt, int, int);
method public void onPhyRead(android.bluetooth.BluetoothGatt, int, int, int);
method public void onPhyUpdate(android.bluetooth.BluetoothGatt, int, int, int);
method public void onReadRemoteRssi(android.bluetooth.BluetoothGatt, int, int);
method public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt, int);
method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
@@ -7568,12 +7586,18 @@ package android.bluetooth {
method public android.bluetooth.BluetoothGattService getService(java.util.UUID);
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean notifyCharacteristicChanged(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothGattCharacteristic, boolean);
method public void readPhy(android.bluetooth.BluetoothDevice);
method public boolean removeService(android.bluetooth.BluetoothGattService);
method public boolean sendResponse(android.bluetooth.BluetoothDevice, int, int, int, byte[]);
method public void setPreferredPhy(android.bluetooth.BluetoothDevice, int, int, int);
}
public abstract class BluetoothGattServerCallback {
public abstract deprecated class BluetoothGattServerCallback extends android.bluetooth.BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallback();
}
public abstract class BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallbackExt();
method public void onCharacteristicReadRequest(android.bluetooth.BluetoothDevice, int, int, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicWriteRequest(android.bluetooth.BluetoothDevice, int, android.bluetooth.BluetoothGattCharacteristic, boolean, boolean, int, byte[]);
method public void onConnectionStateChange(android.bluetooth.BluetoothDevice, int, int);
@@ -7582,6 +7606,8 @@ package android.bluetooth {
method public void onExecuteWrite(android.bluetooth.BluetoothDevice, int, boolean);
method public void onMtuChanged(android.bluetooth.BluetoothDevice, int);
method public void onNotificationSent(android.bluetooth.BluetoothDevice, int);
method public void onPhyRead(android.bluetooth.BluetoothDevice, int, int, int);
method public void onPhyUpdate(android.bluetooth.BluetoothDevice, int, int, int);
method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
}

View File

@@ -7085,6 +7085,9 @@ package android.bluetooth {
public final class BluetoothDevice implements android.os.Parcelable {
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int);
method public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallbackExt, int, int);
method public boolean createBond();
method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException;
@@ -7128,6 +7131,13 @@ package android.bluetooth {
field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2
field public static final int PAIRING_VARIANT_PIN = 0; // 0x0
field public static final int PHY_LE_1M = 1; // 0x1
field public static final int PHY_LE_2M = 2; // 0x2
field public static final int PHY_LE_ANY = 7; // 0x7
field public static final int PHY_LE_CODED = 4; // 0x4
field public static final int PHY_OPTION_NO_PREFERRED = 0; // 0x0
field public static final int PHY_OPTION_S2 = 1; // 0x1
field public static final int PHY_OPTION_S8 = 2; // 0x2
field public static final int TRANSPORT_AUTO = 0; // 0x0
field public static final int TRANSPORT_BREDR = 1; // 0x1
field public static final int TRANSPORT_LE = 2; // 0x2
@@ -7150,10 +7160,12 @@ package android.bluetooth {
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean readCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean readDescriptor(android.bluetooth.BluetoothGattDescriptor);
method public void readPhy();
method public boolean readRemoteRssi();
method public boolean requestConnectionPriority(int);
method public boolean requestMtu(int);
method public boolean setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean);
method public void setPreferredPhy(int, int, int);
method public boolean writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
method public boolean writeDescriptor(android.bluetooth.BluetoothGattDescriptor);
field public static final int CONNECTION_PRIORITY_BALANCED = 0; // 0x0
@@ -7171,8 +7183,12 @@ package android.bluetooth {
field public static final int GATT_WRITE_NOT_PERMITTED = 3; // 0x3
}
public abstract class BluetoothGattCallback {
public abstract deprecated class BluetoothGattCallback extends android.bluetooth.BluetoothGattCallbackExt {
ctor public BluetoothGattCallback();
}
public abstract class BluetoothGattCallbackExt {
ctor public BluetoothGattCallbackExt();
method public void onCharacteristicChanged(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
method public void onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int);
@@ -7180,6 +7196,8 @@ package android.bluetooth {
method public void onDescriptorRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int);
method public void onMtuChanged(android.bluetooth.BluetoothGatt, int, int);
method public void onPhyRead(android.bluetooth.BluetoothGatt, int, int, int);
method public void onPhyUpdate(android.bluetooth.BluetoothGatt, int, int, int);
method public void onReadRemoteRssi(android.bluetooth.BluetoothGatt, int, int);
method public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt, int);
method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
@@ -7273,12 +7291,18 @@ package android.bluetooth {
method public android.bluetooth.BluetoothGattService getService(java.util.UUID);
method public java.util.List<android.bluetooth.BluetoothGattService> getServices();
method public boolean notifyCharacteristicChanged(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothGattCharacteristic, boolean);
method public void readPhy(android.bluetooth.BluetoothDevice);
method public boolean removeService(android.bluetooth.BluetoothGattService);
method public boolean sendResponse(android.bluetooth.BluetoothDevice, int, int, int, byte[]);
method public void setPreferredPhy(android.bluetooth.BluetoothDevice, int, int, int);
}
public abstract class BluetoothGattServerCallback {
public abstract deprecated class BluetoothGattServerCallback extends android.bluetooth.BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallback();
}
public abstract class BluetoothGattServerCallbackExt {
ctor public BluetoothGattServerCallbackExt();
method public void onCharacteristicReadRequest(android.bluetooth.BluetoothDevice, int, int, android.bluetooth.BluetoothGattCharacteristic);
method public void onCharacteristicWriteRequest(android.bluetooth.BluetoothDevice, int, android.bluetooth.BluetoothGattCharacteristic, boolean, boolean, int, byte[]);
method public void onConnectionStateChange(android.bluetooth.BluetoothDevice, int, int);
@@ -7287,6 +7311,8 @@ package android.bluetooth {
method public void onExecuteWrite(android.bluetooth.BluetoothDevice, int, boolean);
method public void onMtuChanged(android.bluetooth.BluetoothDevice, int);
method public void onNotificationSent(android.bluetooth.BluetoothDevice, int);
method public void onPhyRead(android.bluetooth.BluetoothDevice, int, int, int);
method public void onPhyUpdate(android.bluetooth.BluetoothDevice, int, int, int);
method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
}

View File

@@ -592,6 +592,42 @@ public final class BluetoothDevice implements Parcelable {
*/
public static final int TRANSPORT_LE = 2;
/**
* 1M initiating PHY.
*/
public static final int PHY_LE_1M = 1;
/**
* 2M initiating PHY.
*/
public static final int PHY_LE_2M = 2;
/**
* LE Coded initiating PHY.
*/
public static final int PHY_LE_CODED = 4;
/**
* Any LE PHY.
*/
public static final int PHY_LE_ANY = PHY_LE_1M | PHY_LE_2M | PHY_LE_CODED;
/**
* No preferred coding when transmitting on the LE Coded PHY.
*/
public static final int PHY_OPTION_NO_PREFERRED = 0;
/**
* Prefer the S=2 coding to be used when transmitting on the LE Coded PHY.
*/
public static final int PHY_OPTION_S2 = 1;
/**
* Prefer the S=8 coding to be used when transmitting on the LE Coded PHY.
*/
public static final int PHY_OPTION_S8 = 2;
/** @hide */
public static final String EXTRA_MAS_INSTANCE =
"android.bluetooth.device.extra.MAS_INSTANCE";
@@ -1615,6 +1651,67 @@ public final class BluetoothDevice implements Parcelable {
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallback callback, int transport) {
return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO, PHY_LE_1M));
}
/**
* Connect to GATT Server hosted by this device. Caller acts as GATT client.
* The callback is used to deliver results to Caller, such as connection status as well
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
* @param callback GATT callback handler that will receive asynchronous callbacks.
* @param autoConnect Whether to directly connect to the remote device (false)
* or to automatically connect as soon as the remote
* device becomes available (true).
* @throws IllegalArgumentException if callback is null
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallbackExt callback) {
return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
}
/**
* Connect to GATT Server hosted by this device. Caller acts as GATT client.
* The callback is used to deliver results to Caller, such as connection status as well
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
* @param callback GATT callback handler that will receive asynchronous callbacks.
* @param autoConnect Whether to directly connect to the remote device (false)
* or to automatically connect as soon as the remote
* device becomes available (true).
* @param transport preferred transport for GATT connections to remote dual-mode devices
* {@link BluetoothDevice#TRANSPORT_AUTO} or
* {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
* @throws IllegalArgumentException if callback is null
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallbackExt callback, int transport) {
return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO, PHY_LE_1M));
}
/**
* Connect to GATT Server hosted by this device. Caller acts as GATT client.
* The callback is used to deliver results to Caller, such as connection status as well
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
* @param callback GATT callback handler that will receive asynchronous callbacks.
* @param autoConnect Whether to directly connect to the remote device (false)
* or to automatically connect as soon as the remote
* device becomes available (true).
* @param transport preferred transport for GATT connections to remote dual-mode devices
* {@link BluetoothDevice#TRANSPORT_AUTO} or
* {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
* @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of
* {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M},
* and {@link BluetoothDevice#PHY_LE_CODED}. This option does not take effect if
* {@code autoConnect} is set to true.
* @throws IllegalArgumentException if callback is null
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallbackExt callback, int transport, int phy) {
// TODO(Bluetooth) check whether platform support BLE
// Do the check here or in GattServer?
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
@@ -1625,7 +1722,7 @@ public final class BluetoothDevice implements Parcelable {
// BLE is not supported
return null;
}
BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport);
BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport, phy);
gatt.connect(autoConnect, callback);
return gatt;
} catch (RemoteException e) {Log.e(TAG, "", e);}

View File

@@ -31,7 +31,7 @@ import java.util.UUID;
* <p>This class provides Bluetooth GATT functionality to enable communication
* with Bluetooth Smart or Smart Ready devices.
*
* <p>To connect to a remote peripheral device, create a {@link BluetoothGattCallback}
* <p>To connect to a remote peripheral device, create a {@link BluetoothGattCallbackExt}
* and call {@link BluetoothDevice#connectGatt} to get a instance of this class.
* GATT capable devices can be discovered using the Bluetooth device discovery or BLE
* scan process.
@@ -42,7 +42,7 @@ public final class BluetoothGatt implements BluetoothProfile {
private static final boolean VDBG = false;
private IBluetoothGatt mService;
private BluetoothGattCallback mCallback;
private BluetoothGattCallbackExt mCallback;
private int mClientIf;
private BluetoothDevice mDevice;
private boolean mAutoConnect;
@@ -51,6 +51,7 @@ public final class BluetoothGatt implements BluetoothProfile {
private final Object mStateLock = new Object();
private Boolean mDeviceBusy = false;
private int mTransport;
private int mPhy;
private static final int AUTH_RETRY_STATE_IDLE = 0;
private static final int AUTH_RETRY_STATE_NO_MITM = 1;
@@ -132,10 +133,10 @@ public final class BluetoothGatt implements BluetoothProfile {
/*package*/ static final int AUTHENTICATION_MITM = 2;
/**
* Bluetooth GATT callbacks. Overrides the default BluetoothGattCallback implementation.
* Bluetooth GATT callbacks. Overrides the default BluetoothGattCallbackExt implementation.
*/
private final IBluetoothGattCallback mBluetoothGattCallback =
new IBluetoothGattCallback.Stub() {
private final IBluetoothGattCallbackExt mBluetoothGattCallbackExt =
new IBluetoothGattCallbackExt.Stub() {
/**
* Application interface registered - app is ready to go
* @hide
@@ -161,12 +162,50 @@ public final class BluetoothGatt implements BluetoothProfile {
}
try {
mService.clientConnect(mClientIf, mDevice.getAddress(),
!mAutoConnect, mTransport); // autoConnect is inverse of "isDirect"
!mAutoConnect, mTransport, mPhy); // autoConnect is inverse of "isDirect"
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
/**
* Phy update callback
* @hide
*/
@Override
public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
if (DBG) Log.d(TAG, "onPhyUpdate() - status=" + status
+ " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
if (!address.equals(mDevice.getAddress())) {
return;
}
try {
mCallback.onPhyUpdate(BluetoothGatt.this, txPhy, rxPhy, status);
} catch (Exception ex) {
Log.w(TAG, "Unhandled exception in callback", ex);
}
}
/**
* Phy read callback
* @hide
*/
@Override
public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
if (DBG) Log.d(TAG, "onPhyRead() - status=" + status
+ " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
if (!address.equals(mDevice.getAddress())) {
return;
}
try {
mCallback.onPhyRead(BluetoothGatt.this, txPhy, rxPhy, status);
} catch (Exception ex) {
Log.w(TAG, "Unhandled exception in callback", ex);
}
}
/**
* Client connection state changed
* @hide
@@ -503,10 +542,11 @@ public final class BluetoothGatt implements BluetoothProfile {
};
/*package*/ BluetoothGatt(IBluetoothGatt iGatt, BluetoothDevice device,
int transport) {
int transport, int phy) {
mService = iGatt;
mDevice = device;
mTransport = transport;
mPhy = phy;
mServices = new ArrayList<BluetoothGattService>();
mConnState = CONN_STATE_IDLE;
@@ -578,7 +618,7 @@ public final class BluetoothGatt implements BluetoothProfile {
/**
* Register an application callback to start using GATT.
*
* <p>This is an asynchronous call. The callback {@link BluetoothGattCallback#onAppRegistered}
* <p>This is an asynchronous call. The callback {@link BluetoothGattCallbackExt#onAppRegistered}
* is used to notify success or failure if the function returns true.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -587,7 +627,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* @return If true, the callback will be called to notify success or failure,
* false on immediate error
*/
private boolean registerApp(BluetoothGattCallback callback) {
private boolean registerApp(BluetoothGattCallbackExt callback) {
if (DBG) Log.d(TAG, "registerApp()");
if (mService == null) return false;
@@ -596,7 +636,7 @@ public final class BluetoothGatt implements BluetoothProfile {
if (DBG) Log.d(TAG, "registerApp() - UUID=" + uuid);
try {
mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallback);
mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallbackExt);
} catch (RemoteException e) {
Log.e(TAG,"",e);
return false;
@@ -626,7 +666,7 @@ public final class BluetoothGatt implements BluetoothProfile {
*
* <p>The connection may not be established right away, but will be
* completed when the remote device is available. A
* {@link BluetoothGattCallback#onConnectionStateChange} callback will be
* {@link BluetoothGattCallbackExt#onConnectionStateChange} callback will be
* invoked when the connection state changes as a result of this function.
*
* <p>The autoConnect parameter determines whether to actively connect to
@@ -644,7 +684,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* device becomes available (true).
* @return true, if the connection attempt was initiated successfully
*/
/*package*/ boolean connect(Boolean autoConnect, BluetoothGattCallback callback) {
/*package*/ boolean connect(Boolean autoConnect, BluetoothGattCallbackExt callback) {
if (DBG) Log.d(TAG, "connect() - device: " + mDevice.getAddress() + ", auto: " + autoConnect);
synchronized(mStateLock) {
if (mConnState != CONN_STATE_IDLE) {
@@ -696,7 +736,7 @@ public final class BluetoothGatt implements BluetoothProfile {
public boolean connect() {
try {
mService.clientConnect(mClientIf, mDevice.getAddress(),
false, mTransport); // autoConnect is inverse of "isDirect"
false, mTransport, mPhy); // autoConnect is inverse of "isDirect"
return true;
} catch (RemoteException e) {
Log.e(TAG,"",e);
@@ -704,6 +744,45 @@ public final class BluetoothGatt implements BluetoothProfile {
}
}
/**
* Set the preferred connection PHY for this app. Please note that this is just a
* recommendation, wether the PHY change will happen depends on other applications peferences,
* local and remote controller capabilities. Controller can override these settings.
* <p>
* {@link BluetoothGattCallbackExt#onPhyUpdate} will be triggered as a result of this call, even
* if no PHY change happens. It is also triggered when remote device updates the PHY.
*
* @param txPhy preferred transmitter PHY. Bitwise OR of any of
* {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
* {@link BluetoothDevice#PHY_LE_CODED}.
* @param rxPhy preferred receiver PHY. Bitwise OR of any of
* {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
* {@link BluetoothDevice#PHY_LE_CODED}.
* @param phyOptions preferred coding to use when transmitting on the LE Coded PHY. Can be one
* of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED},
* {@link BluetoothDevice#PHY_OPTION_S2} or {@link BluetoothDevice#PHY_OPTION_S8}
*/
public void setPreferredPhy(int txPhy, int rxPhy, int phyOptions) {
try {
mService.clientSetPreferredPhy(mClientIf, mDevice.getAddress(), txPhy, rxPhy,
phyOptions);
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
/**
* Read the current transmitter PHY and receiver PHY of the connection. The values are returned
* in {@link BluetoothGattCallbackExt#onPhyRead}
*/
public void readPhy() {
try {
mService.clientReadPhy(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
/**
* Return the remote bluetooth device this GATT client targets to
*
@@ -718,7 +797,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* characteristics and descriptors.
*
* <p>This is an asynchronous operation. Once service discovery is completed,
* the {@link BluetoothGattCallback#onServicesDiscovered} callback is
* the {@link BluetoothGattCallbackExt#onServicesDiscovered} callback is
* triggered. If the discovery was successful, the remote services can be
* retrieved using the {@link #getServices} function.
*
@@ -797,7 +876,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* Reads the requested characteristic from the associated remote device.
*
* <p>This is an asynchronous operation. The result of the read operation
* is reported by the {@link BluetoothGattCallback#onCharacteristicRead}
* is reported by the {@link BluetoothGattCallbackExt#onCharacteristicRead}
* callback.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -839,7 +918,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* Writes a given characteristic and its values to the associated remote device.
*
* <p>Once the write operation has been completed, the
* {@link BluetoothGattCallback#onCharacteristicWrite} callback is invoked,
* {@link BluetoothGattCallbackExt#onCharacteristicWrite} callback is invoked,
* reporting the result of the operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -883,7 +962,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* Reads the value for a given descriptor from the associated remote device.
*
* <p>Once the read operation has been completed, the
* {@link BluetoothGattCallback#onDescriptorRead} callback is
* {@link BluetoothGattCallbackExt#onDescriptorRead} callback is
* triggered, signaling the result of the operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -924,7 +1003,7 @@ public final class BluetoothGatt implements BluetoothProfile {
/**
* Write the value of a given descriptor to the associated remote device.
*
* <p>A {@link BluetoothGattCallback#onDescriptorWrite} callback is
* <p>A {@link BluetoothGattCallbackExt#onDescriptorWrite} callback is
* triggered to report the result of the write operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -968,7 +1047,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* <p>Once a reliable write transaction has been initiated, all calls
* to {@link #writeCharacteristic} are sent to the remote device for
* verification and queued up for atomic execution. The application will
* receive an {@link BluetoothGattCallback#onCharacteristicWrite} callback
* receive an {@link BluetoothGattCallbackExt#onCharacteristicWrite} callback
* in response to every {@link #writeCharacteristic} call and is responsible
* for verifying if the value has been transmitted accurately.
*
@@ -1002,7 +1081,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* <p>This function will commit all queued up characteristic write
* operations for a given remote device.
*
* <p>A {@link BluetoothGattCallback#onReliableWriteCompleted} callback is
* <p>A {@link BluetoothGattCallbackExt#onReliableWriteCompleted} callback is
* invoked to indicate whether the transaction has been executed correctly.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -1059,7 +1138,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* Enable or disable notifications/indications for a given characteristic.
*
* <p>Once notifications are enabled for a characteristic, a
* {@link BluetoothGattCallback#onCharacteristicChanged} callback will be
* {@link BluetoothGattCallbackExt#onCharacteristicChanged} callback will be
* triggered if the remote device indicates that the given characteristic
* has changed.
*
@@ -1114,7 +1193,7 @@ public final class BluetoothGatt implements BluetoothProfile {
/**
* Read the RSSI for a connected remote device.
*
* <p>The {@link BluetoothGattCallback#onReadRemoteRssi} callback will be
* <p>The {@link BluetoothGattCallbackExt#onReadRemoteRssi} callback will be
* invoked when the RSSI value has been read.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -1142,7 +1221,7 @@ public final class BluetoothGatt implements BluetoothProfile {
* the data sent is truncated to the MTU size. This function may be used
* to request a larger MTU size to be able to send more data at once.
*
* <p>A {@link BluetoothGattCallback#onMtuChanged} callback will indicate
* <p>A {@link BluetoothGattCallbackExt#onMtuChanged} callback will indicate
* whether this operation was successful.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.

View File

@@ -18,138 +18,22 @@ package android.bluetooth;
/**
* This abstract class is used to implement {@link BluetoothGatt} callbacks.
* @deprecated use {@link BluetoothGattCallbackExt}
*/
public abstract class BluetoothGattCallback {
public abstract class BluetoothGattCallback extends BluetoothGattCallbackExt {
/**
* Callback indicating when GATT client has connected/disconnected to/from a remote
* GATT server.
*
* @param gatt GATT client
* @param status Status of the connect or disconnect operation.
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
* @param newState Returns the new connection state. Can be one of
* {@link BluetoothProfile#STATE_DISCONNECTED} or
* {@link BluetoothProfile#STATE_CONNECTED}
* @hide
*/
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {
@Override
public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
}
/**
* Callback invoked when the list of remote services, characteristics and descriptors
* for the remote device have been updated, ie new services have been discovered.
*
* @param gatt GATT client invoked {@link BluetoothGatt#discoverServices}
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device
* has been explored successfully.
* @hide
*/
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
@Override
public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
}
/**
* Callback reporting the result of a characteristic read operation.
*
* @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic}
* @param characteristic Characteristic that was read from the associated
* remote device.
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
* was completed successfully.
*/
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
int status) {
}
/**
* Callback indicating the result of a characteristic write operation.
*
* <p>If this callback is invoked while a reliable write transaction is
* in progress, the value of the characteristic represents the value
* reported by the remote device. An application should compare this
* value to the desired value to be written. If the values don't match,
* the application must abort the reliable write transaction.
*
* @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic}
* @param characteristic Characteristic that was written to the associated
* remote device.
* @param status The result of the write operation
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
*/
public void onCharacteristicWrite(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
}
/**
* Callback triggered as a result of a remote characteristic notification.
*
* @param gatt GATT client the characteristic is associated with
* @param characteristic Characteristic that has been updated as a result
* of a remote notification event.
*/
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
}
/**
* Callback reporting the result of a descriptor read operation.
*
* @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor}
* @param descriptor Descriptor that was read from the associated
* remote device.
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
* was completed successfully
*/
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status) {
}
/**
* Callback indicating the result of a descriptor write operation.
*
* @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor}
* @param descriptor Descriptor that was writte to the associated
* remote device.
* @param status The result of the write operation
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
*/
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status) {
}
/**
* Callback invoked when a reliable write transaction has been completed.
*
* @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite}
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write
* transaction was executed successfully
*/
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
}
/**
* Callback reporting the RSSI for a remote device connection.
*
* This callback is triggered in response to the
* {@link BluetoothGatt#readRemoteRssi} function.
*
* @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi}
* @param rssi The RSSI value for the remote device
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully
*/
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
}
/**
* Callback indicating the MTU for a given device connection has changed.
*
* This callback is triggered in response to the
* {@link BluetoothGatt#requestMtu} function, or in response to a connection
* event.
*
* @param gatt GATT client invoked {@link BluetoothGatt#requestMtu}
* @param mtu The new MTU size
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully
*/
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
}
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.bluetooth;
/**
* This abstract class is used to implement {@link BluetoothGatt} callbacks.
*/
public abstract class BluetoothGattCallbackExt {
/**
* Callback triggered as result of {@link BluetoothGatt#setPreferredPhy}, or as a result of
* remote device changing the PHY.
*
* @param gatt GATT client
* @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
* @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
* @param status status of the operation
*/
public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
}
/**
* Callback triggered as result of {@link BluetoothGatt#readPhy}
*
* @param gatt GATT client
* @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
* @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
* @param status status of the operation
*/
public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
}
/**
* Callback indicating when GATT client has connected/disconnected to/from a remote
* GATT server.
*
* @param gatt GATT client
* @param status Status of the connect or disconnect operation.
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
* @param newState Returns the new connection state. Can be one of
* {@link BluetoothProfile#STATE_DISCONNECTED} or
* {@link BluetoothProfile#STATE_CONNECTED}
*/
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {
}
/**
* Callback invoked when the list of remote services, characteristics and descriptors
* for the remote device have been updated, ie new services have been discovered.
*
* @param gatt GATT client invoked {@link BluetoothGatt#discoverServices}
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device
* has been explored successfully.
*/
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
}
/**
* Callback reporting the result of a characteristic read operation.
*
* @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic}
* @param characteristic Characteristic that was read from the associated
* remote device.
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
* was completed successfully.
*/
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
int status) {
}
/**
* Callback indicating the result of a characteristic write operation.
*
* <p>If this callback is invoked while a reliable write transaction is
* in progress, the value of the characteristic represents the value
* reported by the remote device. An application should compare this
* value to the desired value to be written. If the values don't match,
* the application must abort the reliable write transaction.
*
* @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic}
* @param characteristic Characteristic that was written to the associated
* remote device.
* @param status The result of the write operation
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
*/
public void onCharacteristicWrite(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
}
/**
* Callback triggered as a result of a remote characteristic notification.
*
* @param gatt GATT client the characteristic is associated with
* @param characteristic Characteristic that has been updated as a result
* of a remote notification event.
*/
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
}
/**
* Callback reporting the result of a descriptor read operation.
*
* @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor}
* @param descriptor Descriptor that was read from the associated
* remote device.
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation
* was completed successfully
*/
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status) {
}
/**
* Callback indicating the result of a descriptor write operation.
*
* @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor}
* @param descriptor Descriptor that was writte to the associated
* remote device.
* @param status The result of the write operation
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
*/
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status) {
}
/**
* Callback invoked when a reliable write transaction has been completed.
*
* @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite}
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write
* transaction was executed successfully
*/
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
}
/**
* Callback reporting the RSSI for a remote device connection.
*
* This callback is triggered in response to the
* {@link BluetoothGatt#readRemoteRssi} function.
*
* @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi}
* @param rssi The RSSI value for the remote device
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully
*/
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
}
/**
* Callback indicating the MTU for a given device connection has changed.
*
* This callback is triggered in response to the
* {@link BluetoothGatt#requestMtu} function, or in response to a connection
* event.
*
* @param gatt GATT client invoked {@link BluetoothGatt#requestMtu}
* @param mtu The new MTU size
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully
*/
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
}
}

View File

@@ -46,7 +46,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
private BluetoothAdapter mAdapter;
private IBluetoothGatt mService;
private BluetoothGattServerCallback mCallback;
private BluetoothGattServerCallbackExt mCallback;
private Object mServerIfLock = new Object();
private int mServerIf;
@@ -59,8 +59,8 @@ public final class BluetoothGattServer implements BluetoothProfile {
/**
* Bluetooth GATT interface callbacks
*/
private final IBluetoothGattServerCallback mBluetoothGattServerCallback =
new IBluetoothGattServerCallback.Stub() {
private final IBluetoothGattServerCallbackExt mBluetoothGattServerCallback =
new IBluetoothGattServerCallbackExt.Stub() {
/**
* Application interface registered - app is ready to go
* @hide
@@ -292,6 +292,42 @@ public final class BluetoothGattServer implements BluetoothProfile {
Log.w(TAG, "Unhandled exception: " + ex);
}
}
/**
* The PHY for a connection was updated
* @hide
*/
public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
if (DBG) Log.d(TAG, "onPhyUpdate() - " + "device=" + address + ", txPHy=" + txPhy
+ ", rxPHy=" + rxPhy);
BluetoothDevice device = mAdapter.getRemoteDevice(address);
if (device == null) return;
try {
mCallback.onPhyUpdate(device, txPhy, rxPhy, status);
} catch (Exception ex) {
Log.w(TAG, "Unhandled exception: " + ex);
}
}
/**
* The PHY for a connection was read
* @hide
*/
public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
if (DBG) Log.d(TAG, "onPhyUpdate() - " + "device=" + address + ", txPHy=" + txPhy
+ ", rxPHy=" + rxPhy);
BluetoothDevice device = mAdapter.getRemoteDevice(address);
if (device == null) return;
try {
mCallback.onPhyRead(device, txPhy, rxPhy, status);
} catch (Exception ex) {
Log.w(TAG, "Unhandled exception: " + ex);
}
}
};
/**
@@ -360,7 +396,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
* @return true, the callback will be called to notify success or failure,
* false on immediate error
*/
/*package*/ boolean registerCallback(BluetoothGattServerCallback callback) {
/*package*/ boolean registerCallback(BluetoothGattServerCallbackExt callback) {
if (DBG) Log.d(TAG, "registerCallback()");
if (mService == null) {
Log.e(TAG, "GATT service not available");
@@ -436,7 +472,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
*
* <p>The connection may not be established right away, but will be
* completed when the remote device is available. A
* {@link BluetoothGattServerCallback#onConnectionStateChange} callback will be
* {@link BluetoothGattServerCallbackExt#onConnectionStateChange} callback will be
* invoked when the connection state changes as a result of this function.
*
* <p>The autoConnect paramter determines whether to actively connect to
@@ -487,6 +523,48 @@ public final class BluetoothGattServer implements BluetoothProfile {
}
}
/**
* Set the preferred connection PHY for this app. Please note that this is just a
* recommendation, wether the PHY change will happen depends on other applications peferences,
* local and remote controller capabilities. Controller can override these settings.
* <p>
* {@link BluetoothGattServerCallbackExt#onPhyUpdate} will be triggered as a result of this call, even
* if no PHY change happens. It is also triggered when remote device updates the PHY.
*
* @param device The remote device to send this response to
* @param txPhy preferred transmitter PHY. Bitwise OR of any of
* {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
* {@link BluetoothDevice#PHY_LE_CODED}.
* @param rxPhy preferred receiver PHY. Bitwise OR of any of
* {@link BluetoothDevice#PHY_LE_1M}, {@link BluetoothDevice#PHY_LE_2M}, and
* {@link BluetoothDevice#PHY_LE_CODED}.
* @param phyOptions preferred coding to use when transmitting on the LE Coded PHY. Can be one
* of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED},
* {@link BluetoothDevice#PHY_OPTION_S2} or {@link BluetoothDevice#PHY_OPTION_S8}
*/
public void setPreferredPhy(BluetoothDevice device, int txPhy, int rxPhy, int phyOptions) {
try {
mService.serverSetPreferredPhy(mServerIf, device.getAddress(), txPhy, rxPhy,
phyOptions);
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
/**
* Read the current transmitter PHY and receiver PHY of the connection. The values are returned
* in {@link BluetoothGattServerCallbackExt#onPhyRead}
*
* @param device The remote device to send this response to
*/
public void readPhy(BluetoothDevice device) {
try {
mService.serverReadPhy(mServerIf, device.getAddress());
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
/**
* Send a response to a read or write request to a remote device.
*
@@ -494,10 +572,10 @@ public final class BluetoothGattServer implements BluetoothProfile {
* is received by one of these callback methods:
*
* <ul>
* <li>{@link BluetoothGattServerCallback#onCharacteristicReadRequest}
* <li>{@link BluetoothGattServerCallback#onCharacteristicWriteRequest}
* <li>{@link BluetoothGattServerCallback#onDescriptorReadRequest}
* <li>{@link BluetoothGattServerCallback#onDescriptorWriteRequest}
* <li>{@link BluetoothGattServerCallbackExt#onCharacteristicReadRequest}
* <li>{@link BluetoothGattServerCallbackExt#onCharacteristicWriteRequest}
* <li>{@link BluetoothGattServerCallbackExt#onDescriptorReadRequest}
* <li>{@link BluetoothGattServerCallbackExt#onDescriptorWriteRequest}
* </ul>
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,141 +20,21 @@ import android.bluetooth.BluetoothDevice;
/**
* This abstract class is used to implement {@link BluetoothGattServer} callbacks.
* @deprecated please use {@link BluetoothGattServerCallbackExt}
*/
public abstract class BluetoothGattServerCallback {
public abstract class BluetoothGattServerCallback extends BluetoothGattServerCallbackExt {
/**
* Callback indicating when a remote device has been connected or disconnected.
*
* @param device Remote device that has been connected or disconnected.
* @param status Status of the connect or disconnect operation.
* @param newState Returns the new connection state. Can be one of
* {@link BluetoothProfile#STATE_DISCONNECTED} or
* {@link BluetoothProfile#STATE_CONNECTED}
* @hide
*/
public void onConnectionStateChange(BluetoothDevice device, int status,
int newState) {
@Override
public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) {
}
/**
* Indicates whether a local service has been added successfully.
*
* @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service
* was added successfully.
* @param service The service that has been added
* @hide
*/
public void onServiceAdded(int status, BluetoothGattService service) {
}
/**
* A remote client has requested to read a local characteristic.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the read operation
* @param requestId The Id of the request
* @param offset Offset into the value of the characteristic
* @param characteristic Characteristic to be read
*/
public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
int offset, BluetoothGattCharacteristic characteristic) {
}
/**
* A remote client has requested to write to a local characteristic.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the write operation
* @param requestId The Id of the request
* @param characteristic Characteristic to be written to.
* @param preparedWrite true, if this write operation should be queued for
* later execution.
* @param responseNeeded true, if the remote device requires a response
* @param offset The offset given for the value
* @param value The value the client wants to assign to the characteristic
*/
public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
BluetoothGattCharacteristic characteristic,
boolean preparedWrite, boolean responseNeeded,
int offset, byte[] value) {
}
/**
* A remote client has requested to read a local descriptor.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the read operation
* @param requestId The Id of the request
* @param offset Offset into the value of the characteristic
* @param descriptor Descriptor to be read
*/
public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
int offset, BluetoothGattDescriptor descriptor) {
}
/**
* A remote client has requested to write to a local descriptor.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the write operation
* @param requestId The Id of the request
* @param descriptor Descriptor to be written to.
* @param preparedWrite true, if this write operation should be queued for
* later execution.
* @param responseNeeded true, if the remote device requires a response
* @param offset The offset given for the value
* @param value The value the client wants to assign to the descriptor
*/
public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
BluetoothGattDescriptor descriptor,
boolean preparedWrite, boolean responseNeeded,
int offset, byte[] value) {
}
/**
* Execute all pending write operations for this device.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the write operations
* @param requestId The Id of the request
* @param execute Whether the pending writes should be executed (true) or
* cancelled (false)
*/
public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
}
/**
* Callback invoked when a notification or indication has been sent to
* a remote device.
*
* <p>When multiple notifications are to be sent, an application must
* wait for this callback to be received before sending additional
* notifications.
*
* @param device The remote device the notification has been sent to
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful
*/
public void onNotificationSent(BluetoothDevice device, int status) {
}
/**
* Callback indicating the MTU for a given device connection has changed.
*
* <p>This callback will be invoked if a remote client has requested to change
* the MTU for a given connection.
*
* @param device The remote device that requested the MTU change
* @param mtu The new MTU size
*/
public void onMtuChanged(BluetoothDevice device, int mtu) {
@Override
public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) {
}
}

View File

@@ -0,0 +1,187 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.bluetooth;
import android.bluetooth.BluetoothDevice;
/**
* This abstract class is used to implement {@link BluetoothGattServer} callbacks.
*/
public abstract class BluetoothGattServerCallbackExt {
/**
* Callback indicating when a remote device has been connected or disconnected.
*
* @param device Remote device that has been connected or disconnected.
* @param status Status of the connect or disconnect operation.
* @param newState Returns the new connection state. Can be one of
* {@link BluetoothProfile#STATE_DISCONNECTED} or
* {@link BluetoothProfile#STATE_CONNECTED}
*/
public void onConnectionStateChange(BluetoothDevice device, int status,
int newState) {
}
/**
* Indicates whether a local service has been added successfully.
*
* @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service
* was added successfully.
* @param service The service that has been added
*/
public void onServiceAdded(int status, BluetoothGattService service) {
}
/**
* A remote client has requested to read a local characteristic.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the read operation
* @param requestId The Id of the request
* @param offset Offset into the value of the characteristic
* @param characteristic Characteristic to be read
*/
public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
int offset, BluetoothGattCharacteristic characteristic) {
}
/**
* A remote client has requested to write to a local characteristic.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the write operation
* @param requestId The Id of the request
* @param characteristic Characteristic to be written to.
* @param preparedWrite true, if this write operation should be queued for
* later execution.
* @param responseNeeded true, if the remote device requires a response
* @param offset The offset given for the value
* @param value The value the client wants to assign to the characteristic
*/
public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
BluetoothGattCharacteristic characteristic,
boolean preparedWrite, boolean responseNeeded,
int offset, byte[] value) {
}
/**
* A remote client has requested to read a local descriptor.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the read operation
* @param requestId The Id of the request
* @param offset Offset into the value of the characteristic
* @param descriptor Descriptor to be read
*/
public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
int offset, BluetoothGattDescriptor descriptor) {
}
/**
* A remote client has requested to write to a local descriptor.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the write operation
* @param requestId The Id of the request
* @param descriptor Descriptor to be written to.
* @param preparedWrite true, if this write operation should be queued for
* later execution.
* @param responseNeeded true, if the remote device requires a response
* @param offset The offset given for the value
* @param value The value the client wants to assign to the descriptor
*/
public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
BluetoothGattDescriptor descriptor,
boolean preparedWrite, boolean responseNeeded,
int offset, byte[] value) {
}
/**
* Execute all pending write operations for this device.
*
* <p>An application must call {@link BluetoothGattServer#sendResponse}
* to complete the request.
*
* @param device The remote device that has requested the write operations
* @param requestId The Id of the request
* @param execute Whether the pending writes should be executed (true) or
* cancelled (false)
*/
public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
}
/**
* Callback invoked when a notification or indication has been sent to
* a remote device.
*
* <p>When multiple notifications are to be sent, an application must
* wait for this callback to be received before sending additional
* notifications.
*
* @param device The remote device the notification has been sent to
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful
*/
public void onNotificationSent(BluetoothDevice device, int status) {
}
/**
* Callback indicating the MTU for a given device connection has changed.
*
* <p>This callback will be invoked if a remote client has requested to change
* the MTU for a given connection.
*
* @param device The remote device that requested the MTU change
* @param mtu The new MTU size
*/
public void onMtuChanged(BluetoothDevice device, int mtu) {
}
/**
* Callback triggered as result of {@link BluetoothGattServer#setPreferredPhy}, or as a result
* of remote device changing the PHY.
*
* @param device The remote device
* @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
* @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
* @param status status of the operation
*/
public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) {
}
/**
* Callback triggered as result of {@link BluetoothGattServer#readPhy}
*
* @param device The remote device that requested the PHY read
* @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
* @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
* {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
* @param status status of the operation
*/
public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) {
}
}

View File

@@ -27,8 +27,8 @@ import android.bluetooth.le.ResultStorageDescriptor;
import android.os.ParcelUuid;
import android.os.WorkSource;
import android.bluetooth.IBluetoothGattCallback;
import android.bluetooth.IBluetoothGattServerCallback;
import android.bluetooth.IBluetoothGattCallbackExt;
import android.bluetooth.IBluetoothGattServerCallbackExt;
import android.bluetooth.le.IAdvertiserCallback;
import android.bluetooth.le.IPeriodicAdvertisingCallback;
import android.bluetooth.le.IScannerCallback;
@@ -58,10 +58,12 @@ interface IBluetoothGatt {
void registerSync(in ScanResult scanResult, in int skip, in int timeout, in IPeriodicAdvertisingCallback callback);
void unregisterSync(in IPeriodicAdvertisingCallback callback);
void registerClient(in ParcelUuid appId, in IBluetoothGattCallback callback);
void registerClient(in ParcelUuid appId, in IBluetoothGattCallbackExt callback);
void unregisterClient(in int clientIf);
void clientConnect(in int clientIf, in String address, in boolean isDirect, in int transport);
void clientConnect(in int clientIf, in String address, in boolean isDirect, in int transport, in int phy);
void clientDisconnect(in int clientIf, in String address);
void clientSetPreferredPhy(in int clientIf, in String address, in int txPhy, in int rxPhy, in int phyOptions);
void clientReadPhy(in int clientIf, in String address);
void refreshDevice(in int clientIf, in String address);
void discoverServices(in int clientIf, in String address);
void readCharacteristic(in int clientIf, in String address, in int handle, in int authReq);
@@ -77,10 +79,12 @@ interface IBluetoothGatt {
void configureMTU(in int clientIf, in String address, in int mtu);
void connectionParameterUpdate(in int clientIf, in String address, in int connectionPriority);
void registerServer(in ParcelUuid appId, in IBluetoothGattServerCallback callback);
void registerServer(in ParcelUuid appId, in IBluetoothGattServerCallbackExt callback);
void unregisterServer(in int serverIf);
void serverConnect(in int serverIf, in String address, in boolean isDirect, in int transport);
void serverDisconnect(in int serverIf, in String address);
void serverSetPreferredPhy(in int clientIf, in String address, in int txPhy, in int rxPhy, in int phyOptions);
void serverReadPhy(in int clientIf, in String address);
void addService(in int serverIf, in BluetoothGattService service);
void removeService(in int serverIf, in int handle);
void clearServices(in int serverIf);

View File

@@ -22,10 +22,12 @@ import android.bluetooth.BluetoothGattService;
* Callback definitions for interacting with BLE / GATT
* @hide
*/
oneway interface IBluetoothGattCallback {
oneway interface IBluetoothGattCallbackExt {
void onClientRegistered(in int status, in int clientIf);
void onClientConnectionState(in int status, in int clientIf,
in boolean connected, in String address);
void onPhyUpdate(in String address, in int txPhy, in int rxPhy, in int status);
void onPhyRead(in String address, in int txPhy, in int rxPhy, in int status);
void onSearchComplete(in String address, in List<BluetoothGattService> services, in int status);
void onCharacteristicRead(in String address, in int status, in int handle, in byte[] value);
void onCharacteristicWrite(in String address, in int status, in int handle);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import android.bluetooth.BluetoothGattService;
* Callback definitions for interacting with BLE / GATT
* @hide
*/
oneway interface IBluetoothGattServerCallback {
oneway interface IBluetoothGattServerCallbackExt {
void onServerRegistered(in int status, in int serverIf);
void onServerConnectionState(in int status, in int serverIf,
in boolean connected, in String address);
@@ -40,4 +40,6 @@ oneway interface IBluetoothGattServerCallback {
void onExecuteWrite(in String address, in int transId, in boolean execWrite);
void onNotificationSent(in String address, in int status);
void onMtuChanged(in String address, in int mtu);
void onPhyUpdate(in String address, in int txPhy, in int rxPhy, in int status);
void onPhyRead(in String address, in int txPhy, in int rxPhy, in int status);
}