aboutsummaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothAdapter.java
diff options
context:
space:
mode:
authorWei Wang <weiwa@google.com>2014-03-19 15:47:12 -0700
committerWei Wang <weiwa@google.com>2014-03-20 00:04:27 +0000
commita00d04bb647962db3dcdfc891cbc58b4bc00a708 (patch)
tree9c0fdd3b5966a596ffa9d0d12628bc846efbbdb2 /framework/java/android/bluetooth/BluetoothAdapter.java
parentff51763220f24d110fdf5f48565219410fe02670 (diff)
Move advetise clean up to callback code. fixes b/13289050
Change-Id: Ibf3c772561125821817c947730cf21defafd4cb2
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothAdapter.java26
1 files changed, 21 insertions, 5 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index 8aee4db08c..a4374b86f1 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -590,7 +590,6 @@ public final class BluetoothAdapter {
return false;
}
mAdvertisingGattCallback.stopAdvertising();
- mAdvertisingGattCallback = null;
return true;
} catch (RemoteException e) {
Log.e(TAG, "", e);
@@ -1794,15 +1793,12 @@ public final class BluetoothAdapter {
try {
IBluetoothGatt iGatt = adapter.getBluetoothManager().getBluetoothGatt();
iGatt.stopAdvertising();
- Log.d(TAG, "unregistering client " + mLeHandle);
- iGatt.unregisterClient(mLeHandle);
} catch (RemoteException e) {
- Log.e(TAG, "Failed to stop advertising and unregister" + e);
+ Log.e(TAG, "Failed to stop advertising" + e);
}
} else {
Log.e(TAG, "stopAdvertising, BluetoothAdapter is null");
}
- mLeHandle = -1;
notifyAll();
}
}
@@ -1992,6 +1988,26 @@ public final class BluetoothAdapter {
if (advertiseState == STATE_ADVERTISE_STARTED) {
mAdvertiseCallback.onAdvertiseStart(status);
} else {
+ synchronized (this) {
+ if (status == ADVERTISE_CALLBACK_SUCCESS) {
+ BluetoothAdapter adapter = mBluetoothAdapter.get();
+ if (adapter != null) {
+ try {
+ IBluetoothGatt iGatt =
+ adapter.getBluetoothManager().getBluetoothGatt();
+ Log.d(TAG, "unregistering client " + mLeHandle);
+ iGatt.unregisterClient(mLeHandle);
+ // Reset advertise app handle.
+ mLeHandle = -1;
+ adapter.mAdvertisingGattCallback = null;
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to unregister client" + e);
+ }
+ } else {
+ Log.e(TAG, "cannot unregister client, BluetoothAdapter is null");
+ }
+ }
+ }
mAdvertiseCallback.onAdvertiseStop(status);
}
}