Split loading process for battery header

This cl creates BatteryHeaderPreferenceController, which will first
load the battery level in ui thread(in displayPreference()), then
display the remaining time once we get the battery stats.

This is the best we can do to avoid ui flashing while removing the
animation

Bug: 38349587
Test: RunSettingsRoboTests

Merged-In: Ic3622bb73562ba42e69b37e5674a724c03c45f12
Change-Id: Ic3622bb73562ba42e69b37e5674a724c03c45f12
This commit is contained in:
jackqdyulei
2017-05-19 13:29:09 -07:00
parent 37f6b7f751
commit 4a7c8d7125
5 changed files with 240 additions and 73 deletions

View File

@@ -88,12 +88,9 @@ import static org.mockito.Mockito.when;
})
public class PowerUsageSummaryTest {
private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"};
private static final String TIME_LEFT = "2h30min";
private static final String STUB_STRING = "stub_string";
private static final int BATTERY_LEVEL = 55;
private static final int UID = 123;
private static final int POWER_MAH = 100;
private static final long REMAINING_TIME_US = 100000;
private static final long TIME_SINCE_LAST_FULL_CHARGE_MS = 120 * 60 * 1000;
private static final long TIME_SINCE_LAST_FULL_CHARGE_US =
TIME_SINCE_LAST_FULL_CHARGE_MS * 1000;
@@ -132,8 +129,6 @@ public class PowerUsageSummaryTest {
private TextView mBatteryPercentText;
@Mock
private TextView mSummary1;
@Mock
private BatteryInfo mBatteryInfo;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private BatteryStatsHelper mBatteryHelper;
@Mock
@@ -206,8 +201,6 @@ public class PowerUsageSummaryTest {
mFragment.mScreenUsagePref = mScreenUsagePref;
mFragment.mLastFullChargePref = mLastFullChargePref;
mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext));
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
}
@Test
@@ -327,45 +320,6 @@ public class PowerUsageSummaryTest {
assertThat(mPreference.getSummary().toString()).isEqualTo(expectedSummary);
}
@Test
public void testUpdatePreference_hasRemainingTime_showRemainingLabel() {
mBatteryInfo.remainingLabel = TIME_LEFT;
mFragment.updateHeaderPreference(mBatteryInfo);
verify(mSummary1).setText(mBatteryInfo.remainingLabel);
}
@Test
public void testUpdatePreference_updateBatteryInfo() {
mBatteryInfo.remainingLabel = TIME_LEFT;
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
mBatteryInfo.discharging = true;
mFragment.updateHeaderPreference(mBatteryInfo);
assertThat(mBatteryMeterView.mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
assertThat(mBatteryMeterView.mDrawable.getCharging()).isEqualTo(false);
}
@Test
public void testUpdatePreference_noRemainingTime_showStatusLabel() {
mBatteryInfo.remainingLabel = null;
mFragment.updateHeaderPreference(mBatteryInfo);
verify(mSummary1).setText(mBatteryInfo.statusLabel);
}
@Test
public void testUpdateHeaderPreference_asyncUpdate_shouldNotCrash() {
when(mFragment.getContext()).thenReturn(null);
mBatteryInfo.remainingTimeUs = REMAINING_TIME_US;
//Should not crash
mFragment.updateHeaderPreference(mBatteryInfo);
}
private void testToggleAllApps(final boolean isShowApps) {
mFragment.mShowAllApps = isShowApps;