diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 1d351a5e53b6c..9a95288a69aeb 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -826,11 +826,22 @@ public class CachedBluetoothDevice implements Comparable } /** - * @return resource for string that discribes the connection state of this device. - * case 1: idle or playing media, show "Active" on the only one A2DP active device. - * case 2: in phone call, show "Active" on the only one HFP active device + * Return full summary that describes connection state of this device + * + * @see #getConnectionSummary(boolean shortSummary) */ public String getConnectionSummary() { + return getConnectionSummary(false /* shortSummary */); + } + + /** + * Return summary that describes connection state of this device. Summary depends on: + * 1. Whether device has battery info + * 2. Whether device is in active usage(or in phone call) + * + * @param shortSummary {@code true} if need to return short version summary + */ + public String getConnectionSummary(boolean shortSummary) { boolean profileConnected = false; // Updated as long as BluetoothProfile is connected boolean a2dpConnected = true; // A2DP is connected boolean hfpConnected = true; // HFP is connected @@ -909,9 +920,9 @@ public class CachedBluetoothDevice implements Comparable if ((mIsActiveDeviceHearingAid) || (mIsActiveDeviceHeadset && isOnCall) || (mIsActiveDeviceA2dp && !isOnCall)) { - if (isTwsBatteryAvailable(leftBattery, rightBattery)) { + if (isTwsBatteryAvailable(leftBattery, rightBattery) && !shortSummary) { stringRes = R.string.bluetooth_active_battery_level_untethered; - } else if (batteryLevelPercentageString != null) { + } else if (batteryLevelPercentageString != null && !shortSummary) { stringRes = R.string.bluetooth_active_battery_level; } else { stringRes = R.string.bluetooth_active_no_battery_level; 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 c0a1f11a0a876..93dcbfeab1729 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 @@ -191,6 +191,27 @@ public class CachedBluetoothDeviceTest { assertThat(mCachedDevice.getConnectionSummary()).isNull(); } + @Test + public void getConnectionSummary_shortSummary_returnShortSummary() { + // Test without battery level + // Set A2DP profile to be connected and test connection state summary + updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); + assertThat(mCachedDevice.getConnectionSummary(true /* shortSummary */)).isNull(); + + // Set device as Active for A2DP and test connection state summary + mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); + assertThat(mCachedDevice.getConnectionSummary(true /* shortSummary */)).isEqualTo("Active"); + + // Test with battery level + mBatteryLevel = 10; + assertThat(mCachedDevice.getConnectionSummary(true /* shortSummary */)).isEqualTo( + "Active"); + + // Set A2DP profile to be disconnected and test connection state summary + updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); + assertThat(mCachedDevice.getConnectionSummary()).isNull(); + } + @Test public void getConnectionSummary_testA2dpBatteryInactive_returnBattery() { // Arrange: