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

Commit 5f7160b1 authored by Ze Li's avatar Ze Li
Browse files

[Battery refactor] Use the min battery of 2 earbuds as overall battery.

Test: com.android.settingslib.bluetooth.CachedBluetoothDeviceTest
Bug: 397847825
Flag: com.android.settingslib.flags.refactor_battery_level_display
Change-Id: Id45985716cf106eb146308a08d5e3d5bb643a803
parent 8ae2f4fc
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -1789,7 +1789,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            } else {
                int overallBattery =
                        getMinBatteryLevels(
                                Arrays.stream(new int[]{leftBattery, rightBattery, caseBattery}));
                                Arrays.stream(new int[]{leftBattery, rightBattery}));
                if (overallBattery <= BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
                    overallBattery = caseBattery;
                }
                Log.d(TAG, "Acquired battery info from metadata for untethered device "
                        + mDevice.getAnonymizedAddress()
                        + " left earbud battery: " + leftBattery
@@ -1895,7 +1898,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        }
        int leftBattery = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
        int rightBattery = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
        int overallBattery = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
        int singleBattery = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;

        Set<BluetoothDevice> allDevices =
                Stream.concat(
@@ -1914,15 +1917,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            // We should expect only one device assign to one side, but if it happens,
            // we don't care which one.
            if (isLeftRight) {
                overallBattery = battery;
                singleBattery = battery;
            } else if (isLeft) {
                leftBattery = battery;
            } else if (isRight) {
                rightBattery = battery;
            }
        }
        overallBattery = getMinBatteryLevels(
                Arrays.stream(new int[]{leftBattery, rightBattery, overallBattery}));
        int overallBattery = getMinBatteryLevels(
                Arrays.stream(new int[]{leftBattery, rightBattery}));
        if (overallBattery <= BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
            overallBattery = singleBattery;
        }

        Log.d(TAG, "Acquired battery info from Bluetooth service for le audio device "
                + mDevice.getAnonymizedAddress()