Improve launch time for Apps & notifications page

In original design, we reload usage data at least thrice
for showing recent apps.

For now, we only reload usage data once in constuctor.
And we reload data again when we are calling updateState.

Test: Open App & notifications page, and then I compare the lauch time
with P platform device.
Fixes: 126013076

Change-Id: Ida769f28a4419125e1948e36658686ee55bf51a5
This commit is contained in:
tmfang
2019-02-24 23:21:58 +08:00
parent 74d549fc19
commit ac74050a7c
2 changed files with 57 additions and 19 deletions

View File

@@ -25,9 +25,9 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -146,6 +146,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.reloadData();
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@@ -157,13 +158,17 @@ public class RecentAppsPreferenceControllerTest {
}
@Test
public void displayPreferenceAndUpdateState_shouldRefreshUi() {
doNothing().when(mController).refreshUi();
public void displayPreference_shouldNotReloadData() {
mController.displayPreference(mScreen);
mController.updateState(mScreen);
verify(mController, times(2)).refreshUi();
verify(mController, never()).reloadData();
}
@Test
public void displayPreference_shouldRefreshUi() {
mController.displayPreference(mScreen);
verify(mController).refreshUi();
}
@Test
@@ -173,6 +178,25 @@ public class RecentAppsPreferenceControllerTest {
assertThat(mController.mAppEntitiesController).isNotNull();
}
@Test
public void updateState_firstLaunch_shouldNotReloadData() {
mController.mIsFirstLaunch = true;
mController.updateState(mRecentAppsPreference);
verify(mController, never()).reloadData();
}
@Test
public void updateState_afterFirstLaunch_shouldReloadDataAndRefreshUi() {
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
verify(mController).reloadData();
verify(mController).refreshUi();
}
@Test
public void updateState_threeValidRecentOpenAppsSet_setAppEntityThreeTime() {
final List<UsageStats> stats = new ArrayList<>();
@@ -203,6 +227,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -243,6 +268,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -274,6 +300,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -314,6 +341,7 @@ public class RecentAppsPreferenceControllerTest {
// Make sure stat2 is considered an instant app.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (ApplicationInfo info) -> info == stat2Entry.info);
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -389,6 +417,7 @@ public class RecentAppsPreferenceControllerTest {
.thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);