blob: 0a51e5a4e389794befba857f7f3801c26bde0765 [file] [log] [blame]
Jason Monkd819c312017-08-11 12:53:36 -04001/*
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
15package com.android.systemui.power;
16
17import static android.os.HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN;
18import static android.os.HardwarePropertiesManager.TEMPERATURE_CURRENT;
19import static android.os.HardwarePropertiesManager.TEMPERATURE_SHUTDOWN;
20import static android.provider.Settings.Global.SHOW_TEMPERATURE_WARNING;
21
Salvador Martinezf9e47502018-01-04 13:45:48 -080022import static junit.framework.Assert.assertFalse;
23import static junit.framework.Assert.assertTrue;
Jason Monkd819c312017-08-11 12:53:36 -040024import static org.mockito.Mockito.mock;
25import static org.mockito.Mockito.never;
26import static org.mockito.Mockito.verify;
27import static org.mockito.Mockito.when;
28
29import android.content.Context;
Salvador Martinezf9e47502018-01-04 13:45:48 -080030import android.os.BatteryManager;
Jason Monkd819c312017-08-11 12:53:36 -040031import android.os.HardwarePropertiesManager;
32import android.provider.Settings;
33import android.testing.AndroidTestingRunner;
34import android.testing.TestableLooper.RunWithLooper;
35import android.testing.TestableResources;
36import android.test.suitebuilder.annotation.SmallTest;
37
38import com.android.systemui.R;
39import com.android.systemui.SysuiTestCase;
40import com.android.systemui.power.PowerUI.WarningsUI;
41import com.android.systemui.statusbar.phone.StatusBar;
42
Salvador Martinezbb902fc2018-01-22 19:46:55 -080043import java.time.Duration;
Salvador Martinezf9e47502018-01-04 13:45:48 -080044import java.util.concurrent.TimeUnit;
Jason Monkd819c312017-08-11 12:53:36 -040045import org.junit.Before;
46import org.junit.Test;
47import org.junit.runner.RunWith;
48
49@RunWith(AndroidTestingRunner.class)
50@RunWithLooper
51@SmallTest
52public class PowerUITest extends SysuiTestCase {
53
Salvador Martinezf9e47502018-01-04 13:45:48 -080054 private static final boolean UNPLUGGED = false;
55 private static final boolean POWER_SAVER_OFF = false;
56 private static final int ABOVE_WARNING_BUCKET = 1;
Salvador Martinezbb902fc2018-01-22 19:46:55 -080057 private static final long ONE_HOUR_MILLIS = Duration.ofHours(1).toMillis();
Salvador Martinezf9e47502018-01-04 13:45:48 -080058 public static final int BELOW_WARNING_BUCKET = -1;
59 public static final long BELOW_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(2);
60 public static final long ABOVE_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(4);
Jason Monkd819c312017-08-11 12:53:36 -040061 private HardwarePropertiesManager mHardProps;
62 private WarningsUI mMockWarnings;
63 private PowerUI mPowerUI;
Salvador Martinezbb902fc2018-01-22 19:46:55 -080064 private EnhancedEstimates mEnhancedEstimates;
Jason Monkd819c312017-08-11 12:53:36 -040065
66 @Before
67 public void setup() {
68 mMockWarnings = mDependency.injectMockDependency(WarningsUI.class);
Salvador Martinezbb902fc2018-01-22 19:46:55 -080069 mEnhancedEstimates = mDependency.injectMockDependency(EnhancedEstimates.class);
Jason Monkd819c312017-08-11 12:53:36 -040070 mHardProps = mock(HardwarePropertiesManager.class);
Salvador Martinezf9e47502018-01-04 13:45:48 -080071
Jason Monkd819c312017-08-11 12:53:36 -040072 mContext.putComponent(StatusBar.class, mock(StatusBar.class));
73 mContext.addMockSystemService(Context.HARDWARE_PROPERTIES_SERVICE, mHardProps);
74
75 createPowerUi();
76 }
77
78 @Test
79 public void testNoConfig_NoWarnings() {
80 setOverThreshold();
81 Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null);
82 TestableResources resources = mContext.getOrCreateTestableResources();
83 resources.addOverride(R.integer.config_showTemperatureWarning, 0);
84 resources.addOverride(R.integer.config_warningTemperature, 55);
85
86 mPowerUI.start();
87 verify(mMockWarnings, never()).showHighTemperatureWarning();
88 }
89
90 @Test
91 public void testConfig_NoWarnings() {
92 setUnderThreshold();
93 Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null);
94 TestableResources resources = mContext.getOrCreateTestableResources();
95 resources.addOverride(R.integer.config_showTemperatureWarning, 1);
96 resources.addOverride(R.integer.config_warningTemperature, 55);
97
98 mPowerUI.start();
99 verify(mMockWarnings, never()).showHighTemperatureWarning();
100 }
101
102 @Test
103 public void testConfig_Warnings() {
104 setOverThreshold();
105 Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null);
106 TestableResources resources = mContext.getOrCreateTestableResources();
107 resources.addOverride(R.integer.config_showTemperatureWarning, 1);
108 resources.addOverride(R.integer.config_warningTemperature, 55);
109
110 mPowerUI.start();
111 verify(mMockWarnings).showHighTemperatureWarning();
112 }
113
114 @Test
115 public void testSettingOverrideConfig() {
116 setOverThreshold();
117 Settings.Global.putInt(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, 1);
118 TestableResources resources = mContext.getOrCreateTestableResources();
119 resources.addOverride(R.integer.config_showTemperatureWarning, 0);
120 resources.addOverride(R.integer.config_warningTemperature, 55);
121
122 mPowerUI.start();
123 verify(mMockWarnings).showHighTemperatureWarning();
124 }
125
126 @Test
127 public void testShutdownBasedThreshold() {
128 int tolerance = 2;
129 Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null);
130 TestableResources resources = mContext.getOrCreateTestableResources();
131 resources.addOverride(R.integer.config_showTemperatureWarning, 1);
132 resources.addOverride(R.integer.config_warningTemperature, -1);
133 resources.addOverride(R.integer.config_warningTemperatureTolerance, tolerance);
134 when(mHardProps.getDeviceTemperatures(DEVICE_TEMPERATURE_SKIN, TEMPERATURE_SHUTDOWN))
135 .thenReturn(new float[] { 55 + tolerance });
136
137 setCurrentTemp(54); // Below threshold.
138 mPowerUI.start();
139 verify(mMockWarnings, never()).showHighTemperatureWarning();
140
141 setCurrentTemp(56); // Above threshold.
142 mPowerUI.updateTemperatureWarning();
143 verify(mMockWarnings).showHighTemperatureWarning();
144 }
145
Salvador Martinezf9e47502018-01-04 13:45:48 -0800146 @Test
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800147 public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsNoShow() {
148 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
149 when(mEnhancedEstimates.getLowWarningThreshold())
150 .thenReturn(Duration.ofHours(1).toMillis());
151 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
152 mPowerUI.start();
153
154 // unplugged device that would not show the non-hybrid notification but would show the
155 // hybrid but the threshold has been overriden to be too low
156 boolean shouldShow =
157 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
158 ABOVE_WARNING_BUCKET, Long.MAX_VALUE, BELOW_HYBRID_THRESHOLD,
159 POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
160 assertFalse(shouldShow);
161 }
162
163 @Test
164 public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsShow() {
165 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
166 when(mEnhancedEstimates.getLowWarningThreshold())
167 .thenReturn(Duration.ofHours(5).toMillis());
168 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
169 mPowerUI.start();
170
171 // unplugged device that would not show the non-hybrid notification but would show the
172 // hybrid since the threshold has been overriden to be much higher
173 boolean shouldShow =
174 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
175 ABOVE_WARNING_BUCKET, Long.MAX_VALUE, ABOVE_HYBRID_THRESHOLD,
176 POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
177 assertTrue(shouldShow);
178 }
179
180 @Test
Salvador Martinezf9e47502018-01-04 13:45:48 -0800181 public void testShouldShowLowBatteryWarning_showHybridOnly_returnsShow() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800182 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
183 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
184 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800185 mPowerUI.start();
186
187 // unplugged device that would not show the non-hybrid notification but would show the
188 // hybrid
189 boolean shouldShow =
190 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
191 ABOVE_WARNING_BUCKET, Long.MAX_VALUE, BELOW_HYBRID_THRESHOLD,
192 POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
193 assertTrue(shouldShow);
194 }
195
196 @Test
197 public void testShouldShowLowBatteryWarning_showHybrid_showStandard_returnsShow() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800198 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
199 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
200 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800201 mPowerUI.start();
202
203 // unplugged device that would show the non-hybrid notification and the hybrid
204 boolean shouldShow =
205 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
206 BELOW_WARNING_BUCKET, Long.MAX_VALUE, BELOW_HYBRID_THRESHOLD,
207 POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
208 assertTrue(shouldShow);
209 }
210
211 @Test
212 public void testShouldShowLowBatteryWarning_showStandardOnly_returnsShow() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800213 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
214 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
215 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800216 mPowerUI.start();
217
218 // unplugged device that would show the non-hybrid but not the hybrid
219 boolean shouldShow =
220 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
221 BELOW_WARNING_BUCKET, Long.MAX_VALUE, ABOVE_HYBRID_THRESHOLD,
222 POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
223 assertTrue(shouldShow);
224 }
225
226 @Test
227 public void testShouldShowLowBatteryWarning_deviceHighBattery_returnsNoShow() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800228 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
229 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
230 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800231 mPowerUI.start();
232
233 // unplugged device that would show the neither due to battery level being good
234 boolean shouldShow =
235 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
236 ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, ABOVE_HYBRID_THRESHOLD,
237 POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
238 assertFalse(shouldShow);
239 }
240
241 @Test
242 public void testShouldShowLowBatteryWarning_devicePlugged_returnsNoShow() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800243 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
244 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
245 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800246 mPowerUI.start();
247
248 // plugged device that would show the neither due to being plugged
249 boolean shouldShow =
250 mPowerUI.shouldShowLowBatteryWarning(!UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
251 BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, BELOW_HYBRID_THRESHOLD,
252 POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
253 assertFalse(shouldShow);
254 }
255
256 @Test
257 public void testShouldShowLowBatteryWarning_deviceBatteryStatusUnkown_returnsNoShow() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800258 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
259 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
260 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800261 mPowerUI.start();
262
263 // Unknown battery status device that would show the neither due
264 boolean shouldShow =
265 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
266 BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, BELOW_HYBRID_THRESHOLD,
267 !POWER_SAVER_OFF, BatteryManager.BATTERY_STATUS_UNKNOWN);
268 assertFalse(shouldShow);
269 }
270
271 @Test
272 public void testShouldShowLowBatteryWarning_batterySaverEnabled_returnsNoShow() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800273 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
274 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
275 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800276 mPowerUI.start();
277
278 // BatterySaverEnabled device that would show the neither due to battery saver
279 boolean shouldShow =
280 mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
281 BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, BELOW_HYBRID_THRESHOLD,
282 !POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
283 assertFalse(shouldShow);
284 }
285
286 @Test
287 public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabled() {
288 mPowerUI.start();
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800289 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
290 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
291 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
292
Salvador Martinezf9e47502018-01-04 13:45:48 -0800293 // device that gets power saver turned on should dismiss
294 boolean shouldDismiss =
295 mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET,
296 BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, !POWER_SAVER_OFF);
297 assertTrue(shouldDismiss);
298 }
299
300 @Test
301 public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() {
302 mPowerUI.start();
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800303 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
304 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
305 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800306
307 // device that gets plugged in should dismiss
308 boolean shouldDismiss =
309 mPowerUI.shouldDismissLowBatteryWarning(!UNPLUGGED, BELOW_WARNING_BUCKET,
310 BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF);
311 assertTrue(shouldDismiss);
312 }
313
314 @Test
315 public void testShouldDismissLowBatteryWarning_dismissHybridSignal_showStandardSignal_shouldShow() {
316 mPowerUI.start();
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800317 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
318 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
319 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
320
Salvador Martinezf9e47502018-01-04 13:45:48 -0800321 // would dismiss hybrid but not non-hybrid should not dismiss
322 boolean shouldDismiss =
323 mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET,
324 BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF);
325 assertFalse(shouldDismiss);
326 }
327
328 @Test
329 public void testShouldDismissLowBatteryWarning_showHybridSignal_dismissStandardSignal_shouldShow() {
330 mPowerUI.start();
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800331 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
332 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
333 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800334
335 // would dismiss non-hybrid but not hybrid should not dismiss
336 boolean shouldDismiss =
337 mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET,
338 ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, POWER_SAVER_OFF);
339 assertFalse(shouldDismiss);
340 }
341
342 @Test
343 public void testShouldDismissLowBatteryWarning_showBothSignal_shouldShow() {
344 mPowerUI.start();
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800345 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
346 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
347 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800348
349 // should not dismiss when both would not dismiss
350 boolean shouldDismiss =
351 mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET,
352 BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, POWER_SAVER_OFF);
353 assertFalse(shouldDismiss);
354 }
355
356 @Test
357 public void testShouldDismissLowBatteryWarning_dismissBothSignal_shouldDismiss() {
358 mPowerUI.start();
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800359 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
360 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
361 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800362
363 //should dismiss if both would dismiss
364 boolean shouldDismiss =
365 mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET,
366 ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF);
367 assertTrue(shouldDismiss);
368 }
369
370 @Test
371 public void testShouldDismissLowBatteryWarning_dismissStandardSignal_hybridDisabled_shouldDismiss() {
372 mPowerUI.start();
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800373 when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false);
374 when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
375 when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800376
377 // would dismiss non-hybrid with hybrid disabled should dismiss
378 boolean shouldDismiss =
379 mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET,
380 ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF);
381 assertTrue(shouldDismiss);
382 }
383
Jason Monkd819c312017-08-11 12:53:36 -0400384 private void setCurrentTemp(float temp) {
385 when(mHardProps.getDeviceTemperatures(DEVICE_TEMPERATURE_SKIN, TEMPERATURE_CURRENT))
386 .thenReturn(new float[] { temp });
387 }
388
389 private void setOverThreshold() {
390 setCurrentTemp(50000);
391 }
392
393 private void setUnderThreshold() {
394 setCurrentTemp(5);
395 }
396
397 private void createPowerUi() {
398 mPowerUI = new PowerUI();
399 mPowerUI.mContext = mContext;
400 mPowerUI.mComponents = mContext.getComponents();
401 }
402}