Merge "Fix bluetooth state updated in systemui." into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1186fb76ba
@@ -124,8 +124,9 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
|
|||||||
final boolean transientEnabling = arg == ARG_SHOW_TRANSIENT_ENABLING;
|
final boolean transientEnabling = arg == ARG_SHOW_TRANSIENT_ENABLING;
|
||||||
final boolean enabled = transientEnabling || mController.isBluetoothEnabled();
|
final boolean enabled = transientEnabling || mController.isBluetoothEnabled();
|
||||||
final boolean connected = mController.isBluetoothConnected();
|
final boolean connected = mController.isBluetoothConnected();
|
||||||
state.isTransient = transientEnabling || mController.isBluetoothConnecting()
|
final boolean connecting = mController.isBluetoothConnecting();
|
||||||
|| mController.getBluetoothState() == BluetoothAdapter.STATE_TURNING_ON;
|
state.isTransient = transientEnabling || connecting ||
|
||||||
|
mController.getBluetoothState() == BluetoothAdapter.STATE_TURNING_ON;
|
||||||
state.dualTarget = true;
|
state.dualTarget = true;
|
||||||
state.value = enabled;
|
state.value = enabled;
|
||||||
if (state.slash == null) {
|
if (state.slash == null) {
|
||||||
@@ -134,7 +135,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
|
|||||||
state.slash.isSlashed = !enabled;
|
state.slash.isSlashed = !enabled;
|
||||||
state.label = mContext.getString(R.string.quick_settings_bluetooth_label);
|
state.label = mContext.getString(R.string.quick_settings_bluetooth_label);
|
||||||
state.secondaryLabel = TextUtils.emptyIfNull(
|
state.secondaryLabel = TextUtils.emptyIfNull(
|
||||||
getSecondaryLabel(enabled, connected, state.isTransient));
|
getSecondaryLabel(enabled, connecting, connected, state.isTransient));
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
state.icon = new BluetoothConnectedTileIcon();
|
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
|
* 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
|
* 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}.
|
* devices, or we can't map the bluetooth class to a profile, this instead returns {@code null}.
|
||||||
*
|
|
||||||
* @param enabled whether bluetooth is enabled
|
* @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 connected whether there's a device connected via bluetooth
|
||||||
* @param isTransient whether bluetooth is currently in a transient state turning on
|
* @param isTransient whether bluetooth is currently in a transient state turning on
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@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) {
|
if (isTransient) {
|
||||||
return mContext.getString(R.string.quick_settings_bluetooth_secondary_label_transient);
|
return mContext.getString(R.string.quick_settings_bluetooth_secondary_label_transient);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
|
|||||||
mEnabled = bluetoothState == BluetoothAdapter.STATE_ON
|
mEnabled = bluetoothState == BluetoothAdapter.STATE_ON
|
||||||
|| bluetoothState == BluetoothAdapter.STATE_TURNING_ON;
|
|| bluetoothState == BluetoothAdapter.STATE_TURNING_ON;
|
||||||
mState = bluetoothState;
|
mState = bluetoothState;
|
||||||
|
updateConnected();
|
||||||
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
|
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package com.android.systemui.statusbar.policy;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -162,4 +163,38 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
|
|||||||
mainLooper.destroy();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user