Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.power; |
| 16 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 17 | import static android.provider.Settings.Global.SHOW_TEMPERATURE_WARNING; |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 18 | import static android.provider.Settings.Global.SHOW_USB_TEMPERATURE_ALARM; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 19 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 20 | import static junit.framework.Assert.assertFalse; |
| 21 | import static junit.framework.Assert.assertTrue; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 22 | |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 23 | import static org.mockito.Matchers.eq; |
| 24 | import static org.mockito.Mockito.anyObject; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 25 | import static org.mockito.Mockito.mock; |
| 26 | import static org.mockito.Mockito.never; |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 27 | import static org.mockito.Mockito.times; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 28 | import static org.mockito.Mockito.verify; |
| 29 | import static org.mockito.Mockito.when; |
| 30 | |
| 31 | import android.content.Context; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 32 | import android.content.Intent; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 33 | import android.os.BatteryManager; |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 34 | import android.os.IThermalEventListener; |
Wei Wang | bf05e60 | 2018-11-21 11:46:48 -0800 | [diff] [blame] | 35 | import android.os.IThermalService; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 36 | import android.os.PowerManager; |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 37 | import android.os.Temperature; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 38 | import android.provider.Settings; |
Wei Wang | bf05e60 | 2018-11-21 11:46:48 -0800 | [diff] [blame] | 39 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 40 | import android.testing.AndroidTestingRunner; |
Wei Wang | feb9de6 | 2018-11-26 14:35:17 -0800 | [diff] [blame] | 41 | import android.testing.TestableLooper; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 42 | import android.testing.TestableLooper.RunWithLooper; |
| 43 | import android.testing.TestableResources; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 44 | |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 45 | import com.android.settingslib.utils.ThreadUtils; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 46 | import com.android.systemui.R; |
| 47 | import com.android.systemui.SysuiTestCase; |
| 48 | import com.android.systemui.power.PowerUI.WarningsUI; |
| 49 | import com.android.systemui.statusbar.phone.StatusBar; |
| 50 | |
| 51 | import org.junit.Before; |
| 52 | import org.junit.Test; |
| 53 | import org.junit.runner.RunWith; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 54 | import org.mockito.Mock; |
| 55 | import org.mockito.MockitoAnnotations; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 56 | |
Wei Wang | bf05e60 | 2018-11-21 11:46:48 -0800 | [diff] [blame] | 57 | import java.time.Duration; |
| 58 | import java.util.concurrent.CountDownLatch; |
| 59 | import java.util.concurrent.TimeUnit; |
| 60 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 61 | @RunWith(AndroidTestingRunner.class) |
| 62 | @RunWithLooper |
| 63 | @SmallTest |
| 64 | public class PowerUITest extends SysuiTestCase { |
| 65 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 66 | private static final boolean UNPLUGGED = false; |
| 67 | private static final boolean POWER_SAVER_OFF = false; |
| 68 | private static final int ABOVE_WARNING_BUCKET = 1; |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 69 | private static final long ONE_HOUR_MILLIS = Duration.ofHours(1).toMillis(); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 70 | public static final int BELOW_WARNING_BUCKET = -1; |
| 71 | public static final long BELOW_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(2); |
Salvador Martinez | 88b0d50 | 2018-10-01 11:31:43 -0700 | [diff] [blame] | 72 | public static final long BELOW_SEVERE_HYBRID_THRESHOLD = TimeUnit.MINUTES.toMillis(30); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 73 | public static final long ABOVE_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(4); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 74 | private static final long ABOVE_CHARGE_CYCLE_THRESHOLD = Duration.ofHours(8).toMillis(); |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 75 | private static final int OLD_BATTERY_LEVEL_NINE = 9; |
| 76 | private static final int OLD_BATTERY_LEVEL_10 = 10; |
Salvador Martinez | 88b0d50 | 2018-10-01 11:31:43 -0700 | [diff] [blame] | 77 | private static final long VERY_BELOW_SEVERE_HYBRID_THRESHOLD = TimeUnit.MINUTES.toMillis(15); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 78 | private WarningsUI mMockWarnings; |
| 79 | private PowerUI mPowerUI; |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 80 | private EnhancedEstimates mEnhancedEstimates; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 81 | @Mock private PowerManager mPowerManager; |
Wei Wang | bf05e60 | 2018-11-21 11:46:48 -0800 | [diff] [blame] | 82 | @Mock private IThermalService mThermalServiceMock; |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 83 | private IThermalEventListener mThermalEventUsbListener; |
| 84 | private IThermalEventListener mThermalEventSkinListener; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 85 | |
| 86 | @Before |
| 87 | public void setup() { |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 88 | MockitoAnnotations.initMocks(this); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 89 | mMockWarnings = mDependency.injectMockDependency(WarningsUI.class); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 90 | mEnhancedEstimates = mDependency.injectMockDependency(EnhancedEstimates.class); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 91 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 92 | mContext.putComponent(StatusBar.class, mock(StatusBar.class)); |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 93 | mContext.addMockSystemService(Context.POWER_SERVICE, mPowerManager); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 94 | |
| 95 | createPowerUi(); |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 96 | mThermalEventSkinListener = mPowerUI.new ThermalEventSkinListener(); |
| 97 | mThermalEventUsbListener = mPowerUI.new ThermalEventUsbListener(); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Test |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 101 | public void testSkinWarning_throttlingCritical() throws Exception { |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 102 | mPowerUI.start(); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 103 | |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 104 | final Temperature temp = getCriticalStatusTemp(Temperature.TYPE_SKIN, "skin1"); |
| 105 | mThermalEventSkinListener.notifyThrottling(temp); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 106 | |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 107 | // dismiss skin high temperature warning when throttling status is critical |
Wei Wang | feb9de6 | 2018-11-26 14:35:17 -0800 | [diff] [blame] | 108 | TestableLooper.get(this).processAllMessages(); |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 109 | verify(mMockWarnings, never()).showHighTemperatureWarning(); |
| 110 | verify(mMockWarnings, times(1)).dismissHighTemperatureWarning(); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Test |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 114 | public void testSkinWarning_throttlingEmergency() throws Exception { |
| 115 | mPowerUI.start(); |
| 116 | |
| 117 | final Temperature temp = getEmergencyStatusTemp(Temperature.TYPE_SKIN, "skin2"); |
| 118 | mThermalEventSkinListener.notifyThrottling(temp); |
| 119 | |
| 120 | // show skin high temperature warning when throttling status is emergency |
| 121 | TestableLooper.get(this).processAllMessages(); |
| 122 | verify(mMockWarnings, times(1)).showHighTemperatureWarning(); |
| 123 | verify(mMockWarnings, never()).dismissHighTemperatureWarning(); |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void testUsbAlarm_throttlingCritical() throws Exception { |
| 128 | mPowerUI.start(); |
| 129 | |
| 130 | final Temperature temp = getCriticalStatusTemp(Temperature.TYPE_USB_PORT, "usb1"); |
| 131 | mThermalEventUsbListener.notifyThrottling(temp); |
| 132 | |
| 133 | // not show usb high temperature alarm when throttling status is critical |
| 134 | TestableLooper.get(this).processAllMessages(); |
| 135 | verify(mMockWarnings, never()).showUsbHighTemperatureAlarm(); |
| 136 | } |
| 137 | |
| 138 | @Test |
| 139 | public void testUsbAlarm_throttlingEmergency() throws Exception { |
| 140 | mPowerUI.start(); |
| 141 | |
| 142 | final Temperature temp = getEmergencyStatusTemp(Temperature.TYPE_USB_PORT, "usb2"); |
| 143 | mThermalEventUsbListener.notifyThrottling(temp); |
| 144 | |
| 145 | // show usb high temperature alarm when throttling status is emergency |
| 146 | TestableLooper.get(this).processAllMessages(); |
| 147 | verify(mMockWarnings, times(1)).showUsbHighTemperatureAlarm(); |
| 148 | } |
| 149 | |
| 150 | @Test |
| 151 | public void testSettingOverrideConfig_enableSkinTemperatureWarning() throws Exception { |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 152 | Settings.Global.putInt(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, 1); |
| 153 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 154 | resources.addOverride(R.integer.config_showTemperatureWarning, 0); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 155 | |
| 156 | mPowerUI.start(); |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 157 | mPowerUI.registerThermalEventListener(); |
| 158 | |
Wei Wang | feb9de6 | 2018-11-26 14:35:17 -0800 | [diff] [blame] | 159 | TestableLooper.get(this).processAllMessages(); |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 160 | verify(mThermalServiceMock, times(1)) |
| 161 | .registerThermalEventListenerWithType(anyObject(), eq(Temperature.TYPE_SKIN)); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @Test |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 165 | public void testSettingOverrideConfig_enableUsbTemperatureAlarm() throws Exception { |
| 166 | Settings.Global.putInt(mContext.getContentResolver(), SHOW_USB_TEMPERATURE_ALARM, 1); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 167 | TestableResources resources = mContext.getOrCreateTestableResources(); |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 168 | resources.addOverride(R.integer.config_showUsbPortAlarm, 0); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 169 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 170 | mPowerUI.start(); |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 171 | mPowerUI.registerThermalEventListener(); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 172 | |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 173 | TestableLooper.get(this).processAllMessages(); |
| 174 | verify(mThermalServiceMock, times(1)) |
| 175 | .registerThermalEventListenerWithType(anyObject(), eq(Temperature.TYPE_USB_PORT)); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 178 | @Test |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 179 | public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsNoShow() { |
| 180 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 181 | when(mEnhancedEstimates.getLowWarningThreshold()) |
| 182 | .thenReturn(Duration.ofHours(1).toMillis()); |
| 183 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 184 | mPowerUI.start(); |
| 185 | |
| 186 | // unplugged device that would not show the non-hybrid notification but would show the |
| 187 | // hybrid but the threshold has been overriden to be too low |
| 188 | boolean shouldShow = |
| 189 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 190 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 191 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 192 | assertFalse(shouldShow); |
| 193 | } |
| 194 | |
| 195 | @Test |
| 196 | public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsShow() { |
| 197 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 198 | when(mEnhancedEstimates.getLowWarningThreshold()) |
| 199 | .thenReturn(Duration.ofHours(5).toMillis()); |
| 200 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 201 | mPowerUI.start(); |
| 202 | |
| 203 | // unplugged device that would not show the non-hybrid notification but would show the |
| 204 | // hybrid since the threshold has been overriden to be much higher |
| 205 | boolean shouldShow = |
| 206 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 207 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 208 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 209 | assertTrue(shouldShow); |
| 210 | } |
| 211 | |
| 212 | @Test |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 213 | public void testShouldShowLowBatteryWarning_showHybridOnly_returnsShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 214 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 215 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 216 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 217 | mPowerUI.start(); |
| 218 | |
| 219 | // unplugged device that would not show the non-hybrid notification but would show the |
| 220 | // hybrid |
| 221 | boolean shouldShow = |
| 222 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 223 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 224 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 225 | assertTrue(shouldShow); |
| 226 | } |
| 227 | |
| 228 | @Test |
| 229 | public void testShouldShowLowBatteryWarning_showHybrid_showStandard_returnsShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 230 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 231 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 232 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 233 | mPowerUI.mBatteryLevel = 10; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 234 | mPowerUI.start(); |
| 235 | |
| 236 | // unplugged device that would show the non-hybrid notification and the hybrid |
| 237 | boolean shouldShow = |
| 238 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 239 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 240 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 241 | assertTrue(shouldShow); |
| 242 | } |
| 243 | |
| 244 | @Test |
| 245 | public void testShouldShowLowBatteryWarning_showStandardOnly_returnsShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 246 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 247 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 248 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 249 | mPowerUI.mBatteryLevel = 10; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 250 | mPowerUI.start(); |
| 251 | |
| 252 | // unplugged device that would show the non-hybrid but not the hybrid |
| 253 | boolean shouldShow = |
| 254 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 255 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 256 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 257 | assertTrue(shouldShow); |
| 258 | } |
| 259 | |
| 260 | @Test |
| 261 | public void testShouldShowLowBatteryWarning_deviceHighBattery_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 262 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 263 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 264 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 265 | mPowerUI.start(); |
| 266 | |
| 267 | // unplugged device that would show the neither due to battery level being good |
| 268 | boolean shouldShow = |
| 269 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 270 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 271 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 272 | assertFalse(shouldShow); |
| 273 | } |
| 274 | |
| 275 | @Test |
| 276 | public void testShouldShowLowBatteryWarning_devicePlugged_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 277 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 278 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 279 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 280 | mPowerUI.start(); |
| 281 | |
| 282 | // plugged device that would show the neither due to being plugged |
| 283 | boolean shouldShow = |
| 284 | mPowerUI.shouldShowLowBatteryWarning(!UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 285 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 286 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 287 | assertFalse(shouldShow); |
| 288 | } |
| 289 | |
| 290 | @Test |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 291 | public void testShouldShowLowBatteryWarning_deviceBatteryStatusUnknown_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 292 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 293 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 294 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 295 | mPowerUI.start(); |
| 296 | |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 297 | // Unknown battery status device that would show the neither due to the battery status being |
| 298 | // unknown |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 299 | boolean shouldShow = |
| 300 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 301 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 302 | !POWER_SAVER_OFF, BatteryManager.BATTERY_STATUS_UNKNOWN); |
| 303 | assertFalse(shouldShow); |
| 304 | } |
| 305 | |
| 306 | @Test |
| 307 | public void testShouldShowLowBatteryWarning_batterySaverEnabled_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 308 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 309 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 310 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 311 | mPowerUI.start(); |
| 312 | |
| 313 | // BatterySaverEnabled device that would show the neither due to battery saver |
| 314 | boolean shouldShow = |
| 315 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 316 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 317 | !POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 318 | assertFalse(shouldShow); |
| 319 | } |
| 320 | |
| 321 | @Test |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 322 | public void testShouldShowLowBatteryWarning_onlyShowsOncePerChargeCycle() { |
| 323 | mPowerUI.start(); |
| 324 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 325 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 326 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 327 | when(mEnhancedEstimates.getEstimate()) |
| 328 | .thenReturn(new Estimate(BELOW_HYBRID_THRESHOLD, true)); |
| 329 | mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD; |
| 330 | |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 331 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED, |
| 332 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 333 | |
| 334 | // reduce battery level to handle time based trigger -> level trigger interactions |
| 335 | mPowerUI.mBatteryLevel = 10; |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 336 | boolean shouldShow = |
| 337 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
| 338 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
| 339 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 340 | assertFalse(shouldShow); |
| 341 | } |
| 342 | |
| 343 | @Test |
Salvador Martinez | c25604b | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 344 | public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabledLegacy() { |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 345 | mPowerUI.start(); |
Salvador Martinez | c25604b | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 346 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 347 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 348 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 349 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 350 | // device that gets power saver turned on should dismiss |
| 351 | boolean shouldDismiss = |
| 352 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 353 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, !POWER_SAVER_OFF); |
| 354 | assertTrue(shouldDismiss); |
| 355 | } |
| 356 | |
| 357 | @Test |
Salvador Martinez | c25604b | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 358 | public void testShouldNotDismissLowBatteryWarning_dismissWhenPowerSaverEnabledHybrid() { |
| 359 | mPowerUI.start(); |
| 360 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 361 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 362 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 363 | |
| 364 | // device that gets power saver turned on should dismiss |
| 365 | boolean shouldDismiss = |
| 366 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 367 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, !POWER_SAVER_OFF); |
| 368 | assertFalse(shouldDismiss); |
| 369 | } |
| 370 | |
| 371 | @Test |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 372 | public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() { |
| 373 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 374 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 375 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 376 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 377 | |
| 378 | // device that gets plugged in should dismiss |
| 379 | boolean shouldDismiss = |
| 380 | mPowerUI.shouldDismissLowBatteryWarning(!UNPLUGGED, BELOW_WARNING_BUCKET, |
| 381 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 382 | assertTrue(shouldDismiss); |
| 383 | } |
| 384 | |
| 385 | @Test |
| 386 | public void testShouldDismissLowBatteryWarning_dismissHybridSignal_showStandardSignal_shouldShow() { |
| 387 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 388 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 389 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 390 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 391 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 392 | // would dismiss hybrid but not non-hybrid should not dismiss |
| 393 | boolean shouldDismiss = |
| 394 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 395 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 396 | assertFalse(shouldDismiss); |
| 397 | } |
| 398 | |
| 399 | @Test |
| 400 | public void testShouldDismissLowBatteryWarning_showHybridSignal_dismissStandardSignal_shouldShow() { |
| 401 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 402 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 403 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 404 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 405 | |
| 406 | // would dismiss non-hybrid but not hybrid should not dismiss |
| 407 | boolean shouldDismiss = |
| 408 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 409 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 410 | assertFalse(shouldDismiss); |
| 411 | } |
| 412 | |
| 413 | @Test |
| 414 | public void testShouldDismissLowBatteryWarning_showBothSignal_shouldShow() { |
| 415 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 416 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 417 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 418 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 419 | |
| 420 | // should not dismiss when both would not dismiss |
| 421 | boolean shouldDismiss = |
| 422 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 423 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 424 | assertFalse(shouldDismiss); |
| 425 | } |
| 426 | |
| 427 | @Test |
| 428 | public void testShouldDismissLowBatteryWarning_dismissBothSignal_shouldDismiss() { |
| 429 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 430 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 431 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 432 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 433 | |
| 434 | //should dismiss if both would dismiss |
| 435 | boolean shouldDismiss = |
| 436 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 437 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 438 | assertTrue(shouldDismiss); |
| 439 | } |
| 440 | |
| 441 | @Test |
| 442 | public void testShouldDismissLowBatteryWarning_dismissStandardSignal_hybridDisabled_shouldDismiss() { |
| 443 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 444 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false); |
| 445 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 446 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 447 | |
| 448 | // would dismiss non-hybrid with hybrid disabled should dismiss |
| 449 | boolean shouldDismiss = |
| 450 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 451 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 452 | assertTrue(shouldDismiss); |
| 453 | } |
| 454 | |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 455 | @Test |
| 456 | public void testShouldDismissLowBatteryWarning_powerSaverModeEnabled() |
| 457 | throws InterruptedException { |
| 458 | when(mPowerManager.isPowerSaveMode()).thenReturn(true); |
| 459 | |
| 460 | mPowerUI.start(); |
| 461 | mPowerUI.mReceiver.onReceive(mContext, |
| 462 | new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); |
| 463 | |
| 464 | CountDownLatch latch = new CountDownLatch(1); |
| 465 | ThreadUtils.postOnBackgroundThread(() -> latch.countDown()); |
| 466 | latch.await(5, TimeUnit.SECONDS); |
| 467 | |
| 468 | verify(mMockWarnings).dismissLowBatteryWarning(); |
| 469 | } |
| 470 | |
| 471 | @Test |
| 472 | public void testShouldNotDismissLowBatteryWarning_powerSaverModeDisabled() |
| 473 | throws InterruptedException { |
| 474 | when(mPowerManager.isPowerSaveMode()).thenReturn(false); |
| 475 | |
| 476 | mPowerUI.start(); |
| 477 | mPowerUI.mReceiver.onReceive(mContext, |
| 478 | new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); |
| 479 | |
| 480 | CountDownLatch latch = new CountDownLatch(1); |
| 481 | ThreadUtils.postOnBackgroundThread(() -> latch.countDown()); |
| 482 | latch.await(5, TimeUnit.SECONDS); |
| 483 | |
| 484 | verify(mMockWarnings, never()).dismissLowBatteryWarning(); |
| 485 | } |
| 486 | |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 487 | @Test |
Salvador Martinez | 88b0d50 | 2018-10-01 11:31:43 -0700 | [diff] [blame] | 488 | public void testSevereWarning_countsAsLowAndSevere_WarningOnlyShownOnce() { |
| 489 | mPowerUI.start(); |
| 490 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 491 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 492 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 493 | when(mEnhancedEstimates.getEstimate()) |
| 494 | .thenReturn(new Estimate(BELOW_SEVERE_HYBRID_THRESHOLD, true)); |
| 495 | mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD; |
| 496 | |
| 497 | // reduce battery level to handle time based trigger -> level trigger interactions |
| 498 | mPowerUI.mBatteryLevel = 5; |
| 499 | boolean shouldShow = |
| 500 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
| 501 | ABOVE_WARNING_BUCKET, BELOW_SEVERE_HYBRID_THRESHOLD, |
| 502 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 503 | assertTrue(shouldShow); |
| 504 | |
| 505 | // actually run the end to end since it handles changing the internal state. |
| 506 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_10, UNPLUGGED, UNPLUGGED, |
| 507 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
| 508 | |
| 509 | shouldShow = |
| 510 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
| 511 | ABOVE_WARNING_BUCKET, VERY_BELOW_SEVERE_HYBRID_THRESHOLD, |
| 512 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 513 | assertFalse(shouldShow); |
| 514 | } |
| 515 | |
| 516 | @Test |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 517 | public void testMaybeShowBatteryWarning_onlyQueriesEstimateOnBatteryLevelChangeOrNull() { |
| 518 | mPowerUI.start(); |
| 519 | Estimate estimate = new Estimate(BELOW_HYBRID_THRESHOLD, true); |
| 520 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 521 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 522 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 523 | when(mEnhancedEstimates.getEstimate()).thenReturn(estimate); |
| 524 | mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD; |
| 525 | |
| 526 | // we expect that the first time it will query even if the level is the same |
| 527 | mPowerUI.mBatteryLevel = 9; |
| 528 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED, |
| 529 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
| 530 | verify(mEnhancedEstimates, times(1)).getEstimate(); |
| 531 | |
| 532 | // We should NOT query again if the battery level hasn't changed |
| 533 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED, |
| 534 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
| 535 | verify(mEnhancedEstimates, times(1)).getEstimate(); |
| 536 | |
| 537 | // Battery level has changed, so we should query again |
| 538 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_10, UNPLUGGED, UNPLUGGED, |
| 539 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
| 540 | verify(mEnhancedEstimates, times(2)).getEstimate(); |
| 541 | } |
| 542 | |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 543 | private Temperature getEmergencyStatusTemp(int type, String name) { |
| 544 | final float value = 65; |
| 545 | return new Temperature(value, type, name, Temperature.THROTTLING_EMERGENCY); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Sherry Huang | ce02ed3 | 2019-01-17 20:37:29 +0800 | [diff] [blame] | 548 | private Temperature getCriticalStatusTemp(int type, String name) { |
| 549 | final float value = 60; |
| 550 | return new Temperature(value, type, name, Temperature.THROTTLING_CRITICAL); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | private void createPowerUi() { |
| 554 | mPowerUI = new PowerUI(); |
| 555 | mPowerUI.mContext = mContext; |
| 556 | mPowerUI.mComponents = mContext.getComponents(); |
Wei Wang | bf05e60 | 2018-11-21 11:46:48 -0800 | [diff] [blame] | 557 | mPowerUI.mThermalService = mThermalServiceMock; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 558 | } |
| 559 | } |