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

Commit 69c1d22b authored by William Escande's avatar William Escande
Browse files

SystemServer: path to a reliable turn off

Add extra time to register bluetooth death and increase the time after
the bluetooth is killed from the binder thread
Also add a small sleep after death reception to let more time to the
ActivityManager to register Bluetooth death

Bug: 356931756
Bug: 361850050
Test: atest CtsBluetoothTestCases
Change-Id: Id08763bae16ab5044f29501e9e98de14840fa5c8
parent ddc585d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2281,7 +2281,7 @@ public class AdapterService extends Service {

            try {
                // Wait for Bluetooth to be killed from its main thread
                Thread.sleep(950); // SystemServer is waiting 1000 ms, we need to wait less here
                Thread.sleep(1_000); // SystemServer is waiting 2000 ms, we need to wait less here
            } catch (InterruptedException e) {
                Log.e(TAG, "killBluetoothProcess: Interrupted while waiting for kill");
            }
+5 −2
Original line number Diff line number Diff line
@@ -1226,16 +1226,19 @@ class BluetoothManagerService {
                // TODO: b/339501753 - Properly stop Bluetooth without killing it
                mAdapter.killBluetoothProcess();

                binderDead.get(1, TimeUnit.SECONDS);
                binderDead.get(2_000, TimeUnit.MILLISECONDS);
            } catch (android.os.DeadObjectException e) {
                // Reduce exception to info and skip waiting (Bluetooth is dead as wanted)
                Log.i(TAG, "Bluetooth already dead 💀");
            } catch (RemoteException e) {
                Log.e(TAG, "Unexpected RemoteException when calling killBluetoothProcess", e);
            } catch (TimeoutException | InterruptedException | ExecutionException e) {
                Log.e(TAG, "Bluetooth death not received correctly", e);
                Log.e(TAG, "Bluetooth death not received correctly after > 2000ms", e);
            }

            // TODO: b/356931756 - Remove sleep
            SystemClock.sleep(100); // required to let the ActivityManager be notified of BT death

            mAdapter = null;
            mHandler.removeMessages(MESSAGE_TIMEOUT_BIND);
        } finally {