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 | |
| 17 | import static android.os.HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN; |
| 18 | import static android.os.HardwarePropertiesManager.TEMPERATURE_CURRENT; |
| 19 | import static android.os.HardwarePropertiesManager.TEMPERATURE_SHUTDOWN; |
Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 20 | import static android.os.HardwarePropertiesManager.TEMPERATURE_THROTTLING; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 21 | import static android.provider.Settings.Global.SHOW_TEMPERATURE_WARNING; |
| 22 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 23 | import static junit.framework.Assert.assertFalse; |
| 24 | import static junit.framework.Assert.assertTrue; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 25 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 26 | import static org.mockito.Mockito.mock; |
| 27 | import static org.mockito.Mockito.never; |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 28 | import static org.mockito.Mockito.times; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 29 | import static org.mockito.Mockito.verify; |
| 30 | import static org.mockito.Mockito.when; |
| 31 | |
| 32 | import android.content.Context; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 33 | import android.content.Intent; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 34 | import android.os.BatteryManager; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 35 | import android.os.HardwarePropertiesManager; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 36 | import android.os.PowerManager; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 37 | import android.provider.Settings; |
| 38 | import android.testing.AndroidTestingRunner; |
| 39 | import android.testing.TestableLooper.RunWithLooper; |
| 40 | import android.testing.TestableResources; |
| 41 | import android.test.suitebuilder.annotation.SmallTest; |
| 42 | |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 43 | import com.android.settingslib.utils.ThreadUtils; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 44 | import com.android.systemui.R; |
| 45 | import com.android.systemui.SysuiTestCase; |
| 46 | import com.android.systemui.power.PowerUI.WarningsUI; |
| 47 | import com.android.systemui.statusbar.phone.StatusBar; |
| 48 | |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 49 | import java.time.Duration; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 50 | import java.util.concurrent.CountDownLatch; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 51 | import java.util.concurrent.TimeUnit; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 52 | import org.junit.Before; |
| 53 | import org.junit.Test; |
| 54 | import org.junit.runner.RunWith; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 55 | import org.mockito.Mock; |
| 56 | import org.mockito.MockitoAnnotations; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 57 | |
| 58 | @RunWith(AndroidTestingRunner.class) |
| 59 | @RunWithLooper |
| 60 | @SmallTest |
| 61 | public class PowerUITest extends SysuiTestCase { |
| 62 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 63 | private static final boolean UNPLUGGED = false; |
| 64 | private static final boolean POWER_SAVER_OFF = false; |
| 65 | private static final int ABOVE_WARNING_BUCKET = 1; |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 66 | private static final long ONE_HOUR_MILLIS = Duration.ofHours(1).toMillis(); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 67 | public static final int BELOW_WARNING_BUCKET = -1; |
| 68 | public static final long BELOW_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(2); |
| 69 | public static final long ABOVE_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(4); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 70 | private static final long ABOVE_CHARGE_CYCLE_THRESHOLD = Duration.ofHours(8).toMillis(); |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 71 | private static final int OLD_BATTERY_LEVEL_NINE = 9; |
| 72 | private static final int OLD_BATTERY_LEVEL_10 = 10; |
Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 73 | private static final int DEFAULT_OVERHEAT_ALARM_THRESHOLD = 58; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 74 | private HardwarePropertiesManager mHardProps; |
| 75 | private WarningsUI mMockWarnings; |
| 76 | private PowerUI mPowerUI; |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 77 | private EnhancedEstimates mEnhancedEstimates; |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 78 | @Mock private PowerManager mPowerManager; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 79 | |
| 80 | @Before |
| 81 | public void setup() { |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 82 | MockitoAnnotations.initMocks(this); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 83 | mMockWarnings = mDependency.injectMockDependency(WarningsUI.class); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 84 | mEnhancedEstimates = mDependency.injectMockDependency(EnhancedEstimates.class); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 85 | mHardProps = mock(HardwarePropertiesManager.class); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 86 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 87 | mContext.putComponent(StatusBar.class, mock(StatusBar.class)); |
| 88 | mContext.addMockSystemService(Context.HARDWARE_PROPERTIES_SERVICE, mHardProps); |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 89 | mContext.addMockSystemService(Context.POWER_SERVICE, mPowerManager); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 90 | |
Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 91 | setUnderThreshold(); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 92 | createPowerUi(); |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void testNoConfig_NoWarnings() { |
| 97 | setOverThreshold(); |
| 98 | Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null); |
| 99 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 100 | resources.addOverride(R.integer.config_showTemperatureWarning, 0); |
| 101 | resources.addOverride(R.integer.config_warningTemperature, 55); |
| 102 | |
| 103 | mPowerUI.start(); |
| 104 | verify(mMockWarnings, never()).showHighTemperatureWarning(); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void testConfig_NoWarnings() { |
| 109 | setUnderThreshold(); |
| 110 | Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null); |
| 111 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 112 | resources.addOverride(R.integer.config_showTemperatureWarning, 1); |
| 113 | resources.addOverride(R.integer.config_warningTemperature, 55); |
| 114 | |
| 115 | mPowerUI.start(); |
| 116 | verify(mMockWarnings, never()).showHighTemperatureWarning(); |
| 117 | } |
| 118 | |
| 119 | @Test |
| 120 | public void testConfig_Warnings() { |
| 121 | setOverThreshold(); |
| 122 | Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null); |
| 123 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 124 | resources.addOverride(R.integer.config_showTemperatureWarning, 1); |
| 125 | resources.addOverride(R.integer.config_warningTemperature, 55); |
| 126 | |
| 127 | mPowerUI.start(); |
| 128 | verify(mMockWarnings).showHighTemperatureWarning(); |
| 129 | } |
| 130 | |
| 131 | @Test |
| 132 | public void testSettingOverrideConfig() { |
| 133 | setOverThreshold(); |
| 134 | Settings.Global.putInt(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, 1); |
| 135 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 136 | resources.addOverride(R.integer.config_showTemperatureWarning, 0); |
| 137 | resources.addOverride(R.integer.config_warningTemperature, 55); |
| 138 | |
| 139 | mPowerUI.start(); |
| 140 | verify(mMockWarnings).showHighTemperatureWarning(); |
| 141 | } |
| 142 | |
| 143 | @Test |
| 144 | public void testShutdownBasedThreshold() { |
| 145 | int tolerance = 2; |
| 146 | Settings.Global.putString(mContext.getContentResolver(), SHOW_TEMPERATURE_WARNING, null); |
| 147 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 148 | resources.addOverride(R.integer.config_showTemperatureWarning, 1); |
| 149 | resources.addOverride(R.integer.config_warningTemperature, -1); |
| 150 | resources.addOverride(R.integer.config_warningTemperatureTolerance, tolerance); |
| 151 | when(mHardProps.getDeviceTemperatures(DEVICE_TEMPERATURE_SKIN, TEMPERATURE_SHUTDOWN)) |
| 152 | .thenReturn(new float[] { 55 + tolerance }); |
| 153 | |
| 154 | setCurrentTemp(54); // Below threshold. |
| 155 | mPowerUI.start(); |
| 156 | verify(mMockWarnings, never()).showHighTemperatureWarning(); |
| 157 | |
| 158 | setCurrentTemp(56); // Above threshold. |
Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 159 | mPowerUI.updateTemperature(); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 160 | verify(mMockWarnings).showHighTemperatureWarning(); |
| 161 | } |
| 162 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 163 | @Test |
Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 164 | public void testNoConfig_noAlarms() { |
| 165 | setOverThreshold(); |
| 166 | final Boolean overheat = false; |
| 167 | final Boolean shouldBeepSound = false; |
| 168 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 169 | resources.addOverride(R.integer.config_showTemperatureWarning, 0); |
| 170 | resources.addOverride(R.integer.config_alarmTemperature, 55); |
| 171 | resources.addOverride(R.bool.config_alarmTemperatureBeepSound, shouldBeepSound); |
| 172 | |
| 173 | mPowerUI.start(); |
| 174 | verify(mMockWarnings, never()).notifyHighTemperatureAlarm(overheat, shouldBeepSound); |
| 175 | } |
| 176 | |
| 177 | @Test |
| 178 | public void testConfig_noAlarms() { |
| 179 | setUnderThreshold(); |
| 180 | final Boolean overheat = false; |
| 181 | final Boolean shouldBeepSound = false; |
| 182 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 183 | resources.addOverride(R.integer.config_showTemperatureAlarm, 1); |
| 184 | resources.addOverride(R.integer.config_alarmTemperature, 58); |
| 185 | resources.addOverride(R.bool.config_alarmTemperatureBeepSound, shouldBeepSound); |
| 186 | |
| 187 | mPowerUI.start(); |
| 188 | verify(mMockWarnings, never()).notifyHighTemperatureAlarm(overheat, shouldBeepSound); |
| 189 | } |
| 190 | |
| 191 | @Test |
| 192 | public void testConfig_alarms() { |
| 193 | setOverThreshold(); |
| 194 | final Boolean overheat = true; |
| 195 | final Boolean shouldBeepSound = false; |
| 196 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 197 | resources.addOverride(R.integer.config_showTemperatureAlarm, 1); |
| 198 | resources.addOverride(R.integer.config_alarmTemperature, 58); |
| 199 | resources.addOverride(R.bool.config_alarmTemperatureBeepSound, shouldBeepSound); |
| 200 | |
| 201 | mPowerUI.start(); |
| 202 | verify(mMockWarnings).notifyHighTemperatureAlarm(overheat, shouldBeepSound); |
| 203 | } |
| 204 | |
| 205 | @Test |
| 206 | public void testConfig_alarmsWithBeepSound() { |
| 207 | setOverThreshold(); |
| 208 | final Boolean overheat = true; |
| 209 | final Boolean shouldBeepSound = true; |
| 210 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 211 | resources.addOverride(R.integer.config_showTemperatureAlarm, 1); |
| 212 | resources.addOverride(R.integer.config_alarmTemperature, 58); |
| 213 | resources.addOverride(R.bool.config_alarmTemperatureBeepSound, shouldBeepSound); |
| 214 | |
| 215 | mPowerUI.start(); |
| 216 | verify(mMockWarnings).notifyHighTemperatureAlarm(overheat, shouldBeepSound); |
| 217 | } |
| 218 | |
| 219 | @Test |
| 220 | public void testHardPropsThrottlingThreshold_alarms() { |
| 221 | setThrottlingThreshold(DEFAULT_OVERHEAT_ALARM_THRESHOLD); |
| 222 | setOverThreshold(); |
| 223 | final Boolean overheat = true; |
| 224 | final Boolean shouldBeepSound = false; |
| 225 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 226 | resources.addOverride(R.integer.config_showTemperatureAlarm, 1); |
| 227 | resources.addOverride(R.bool.config_alarmTemperatureBeepSound, shouldBeepSound); |
| 228 | |
| 229 | mPowerUI.start(); |
| 230 | verify(mMockWarnings).notifyHighTemperatureAlarm(overheat, shouldBeepSound); |
| 231 | } |
| 232 | |
| 233 | @Test |
| 234 | public void testHardPropsThrottlingThreshold_noAlarms() { |
| 235 | setThrottlingThreshold(DEFAULT_OVERHEAT_ALARM_THRESHOLD); |
| 236 | setUnderThreshold(); |
| 237 | final Boolean overheat = false; |
| 238 | final Boolean shouldBeepSound = false; |
| 239 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 240 | resources.addOverride(R.integer.config_showTemperatureAlarm, 1); |
| 241 | resources.addOverride(R.bool.config_alarmTemperatureBeepSound, shouldBeepSound); |
| 242 | |
| 243 | mPowerUI.start(); |
| 244 | verify(mMockWarnings, never()).notifyHighTemperatureAlarm(overheat, shouldBeepSound); |
| 245 | } |
| 246 | |
| 247 | @Test |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 248 | public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsNoShow() { |
| 249 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 250 | when(mEnhancedEstimates.getLowWarningThreshold()) |
| 251 | .thenReturn(Duration.ofHours(1).toMillis()); |
| 252 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 253 | mPowerUI.start(); |
| 254 | |
| 255 | // unplugged device that would not show the non-hybrid notification but would show the |
| 256 | // hybrid but the threshold has been overriden to be too low |
| 257 | boolean shouldShow = |
| 258 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 259 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 260 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 261 | assertFalse(shouldShow); |
| 262 | } |
| 263 | |
| 264 | @Test |
| 265 | public void testShouldShowLowBatteryWarning_showHybridOnly_overrideThresholdHigh_returnsShow() { |
| 266 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 267 | when(mEnhancedEstimates.getLowWarningThreshold()) |
| 268 | .thenReturn(Duration.ofHours(5).toMillis()); |
| 269 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 270 | mPowerUI.start(); |
| 271 | |
| 272 | // unplugged device that would not show the non-hybrid notification but would show the |
| 273 | // hybrid since the threshold has been overriden to be much higher |
| 274 | boolean shouldShow = |
| 275 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 276 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 277 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 278 | assertTrue(shouldShow); |
| 279 | } |
| 280 | |
| 281 | @Test |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 282 | public void testShouldShowLowBatteryWarning_showHybridOnly_returnsShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 283 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 284 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 285 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 286 | mPowerUI.start(); |
| 287 | |
| 288 | // unplugged device that would not show the non-hybrid notification but would show the |
| 289 | // hybrid |
| 290 | boolean shouldShow = |
| 291 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 292 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 293 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 294 | assertTrue(shouldShow); |
| 295 | } |
| 296 | |
| 297 | @Test |
| 298 | public void testShouldShowLowBatteryWarning_showHybrid_showStandard_returnsShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 299 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 300 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 301 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 302 | mPowerUI.mBatteryLevel = 10; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 303 | mPowerUI.start(); |
| 304 | |
| 305 | // unplugged device that would show the non-hybrid notification and the hybrid |
| 306 | boolean shouldShow = |
| 307 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 308 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 309 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 310 | assertTrue(shouldShow); |
| 311 | } |
| 312 | |
| 313 | @Test |
| 314 | public void testShouldShowLowBatteryWarning_showStandardOnly_returnsShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 315 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 316 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 317 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 318 | mPowerUI.mBatteryLevel = 10; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 319 | mPowerUI.start(); |
| 320 | |
| 321 | // unplugged device that would show the non-hybrid but not the hybrid |
| 322 | boolean shouldShow = |
| 323 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 324 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 325 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 326 | assertTrue(shouldShow); |
| 327 | } |
| 328 | |
| 329 | @Test |
| 330 | public void testShouldShowLowBatteryWarning_deviceHighBattery_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 331 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 332 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 333 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 334 | mPowerUI.start(); |
| 335 | |
| 336 | // unplugged device that would show the neither due to battery level being good |
| 337 | boolean shouldShow = |
| 338 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 339 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 340 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 341 | assertFalse(shouldShow); |
| 342 | } |
| 343 | |
| 344 | @Test |
| 345 | public void testShouldShowLowBatteryWarning_devicePlugged_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 346 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 347 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 348 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 349 | mPowerUI.start(); |
| 350 | |
| 351 | // plugged device that would show the neither due to being plugged |
| 352 | boolean shouldShow = |
| 353 | mPowerUI.shouldShowLowBatteryWarning(!UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 354 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 355 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 356 | assertFalse(shouldShow); |
| 357 | } |
| 358 | |
| 359 | @Test |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 360 | public void testShouldShowLowBatteryWarning_deviceBatteryStatusUnknown_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 361 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 362 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 363 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 364 | mPowerUI.start(); |
| 365 | |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 366 | // Unknown battery status device that would show the neither due to the battery status being |
| 367 | // unknown |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 368 | boolean shouldShow = |
| 369 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 370 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 371 | !POWER_SAVER_OFF, BatteryManager.BATTERY_STATUS_UNKNOWN); |
| 372 | assertFalse(shouldShow); |
| 373 | } |
| 374 | |
| 375 | @Test |
| 376 | public void testShouldShowLowBatteryWarning_batterySaverEnabled_returnsNoShow() { |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 377 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 378 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 379 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 380 | mPowerUI.start(); |
| 381 | |
| 382 | // BatterySaverEnabled device that would show the neither due to battery saver |
| 383 | boolean shouldShow = |
| 384 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 385 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 386 | !POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 387 | assertFalse(shouldShow); |
| 388 | } |
| 389 | |
| 390 | @Test |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 391 | public void testShouldShowLowBatteryWarning_onlyShowsOncePerChargeCycle() { |
| 392 | mPowerUI.start(); |
| 393 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 394 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 395 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 396 | when(mEnhancedEstimates.getEstimate()) |
| 397 | .thenReturn(new Estimate(BELOW_HYBRID_THRESHOLD, true)); |
| 398 | mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD; |
| 399 | |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 400 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED, |
| 401 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 402 | |
| 403 | // reduce battery level to handle time based trigger -> level trigger interactions |
| 404 | mPowerUI.mBatteryLevel = 10; |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 405 | boolean shouldShow = |
| 406 | mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET, |
| 407 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, |
| 408 | POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD); |
| 409 | assertFalse(shouldShow); |
| 410 | } |
| 411 | |
| 412 | @Test |
Salvador Martinez | c50a9bd | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 413 | public void testShouldDismissLowBatteryWarning_dismissWhenPowerSaverEnabledLegacy() { |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 414 | mPowerUI.start(); |
Salvador Martinez | c50a9bd | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 415 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 416 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 417 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 418 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 419 | // device that gets power saver turned on should dismiss |
| 420 | boolean shouldDismiss = |
| 421 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 422 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, !POWER_SAVER_OFF); |
| 423 | assertTrue(shouldDismiss); |
| 424 | } |
| 425 | |
| 426 | @Test |
Salvador Martinez | c50a9bd | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 427 | public void testShouldNotDismissLowBatteryWarning_dismissWhenPowerSaverEnabledHybrid() { |
| 428 | mPowerUI.start(); |
| 429 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 430 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 431 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 432 | |
| 433 | // device that gets power saver turned on should dismiss |
| 434 | boolean shouldDismiss = |
| 435 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 436 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, !POWER_SAVER_OFF); |
| 437 | assertFalse(shouldDismiss); |
| 438 | } |
| 439 | |
| 440 | @Test |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 441 | public void testShouldDismissLowBatteryWarning_dismissWhenPlugged() { |
| 442 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 443 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 444 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 445 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 446 | |
| 447 | // device that gets plugged in should dismiss |
| 448 | boolean shouldDismiss = |
| 449 | mPowerUI.shouldDismissLowBatteryWarning(!UNPLUGGED, BELOW_WARNING_BUCKET, |
| 450 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 451 | assertTrue(shouldDismiss); |
| 452 | } |
| 453 | |
| 454 | @Test |
| 455 | public void testShouldDismissLowBatteryWarning_dismissHybridSignal_showStandardSignal_shouldShow() { |
| 456 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 457 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 458 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 459 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 460 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 461 | // would dismiss hybrid but not non-hybrid should not dismiss |
| 462 | boolean shouldDismiss = |
| 463 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 464 | BELOW_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 465 | assertFalse(shouldDismiss); |
| 466 | } |
| 467 | |
| 468 | @Test |
| 469 | public void testShouldDismissLowBatteryWarning_showHybridSignal_dismissStandardSignal_shouldShow() { |
| 470 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 471 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 472 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 473 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 474 | |
| 475 | // would dismiss non-hybrid but not hybrid should not dismiss |
| 476 | boolean shouldDismiss = |
| 477 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 478 | ABOVE_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 479 | assertFalse(shouldDismiss); |
| 480 | } |
| 481 | |
| 482 | @Test |
| 483 | public void testShouldDismissLowBatteryWarning_showBothSignal_shouldShow() { |
| 484 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 485 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 486 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 487 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 488 | |
| 489 | // should not dismiss when both would not dismiss |
| 490 | boolean shouldDismiss = |
| 491 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 492 | BELOW_WARNING_BUCKET, BELOW_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 493 | assertFalse(shouldDismiss); |
| 494 | } |
| 495 | |
| 496 | @Test |
| 497 | public void testShouldDismissLowBatteryWarning_dismissBothSignal_shouldDismiss() { |
| 498 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 499 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 500 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 501 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 502 | |
| 503 | //should dismiss if both would dismiss |
| 504 | boolean shouldDismiss = |
| 505 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 506 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 507 | assertTrue(shouldDismiss); |
| 508 | } |
| 509 | |
| 510 | @Test |
| 511 | public void testShouldDismissLowBatteryWarning_dismissStandardSignal_hybridDisabled_shouldDismiss() { |
| 512 | mPowerUI.start(); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 513 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(false); |
| 514 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 515 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 516 | |
| 517 | // would dismiss non-hybrid with hybrid disabled should dismiss |
| 518 | boolean shouldDismiss = |
| 519 | mPowerUI.shouldDismissLowBatteryWarning(UNPLUGGED, BELOW_WARNING_BUCKET, |
| 520 | ABOVE_WARNING_BUCKET, ABOVE_HYBRID_THRESHOLD, POWER_SAVER_OFF); |
| 521 | assertTrue(shouldDismiss); |
| 522 | } |
| 523 | |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 524 | @Test |
| 525 | public void testShouldDismissLowBatteryWarning_powerSaverModeEnabled() |
| 526 | throws InterruptedException { |
| 527 | when(mPowerManager.isPowerSaveMode()).thenReturn(true); |
| 528 | |
| 529 | mPowerUI.start(); |
| 530 | mPowerUI.mReceiver.onReceive(mContext, |
| 531 | new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); |
| 532 | |
| 533 | CountDownLatch latch = new CountDownLatch(1); |
| 534 | ThreadUtils.postOnBackgroundThread(() -> latch.countDown()); |
| 535 | latch.await(5, TimeUnit.SECONDS); |
| 536 | |
| 537 | verify(mMockWarnings).dismissLowBatteryWarning(); |
| 538 | } |
| 539 | |
| 540 | @Test |
| 541 | public void testShouldNotDismissLowBatteryWarning_powerSaverModeDisabled() |
| 542 | throws InterruptedException { |
| 543 | when(mPowerManager.isPowerSaveMode()).thenReturn(false); |
| 544 | |
| 545 | mPowerUI.start(); |
| 546 | mPowerUI.mReceiver.onReceive(mContext, |
| 547 | new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); |
| 548 | |
| 549 | CountDownLatch latch = new CountDownLatch(1); |
| 550 | ThreadUtils.postOnBackgroundThread(() -> latch.countDown()); |
| 551 | latch.await(5, TimeUnit.SECONDS); |
| 552 | |
| 553 | verify(mMockWarnings, never()).dismissLowBatteryWarning(); |
| 554 | } |
| 555 | |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 556 | @Test |
| 557 | public void testMaybeShowBatteryWarning_onlyQueriesEstimateOnBatteryLevelChangeOrNull() { |
| 558 | mPowerUI.start(); |
| 559 | Estimate estimate = new Estimate(BELOW_HYBRID_THRESHOLD, true); |
| 560 | when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true); |
| 561 | when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS); |
| 562 | when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS); |
| 563 | when(mEnhancedEstimates.getEstimate()).thenReturn(estimate); |
| 564 | mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD; |
| 565 | |
| 566 | // we expect that the first time it will query even if the level is the same |
| 567 | mPowerUI.mBatteryLevel = 9; |
| 568 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED, |
| 569 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
| 570 | verify(mEnhancedEstimates, times(1)).getEstimate(); |
| 571 | |
| 572 | // We should NOT query again if the battery level hasn't changed |
| 573 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED, |
| 574 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
| 575 | verify(mEnhancedEstimates, times(1)).getEstimate(); |
| 576 | |
| 577 | // Battery level has changed, so we should query again |
| 578 | mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_10, UNPLUGGED, UNPLUGGED, |
| 579 | ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET); |
| 580 | verify(mEnhancedEstimates, times(2)).getEstimate(); |
| 581 | } |
| 582 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 583 | private void setCurrentTemp(float temp) { |
| 584 | when(mHardProps.getDeviceTemperatures(DEVICE_TEMPERATURE_SKIN, TEMPERATURE_CURRENT)) |
Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 585 | .thenReturn(new float[] { temp, temp }); |
| 586 | } |
| 587 | |
| 588 | private void setThrottlingThreshold(float temp) { |
| 589 | when(mHardProps.getDeviceTemperatures(DEVICE_TEMPERATURE_SKIN, TEMPERATURE_THROTTLING)) |
| 590 | .thenReturn(new float[] { temp, temp }); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | private void setOverThreshold() { |
| 594 | setCurrentTemp(50000); |
| 595 | } |
| 596 | |
| 597 | private void setUnderThreshold() { |
| 598 | setCurrentTemp(5); |
| 599 | } |
| 600 | |
| 601 | private void createPowerUi() { |
| 602 | mPowerUI = new PowerUI(); |
| 603 | mPowerUI.mContext = mContext; |
| 604 | mPowerUI.mComponents = mContext.getComponents(); |
| 605 | } |
| 606 | } |