summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jacky Cheung <jackyc@google.com> 2016-10-20 23:11:51 +0000
committer android-build-merger <android-build-merger@google.com> 2016-10-20 23:11:51 +0000
commitbd12e5c9db5ffea147f7fa34a904e1bb5fe8de01 (patch)
tree15b281232841ea2efc742b04d3d1647cf8cbfd02
parent4f2845825095775b92337e1ade49857d1b932f2e (diff)
parent046a5c3a0046bc05290882d5b70b6213d6099368 (diff)
Merge "Gradually increase the level of authentication on failed GATT operations." am: 6071abdb92
am: 046a5c3a00 Change-Id: I749b2e4d4a13f099cfdc164f7fec8556d09f8433
-rw-r--r--core/java/android/bluetooth/BluetoothGatt.java49
1 files changed, 31 insertions, 18 deletions
diff --git a/core/java/android/bluetooth/BluetoothGatt.java b/core/java/android/bluetooth/BluetoothGatt.java
index 2843e3501904..e852ef2d3d5c 100644
--- a/core/java/android/bluetooth/BluetoothGatt.java
+++ b/core/java/android/bluetooth/BluetoothGatt.java
@@ -44,14 +44,18 @@ public final class BluetoothGatt implements BluetoothProfile {
private IBluetoothGatt mService;
private BluetoothGattCallback mCallback;
private int mClientIf;
- private boolean mAuthRetry = false;
private BluetoothDevice mDevice;
private boolean mAutoConnect;
+ private int mAuthRetryState;
private int mConnState;
private final Object mStateLock = new Object();
private Boolean mDeviceBusy = false;
private int mTransport;
+ private static final int AUTH_RETRY_STATE_IDLE = 0;
+ private static final int AUTH_RETRY_STATE_NO_MITM = 1;
+ private static final int AUTH_RETRY_STATE_MITM = 2;
+
private static final int CONN_STATE_IDLE = 0;
private static final int CONN_STATE_CONNECTING = 1;
private static final int CONN_STATE_CONNECTED = 2;
@@ -259,17 +263,19 @@ public final class BluetoothGatt implements BluetoothProfile {
if ((status == GATT_INSUFFICIENT_AUTHENTICATION
|| status == GATT_INSUFFICIENT_ENCRYPTION)
- && mAuthRetry == false) {
+ && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
try {
- mAuthRetry = true;
- mService.readCharacteristic(mClientIf, address, handle, AUTHENTICATION_MITM);
+ final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+ AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
+ mService.readCharacteristic(mClientIf, address, handle, authReq);
+ mAuthRetryState++;
return;
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
- mAuthRetry = false;
+ mAuthRetryState = AUTH_RETRY_STATE_IDLE;
BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice, handle);
if (characteristic == null) {
@@ -308,19 +314,20 @@ public final class BluetoothGatt implements BluetoothProfile {
if ((status == GATT_INSUFFICIENT_AUTHENTICATION
|| status == GATT_INSUFFICIENT_ENCRYPTION)
- && mAuthRetry == false) {
+ && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
try {
- mAuthRetry = true;
+ final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+ AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
mService.writeCharacteristic(mClientIf, address, handle,
- characteristic.getWriteType(), AUTHENTICATION_MITM,
- characteristic.getValue());
+ characteristic.getWriteType(), authReq, characteristic.getValue());
+ mAuthRetryState++;
return;
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
- mAuthRetry = false;
+ mAuthRetryState = AUTH_RETRY_STATE_IDLE;
try {
mCallback.onCharacteristicWrite(BluetoothGatt.this, characteristic, status);
@@ -375,17 +382,19 @@ public final class BluetoothGatt implements BluetoothProfile {
if ((status == GATT_INSUFFICIENT_AUTHENTICATION
|| status == GATT_INSUFFICIENT_ENCRYPTION)
- && mAuthRetry == false) {
+ && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
try {
- mAuthRetry = true;
- mService.readDescriptor(mClientIf, address, handle, AUTHENTICATION_MITM);
+ final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+ AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
+ mService.readDescriptor(mClientIf, address, handle, authReq);
+ mAuthRetryState++;
return;
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
- mAuthRetry = true;
+ mAuthRetryState = AUTH_RETRY_STATE_IDLE;
try {
mCallback.onDescriptorRead(BluetoothGatt.this, descriptor, status);
@@ -414,18 +423,20 @@ public final class BluetoothGatt implements BluetoothProfile {
if ((status == GATT_INSUFFICIENT_AUTHENTICATION
|| status == GATT_INSUFFICIENT_ENCRYPTION)
- && mAuthRetry == false) {
+ && (mAuthRetryState != AUTH_RETRY_STATE_MITM)) {
try {
- mAuthRetry = true;
+ final int authReq = (mAuthRetryState == AUTH_RETRY_STATE_IDLE) ?
+ AUTHENTICATION_NO_MITM : AUTHENTICATION_MITM;
mService.writeDescriptor(mClientIf, address, handle,
- AUTHENTICATION_MITM, descriptor.getValue());
+ authReq, descriptor.getValue());
+ mAuthRetryState++;
return;
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
- mAuthRetry = false;
+ mAuthRetryState = AUTH_RETRY_STATE_IDLE;
try {
mCallback.onDescriptorWrite(BluetoothGatt.this, descriptor, status);
@@ -499,6 +510,7 @@ public final class BluetoothGatt implements BluetoothProfile {
mServices = new ArrayList<BluetoothGattService>();
mConnState = CONN_STATE_IDLE;
+ mAuthRetryState = AUTH_RETRY_STATE_IDLE;
}
/**
@@ -512,6 +524,7 @@ public final class BluetoothGatt implements BluetoothProfile {
unregisterApp();
mConnState = CONN_STATE_CLOSED;
+ mAuthRetryState = AUTH_RETRY_STATE_IDLE;
}
/**