Loading packages/SystemUI/src/com/android/systemui/power/BatteryStateSnapshot.kt +4 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,8 @@ data class BatteryStateSnapshot( val timeRemainingMillis: Long, val severeThresholdMillis: Long, val lowThresholdMillis: Long, val isBasedOnUsage: Boolean val isBasedOnUsage: Boolean, val isLowWarningEnabled: Boolean ) { /** * Returns whether hybrid warning logic/copy should be used for this snapshot Loading Loading @@ -48,7 +49,8 @@ data class BatteryStateSnapshot( NO_ESTIMATE_AVAILABLE.toLong(), NO_ESTIMATE_AVAILABLE.toLong(), NO_ESTIMATE_AVAILABLE.toLong(), false false, true ) { this.isHybrid = false } Loading packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java +5 −0 Original line number Diff line number Diff line Loading @@ -23,4 +23,9 @@ public interface EnhancedEstimates { * show a severe warning to the user. */ long getSevereWarningThreshold(); /** * Returns a boolean indicating if the low warning should be shown at all or not. */ boolean getLowWarningEnabled(); } packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java +5 −0 Original line number Diff line number Diff line Loading @@ -21,4 +21,9 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates { public long getSevereWarningThreshold() { return 0; } @Override public boolean getLowWarningEnabled() { return true; } } packages/SystemUI/src/com/android/systemui/power/PowerUI.java +6 −4 Original line number Diff line number Diff line Loading @@ -284,7 +284,8 @@ public class PowerUI extends SystemUI { plugged, bucket, mBatteryStatus, mLowBatteryReminderLevels[1], mLowBatteryReminderLevels[0], estimate.getEstimateMillis(), mEnhancedEstimates.getSevereWarningThreshold(), mEnhancedEstimates.getLowWarningThreshold(), estimate.isBasedOnUsage()); mEnhancedEstimates.getLowWarningThreshold(), estimate.isBasedOnUsage(), mEnhancedEstimates.getLowWarningEnabled()); } else { if (DEBUG) { Slog.d(TAG, "using standard"); Loading Loading @@ -351,7 +352,6 @@ public class PowerUI extends SystemUI { Slog.d(TAG, "Low warning marked as shown this cycle"); mLowWarningShownThisChargeCycle = true; } } else if (shouldDismissHybridWarning(currentSnapshot)) { if (DEBUG) { Slog.d(TAG, "Dismissing warning"); Loading @@ -375,8 +375,9 @@ public class PowerUI extends SystemUI { return false; } // Only show the low warning once per charge cycle & no battery saver final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver() // Only show the low warning if enabled once per charge cycle & no battery saver final boolean canShowWarning = snapshot.isLowWarningEnabled() && !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver() && (snapshot.getTimeRemainingMillis() < snapshot.getLowThresholdMillis() || snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold()); Loading @@ -386,6 +387,7 @@ public class PowerUI extends SystemUI { || snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold()); final boolean canShow = canShowWarning || canShowSevereWarning; if (DEBUG) { Slog.d(TAG, "Enhanced trigger is: " + canShow + "\nwith battery snapshot:" + " mLowWarningShownThisChargeCycle: " + mLowWarningShownThisChargeCycle Loading packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java +10 −3 Original line number Diff line number Diff line Loading @@ -265,6 +265,12 @@ public class PowerUITest extends SysuiTestCase { state.mIsPowerSaver = true; shouldShow = mPowerUI.shouldShowHybridWarning(state.get()); assertThat(shouldShow).isFalse(); state.mIsPowerSaver = false; // if disabled we should not show the low warning. state.mIsLowLevelWarningEnabled = false; shouldShow = mPowerUI.shouldShowHybridWarning(state.get()); assertThat(shouldShow).isFalse(); } @Test Loading Loading @@ -365,7 +371,7 @@ public class PowerUITest extends SysuiTestCase { assertThat(refreshedEstimate.getEstimateMillis()).isEqualTo(BELOW_HYBRID_THRESHOLD); BatteryStateSnapshot snapshot = new BatteryStateSnapshot( BATTERY_LEVEL_10, false, false, 0, BatteryManager.BATTERY_HEALTH_GOOD, 0, 0, -1, 0, 0, false); 0, 0, -1, 0, 0, false, true); mPowerUI.mLastBatteryStateSnapshot = snapshot; // query again since the estimate was -1 Loading @@ -375,7 +381,7 @@ public class PowerUITest extends SysuiTestCase { assertThat(refreshedEstimate.getEstimateMillis()).isEqualTo(BELOW_SEVERE_HYBRID_THRESHOLD); snapshot = new BatteryStateSnapshot( BATTERY_LEVEL_10, false, false, 0, BatteryManager.BATTERY_HEALTH_GOOD, 0, 0, BELOW_SEVERE_HYBRID_THRESHOLD, 0, 0, false); 0, BELOW_SEVERE_HYBRID_THRESHOLD, 0, 0, false, true); mPowerUI.mLastBatteryStateSnapshot = snapshot; // Battery level hasn't changed, so we don't query again Loading Loading @@ -536,13 +542,14 @@ public class PowerUITest extends SysuiTestCase { public long mTimeRemainingMillis = Duration.ofHours(24).toMillis(); public boolean mIsBasedOnUsage = true; public boolean mIsHybrid = true; public boolean mIsLowLevelWarningEnabled = true; public BatteryStateSnapshot get() { if (mIsHybrid) { return new BatteryStateSnapshot(mBatteryLevel, mIsPowerSaver, mPlugged, mBucket, mBatteryStatus, mSevereLevelThreshold, mLowLevelThreshold, mTimeRemainingMillis, mSevereThresholdMillis, mLowThresholdMillis, mIsBasedOnUsage); mIsBasedOnUsage, mIsLowLevelWarningEnabled); } else { return new BatteryStateSnapshot(mBatteryLevel, mIsPowerSaver, mPlugged, mBucket, mBatteryStatus, mSevereLevelThreshold, mLowLevelThreshold); Loading Loading
packages/SystemUI/src/com/android/systemui/power/BatteryStateSnapshot.kt +4 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,8 @@ data class BatteryStateSnapshot( val timeRemainingMillis: Long, val severeThresholdMillis: Long, val lowThresholdMillis: Long, val isBasedOnUsage: Boolean val isBasedOnUsage: Boolean, val isLowWarningEnabled: Boolean ) { /** * Returns whether hybrid warning logic/copy should be used for this snapshot Loading Loading @@ -48,7 +49,8 @@ data class BatteryStateSnapshot( NO_ESTIMATE_AVAILABLE.toLong(), NO_ESTIMATE_AVAILABLE.toLong(), NO_ESTIMATE_AVAILABLE.toLong(), false false, true ) { this.isHybrid = false } Loading
packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java +5 −0 Original line number Diff line number Diff line Loading @@ -23,4 +23,9 @@ public interface EnhancedEstimates { * show a severe warning to the user. */ long getSevereWarningThreshold(); /** * Returns a boolean indicating if the low warning should be shown at all or not. */ boolean getLowWarningEnabled(); }
packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java +5 −0 Original line number Diff line number Diff line Loading @@ -21,4 +21,9 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates { public long getSevereWarningThreshold() { return 0; } @Override public boolean getLowWarningEnabled() { return true; } }
packages/SystemUI/src/com/android/systemui/power/PowerUI.java +6 −4 Original line number Diff line number Diff line Loading @@ -284,7 +284,8 @@ public class PowerUI extends SystemUI { plugged, bucket, mBatteryStatus, mLowBatteryReminderLevels[1], mLowBatteryReminderLevels[0], estimate.getEstimateMillis(), mEnhancedEstimates.getSevereWarningThreshold(), mEnhancedEstimates.getLowWarningThreshold(), estimate.isBasedOnUsage()); mEnhancedEstimates.getLowWarningThreshold(), estimate.isBasedOnUsage(), mEnhancedEstimates.getLowWarningEnabled()); } else { if (DEBUG) { Slog.d(TAG, "using standard"); Loading Loading @@ -351,7 +352,6 @@ public class PowerUI extends SystemUI { Slog.d(TAG, "Low warning marked as shown this cycle"); mLowWarningShownThisChargeCycle = true; } } else if (shouldDismissHybridWarning(currentSnapshot)) { if (DEBUG) { Slog.d(TAG, "Dismissing warning"); Loading @@ -375,8 +375,9 @@ public class PowerUI extends SystemUI { return false; } // Only show the low warning once per charge cycle & no battery saver final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver() // Only show the low warning if enabled once per charge cycle & no battery saver final boolean canShowWarning = snapshot.isLowWarningEnabled() && !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver() && (snapshot.getTimeRemainingMillis() < snapshot.getLowThresholdMillis() || snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold()); Loading @@ -386,6 +387,7 @@ public class PowerUI extends SystemUI { || snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold()); final boolean canShow = canShowWarning || canShowSevereWarning; if (DEBUG) { Slog.d(TAG, "Enhanced trigger is: " + canShow + "\nwith battery snapshot:" + " mLowWarningShownThisChargeCycle: " + mLowWarningShownThisChargeCycle Loading
packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java +10 −3 Original line number Diff line number Diff line Loading @@ -265,6 +265,12 @@ public class PowerUITest extends SysuiTestCase { state.mIsPowerSaver = true; shouldShow = mPowerUI.shouldShowHybridWarning(state.get()); assertThat(shouldShow).isFalse(); state.mIsPowerSaver = false; // if disabled we should not show the low warning. state.mIsLowLevelWarningEnabled = false; shouldShow = mPowerUI.shouldShowHybridWarning(state.get()); assertThat(shouldShow).isFalse(); } @Test Loading Loading @@ -365,7 +371,7 @@ public class PowerUITest extends SysuiTestCase { assertThat(refreshedEstimate.getEstimateMillis()).isEqualTo(BELOW_HYBRID_THRESHOLD); BatteryStateSnapshot snapshot = new BatteryStateSnapshot( BATTERY_LEVEL_10, false, false, 0, BatteryManager.BATTERY_HEALTH_GOOD, 0, 0, -1, 0, 0, false); 0, 0, -1, 0, 0, false, true); mPowerUI.mLastBatteryStateSnapshot = snapshot; // query again since the estimate was -1 Loading @@ -375,7 +381,7 @@ public class PowerUITest extends SysuiTestCase { assertThat(refreshedEstimate.getEstimateMillis()).isEqualTo(BELOW_SEVERE_HYBRID_THRESHOLD); snapshot = new BatteryStateSnapshot( BATTERY_LEVEL_10, false, false, 0, BatteryManager.BATTERY_HEALTH_GOOD, 0, 0, BELOW_SEVERE_HYBRID_THRESHOLD, 0, 0, false); 0, BELOW_SEVERE_HYBRID_THRESHOLD, 0, 0, false, true); mPowerUI.mLastBatteryStateSnapshot = snapshot; // Battery level hasn't changed, so we don't query again Loading Loading @@ -536,13 +542,14 @@ public class PowerUITest extends SysuiTestCase { public long mTimeRemainingMillis = Duration.ofHours(24).toMillis(); public boolean mIsBasedOnUsage = true; public boolean mIsHybrid = true; public boolean mIsLowLevelWarningEnabled = true; public BatteryStateSnapshot get() { if (mIsHybrid) { return new BatteryStateSnapshot(mBatteryLevel, mIsPowerSaver, mPlugged, mBucket, mBatteryStatus, mSevereLevelThreshold, mLowLevelThreshold, mTimeRemainingMillis, mSevereThresholdMillis, mLowThresholdMillis, mIsBasedOnUsage); mIsBasedOnUsage, mIsLowLevelWarningEnabled); } else { return new BatteryStateSnapshot(mBatteryLevel, mIsPowerSaver, mPlugged, mBucket, mBatteryStatus, mSevereLevelThreshold, mLowLevelThreshold); Loading