summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/tests/coretests/src/android/provider/SettingsBackupTest.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java18
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java17
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/PowerUI.java7
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java98
6 files changed, 136 insertions, 21 deletions
diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
index 7403c26dd5b5..f5ec4ae36bc4 100644
--- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java
+++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
@@ -44,6 +44,12 @@ import java.util.Set;
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
* blacklisted (and conversely, things that *are* user configurable *should* be backed up)
@@ -226,6 +232,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,
diff --git a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java
index 8f41a6036072..bd130f4b40f3 100644
--- a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java
+++ b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java
@@ -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();
}
diff --git a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java
index d447542588c5..5686d801bca2 100644
--- a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java
@@ -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;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
index 736286f21bfe..aa56694775fc 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
@@ -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;
@@ -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);
@@ -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);
@@ -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,
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index c5aab601283c..b43e99be828e 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -269,6 +269,8 @@ public class PowerUI extends SystemUI {
if (estimate != null) {
mTimeRemaining = estimate.estimateMillis;
mWarnings.updateEstimate(estimate);
+ mWarnings.updateThresholds(mEnhancedEstimates.getLowWarningThreshold(),
+ mEnhancedEstimates.getSevereWarningThreshold());
}
}
@@ -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;
}
@@ -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
@@ -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();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
index fdb7f8d005b6..0a51e5a4e389 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
@@ -40,6 +40,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.power.PowerUI.WarningsUI;
import com.android.systemui.statusbar.phone.StatusBar;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
@@ -53,18 +54,19 @@ public class PowerUITest extends SysuiTestCase {
private static final boolean UNPLUGGED = false;
private static final boolean POWER_SAVER_OFF = false;
private static final int ABOVE_WARNING_BUCKET = 1;
+ private static final long ONE_HOUR_MILLIS = Duration.ofHours(1).toMillis();
public static final int BELOW_WARNING_BUCKET = -1;
public static final long BELOW_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(2);
public static final long ABOVE_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(4);
private HardwarePropertiesManager mHardProps;
private WarningsUI mMockWarnings;
private PowerUI mPowerUI;
- private EnhancedEstimates mEnhacedEstimates;
+ private EnhancedEstimates mEnhancedEstimates;
@Before
public void setup() {
mMockWarnings = mDependency.injectMockDependency(WarningsUI.class);
- mEnhacedEstimates = mDependency.injectMockDependency(EnhancedEstimates.class);
+ mEnhancedEstimates = mDependency.injectMockDependency(EnhancedEstimates.class);
mHardProps = mock(HardwarePropertiesManager.class);
mContext.putComponent(StatusBar.class, mock(StatusBar.class));
@@ -142,8 +144,44 @@ public class PowerUITest extends SysuiTestCase {
}
@Test
+ public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsNoShow() {
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold())
+ .thenReturn(Duration.ofHours(1).toMillis());
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
+ mPowerUI.start();
+
+ // unplugged device that would not show the non-hybrid notification but would show the
+ // hybrid but the threshold has been overriden to be too low
+ boolean shouldShow =
+ mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
+ ABOVE_WARNING_BUCKET, Long.MAX_VALUE, BELOW_HYBRID_THRESHOLD,
+ POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
+ assertFalse(shouldShow);
+ }
+
+ @Test
+ public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsShow() {
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold())
+ .thenReturn(Duration.ofHours(5).toMillis());
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
+ mPowerUI.start();
+
+ // unplugged device that would not show the non-hybrid notification but would show the
+ // hybrid since the threshold has been overriden to be much higher
+ boolean shouldShow =
+ mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
+ ABOVE_WARNING_BUCKET, Long.MAX_VALUE, ABOVE_HYBRID_THRESHOLD,
+ POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
+ assertTrue(shouldShow);
+ }
+
+ @Test
public void testShouldShowLowBatteryWarning_showHybridOnly_returnsShow() {
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
mPowerUI.start();
// unplugged device that would not show the non-hybrid notification but would show the
@@ -157,7 +195,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldShowLowBatteryWarning_showHybrid_showStandard_returnsShow() {
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
mPowerUI.start();
// unplugged device that would show the non-hybrid notification and the hybrid
@@ -170,7 +210,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldShowLowBatteryWarning_showStandardOnly_returnsShow() {
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
mPowerUI.start();
// unplugged device that would show the non-hybrid but not the hybrid
@@ -183,7 +225,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldShowLowBatteryWarning_deviceHighBattery_returnsNoShow() {
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
mPowerUI.start();
// unplugged device that would show the neither due to battery level being good
@@ -196,7 +240,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldShowLowBatteryWarning_devicePlugged_returnsNoShow() {
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
mPowerUI.start();
// plugged device that would show the neither due to being plugged
@@ -209,7 +255,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldShowLowBatteryWarning_deviceBatteryStatusUnkown_returnsNoShow() {
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
mPowerUI.start();
// Unknown battery status device that would show the neither due
@@ -222,7 +270,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldShowLowBatteryWarning_batterySaverEnabled_returnsNoShow() {
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
mPowerUI.start();
// BatterySaverEnabled device that would show the neither due to battery saver
@@ -236,7 +286,10 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabled() {
mPowerUI.start();
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ 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,
@@ -247,7 +300,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() {
mPowerUI.start();
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
// device that gets plugged in should dismiss
boolean shouldDismiss =
@@ -259,7 +314,10 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldDismissLowBatteryWarning_dismissHybridSignal_showStandardSignal_shouldShow() {
mPowerUI.start();
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
+
// would dismiss hybrid but not non-hybrid should not dismiss
boolean shouldDismiss =
mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET,
@@ -270,7 +328,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldDismissLowBatteryWarning_showHybridSignal_dismissStandardSignal_shouldShow() {
mPowerUI.start();
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
// would dismiss non-hybrid but not hybrid should not dismiss
boolean shouldDismiss =
@@ -282,7 +342,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldDismissLowBatteryWarning_showBothSignal_shouldShow() {
mPowerUI.start();
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
// should not dismiss when both would not dismiss
boolean shouldDismiss =
@@ -294,7 +356,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldDismissLowBatteryWarning_dismissBothSignal_shouldDismiss() {
mPowerUI.start();
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
//should dismiss if both would dismiss
boolean shouldDismiss =
@@ -306,7 +370,9 @@ public class PowerUITest extends SysuiTestCase {
@Test
public void testShouldDismissLowBatteryWarning_dismissStandardSignal_hybridDisabled_shouldDismiss() {
mPowerUI.start();
- when(mEnhacedEstimates.isHybridNotificationEnabled()).thenReturn(false);
+ when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false);
+ when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
+ when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
// would dismiss non-hybrid with hybrid disabled should dismiss
boolean shouldDismiss =