am 54499194: am 2e8a2d20: Merge "LE: Return false if an attribute read/write is in progress" into klp-modular-dev
* commit '544991946287bdd3a9e6a71855642e378594bf73':
LE: Return false if an attribute read/write is in progress
diff --git a/core/java/android/bluetooth/BluetoothGatt.java b/core/java/android/bluetooth/BluetoothGatt.java
index 101b721..ff3af7c 100644
--- a/core/java/android/bluetooth/BluetoothGatt.java
+++ b/core/java/android/bluetooth/BluetoothGatt.java
@@ -50,6 +50,7 @@
private boolean mAutoConnect;
private int mConnState;
private final Object mStateLock = new Object();
+ private Boolean mDeviceBusy = false;
private static final int CONN_STATE_IDLE = 0;
private static final int CONN_STATE_CONNECTING = 1;
@@ -166,6 +167,10 @@
mConnState = CONN_STATE_IDLE;
}
}
+
+ synchronized(mDeviceBusy) {
+ mDeviceBusy = false;
+ }
}
/**
@@ -301,6 +306,11 @@
if (!address.equals(mDevice.getAddress())) {
return;
}
+
+ synchronized(mDeviceBusy) {
+ mDeviceBusy = false;
+ }
+
if ((status == GATT_INSUFFICIENT_AUTHENTICATION
|| status == GATT_INSUFFICIENT_ENCRYPTION)
&& mAuthRetry == false) {
@@ -348,6 +358,11 @@
if (!address.equals(mDevice.getAddress())) {
return;
}
+
+ synchronized(mDeviceBusy) {
+ mDeviceBusy = false;
+ }
+
BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
srvcInstId, srvcType);
if (service == null) return;
@@ -425,6 +440,11 @@
if (!address.equals(mDevice.getAddress())) {
return;
}
+
+ synchronized(mDeviceBusy) {
+ mDeviceBusy = false;
+ }
+
BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
srvcInstId, srvcType);
if (service == null) return;
@@ -474,6 +494,11 @@
if (!address.equals(mDevice.getAddress())) {
return;
}
+
+ synchronized(mDeviceBusy) {
+ mDeviceBusy = false;
+ }
+
BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
srvcInstId, srvcType);
if (service == null) return;
@@ -519,6 +544,11 @@
if (!address.equals(mDevice.getAddress())) {
return;
}
+
+ synchronized(mDeviceBusy) {
+ mDeviceBusy = false;
+ }
+
try {
mCallback.onReliableWriteCompleted(BluetoothGatt.this, status);
} catch (Exception ex) {
@@ -851,6 +881,11 @@
BluetoothDevice device = service.getDevice();
if (device == null) return false;
+ synchronized(mDeviceBusy) {
+ if (mDeviceBusy) return false;
+ mDeviceBusy = true;
+ }
+
try {
mService.readCharacteristic(mClientIf, device.getAddress(),
service.getType(), service.getInstanceId(),
@@ -858,6 +893,7 @@
new ParcelUuid(characteristic.getUuid()), AUTHENTICATION_NONE);
} catch (RemoteException e) {
Log.e(TAG,"",e);
+ mDeviceBusy = false;
return false;
}
@@ -890,6 +926,11 @@
BluetoothDevice device = service.getDevice();
if (device == null) return false;
+ synchronized(mDeviceBusy) {
+ if (mDeviceBusy) return false;
+ mDeviceBusy = true;
+ }
+
try {
mService.writeCharacteristic(mClientIf, device.getAddress(),
service.getType(), service.getInstanceId(),
@@ -899,6 +940,7 @@
characteristic.getValue());
} catch (RemoteException e) {
Log.e(TAG,"",e);
+ mDeviceBusy = false;
return false;
}
@@ -930,6 +972,11 @@
BluetoothDevice device = service.getDevice();
if (device == null) return false;
+ synchronized(mDeviceBusy) {
+ if (mDeviceBusy) return false;
+ mDeviceBusy = true;
+ }
+
try {
mService.readDescriptor(mClientIf, device.getAddress(), service.getType(),
service.getInstanceId(), new ParcelUuid(service.getUuid()),
@@ -938,6 +985,7 @@
AUTHENTICATION_NONE);
} catch (RemoteException e) {
Log.e(TAG,"",e);
+ mDeviceBusy = false;
return false;
}
@@ -968,6 +1016,11 @@
BluetoothDevice device = service.getDevice();
if (device == null) return false;
+ synchronized(mDeviceBusy) {
+ if (mDeviceBusy) return false;
+ mDeviceBusy = true;
+ }
+
try {
mService.writeDescriptor(mClientIf, device.getAddress(), service.getType(),
service.getInstanceId(), new ParcelUuid(service.getUuid()),
@@ -977,6 +1030,7 @@
descriptor.getValue());
} catch (RemoteException e) {
Log.e(TAG,"",e);
+ mDeviceBusy = false;
return false;
}
@@ -1034,10 +1088,16 @@
if (DBG) Log.d(TAG, "executeReliableWrite() - device: " + mDevice.getAddress());
if (mService == null || mClientIf == 0) return false;
+ synchronized(mDeviceBusy) {
+ if (mDeviceBusy) return false;
+ mDeviceBusy = true;
+ }
+
try {
mService.endReliableWrite(mClientIf, mDevice.getAddress(), true);
} catch (RemoteException e) {
Log.e(TAG,"",e);
+ mDeviceBusy = false;
return false;
}