Loading core/java/android/bluetooth/BluetoothGatt.java +31 −18 Original line number Diff line number Diff line Loading @@ -45,14 +45,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; Loading Loading @@ -260,17 +264,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) { Loading Loading @@ -309,19 +315,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); Loading Loading @@ -376,17 +383,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); Loading Loading @@ -415,18 +424,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); Loading Loading @@ -501,6 +512,7 @@ public final class BluetoothGatt implements BluetoothProfile { mServices = new ArrayList<BluetoothGattService>(); mConnState = CONN_STATE_IDLE; mAuthRetryState = AUTH_RETRY_STATE_IDLE; } /** Loading @@ -514,6 +526,7 @@ public final class BluetoothGatt implements BluetoothProfile { unregisterApp(); mConnState = CONN_STATE_CLOSED; mAuthRetryState = AUTH_RETRY_STATE_IDLE; } /** Loading Loading
core/java/android/bluetooth/BluetoothGatt.java +31 −18 Original line number Diff line number Diff line Loading @@ -45,14 +45,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; Loading Loading @@ -260,17 +264,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) { Loading Loading @@ -309,19 +315,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); Loading Loading @@ -376,17 +383,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); Loading Loading @@ -415,18 +424,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); Loading Loading @@ -501,6 +512,7 @@ public final class BluetoothGatt implements BluetoothProfile { mServices = new ArrayList<BluetoothGattService>(); mConnState = CONN_STATE_IDLE; mAuthRetryState = AUTH_RETRY_STATE_IDLE; } /** Loading @@ -514,6 +526,7 @@ public final class BluetoothGatt implements BluetoothProfile { unregisterApp(); mConnState = CONN_STATE_CLOSED; mAuthRetryState = AUTH_RETRY_STATE_IDLE; } /** Loading