From 77ad3c2531c00c7b654162be826e93abb5e4dc75 Mon Sep 17 00:00:00 2001 From: Sanket Agarwal Date: Wed, 27 Apr 2016 13:22:44 -0700 Subject: [PATCH] Handle return value when Bluetooth is enabled If the Bluetooth enable(true) returns false currently we are waiting for a broadcast (which may not happen if enable returns false). We mark the toggle to have failed (i.e. it is clickable and in OFF state) and the switch bar text is appropriately shown. Bug: b/28318203 Change-Id: I09ba46d2e102e7f2c4ef9a72bf38dedc1346364f --- .../android/settings/bluetooth/BluetoothEnabler.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java index aac7053eace..d9de56dff29 100644 --- a/src/com/android/settings/bluetooth/BluetoothEnabler.java +++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java @@ -24,6 +24,7 @@ import android.content.IntentFilter; import android.os.Handler; import android.os.Message; import android.provider.Settings; +import android.util.Log; import android.widget.Switch; import android.widget.Toast; @@ -189,7 +190,16 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener MetricsLogger.action(mContext, MetricsEvent.ACTION_BLUETOOTH_TOGGLE, isChecked); if (mLocalAdapter != null) { - mLocalAdapter.setBluetoothEnabled(isChecked); + boolean status = mLocalAdapter.setBluetoothEnabled(isChecked); + // If we cannot toggle it ON then reset the UI assets: + // a) The switch should be OFF but it should still be togglable (enabled = True) + // b) The switch bar should have OFF text. + if (isChecked && !status) { + switchView.setChecked(false); + mSwitch.setEnabled(true); + mSwitchBar.setTextViewLabel(false); + return; + } } mSwitch.setEnabled(false); }