summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Amin Shaikh <ashaikh@google.com> 2018-04-16 14:00:09 -0400
committer Amin Shaikh <ashaikh@google.com> 2018-04-16 14:21:04 -0400
commit2f6c45c9e37ace8b96ee07f22c3f0029ca6d2b0a (patch)
treec86811a901c32dc89fc038063e9a3b517702892f
parent606440f1422d63474d0cedb827b3f10c01fc04e2 (diff)
Dismiss low battery warning on toggling saver.
Change-Id: If6988a67ce0e97c2c9df93648169b9c9b85da7ce Fixes: 66987022 Test: runtest systemui
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/PowerUI.java15
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java42
2 files changed, 54 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index c409f738ec2a..6801e6917d3d 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -66,7 +66,8 @@ public class PowerUI extends SystemUI {
private static final long SIX_HOURS_MILLIS = Duration.ofHours(6).toMillis();
private final Handler mHandler = new Handler();
- private final Receiver mReceiver = new Receiver();
+ @VisibleForTesting
+ final Receiver mReceiver = new Receiver();
private PowerManager mPowerManager;
private HardwarePropertiesManager mHardwarePropertiesManager;
@@ -180,11 +181,13 @@ public class PowerUI extends SystemUI {
throw new RuntimeException("not possible!");
}
- private final class Receiver extends BroadcastReceiver {
+ @VisibleForTesting
+ final class Receiver extends BroadcastReceiver {
public void init() {
// Register for Intent broadcasts for...
IntentFilter filter = new IntentFilter();
+ filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
@@ -195,7 +198,13 @@ public class PowerUI extends SystemUI {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
+ if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action)) {
+ ThreadUtils.postOnBackgroundThread(() -> {
+ if (mPowerManager.isPowerSaveMode()) {
+ mWarnings.dismissLowBatteryWarning();
+ }
+ });
+ } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
final int oldBatteryLevel = mBatteryLevel;
mBatteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100);
final int oldBatteryStatus = mBatteryStatus;
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 149f2de06be4..d19715d5c5cc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
@@ -21,30 +21,37 @@ import static android.provider.Settings.Global.SHOW_TEMPERATURE_WARNING;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.Intent;
import android.os.BatteryManager;
import android.os.HardwarePropertiesManager;
+import android.os.PowerManager;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import android.testing.TestableResources;
import android.test.suitebuilder.annotation.SmallTest;
+import com.android.settingslib.utils.ThreadUtils;
import com.android.systemui.R;
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.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
@RunWith(AndroidTestingRunner.class)
@RunWithLooper
@@ -63,15 +70,18 @@ public class PowerUITest extends SysuiTestCase {
private WarningsUI mMockWarnings;
private PowerUI mPowerUI;
private EnhancedEstimates mEnhancedEstimates;
+ @Mock private PowerManager mPowerManager;
@Before
public void setup() {
+ MockitoAnnotations.initMocks(this);
mMockWarnings = mDependency.injectMockDependency(WarningsUI.class);
mEnhancedEstimates = mDependency.injectMockDependency(EnhancedEstimates.class);
mHardProps = mock(HardwarePropertiesManager.class);
mContext.putComponent(StatusBar.class, mock(StatusBar.class));
mContext.addMockSystemService(Context.HARDWARE_PROPERTIES_SERVICE, mHardProps);
+ mContext.addMockSystemService(Context.POWER_SERVICE, mPowerManager);
createPowerUi();
}
@@ -407,6 +417,38 @@ public class PowerUITest extends SysuiTestCase {
assertTrue(shouldDismiss);
}
+ @Test
+ public void testShouldDismissLowBatteryWarning_powerSaverModeEnabled()
+ throws InterruptedException {
+ when(mPowerManager.isPowerSaveMode()).thenReturn(true);
+
+ mPowerUI.start();
+ mPowerUI.mReceiver.onReceive(mContext,
+ new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
+
+ CountDownLatch latch = new CountDownLatch(1);
+ ThreadUtils.postOnBackgroundThread(() -> latch.countDown());
+ latch.await(5, TimeUnit.SECONDS);
+
+ verify(mMockWarnings).dismissLowBatteryWarning();
+ }
+
+ @Test
+ public void testShouldNotDismissLowBatteryWarning_powerSaverModeDisabled()
+ throws InterruptedException {
+ when(mPowerManager.isPowerSaveMode()).thenReturn(false);
+
+ mPowerUI.start();
+ mPowerUI.mReceiver.onReceive(mContext,
+ new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
+
+ CountDownLatch latch = new CountDownLatch(1);
+ ThreadUtils.postOnBackgroundThread(() -> latch.countDown());
+ latch.await(5, TimeUnit.SECONDS);
+
+ verify(mMockWarnings, never()).dismissLowBatteryWarning();
+ }
+
private void setCurrentTemp(float temp) {
when(mHardProps.getDeviceTemperatures(DEVICE_TEMPERATURE_SKIN, TEMPERATURE_CURRENT))
.thenReturn(new float[] { temp });