Loading packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +6 −3 Original line number Original line Diff line number Diff line Loading @@ -266,9 +266,12 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { || mEstimate.estimateMillis < mSevereWarningThreshold) { || mEstimate.estimateMillis < mSevereWarningThreshold) { nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError)); nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError)); } } if (!mPowerMan.isPowerSaveMode()) { nb.addAction(0, nb.addAction(0, mContext.getString(R.string.battery_saver_start_action), mContext.getString(R.string.battery_saver_start_action), pendingBroadcast(ACTION_START_SAVER)); pendingBroadcast(ACTION_START_SAVER)); } nb.setOnlyAlertOnce(!mPlaySound); nb.setOnlyAlertOnce(!mPlaySound); mPlaySound = false; mPlaySound = false; SystemUI.overrideNotificationAppName(mContext, nb, false); SystemUI.overrideNotificationAppName(mContext, nb, false); Loading packages/SystemUI/src/com/android/systemui/power/PowerUI.java +6 −5 Original line number Original line Diff line number Diff line Loading @@ -333,10 +333,11 @@ public class PowerUI extends SystemUI { @VisibleForTesting @VisibleForTesting boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket, boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket, long timeRemaining, boolean isPowerSaver) { long timeRemaining, boolean isPowerSaver) { final boolean hybridWouldDismiss = mEnhancedEstimates.isHybridNotificationEnabled() final boolean hybridEnabled = mEnhancedEstimates.isHybridNotificationEnabled(); final boolean hybridWouldDismiss = hybridEnabled && timeRemaining > mEnhancedEstimates.getLowWarningThreshold(); && timeRemaining > mEnhancedEstimates.getLowWarningThreshold(); final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0); final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0); return isPowerSaver return (isPowerSaver && !hybridEnabled) || plugged || plugged || (standardWouldDismiss && (!mEnhancedEstimates.isHybridNotificationEnabled() || (standardWouldDismiss && (!mEnhancedEstimates.isHybridNotificationEnabled() || hybridWouldDismiss)); || hybridWouldDismiss)); Loading @@ -344,14 +345,14 @@ public class PowerUI extends SystemUI { private boolean isEnhancedTrigger(boolean plugged, long timeRemaining, boolean isPowerSaver, private boolean isEnhancedTrigger(boolean plugged, long timeRemaining, boolean isPowerSaver, int batteryStatus) { int batteryStatus) { if (plugged || isPowerSaver || batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) { if (plugged || batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) { return false; return false; } } int warnLevel = mLowBatteryReminderLevels[0]; int warnLevel = mLowBatteryReminderLevels[0]; int critLevel = mLowBatteryReminderLevels[1]; int critLevel = mLowBatteryReminderLevels[1]; // Only show the low warning once per charge cycle // Only show the low warning once per charge cycle & no battery saver final boolean canShowWarning = !mLowWarningShownThisChargeCycle final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !isPowerSaver && (timeRemaining < mEnhancedEstimates.getLowWarningThreshold() && (timeRemaining < mEnhancedEstimates.getLowWarningThreshold() || mBatteryLevel <= warnLevel); || mBatteryLevel <= warnLevel); Loading packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java +16 −2 Original line number Original line Diff line number Diff line Loading @@ -323,9 +323,9 @@ public class PowerUITest extends SysuiTestCase { } } @Test @Test public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabled() { public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabledLegacy() { mPowerUI.start(); mPowerUI.start(); when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false); when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); Loading @@ -336,6 +336,20 @@ public class PowerUITest extends SysuiTestCase { assertTrue(shouldDismiss); assertTrue(shouldDismiss); } } @Test public void testShouldNotDismissLowBatteryWarning_dismissWhenPowerSaverEnabledHybrid() { mPowerUI.start(); when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); // device that gets power saver turned on should dismiss boolean shouldDismiss = mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, !POWER_SAVER_OFF); assertFalse(shouldDismiss); } @Test @Test public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() { public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() { mPowerUI.start(); mPowerUI.start(); Loading Loading
packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +6 −3 Original line number Original line Diff line number Diff line Loading @@ -266,9 +266,12 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { || mEstimate.estimateMillis < mSevereWarningThreshold) { || mEstimate.estimateMillis < mSevereWarningThreshold) { nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError)); nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError)); } } if (!mPowerMan.isPowerSaveMode()) { nb.addAction(0, nb.addAction(0, mContext.getString(R.string.battery_saver_start_action), mContext.getString(R.string.battery_saver_start_action), pendingBroadcast(ACTION_START_SAVER)); pendingBroadcast(ACTION_START_SAVER)); } nb.setOnlyAlertOnce(!mPlaySound); nb.setOnlyAlertOnce(!mPlaySound); mPlaySound = false; mPlaySound = false; SystemUI.overrideNotificationAppName(mContext, nb, false); SystemUI.overrideNotificationAppName(mContext, nb, false); Loading
packages/SystemUI/src/com/android/systemui/power/PowerUI.java +6 −5 Original line number Original line Diff line number Diff line Loading @@ -333,10 +333,11 @@ public class PowerUI extends SystemUI { @VisibleForTesting @VisibleForTesting boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket, boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket, long timeRemaining, boolean isPowerSaver) { long timeRemaining, boolean isPowerSaver) { final boolean hybridWouldDismiss = mEnhancedEstimates.isHybridNotificationEnabled() final boolean hybridEnabled = mEnhancedEstimates.isHybridNotificationEnabled(); final boolean hybridWouldDismiss = hybridEnabled && timeRemaining > mEnhancedEstimates.getLowWarningThreshold(); && timeRemaining > mEnhancedEstimates.getLowWarningThreshold(); final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0); final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0); return isPowerSaver return (isPowerSaver && !hybridEnabled) || plugged || plugged || (standardWouldDismiss && (!mEnhancedEstimates.isHybridNotificationEnabled() || (standardWouldDismiss && (!mEnhancedEstimates.isHybridNotificationEnabled() || hybridWouldDismiss)); || hybridWouldDismiss)); Loading @@ -344,14 +345,14 @@ public class PowerUI extends SystemUI { private boolean isEnhancedTrigger(boolean plugged, long timeRemaining, boolean isPowerSaver, private boolean isEnhancedTrigger(boolean plugged, long timeRemaining, boolean isPowerSaver, int batteryStatus) { int batteryStatus) { if (plugged || isPowerSaver || batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) { if (plugged || batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) { return false; return false; } } int warnLevel = mLowBatteryReminderLevels[0]; int warnLevel = mLowBatteryReminderLevels[0]; int critLevel = mLowBatteryReminderLevels[1]; int critLevel = mLowBatteryReminderLevels[1]; // Only show the low warning once per charge cycle // Only show the low warning once per charge cycle & no battery saver final boolean canShowWarning = !mLowWarningShownThisChargeCycle final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !isPowerSaver && (timeRemaining < mEnhancedEstimates.getLowWarningThreshold() && (timeRemaining < mEnhancedEstimates.getLowWarningThreshold() || mBatteryLevel <= warnLevel); || mBatteryLevel <= warnLevel); Loading
packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java +16 −2 Original line number Original line Diff line number Diff line Loading @@ -323,9 +323,9 @@ public class PowerUITest extends SysuiTestCase { } } @Test @Test public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabled() { public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabledLegacy() { mPowerUI.start(); mPowerUI.start(); when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false); when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); Loading @@ -336,6 +336,20 @@ public class PowerUITest extends SysuiTestCase { assertTrue(shouldDismiss); assertTrue(shouldDismiss); } } @Test public void testShouldNotDismissLowBatteryWarning_dismissWhenPowerSaverEnabledHybrid() { mPowerUI.start(); when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); // device that gets power saver turned on should dismiss boolean shouldDismiss = mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, !POWER_SAVER_OFF); assertFalse(shouldDismiss); } @Test @Test public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() { public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() { mPowerUI.start(); mPowerUI.start(); Loading