Loading core/tests/coretests/src/android/provider/SettingsBackupTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,12 @@ import java.util.Set; @SmallTest public class SettingsBackupTest { /** * see {@link com.google.android.systemui.power.EnhancedEstimatesGoogleImpl} for more details */ public static final String HYBRID_SYSUI_BATTERY_WARNING_FLAGS = "hybrid_sysui_battery_warning_flags"; /** * The following blacklists contain settings that should *not* be backed up and restored to * another device. As a general rule, anything that is not user configurable should be Loading Loading @@ -232,6 +238,7 @@ public class SettingsBackupTest { Settings.Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, Settings.Global.HTTP_PROXY, HYBRID_SYSUI_BATTERY_WARNING_FLAGS, Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY, Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, Settings.Global.INSTANT_APP_DEXOPT_ENABLED, Loading packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java +18 −0 Original line number Diff line number Diff line Loading @@ -2,7 +2,25 @@ package com.android.systemui.power; public interface EnhancedEstimates { /** * Returns a boolean indicating if the hybrid notification should be used. */ boolean isHybridNotificationEnabled(); /** * Returns an estimate object if the feature is enabled. */ Estimate getEstimate(); /** * Returns a long indicating the amount of time remaining in milliseconds under which we will * show a regular warning to the user. */ long getLowWarningThreshold(); /** * Returns a long indicating the amount of time remaining in milliseconds under which we will * show a severe warning to the user. */ long getSevereWarningThreshold(); } packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java +10 −0 Original line number Diff line number Diff line Loading @@ -13,4 +13,14 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates { public Estimate getEstimate() { return null; } @Override public long getLowWarningThreshold() { return 0; } @Override public long getSevereWarningThreshold() { return 0; } } packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +14 −3 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private long mWarningTriggerTimeMs; private Estimate mEstimate; private long mLowWarningThreshold; private long mSevereWarningThreshold; private boolean mWarning; private boolean mPlaySound; private boolean mInvalidCharger; Loading Loading @@ -142,11 +144,18 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { @Override public void updateEstimate(Estimate estimate) { mEstimate = estimate; if (estimate.estimateMillis <= PowerUI.THREE_HOURS_IN_MILLIS) { if (estimate.estimateMillis <= mLowWarningThreshold) { mWarningTriggerTimeMs = System.currentTimeMillis(); } } @Override public void updateThresholds(long lowThreshold, long severeThreshold) { mLowWarningThreshold = lowThreshold; mSevereWarningThreshold = severeThreshold; } private void updateNotification() { if (DEBUG) Slog.d(TAG, "updateNotification mWarning=" + mWarning + " mPlaySound=" + mPlaySound + " mInvalidCharger=" + mInvalidCharger); Loading Loading @@ -181,7 +190,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } protected void showWarningNotification() { final String percentage = NumberFormat.getPercentInstance().format((double) mBatteryLevel / 100.0); final String percentage = NumberFormat.getPercentInstance() .format((double) mBatteryLevel / 100.0); // get standard notification copy String title = mContext.getString(R.string.battery_low_title); Loading Loading @@ -214,7 +224,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } // Make the notification red if the percentage goes below a certain amount or the time // remaining estimate is disabled if (mEstimate == null || mBucket < 0) { if (mEstimate == null || mBucket < 0 || mEstimate.estimateMillis < mSevereWarningThreshold) { nb.setColor(Utils.getColorAttr(mContext, android.R.attr.colorError)); } nb.addAction(0, Loading packages/SystemUI/src/com/android/systemui/power/PowerUI.java +5 −2 Original line number Diff line number Diff line Loading @@ -269,6 +269,8 @@ public class PowerUI extends SystemUI { if (estimate != null) { mTimeRemaining = estimate.estimateMillis; mWarnings.updateEstimate(estimate); mWarnings.updateThresholds(mEnhancedEstimates.getLowWarningThreshold(), mEnhancedEstimates.getSevereWarningThreshold()); } } Loading @@ -292,7 +294,7 @@ public class PowerUI extends SystemUI { && !isPowerSaver && (((bucket < oldBucket || oldPlugged) && bucket < 0) || (mEnhancedEstimates.isHybridNotificationEnabled() && timeRemaining < THREE_HOURS_IN_MILLIS && timeRemaining < mEnhancedEstimates.getLowWarningThreshold() && isHourLess(oldTimeRemaining, timeRemaining))) && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN; } Loading @@ -306,7 +308,7 @@ public class PowerUI extends SystemUI { boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket, long timeRemaining, boolean isPowerSaver) { final boolean hybridWouldDismiss = mEnhancedEstimates.isHybridNotificationEnabled() && timeRemaining > THREE_HOURS_IN_MILLIS; && timeRemaining > mEnhancedEstimates.getLowWarningThreshold(); final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0); return isPowerSaver || plugged Loading Loading @@ -485,6 +487,7 @@ public class PowerUI extends SystemUI { public interface WarningsUI { void update(int batteryLevel, int bucket, long screenOffTime); void updateEstimate(Estimate estimate); void updateThresholds(long lowThreshold, long severeThreshold); void dismissLowBatteryWarning(); void showLowBatteryWarning(boolean playSound); void dismissInvalidChargerWarning(); Loading Loading
core/tests/coretests/src/android/provider/SettingsBackupTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,12 @@ import java.util.Set; @SmallTest public class SettingsBackupTest { /** * see {@link com.google.android.systemui.power.EnhancedEstimatesGoogleImpl} for more details */ public static final String HYBRID_SYSUI_BATTERY_WARNING_FLAGS = "hybrid_sysui_battery_warning_flags"; /** * The following blacklists contain settings that should *not* be backed up and restored to * another device. As a general rule, anything that is not user configurable should be Loading Loading @@ -232,6 +238,7 @@ public class SettingsBackupTest { Settings.Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, Settings.Global.HTTP_PROXY, HYBRID_SYSUI_BATTERY_WARNING_FLAGS, Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY, Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, Settings.Global.INSTANT_APP_DEXOPT_ENABLED, Loading
packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java +18 −0 Original line number Diff line number Diff line Loading @@ -2,7 +2,25 @@ package com.android.systemui.power; public interface EnhancedEstimates { /** * Returns a boolean indicating if the hybrid notification should be used. */ boolean isHybridNotificationEnabled(); /** * Returns an estimate object if the feature is enabled. */ Estimate getEstimate(); /** * Returns a long indicating the amount of time remaining in milliseconds under which we will * show a regular warning to the user. */ long getLowWarningThreshold(); /** * Returns a long indicating the amount of time remaining in milliseconds under which we will * show a severe warning to the user. */ long getSevereWarningThreshold(); }
packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java +10 −0 Original line number Diff line number Diff line Loading @@ -13,4 +13,14 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates { public Estimate getEstimate() { return null; } @Override public long getLowWarningThreshold() { return 0; } @Override public long getSevereWarningThreshold() { return 0; } }
packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +14 −3 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private long mWarningTriggerTimeMs; private Estimate mEstimate; private long mLowWarningThreshold; private long mSevereWarningThreshold; private boolean mWarning; private boolean mPlaySound; private boolean mInvalidCharger; Loading Loading @@ -142,11 +144,18 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { @Override public void updateEstimate(Estimate estimate) { mEstimate = estimate; if (estimate.estimateMillis <= PowerUI.THREE_HOURS_IN_MILLIS) { if (estimate.estimateMillis <= mLowWarningThreshold) { mWarningTriggerTimeMs = System.currentTimeMillis(); } } @Override public void updateThresholds(long lowThreshold, long severeThreshold) { mLowWarningThreshold = lowThreshold; mSevereWarningThreshold = severeThreshold; } private void updateNotification() { if (DEBUG) Slog.d(TAG, "updateNotification mWarning=" + mWarning + " mPlaySound=" + mPlaySound + " mInvalidCharger=" + mInvalidCharger); Loading Loading @@ -181,7 +190,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } protected void showWarningNotification() { final String percentage = NumberFormat.getPercentInstance().format((double) mBatteryLevel / 100.0); final String percentage = NumberFormat.getPercentInstance() .format((double) mBatteryLevel / 100.0); // get standard notification copy String title = mContext.getString(R.string.battery_low_title); Loading Loading @@ -214,7 +224,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } // Make the notification red if the percentage goes below a certain amount or the time // remaining estimate is disabled if (mEstimate == null || mBucket < 0) { if (mEstimate == null || mBucket < 0 || mEstimate.estimateMillis < mSevereWarningThreshold) { nb.setColor(Utils.getColorAttr(mContext, android.R.attr.colorError)); } nb.addAction(0, Loading
packages/SystemUI/src/com/android/systemui/power/PowerUI.java +5 −2 Original line number Diff line number Diff line Loading @@ -269,6 +269,8 @@ public class PowerUI extends SystemUI { if (estimate != null) { mTimeRemaining = estimate.estimateMillis; mWarnings.updateEstimate(estimate); mWarnings.updateThresholds(mEnhancedEstimates.getLowWarningThreshold(), mEnhancedEstimates.getSevereWarningThreshold()); } } Loading @@ -292,7 +294,7 @@ public class PowerUI extends SystemUI { && !isPowerSaver && (((bucket < oldBucket || oldPlugged) && bucket < 0) || (mEnhancedEstimates.isHybridNotificationEnabled() && timeRemaining < THREE_HOURS_IN_MILLIS && timeRemaining < mEnhancedEstimates.getLowWarningThreshold() && isHourLess(oldTimeRemaining, timeRemaining))) && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN; } Loading @@ -306,7 +308,7 @@ public class PowerUI extends SystemUI { boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket, long timeRemaining, boolean isPowerSaver) { final boolean hybridWouldDismiss = mEnhancedEstimates.isHybridNotificationEnabled() && timeRemaining > THREE_HOURS_IN_MILLIS; && timeRemaining > mEnhancedEstimates.getLowWarningThreshold(); final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0); return isPowerSaver || plugged Loading Loading @@ -485,6 +487,7 @@ public class PowerUI extends SystemUI { public interface WarningsUI { void update(int batteryLevel, int bucket, long screenOffTime); void updateEstimate(Estimate estimate); void updateThresholds(long lowThreshold, long severeThreshold); void dismissLowBatteryWarning(); void showLowBatteryWarning(boolean playSound); void dismissInvalidChargerWarning(); Loading