Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b899f8ab authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge "Add short version bluetooth device summary" into qt-dev

parents e6f11ab8 e63ca1b8
Loading
Loading
Loading
Loading
+16 −5
Original line number Original line Diff line number Diff line
@@ -826,11 +826,22 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    }
    }


    /**
    /**
     * @return resource for string that discribes the connection state of this device.
     * Return full summary that describes 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
     * @see #getConnectionSummary(boolean shortSummary)
     */
     */
    public String getConnectionSummary() {
    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 profileConnected = false;    // Updated as long as BluetoothProfile is connected
        boolean a2dpConnected = true;        // A2DP is connected
        boolean a2dpConnected = true;        // A2DP is connected
        boolean hfpConnected = true;         // HFP is connected
        boolean hfpConnected = true;         // HFP is connected
@@ -909,9 +920,9 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                if ((mIsActiveDeviceHearingAid)
                if ((mIsActiveDeviceHearingAid)
                        || (mIsActiveDeviceHeadset && isOnCall)
                        || (mIsActiveDeviceHeadset && isOnCall)
                        || (mIsActiveDeviceA2dp && !isOnCall)) {
                        || (mIsActiveDeviceA2dp && !isOnCall)) {
                    if (isTwsBatteryAvailable(leftBattery, rightBattery)) {
                    if (isTwsBatteryAvailable(leftBattery, rightBattery) && !shortSummary) {
                        stringRes = R.string.bluetooth_active_battery_level_untethered;
                        stringRes = R.string.bluetooth_active_battery_level_untethered;
                    } else if (batteryLevelPercentageString != null) {
                    } else if (batteryLevelPercentageString != null && !shortSummary) {
                        stringRes = R.string.bluetooth_active_battery_level;
                        stringRes = R.string.bluetooth_active_battery_level;
                    } else {
                    } else {
                        stringRes = R.string.bluetooth_active_no_battery_level;
                        stringRes = R.string.bluetooth_active_no_battery_level;
+21 −0
Original line number Original line Diff line number Diff line
@@ -191,6 +191,27 @@ public class CachedBluetoothDeviceTest {
        assertThat(mCachedDevice.getConnectionSummary()).isNull();
        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
    @Test
    public void getConnectionSummary_testA2dpBatteryInactive_returnBattery() {
    public void getConnectionSummary_testA2dpBatteryInactive_returnBattery() {
        // Arrange:
        // Arrange: