QS: Make BT detail be more consistent with Settings

 - Show turning on as on
 - Disable switch when in a turning on/off state

Change-Id: I55f977808d1b881f6dc27192dcc2e907b0576447
Fixes: 29237638
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSDetail.java b/packages/SystemUI/src/com/android/systemui/qs/QSDetail.java
index 6206cef9..ee55a80 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSDetail.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSDetail.java
@@ -249,6 +249,9 @@
             return;
         }
         mQsDetailHeaderSwitch.setChecked(state);
+        final boolean toggleEnabled = mDetailAdapter != null && mDetailAdapter.getToggleEnabled();
+        mQsDetailHeader.setEnabled(toggleEnabled);
+        mQsDetailHeaderSwitch.setEnabled(toggleEnabled);
     }
 
     private void handleScanStateChanged(boolean state) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java
index ca853fe..2fda6ea 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java
@@ -148,6 +148,9 @@
     public interface DetailAdapter {
         CharSequence getTitle();
         Boolean getToggleState();
+        default boolean getToggleEnabled() {
+            return true;
+        }
         View createDetailView(Context context, View convertView, ViewGroup parent);
         Intent getSettingsIntent();
         void setToggleState(boolean state);
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
index 794610e..f1e8749 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
@@ -16,6 +16,7 @@
 
 package com.android.systemui.qs.tiles;
 
+import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothProfile;
 import android.content.Context;
@@ -208,6 +209,12 @@
         }
 
         @Override
+        public boolean getToggleEnabled() {
+            return mController.getBluetoothState() == BluetoothAdapter.STATE_OFF
+                    || mController.getBluetoothState() == BluetoothAdapter.STATE_ON;
+        }
+
+        @Override
         public Intent getSettingsIntent() {
             return BLUETOOTH_SETTINGS;
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java
index e7e2ac2..08675c4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java
@@ -26,6 +26,9 @@
 
     boolean isBluetoothSupported();
     boolean isBluetoothEnabled();
+
+    int getBluetoothState();
+
     boolean isBluetoothConnected();
     boolean isBluetoothConnecting();
     String getLastDeviceName();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java
index 014cc49..4f880b4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java
@@ -49,6 +49,7 @@
     private CachedBluetoothDevice mLastDevice;
 
     private final H mHandler = new H();
+    private int mState;
 
     public BluetoothControllerImpl(Context context, Looper bgLooper) {
         mLocalBluetoothManager = LocalBluetoothManager.getInstance(context, null);
@@ -120,6 +121,11 @@
     }
 
     @Override
+    public int getBluetoothState() {
+        return mState;
+    }
+
+    @Override
     public boolean isBluetoothConnected() {
         return mConnectionState == BluetoothAdapter.STATE_CONNECTED;
     }
@@ -192,7 +198,9 @@
 
     @Override
     public void onBluetoothStateChanged(int bluetoothState) {
-        mEnabled = bluetoothState == BluetoothAdapter.STATE_ON;
+        mEnabled = bluetoothState == BluetoothAdapter.STATE_ON
+                || bluetoothState == BluetoothAdapter.STATE_TURNING_ON;
+        mState = bluetoothState;
         mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
     }