diff options
| author | William Escande <wescande@google.com> | 2022-12-19 17:54:08 -0800 |
|---|---|---|
| committer | Cherrypicker Worker <android-build-cherrypicker-worker@google.com> | 2022-12-20 21:52:58 +0000 |
| commit | 4ffb8eb23969457b49231a6809e549df7e3333fe (patch) | |
| tree | 8d4489c0b182b3b13a6da94d0b95007799af9ab5 /service/java/com/android/server/bluetooth/BluetoothManagerService.java | |
| parent | c33fdf19bd24d2b2ffd7b60e120bdf85dd69c8cb (diff) | |
Add wait-for-state command
Disable and enable are async shell command.
This is creating flakyness in test that expect the bluetooth to be
already enabled / disabled.
Test: atest BluetoothInstrumentationTests
Test: atest BluetoothShellCommandTest
Test: atest 'BluetoothTest#AdapterEnableDisable' // net_test_bluetooth
Fix: 261772749
Tag: #refactor
Change-Id: I3ca29dde23a5182ede28eceaf1ac97e4668ab5d5
(cherry picked from commit ca23daa448294ebea1b5cfd421732e85440fe4b9)
Merged-In: I3ca29dde23a5182ede28eceaf1ac97e4668ab5d5
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; |
