Merge "Fix bluetooth state updated in systemui." into pi-dev

am: 1186fb76ba

Change-Id: Iab6e5a5ff5d3875bdfcc3be69d9f403c2bcf5340
This commit is contained in:
Amin Shaikh
2018-04-26 20:28:58 -07:00
committed by android-build-merger
3 changed files with 46 additions and 5 deletions

View File

@@ -124,8 +124,9 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
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<BooleanState> {
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<BooleanState> {
* 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);
}

View File

@@ -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);
}

View File

@@ -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());
}
}