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

Commit 74400c27 authored by Will Leshner's avatar Will Leshner
Browse files

Update charging string to match keyguard.

Use the keyguard algorithm for computing the charging string in the
low-light clock dream, so that the same string appears in both keyguard
and the low-light clock.

Fixes: 424297980
Test: atest ChargingStatusProviderTest, KeyguardIndicationControllerTest
Flag: com.android.systemui.lowlight_clock_uses_keyguard_charging_status
Change-Id: If93d65e6f45271921ef3a013e67ee7ff2bcbed46
parent abfdc572
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2050,3 +2050,13 @@ flag {
    description: "Migrate from the old remote animation APIs to the new Shell RemoteTransition-based ones."
    bug: "397180418"
}

flag {
    name: "lowlight_clock_uses_keyguard_charging_status"
    namespace: "systemui"
    description: "Make sure keyguard and low-light clock show the same charging status."
    bug: "424297980"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}
+19 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.lowlightclock;

import static com.android.systemui.Flags.lowlightClockUsesKeyguardChargingStatus;

import android.content.Context;
import android.content.res.Resources;
import android.os.BatteryManager;
@@ -30,6 +32,9 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.settingslib.fuelgauge.BatteryStatus;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.KeyguardIndicationController;

import dagger.Lazy;

import java.text.NumberFormat;

@@ -53,6 +58,8 @@ public class ChargingStatusProvider {
    // callback being GC'd.
    private ChargingStatusCallback mChargingStatusCallback;

    private final Lazy<KeyguardIndicationController> mKeyguardIndicationController;

    private Callback mCallback;

    @Inject
@@ -60,11 +67,13 @@ public class ChargingStatusProvider {
            Context context,
            @Main Resources resources,
            IBatteryStats iBatteryStats,
            KeyguardUpdateMonitor keyguardUpdateMonitor) {
            KeyguardUpdateMonitor keyguardUpdateMonitor,
            Lazy<KeyguardIndicationController> keyguardIndicationController) {
        mContext = context;
        mResources = resources;
        mBatteryInfo = iBatteryStats;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mKeyguardIndicationController = keyguardIndicationController;
    }

    /**
@@ -157,7 +166,15 @@ public class ChargingStatusProvider {
        if (mCallback != null) {
            final boolean shouldShowStatus =
                    mBatteryState.isPowerPluggedIn() || mBatteryState.isBatteryDefenderEnabled();
            mCallback.onChargingStatusChanged(shouldShowStatus, computeChargingString());
            mCallback.onChargingStatusChanged(shouldShowStatus, getChargingString());
        }
    }

    private String getChargingString() {
        if (lowlightClockUsesKeyguardChargingStatus()) {
            return mKeyguardIndicationController.get().getPowerChargingString();
        } else {
            return computeChargingString();
        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -479,6 +479,10 @@ public class KeyguardIndicationController {
        mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver);
    }

    public String getPowerChargingString() {
        return computePowerChargingStringIndication();
    }

    private void handleAlignStateChanged(int alignState) {
        String alignmentIndication = "";
        if (alignState == DockManager.ALIGN_STATE_POOR) {
+30 −3
Original line number Diff line number Diff line
@@ -26,16 +26,22 @@ import static org.mockito.Mockito.when;
import android.content.res.Resources;
import android.os.BatteryManager;
import android.os.RemoteException;
import android.testing.AndroidTestingRunner;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.internal.app.IBatteryStats;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.settingslib.fuelgauge.BatteryStatus;
import com.android.systemui.Flags;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.KeyguardIndicationController;

import dagger.Lazy;

import org.junit.Before;
import org.junit.Test;
@@ -45,7 +51,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWith(AndroidJUnit4.class)
public class ChargingStatusProviderTest extends SysuiTestCase {
    @Mock
    private Resources mResources;
@@ -54,6 +60,10 @@ public class ChargingStatusProviderTest extends SysuiTestCase {
    @Mock
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    @Mock
    private Lazy<KeyguardIndicationController> mKeyguardIndicationControllerLazy;
    @Mock
    private KeyguardIndicationController mKeyguardIndicationController;
    @Mock
    private ChargingStatusProvider.Callback mCallback;

    private ChargingStatusProvider mProvider;
@@ -62,8 +72,13 @@ public class ChargingStatusProviderTest extends SysuiTestCase {
    public void setup() {
        MockitoAnnotations.initMocks(this);

        when(mKeyguardIndicationControllerLazy.get()).thenReturn(mKeyguardIndicationController);
        mProvider = new ChargingStatusProvider(
                mContext, mResources, mBatteryInfo, mKeyguardUpdateMonitor);
                mContext,
                mResources,
                mBatteryInfo,
                mKeyguardUpdateMonitor,
                mKeyguardIndicationControllerLazy);
    }

    @Test
@@ -143,6 +158,7 @@ public class ChargingStatusProviderTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(Flags.FLAG_LOWLIGHT_CLOCK_USES_KEYGUARD_CHARGING_STATUS)
    public void testChargingStatusReportsChargingLimitedWhenOverheated() {
        ArgumentCaptor<KeyguardUpdateMonitorCallback> keyguardUpdateMonitorCallbackArgumentCaptor =
                ArgumentCaptor.forClass(KeyguardUpdateMonitorCallback.class);
@@ -156,6 +172,7 @@ public class ChargingStatusProviderTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(Flags.FLAG_LOWLIGHT_CLOCK_USES_KEYGUARD_CHARGING_STATUS)
    public void testChargingStatusReportsChargedWhenCharged() {
        ArgumentCaptor<KeyguardUpdateMonitorCallback> keyguardUpdateMonitorCallbackArgumentCaptor =
                ArgumentCaptor.forClass(KeyguardUpdateMonitorCallback.class);
@@ -169,6 +186,7 @@ public class ChargingStatusProviderTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(Flags.FLAG_LOWLIGHT_CLOCK_USES_KEYGUARD_CHARGING_STATUS)
    public void testChargingStatusReportsPluggedInWhenDockedAndChargingTimeUnknown() throws
            RemoteException {
        ArgumentCaptor<KeyguardUpdateMonitorCallback> keyguardUpdateMonitorCallbackArgumentCaptor =
@@ -185,6 +203,7 @@ public class ChargingStatusProviderTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(Flags.FLAG_LOWLIGHT_CLOCK_USES_KEYGUARD_CHARGING_STATUS)
    public void testChargingStatusReportsTimeRemainingWhenDockedAndCharging() throws
            RemoteException {
        ArgumentCaptor<KeyguardUpdateMonitorCallback> keyguardUpdateMonitorCallbackArgumentCaptor =
@@ -200,6 +219,14 @@ public class ChargingStatusProviderTest extends SysuiTestCase {
                eq(R.string.keyguard_indication_charging_time_dock), any(), any());
    }

    @Test
    @EnableFlags(Flags.FLAG_LOWLIGHT_CLOCK_USES_KEYGUARD_CHARGING_STATUS)
    public void testAsksKeyguardForChargingStatusWhenFlagEnabled() {
        mProvider.startUsing(mCallback);
        verify(mCallback).onChargingStatusChanged(false, null);
        verify(mKeyguardIndicationController).getPowerChargingString();
    }

    private BatteryStatus getUnpluggedBattery() {
        return new BatteryStatus(BatteryManager.BATTERY_STATUS_NOT_CHARGING,
                80, BatteryManager.BATTERY_PLUGGED_ANY, BatteryManager.BATTERY_HEALTH_GOOD,