From 6339aed7a2c92bf6a68128e11ea417e2ebb32f24 Mon Sep 17 00:00:00 2001 From: Alex Stetson Date: Wed, 22 Dec 2021 13:42:10 -0800 Subject: [PATCH] Update CarConnectionSummary Per UX guidance, it's desired to always show the "disconnected" string as the connected summary and to have a short summary option that simply shows the "connected" string without any additional information. Bug: 204943159 Test: make RunSettingsLibRoboTests ROBOTEST_FILTER=com.android.settingslib.bluetooth.CachedBluetoothDeviceTest Change-Id: I7744ceec534177bb6da8cd784e4cb3888f921f6f --- .../bluetooth/CachedBluetoothDevice.java | 19 ++++++-- .../bluetooth/CachedBluetoothDeviceTest.java | 43 ++++++++++++++----- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index a9011601f32b9..290055ce91a77 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -21,7 +21,6 @@ import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHearingAid; -import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.content.Context; @@ -1131,9 +1130,18 @@ public class CachedBluetoothDevice implements Comparable } /** - * @return resource for android auto string that describes the connection state of this device. + * See {@link #getCarConnectionSummary(boolean)} */ public String getCarConnectionSummary() { + return getCarConnectionSummary(false); + } + + /** + * Returns android auto string that describes the connection state of this device. + * + * @param shortSummary {@code true} if need to return short version summary + */ + public String getCarConnectionSummary(boolean shortSummary) { boolean profileConnected = false; // at least one profile is connected boolean a2dpNotConnected = false; // A2DP is preferred but not connected boolean hfpNotConnected = false; // HFP is preferred but not connected @@ -1151,6 +1159,10 @@ public class CachedBluetoothDevice implements Comparable BluetoothUtils.getConnectionStateSummary(connectionStatus)); case BluetoothProfile.STATE_CONNECTED: + if (shortSummary) { + return mContext.getString(BluetoothUtils.getConnectionStateSummary( + connectionStatus), /* formatArgs= */ ""); + } profileConnected = true; break; @@ -1248,7 +1260,8 @@ public class CachedBluetoothDevice implements Comparable } return getBondState() == BluetoothDevice.BOND_BONDING ? - mContext.getString(R.string.bluetooth_pairing) : null; + mContext.getString(R.string.bluetooth_pairing) : + mContext.getString(R.string.bluetooth_disconnected); } /** diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java index d8f4d7f31e55c..55d125e01388d 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java @@ -527,7 +527,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with battery level mBatteryLevel = 10; @@ -537,7 +537,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; @@ -548,7 +548,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test @@ -579,7 +579,7 @@ public class CachedBluetoothDeviceTest { // Disconnect all profiles and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test @@ -600,7 +600,7 @@ public class CachedBluetoothDeviceTest { // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; @@ -611,7 +611,7 @@ public class CachedBluetoothDeviceTest { // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test @@ -632,7 +632,7 @@ public class CachedBluetoothDeviceTest { // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; @@ -643,7 +643,7 @@ public class CachedBluetoothDeviceTest { // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test @@ -660,7 +660,7 @@ public class CachedBluetoothDeviceTest { // Set Hearing Aid profile to be disconnected and test connection state summary mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.HEARING_AID); updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test @@ -707,9 +707,32 @@ public class CachedBluetoothDeviceTest { // Set A2DP and HFP profiles to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); - assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); + assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } + @Test + public void getCarConnectionSummary_shortSummary_returnShortSummary() { + // Test without battery level + // Set A2DP profile to be connected and test connection state summary + updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); + assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) + .isEqualTo("Connected"); + + // Set device as Active for A2DP and test connection state summary + mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); + assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) + .isEqualTo("Connected"); + + // Test with battery level + mBatteryLevel = 10; + assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) + .isEqualTo("Connected"); + + // Set A2DP profile to be disconnected and test connection state summary + updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); + assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) + .isEqualTo("Disconnected"); + } @Test public void deviceName_testAliasNameAvailable() {