diff options
Diffstat (limited to 'service/java/com/android/server/bluetooth/BluetoothManagerService.java')
| -rw-r--r-- | service/java/com/android/server/bluetooth/BluetoothManagerService.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java index 60d61b8e12..da4b71ed55 100644 --- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java @@ -2861,15 +2861,25 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } } + boolean waitForManagerState(int state) { + return waitForState(Set.of(state), false); + } + private boolean waitForState(Set<Integer> states) { - int i = 0; - while (i < 10) { + return waitForState(states, true); + } + private boolean waitForState(Set<Integer> states, boolean failIfUnbind) { + for (int i = 0; i < 10; i++) { + mBluetoothLock.readLock().lock(); try { - mBluetoothLock.readLock().lock(); - if (mBluetooth == null) { - break; + if (mBluetooth == null && failIfUnbind) { + Log.e(TAG, "waitForState " + states + " Bluetooth is not unbind"); + return false; + } + if (mBluetooth == null && states.contains(BluetoothAdapter.STATE_OFF)) { + return true; // We are so OFF that the bluetooth is not bind } - if (states.contains(synchronousGetState())) { + if (mBluetooth != null && states.contains(synchronousGetState())) { return true; } } catch (RemoteException | TimeoutException e) { @@ -2879,7 +2889,6 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { mBluetoothLock.readLock().unlock(); } SystemClock.sleep(300); - i++; } Log.e(TAG, "waitForState " + states + " time out"); return false; |
