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 a25c466a2b403..cd0031173f8b2 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java @@ -124,8 +124,9 @@ public class BluetoothTile extends QSTileImpl { final boolean transientEnabling = arg == ARG_SHOW_TRANSIENT_ENABLING; final boolean enabled = transientEnabling || mController.isBluetoothEnabled(); final boolean connected = mController.isBluetoothConnected(); - state.isTransient = transientEnabling || mController.isBluetoothConnecting() - || mController.getBluetoothState() == BluetoothAdapter.STATE_TURNING_ON; + final boolean connecting = mController.isBluetoothConnecting(); + state.isTransient = transientEnabling || connecting || + mController.getBluetoothState() == BluetoothAdapter.STATE_TURNING_ON; state.dualTarget = true; state.value = enabled; if (state.slash == null) { @@ -134,7 +135,7 @@ public class BluetoothTile extends QSTileImpl { state.slash.isSlashed = !enabled; state.label = mContext.getString(R.string.quick_settings_bluetooth_label); state.secondaryLabel = TextUtils.emptyIfNull( - getSecondaryLabel(enabled, connected, state.isTransient)); + getSecondaryLabel(enabled, connecting, connected, state.isTransient)); if (enabled) { if (connected) { state.icon = new BluetoothConnectedTileIcon(); @@ -170,13 +171,17 @@ public class BluetoothTile extends QSTileImpl { * Returns the secondary label to use for the given bluetooth connection in the form of the * battery level or bluetooth profile name. If the bluetooth is disabled, there's no connected * devices, or we can't map the bluetooth class to a profile, this instead returns {@code null}. - * * @param enabled whether bluetooth is enabled + * @param connecting whether bluetooth is connecting to a device * @param connected whether there's a device connected via bluetooth * @param isTransient whether bluetooth is currently in a transient state turning on */ @Nullable - private String getSecondaryLabel(boolean enabled, boolean connected, boolean isTransient) { + private String getSecondaryLabel(boolean enabled, boolean connecting, boolean connected, + boolean isTransient) { + if (connecting) { + return mContext.getString(R.string.quick_settings_connecting); + } if (isTransient) { return mContext.getString(R.string.quick_settings_bluetooth_secondary_label_transient); } 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 44e87ff7b24ab..8df51dbf5e68a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java @@ -234,6 +234,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa mEnabled = bluetoothState == BluetoothAdapter.STATE_ON || bluetoothState == BluetoothAdapter.STATE_TURNING_ON; mState = bluetoothState; + updateConnected(); mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java index 54153a75f1b12..d2463502cb196 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java @@ -16,6 +16,7 @@ package com.android.systemui.statusbar.policy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -162,4 +163,38 @@ public class BluetoothControllerImplTest extends SysuiTestCase { mainLooper.destroy(); } } + + @Test + public void testOnServiceConnected_updatesConnectionState() { + when(mMockAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTING); + + mBluetoothControllerImpl.onServiceConnected(); + + assertTrue(mBluetoothControllerImpl.isBluetoothConnecting()); + assertFalse(mBluetoothControllerImpl.isBluetoothConnected()); + } + + @Test + public void testOnBluetoothStateChange_updatesBluetoothState() { + mBluetoothControllerImpl.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF); + + assertEquals(BluetoothAdapter.STATE_OFF, mBluetoothControllerImpl.getBluetoothState()); + + mBluetoothControllerImpl.onBluetoothStateChanged(BluetoothAdapter.STATE_ON); + + assertEquals(BluetoothAdapter.STATE_ON, mBluetoothControllerImpl.getBluetoothState()); + } + + @Test + public void testOnBluetoothStateChange_updatesConnectionState() { + when(mMockAdapter.getConnectionState()).thenReturn( + BluetoothAdapter.STATE_CONNECTING, + BluetoothAdapter.STATE_DISCONNECTED); + + mBluetoothControllerImpl.onServiceConnected(); + mBluetoothControllerImpl.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF); + + assertFalse(mBluetoothControllerImpl.isBluetoothConnecting()); + assertFalse(mBluetoothControllerImpl.isBluetoothConnected()); + } }