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 Change-Id: Ic3622bb73562ba42e69b37e5674a724c03c45f12
This commit is contained in:
@@ -90,13 +90,10 @@ 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 UID_2 = 234;
|
||||
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;
|
||||
@@ -135,8 +132,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
|
||||
@@ -214,8 +209,6 @@ public class PowerUsageSummaryTest {
|
||||
mFragment.mScreenUsagePref = mScreenUsagePref;
|
||||
mFragment.mLastFullChargePref = mLastFullChargePref;
|
||||
mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext));
|
||||
|
||||
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -335,45 +328,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;
|
||||
|
||||
|
Reference in New Issue
Block a user