1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * 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 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 package com.android.settings.fuelgauge; 16 17 import static com.google.common.truth.Truth.assertThat; 18 19 import static org.mockito.ArgumentMatchers.any; 20 import static org.mockito.ArgumentMatchers.eq; 21 import static org.mockito.Mockito.doReturn; 22 import static org.mockito.Mockito.never; 23 import static org.mockito.Mockito.spy; 24 import static org.mockito.Mockito.verify; 25 import static org.mockito.Mockito.verifyNoInteractions; 26 import static org.mockito.Mockito.when; 27 28 import android.content.Context; 29 import android.content.Intent; 30 import android.hardware.usb.UsbManager; 31 import android.hardware.usb.UsbPort; 32 import android.hardware.usb.UsbPortStatus; 33 import android.os.BatteryManager; 34 import android.os.PowerManager; 35 import android.os.SystemProperties; 36 37 import androidx.preference.PreferenceScreen; 38 39 import com.android.settings.core.BasePreferenceController; 40 import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; 41 import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; 42 import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip; 43 import com.android.settings.testutils.BatteryTestUtils; 44 import com.android.settings.testutils.FakeFeatureFactory; 45 import com.android.settings.testutils.shadow.ShadowEntityHeaderController; 46 import com.android.settings.testutils.shadow.ShadowUtils; 47 import com.android.settings.widget.EntityHeaderController; 48 import com.android.settingslib.fuelgauge.BatteryUtils; 49 import com.android.settingslib.widget.UsageProgressBarPreference; 50 51 import org.junit.After; 52 import org.junit.Before; 53 import org.junit.Test; 54 import org.junit.runner.RunWith; 55 import org.mockito.Mock; 56 import org.mockito.MockitoAnnotations; 57 import org.robolectric.RobolectricTestRunner; 58 import org.robolectric.RuntimeEnvironment; 59 import org.robolectric.Shadows; 60 import org.robolectric.annotation.Config; 61 import org.robolectric.shadows.ShadowPowerManager; 62 63 @RunWith(RobolectricTestRunner.class) 64 @Config(shadows = {ShadowEntityHeaderController.class, ShadowUtils.class}) 65 public class BatteryHeaderPreferenceControllerTest { 66 67 private static final String PREF_KEY = "battery_header"; 68 private static final int BATTERY_LEVEL = 60; 69 private static final int BATTERY_MAX_LEVEL = 100; 70 private static final String TIME_LEFT = "2h30min"; 71 private static final String BATTERY_STATUS = "Charging"; 72 73 @Mock private PreferenceScreen mPreferenceScreen; 74 @Mock private BatteryInfo mBatteryInfo; 75 @Mock private EntityHeaderController mEntityHeaderController; 76 @Mock private UsageProgressBarPreference mBatteryUsageProgressBarPref; 77 @Mock private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider; 78 @Mock private UsbPort mUsbPort; 79 @Mock private UsbManager mUsbManager; 80 @Mock private UsbPortStatus mUsbPortStatus; 81 82 private BatteryHeaderPreferenceController mController; 83 private Context mContext; 84 private ShadowPowerManager mShadowPowerManager; 85 private Intent mBatteryIntent; 86 private FakeFeatureFactory mFactory; 87 88 @Before setUp()89 public void setUp() { 90 MockitoAnnotations.initMocks(this); 91 92 mContext = spy(RuntimeEnvironment.application); 93 when(mContext.getSystemService(UsbManager.class)).thenReturn(mUsbManager); 94 ShadowEntityHeaderController.setUseMock(mEntityHeaderController); 95 96 mBatteryIntent = new Intent(); 97 mBatteryIntent.putExtra(BatteryManager.EXTRA_LEVEL, BATTERY_LEVEL); 98 mBatteryIntent.putExtra(BatteryManager.EXTRA_SCALE, 100); 99 mBatteryIntent.putExtra(BatteryManager.EXTRA_PLUGGED, 1); 100 doReturn(mBatteryIntent).when(mContext).registerReceiver(any(), any()); 101 102 doReturn(mBatteryUsageProgressBarPref) 103 .when(mPreferenceScreen) 104 .findPreference(BatteryHeaderPreferenceController.KEY_BATTERY_HEADER); 105 106 mBatteryInfo.batteryLevel = BATTERY_LEVEL; 107 108 mShadowPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class)); 109 mFactory = FakeFeatureFactory.setupForTest(); 110 111 mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY)); 112 mController.mBatteryUsageProgressBarPref = mBatteryUsageProgressBarPref; 113 mController.mBatteryStatusFeatureProvider = mBatteryStatusFeatureProvider; 114 115 BatteryUtils.setChargingStringV2Enabled(null); 116 } 117 118 @After tearDown()119 public void tearDown() { 120 ShadowEntityHeaderController.reset(); 121 ShadowUtils.reset(); 122 } 123 124 @Test displayPreference_displayBatteryLevel()125 public void displayPreference_displayBatteryLevel() { 126 mController.displayPreference(mPreferenceScreen); 127 128 verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText()); 129 verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL); 130 } 131 132 @Test updatePreference_hasRemainingTime_showRemainingLabel()133 public void updatePreference_hasRemainingTime_showRemainingLabel() { 134 mBatteryInfo.remainingLabel = TIME_LEFT; 135 136 mController.updateHeaderPreference(mBatteryInfo); 137 138 verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel); 139 } 140 141 @Test updatePreference_updateBatteryInfo()142 public void updatePreference_updateBatteryInfo() { 143 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 144 145 mController.updateHeaderPreference(mBatteryInfo); 146 147 verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText()); 148 verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel); 149 verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL); 150 } 151 152 @Test updatePreference_noRemainingTime_showStatusLabel()153 public void updatePreference_noRemainingTime_showStatusLabel() { 154 mBatteryInfo.remainingLabel = null; 155 mBatteryInfo.statusLabel = BATTERY_STATUS; 156 157 mController.updateHeaderPreference(mBatteryInfo); 158 159 verify(mBatteryUsageProgressBarPref).setBottomSummary(BATTERY_STATUS); 160 } 161 162 @Test updatePreference_statusAnomalous_showStatusLabel()163 public void updatePreference_statusAnomalous_showStatusLabel() { 164 mBatteryInfo.remainingLabel = TIME_LEFT; 165 mBatteryInfo.statusLabel = BATTERY_STATUS; 166 mBatteryInfo.batteryStatus = BatteryManager.BATTERY_STATUS_NOT_CHARGING; 167 168 mController.updateHeaderPreference(mBatteryInfo); 169 170 verify(mBatteryUsageProgressBarPref).setBottomSummary(BATTERY_STATUS); 171 } 172 173 @Test updatePreference_charging_showFullText()174 public void updatePreference_charging_showFullText() { 175 setChargingState(/* isDischarging */ false, /* updatedByStatusFeature */ false); 176 177 mController.updateHeaderPreference(mBatteryInfo); 178 179 final String expectedResult = BATTERY_STATUS + " • " + TIME_LEFT; 180 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult); 181 } 182 183 @Test updatePreference_powerSaverOn_showPowerSaverOn()184 public void updatePreference_powerSaverOn_showPowerSaverOn() { 185 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 186 mShadowPowerManager.setIsPowerSaveMode(true); 187 188 mController.updateHeaderPreference(mBatteryInfo); 189 190 final String expectedResult = "Battery Saver on • " + TIME_LEFT; 191 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult); 192 } 193 194 @Test updatePreference_triggerBatteryStatusUpdateTrue_updatePercentageAndUsageOnly()195 public void updatePreference_triggerBatteryStatusUpdateTrue_updatePercentageAndUsageOnly() { 196 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ true); 197 198 mController.updateHeaderPreference(mBatteryInfo); 199 200 verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText()); 201 verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL); 202 } 203 204 @Test updatePreference_triggerBatteryStatusUpdateFalse_updateBatteryInfo()205 public void updatePreference_triggerBatteryStatusUpdateFalse_updateBatteryInfo() { 206 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 207 208 mController.updateHeaderPreference(mBatteryInfo); 209 210 verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText()); 211 verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel); 212 verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL); 213 } 214 215 @Test updateBatteryStatus_nullLabel_updateSummaryOnly()216 public void updateBatteryStatus_nullLabel_updateSummaryOnly() { 217 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 218 219 mController.updateBatteryStatus(null, mBatteryInfo); 220 221 verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel); 222 } 223 224 @Test updateBatteryStatus_withLabel_showLabelText()225 public void updateBatteryStatus_withLabel_showLabelText() { 226 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 227 228 final String label = "Update by battery status • " + TIME_LEFT; 229 mController.updateBatteryStatus(label, mBatteryInfo); 230 231 verify(mBatteryUsageProgressBarPref).setBottomSummary(label); 232 } 233 234 @Test updateBatteryStatus_chargingString_statusWithRemainingLabel()235 public void updateBatteryStatus_chargingString_statusWithRemainingLabel() { 236 var batteryInfo = 237 arrangeUpdateBatteryStatusTestWithRemainingLabel( 238 /* remainingLabel= */ "1 hr, 40 min left until full", 239 /* statusLabel= */ "Charging rapidly", 240 /* isFastCharging= */ true, 241 /* isChargingStringV2= */ false); 242 var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel; 243 244 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 245 246 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 247 } 248 249 @Test updateBatteryStatus_chargingStringV2FastCharging_statusWithRemainingLabel()250 public void updateBatteryStatus_chargingStringV2FastCharging_statusWithRemainingLabel() { 251 var batteryInfo = 252 arrangeUpdateBatteryStatusTestWithRemainingLabel( 253 /* remainingLabel= */ "Full by 1:30 PM", 254 /* statusLabel= */ "Fast Charging", 255 /* isFastCharging= */ true, 256 /* isChargingStringV2= */ true); 257 var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel; 258 259 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 260 261 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 262 } 263 264 @Test updateBatteryStatus_chargingStringV2NonFastCharging_remainingLabel()265 public void updateBatteryStatus_chargingStringV2NonFastCharging_remainingLabel() { 266 var batteryInfo = 267 arrangeUpdateBatteryStatusTestWithRemainingLabel( 268 /* remainingLabel= */ "Fully charged by 11:10 PM", 269 /* statusLabel= */ "Charging", 270 /* isFastCharging= */ false, 271 /* isChargingStringV2= */ true); 272 var expectedChargingString = batteryInfo.remainingLabel; 273 274 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 275 276 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 277 } 278 279 @Test updateBatteryStatus_customizedWirelessChargingLabel_customizedLabel()280 public void updateBatteryStatus_customizedWirelessChargingLabel_customizedLabel() { 281 var label = "Customized Wireless Charging Label"; 282 var contentDescription = "Customized Wireless Charging description"; 283 var batteryInfo = 284 arrangeUpdateBatteryStatusTestWithRemainingLabel( 285 /* remainingLabel= */ "Full by 1:30 PM", 286 /* statusLabel= */ "Fast Charging", 287 /* isFastCharging= */ true, 288 /* isChargingStringV2= */ true); 289 batteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_WIRELESS; 290 when(mFactory.batterySettingsFeatureProvider.getWirelessChargingLabel( 291 eq(mContext), any(BatteryInfo.class))) 292 .thenReturn(label); 293 when(mFactory.batterySettingsFeatureProvider.getWirelessChargingContentDescription( 294 eq(mContext), any(BatteryInfo.class))) 295 .thenReturn(contentDescription); 296 297 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 298 299 verify(mBatteryUsageProgressBarPref).setBottomSummary(label); 300 verify(mBatteryUsageProgressBarPref).setBottomSummaryContentDescription(contentDescription); 301 } 302 303 @Test updateBatteryStatus_noCustomizedWirelessChargingLabel_statusWithRemainingLabel()304 public void updateBatteryStatus_noCustomizedWirelessChargingLabel_statusWithRemainingLabel() { 305 var contentDescription = "Customized Wireless Charging description"; 306 var batteryInfo = 307 arrangeUpdateBatteryStatusTestWithRemainingLabel( 308 /* remainingLabel= */ "Full by 1:30 PM", 309 /* statusLabel= */ "Fast Charging", 310 /* isFastCharging= */ true, 311 /* isChargingStringV2= */ true); 312 batteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_WIRELESS; 313 var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel; 314 315 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 316 317 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 318 verify(mBatteryUsageProgressBarPref, never()) 319 .setBottomSummaryContentDescription(contentDescription); 320 } 321 322 @Test updateBatteryStatus_noCustomizedWirelessChargingLabel_v1StatusWithRemainingLabel()323 public void updateBatteryStatus_noCustomizedWirelessChargingLabel_v1StatusWithRemainingLabel() { 324 var contentDescription = "Customized Wireless Charging description"; 325 var batteryInfo = 326 arrangeUpdateBatteryStatusTestWithRemainingLabel( 327 /* remainingLabel= */ "1 hr, 40 min left until full", 328 /* statusLabel= */ "Charging wirelessly", 329 /* isFastCharging= */ false, 330 /* isChargingStringV2= */ false); 331 batteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_WIRELESS; 332 var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel; 333 334 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 335 336 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 337 verify(mBatteryUsageProgressBarPref, never()) 338 .setBottomSummaryContentDescription(contentDescription); 339 } 340 341 @Test updateBatteryStatus_chargingOptimizationMode_remainingLabel()342 public void updateBatteryStatus_chargingOptimizationMode_remainingLabel() { 343 var batteryInfo = 344 arrangeUpdateBatteryStatusTestWithRemainingLabel( 345 /* remainingLabel= */ "Expected remaining label", 346 /* statusLabel= */ "Fast Charging", 347 /* isFastCharging= */ true, 348 /* isChargingStringV2= */ true); 349 var expectedChargingString = batteryInfo.remainingLabel; 350 when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext)) 351 .thenReturn(true); 352 353 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 354 355 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 356 } 357 358 @Test updateBatteryStatus_chargingOptimizationModeNoRemainingLabel_statusLabel()359 public void updateBatteryStatus_chargingOptimizationModeNoRemainingLabel_statusLabel() { 360 var batteryInfo = 361 arrangeUpdateBatteryStatusTestWithRemainingLabel( 362 /* remainingLabel= */ null, 363 /* statusLabel= */ "Fast Charging", 364 /* isFastCharging= */ true, 365 /* isChargingStringV2= */ true); 366 var expectedChargingString = batteryInfo.statusLabel; 367 when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext)) 368 .thenReturn(true); 369 370 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 371 372 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 373 } 374 375 @Test updateBatteryStatus_notChargingOptimizationMode_statusWithRemainingLabel()376 public void updateBatteryStatus_notChargingOptimizationMode_statusWithRemainingLabel() { 377 var batteryInfo = 378 arrangeUpdateBatteryStatusTestWithRemainingLabel( 379 /* remainingLabel= */ "Full by 1:30 PM", 380 /* statusLabel= */ "Fast Charging", 381 /* isFastCharging= */ true, 382 /* isChargingStringV2= */ true); 383 var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel; 384 when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext)) 385 .thenReturn(false); 386 387 mController.updateBatteryStatus(/* label= */ null, batteryInfo); 388 389 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString); 390 } 391 arrangeUpdateBatteryStatusTestWithRemainingLabel( String remainingLabel, String statusLabel, boolean isFastCharging, boolean isChargingStringV2)392 private BatteryInfo arrangeUpdateBatteryStatusTestWithRemainingLabel( 393 String remainingLabel, 394 String statusLabel, 395 boolean isFastCharging, 396 boolean isChargingStringV2) { 397 SystemProperties.set( 398 BatteryUtils.PROPERTY_CHARGING_STRING_V2_KEY, String.valueOf(isChargingStringV2)); 399 mBatteryInfo.isBatteryDefender = false; 400 mBatteryInfo.remainingLabel = remainingLabel; 401 mBatteryInfo.statusLabel = statusLabel; 402 mBatteryInfo.discharging = false; 403 mBatteryInfo.isFastCharging = isFastCharging; 404 return mBatteryInfo; 405 } 406 407 @Test updateHeaderByBatteryTips_lowBatteryTip_showLowBattery()408 public void updateHeaderByBatteryTips_lowBatteryTip_showLowBattery() { 409 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 410 BatteryTip lowBatteryTip = 411 new LowBatteryTip(BatteryTip.StateType.NEW, /* powerSaveModeOn */ false); 412 413 mController.updateHeaderByBatteryTips(lowBatteryTip, mBatteryInfo); 414 415 final String expectedResult = "Low battery • " + TIME_LEFT; 416 verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult); 417 } 418 419 @Test updateHeaderByBatteryTips_notLowBatteryTip_showRemainingLabel()420 public void updateHeaderByBatteryTips_notLowBatteryTip_showRemainingLabel() { 421 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 422 BatteryTip lowBatteryTip = new SmartBatteryTip(BatteryTip.StateType.NEW); 423 424 mController.updateHeaderByBatteryTips(lowBatteryTip, mBatteryInfo); 425 426 verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel); 427 } 428 429 @Test updateHeaderByBatteryTips_noTip_noAction()430 public void updateHeaderByBatteryTips_noTip_noAction() { 431 setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false); 432 433 mController.updateHeaderByBatteryTips(null, mBatteryInfo); 434 435 verifyNoInteractions(mBatteryUsageProgressBarPref); 436 } 437 438 @Test updateHeaderByBatteryTips_noBatteryInfo_noAction()439 public void updateHeaderByBatteryTips_noBatteryInfo_noAction() { 440 BatteryTip lowBatteryTip = 441 new LowBatteryTip(BatteryTip.StateType.NEW, /* powerSaveModeOn */ false); 442 443 mController.updateHeaderByBatteryTips(lowBatteryTip, null); 444 445 verifyNoInteractions(mBatteryUsageProgressBarPref); 446 } 447 448 @Test updatePreference_isBatteryDefender_showEmptyText()449 public void updatePreference_isBatteryDefender_showEmptyText() { 450 mBatteryInfo.isBatteryDefender = true; 451 452 mController.updateHeaderPreference(mBatteryInfo); 453 454 verify(mBatteryUsageProgressBarPref) 455 .setBottomSummary( 456 mContext.getString( 457 com.android.settingslib.R.string 458 .battery_info_status_charging_on_hold)); 459 } 460 461 @Test updatePreference_incompatibleCharger_showNotChargingState()462 public void updatePreference_incompatibleCharger_showNotChargingState() { 463 BatteryTestUtils.setupIncompatibleEvent(mUsbPort, mUsbManager, mUsbPortStatus); 464 465 mController.updateHeaderPreference(mBatteryInfo); 466 467 verify(mBatteryUsageProgressBarPref) 468 .setBottomSummary( 469 mContext.getString( 470 com.android.settingslib.R.string.battery_info_status_not_charging)); 471 } 472 473 @Test quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState()474 public void quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState() { 475 mController.quickUpdateHeaderPreference(); 476 477 verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText()); 478 verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL); 479 } 480 481 @Test getAvailabilityStatus_returnAvailableUnsearchable()482 public void getAvailabilityStatus_returnAvailableUnsearchable() { 483 assertThat(mController.getAvailabilityStatus()) 484 .isEqualTo(BasePreferenceController.AVAILABLE_UNSEARCHABLE); 485 } 486 487 @Test displayPreference_batteryNotPresent_isInvisible()488 public void displayPreference_batteryNotPresent_isInvisible() { 489 ShadowUtils.setIsBatteryPresent(false); 490 491 mController.displayPreference(mPreferenceScreen); 492 493 assertThat(mBatteryUsageProgressBarPref.isVisible()).isFalse(); 494 } 495 496 @Test displayPreference_init_showEmptySpace()497 public void displayPreference_init_showEmptySpace() { 498 mController.displayPreference(mPreferenceScreen); 499 500 verify(mBatteryUsageProgressBarPref).setBottomSummary(" "); 501 } 502 formatBatteryPercentageText()503 private CharSequence formatBatteryPercentageText() { 504 return com.android.settings.Utils.formatPercentage(BATTERY_LEVEL); 505 } 506 setChargingState(boolean isDischarging, boolean updatedByStatusFeature)507 private void setChargingState(boolean isDischarging, boolean updatedByStatusFeature) { 508 mBatteryInfo.remainingLabel = TIME_LEFT; 509 mBatteryInfo.statusLabel = BATTERY_STATUS; 510 mBatteryInfo.discharging = isDischarging; 511 512 when(mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(mController, mBatteryInfo)) 513 .thenReturn(updatedByStatusFeature); 514 } 515 } 516