From 4d282544c3ebf5ade44d56963c23a474916e61ba Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Mon, 7 Aug 2017 15:35:13 -0700 Subject: [PATCH] Shutdown: Continue shutdown with BLE only mode Bug: 64213593 Test: shutdown no timeout Change-Id: I5007e7cfc00ab22fce3b6ef13bacbcc951197b9e --- .../android/server/power/ShutdownThread.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java index e894275fe2b67..175f44c5576c5 100644 --- a/services/core/java/com/android/server/power/ShutdownThread.java +++ b/services/core/java/com/android/server/power/ShutdownThread.java @@ -561,7 +561,7 @@ public final class ShutdownThread extends Thread { Thread t = new Thread() { public void run() { boolean nfcOff; - boolean bluetoothOff; + boolean bluetoothReadyForShutdown; boolean radioOff; final INfcAdapter nfc = @@ -585,15 +585,15 @@ public final class ShutdownThread extends Thread { } try { - bluetoothOff = bluetooth == null || + bluetoothReadyForShutdown = bluetooth == null || bluetooth.getState() == BluetoothAdapter.STATE_OFF; - if (!bluetoothOff) { + if (!bluetoothReadyForShutdown) { Log.w(TAG, "Disabling Bluetooth..."); bluetooth.disable(mContext.getPackageName(), false); // disable but don't persist new state } } catch (RemoteException ex) { Log.e(TAG, "RemoteException during bluetooth shutdown", ex); - bluetoothOff = true; + bluetoothReadyForShutdown = true; } try { @@ -618,14 +618,19 @@ public final class ShutdownThread extends Thread { sInstance.setRebootProgress(status, null); } - if (!bluetoothOff) { + if (!bluetoothReadyForShutdown) { try { - bluetoothOff = bluetooth.getState() == BluetoothAdapter.STATE_OFF; + // BLE only mode can happen when BT is turned off + // We will continue shutting down in such case + bluetoothReadyForShutdown = + bluetooth.getState() == BluetoothAdapter.STATE_OFF || + bluetooth.getState() == BluetoothAdapter.STATE_BLE_TURNING_OFF || + bluetooth.getState() == BluetoothAdapter.STATE_BLE_ON; } catch (RemoteException ex) { Log.e(TAG, "RemoteException during bluetooth shutdown", ex); - bluetoothOff = true; + bluetoothReadyForShutdown = true; } - if (bluetoothOff) { + if (bluetoothReadyForShutdown) { Log.i(TAG, "Bluetooth turned off."); } } @@ -652,7 +657,7 @@ public final class ShutdownThread extends Thread { } } - if (radioOff && bluetoothOff && nfcOff) { + if (radioOff && bluetoothReadyForShutdown && nfcOff) { Log.i(TAG, "NFC, Radio and Bluetooth shutdown complete."); done[0] = true; break;