Loading packages/SystemUI/aconfig/systemui.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -2040,3 +2040,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 } } packages/SystemUI/src/com/android/systemui/lowlightclock/ChargingStatusProvider.java +19 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -53,6 +58,8 @@ public class ChargingStatusProvider { // callback being GC'd. private ChargingStatusCallback mChargingStatusCallback; private final Lazy<KeyguardIndicationController> mKeyguardIndicationController; private Callback mCallback; @Inject Loading @@ -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; } /** Loading Loading @@ -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(); } } Loading packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +4 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading packages/SystemUI/tests/src/com/android/systemui/lowlightclock/ChargingStatusProviderTest.java +30 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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 Loading Loading @@ -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); Loading @@ -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); Loading @@ -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 = Loading @@ -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 = Loading @@ -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, Loading Loading
packages/SystemUI/aconfig/systemui.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -2040,3 +2040,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 } }
packages/SystemUI/src/com/android/systemui/lowlightclock/ChargingStatusProvider.java +19 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -53,6 +58,8 @@ public class ChargingStatusProvider { // callback being GC'd. private ChargingStatusCallback mChargingStatusCallback; private final Lazy<KeyguardIndicationController> mKeyguardIndicationController; private Callback mCallback; @Inject Loading @@ -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; } /** Loading Loading @@ -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(); } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +4 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
packages/SystemUI/tests/src/com/android/systemui/lowlightclock/ChargingStatusProviderTest.java +30 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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 Loading Loading @@ -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); Loading @@ -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); Loading @@ -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 = Loading @@ -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 = Loading @@ -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, Loading