Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e6fe14f authored by Zhihai Xu's avatar Zhihai Xu Committed by Android Git Automerger
Browse files

am 54499194: am 2e8a2d20: Merge "LE: Return false if an attribute read/write...

am 54499194: am 2e8a2d20: Merge "LE: Return false if an attribute read/write is in progress" into klp-modular-dev

* commit '54499194':
  LE: Return false if an attribute read/write is in progress
parents ece41093 54499194
Loading
Loading
Loading
Loading
+60 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ public final class BluetoothGatt implements BluetoothProfile {
    private boolean mAutoConnect;
    private boolean mAutoConnect;
    private int mConnState;
    private int mConnState;
    private final Object mStateLock = new Object();
    private final Object mStateLock = new Object();
    private Boolean mDeviceBusy = false;


    private static final int CONN_STATE_IDLE = 0;
    private static final int CONN_STATE_IDLE = 0;
    private static final int CONN_STATE_CONNECTING = 1;
    private static final int CONN_STATE_CONNECTING = 1;
@@ -166,6 +167,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                        mConnState = CONN_STATE_IDLE;
                        mConnState = CONN_STATE_IDLE;
                    }
                    }
                }
                }

                synchronized(mDeviceBusy) {
                    mDeviceBusy = false;
                }
            }
            }


            /**
            /**
@@ -301,6 +306,11 @@ public final class BluetoothGatt implements BluetoothProfile {
                if (!address.equals(mDevice.getAddress())) {
                if (!address.equals(mDevice.getAddress())) {
                    return;
                    return;
                }
                }

                synchronized(mDeviceBusy) {
                    mDeviceBusy = false;
                }

                if ((status == GATT_INSUFFICIENT_AUTHENTICATION
                if ((status == GATT_INSUFFICIENT_AUTHENTICATION
                  || status == GATT_INSUFFICIENT_ENCRYPTION)
                  || status == GATT_INSUFFICIENT_ENCRYPTION)
                  && mAuthRetry == false) {
                  && mAuthRetry == false) {
@@ -348,6 +358,11 @@ public final class BluetoothGatt implements BluetoothProfile {
                if (!address.equals(mDevice.getAddress())) {
                if (!address.equals(mDevice.getAddress())) {
                    return;
                    return;
                }
                }

                synchronized(mDeviceBusy) {
                    mDeviceBusy = false;
                }

                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                                                          srvcInstId, srvcType);
                                                          srvcInstId, srvcType);
                if (service == null) return;
                if (service == null) return;
@@ -425,6 +440,11 @@ public final class BluetoothGatt implements BluetoothProfile {
                if (!address.equals(mDevice.getAddress())) {
                if (!address.equals(mDevice.getAddress())) {
                    return;
                    return;
                }
                }

                synchronized(mDeviceBusy) {
                    mDeviceBusy = false;
                }

                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                                                          srvcInstId, srvcType);
                                                          srvcInstId, srvcType);
                if (service == null) return;
                if (service == null) return;
@@ -474,6 +494,11 @@ public final class BluetoothGatt implements BluetoothProfile {
                if (!address.equals(mDevice.getAddress())) {
                if (!address.equals(mDevice.getAddress())) {
                    return;
                    return;
                }
                }

                synchronized(mDeviceBusy) {
                    mDeviceBusy = false;
                }

                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                                                          srvcInstId, srvcType);
                                                          srvcInstId, srvcType);
                if (service == null) return;
                if (service == null) return;
@@ -519,6 +544,11 @@ public final class BluetoothGatt implements BluetoothProfile {
                if (!address.equals(mDevice.getAddress())) {
                if (!address.equals(mDevice.getAddress())) {
                    return;
                    return;
                }
                }

                synchronized(mDeviceBusy) {
                    mDeviceBusy = false;
                }

                try {
                try {
                    mCallback.onReliableWriteCompleted(BluetoothGatt.this, status);
                    mCallback.onReliableWriteCompleted(BluetoothGatt.this, status);
                } catch (Exception ex) {
                } catch (Exception ex) {
@@ -851,6 +881,11 @@ public final class BluetoothGatt implements BluetoothProfile {
        BluetoothDevice device = service.getDevice();
        BluetoothDevice device = service.getDevice();
        if (device == null) return false;
        if (device == null) return false;


        synchronized(mDeviceBusy) {
            if (mDeviceBusy) return false;
            mDeviceBusy = true;
        }

        try {
        try {
            mService.readCharacteristic(mClientIf, device.getAddress(),
            mService.readCharacteristic(mClientIf, device.getAddress(),
                service.getType(), service.getInstanceId(),
                service.getType(), service.getInstanceId(),
@@ -858,6 +893,7 @@ public final class BluetoothGatt implements BluetoothProfile {
                new ParcelUuid(characteristic.getUuid()), AUTHENTICATION_NONE);
                new ParcelUuid(characteristic.getUuid()), AUTHENTICATION_NONE);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG,"",e);
            Log.e(TAG,"",e);
            mDeviceBusy = false;
            return false;
            return false;
        }
        }


@@ -890,6 +926,11 @@ public final class BluetoothGatt implements BluetoothProfile {
        BluetoothDevice device = service.getDevice();
        BluetoothDevice device = service.getDevice();
        if (device == null) return false;
        if (device == null) return false;


        synchronized(mDeviceBusy) {
            if (mDeviceBusy) return false;
            mDeviceBusy = true;
        }

        try {
        try {
            mService.writeCharacteristic(mClientIf, device.getAddress(),
            mService.writeCharacteristic(mClientIf, device.getAddress(),
                service.getType(), service.getInstanceId(),
                service.getType(), service.getInstanceId(),
@@ -899,6 +940,7 @@ public final class BluetoothGatt implements BluetoothProfile {
                characteristic.getValue());
                characteristic.getValue());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG,"",e);
            Log.e(TAG,"",e);
            mDeviceBusy = false;
            return false;
            return false;
        }
        }


@@ -930,6 +972,11 @@ public final class BluetoothGatt implements BluetoothProfile {
        BluetoothDevice device = service.getDevice();
        BluetoothDevice device = service.getDevice();
        if (device == null) return false;
        if (device == null) return false;


        synchronized(mDeviceBusy) {
            if (mDeviceBusy) return false;
            mDeviceBusy = true;
        }

        try {
        try {
            mService.readDescriptor(mClientIf, device.getAddress(), service.getType(),
            mService.readDescriptor(mClientIf, device.getAddress(), service.getType(),
                service.getInstanceId(), new ParcelUuid(service.getUuid()),
                service.getInstanceId(), new ParcelUuid(service.getUuid()),
@@ -938,6 +985,7 @@ public final class BluetoothGatt implements BluetoothProfile {
                AUTHENTICATION_NONE);
                AUTHENTICATION_NONE);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG,"",e);
            Log.e(TAG,"",e);
            mDeviceBusy = false;
            return false;
            return false;
        }
        }


@@ -968,6 +1016,11 @@ public final class BluetoothGatt implements BluetoothProfile {
        BluetoothDevice device = service.getDevice();
        BluetoothDevice device = service.getDevice();
        if (device == null) return false;
        if (device == null) return false;


        synchronized(mDeviceBusy) {
            if (mDeviceBusy) return false;
            mDeviceBusy = true;
        }

        try {
        try {
            mService.writeDescriptor(mClientIf, device.getAddress(), service.getType(),
            mService.writeDescriptor(mClientIf, device.getAddress(), service.getType(),
                service.getInstanceId(), new ParcelUuid(service.getUuid()),
                service.getInstanceId(), new ParcelUuid(service.getUuid()),
@@ -977,6 +1030,7 @@ public final class BluetoothGatt implements BluetoothProfile {
                descriptor.getValue());
                descriptor.getValue());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG,"",e);
            Log.e(TAG,"",e);
            mDeviceBusy = false;
            return false;
            return false;
        }
        }


@@ -1034,10 +1088,16 @@ public final class BluetoothGatt implements BluetoothProfile {
        if (DBG) Log.d(TAG, "executeReliableWrite() - device: " + mDevice.getAddress());
        if (DBG) Log.d(TAG, "executeReliableWrite() - device: " + mDevice.getAddress());
        if (mService == null || mClientIf == 0) return false;
        if (mService == null || mClientIf == 0) return false;


        synchronized(mDeviceBusy) {
            if (mDeviceBusy) return false;
            mDeviceBusy = true;
        }

        try {
        try {
            mService.endReliableWrite(mClientIf, mDevice.getAddress(), true);
            mService.endReliableWrite(mClientIf, mDevice.getAddress(), true);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG,"",e);
            Log.e(TAG,"",e);
            mDeviceBusy = false;
            return false;
            return false;
        }
        }