Loading res/values/config.xml +1 −1 Original line number Diff line number Diff line Loading @@ -106,6 +106,6 @@ <bool name="config_tintSettingIcon">true</bool> <!-- Whether or not App & Notification screen should display recently used apps --> <bool name="config_display_recent_apps">false</bool> <bool name="config_display_recent_apps">true</bool> </resources> src/com/android/settings/applications/RecentAppsPreferenceController.java +4 −12 Original line number Diff line number Diff line Loading @@ -153,8 +153,9 @@ public class RecentAppsPreferenceController extends PreferenceController @VisibleForTesting void refreshUi(Context prefContext) { reloadData(); if (shouldDisplayRecentApps()) { displayRecentApps(prefContext); final List<UsageStats> recentApps = getDisplayableRecentAppList(); if (recentApps != null && !recentApps.isEmpty()) { displayRecentApps(prefContext, recentApps); } else { displayOnlyAppInfo(); } Loading Loading @@ -182,11 +183,10 @@ public class RecentAppsPreferenceController extends PreferenceController } } private void displayRecentApps(Context prefContext) { private void displayRecentApps(Context prefContext, List<UsageStats> recentApps) { mCategory.setTitle(R.string.recent_app_category_title); mSeeAllPref.setTitle(R.string.see_all_apps_title); mSeeAllPref.setIcon(R.drawable.ic_chevron_right_24dp); final List<UsageStats> recentApps = getDisplayableRecentAppList(); // Rebind prefs/avoid adding new prefs if possible. Adding/removing prefs causes jank. // Build a cached preference pool Loading Loading @@ -276,14 +276,6 @@ public class RecentAppsPreferenceController extends PreferenceController return recentApps; } /** * Whether or not we should show a list of recent apps, and a see all link. */ @VisibleForTesting boolean shouldDisplayRecentApps() { return mContext.getResources().getBoolean(R.bool.config_display_recent_apps) && mApplicationsState != null && mStats != null && !mStats.isEmpty(); } /** * Whether or not the app should be included in recent list. Loading tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java +33 −24 Original line number Diff line number Diff line Loading @@ -124,30 +124,6 @@ public class RecentAppsPreferenceControllerTest { verify(mController, times(2)).refreshUi(mContext); } @Test public void configOff_shouldNotDisplayRecentApps() { mController = new RecentAppsPreferenceController(mMockContext, (Application) null, null); when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps)) .thenReturn(false); assertThat(mController.shouldDisplayRecentApps()).isFalse(); } @Test public void configOn_shouldDisplayRecentAppsWhenHaveData() { final List<UsageStats> stats = new ArrayList<>(); stats.add(mock(UsageStats.class)); when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps)) .thenReturn(true); when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())) .thenReturn(stats); mController = new RecentAppsPreferenceController(mMockContext, mAppState, null); mController.reloadData(); assertThat(mController.shouldDisplayRecentApps()).isTrue(); } @Test public void display_shouldNotShowRecents_showAppInfoPreference() { mController = new RecentAppsPreferenceController(mMockContext, mAppState, null); Loading Loading @@ -206,4 +182,37 @@ public class RecentAppsPreferenceControllerTest { verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp); } @Test public void display_hasRecentButNoneDisplayable_showAppInfo() { when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps)) .thenReturn(true); final List<UsageStats> stats = new ArrayList<>(); final UsageStats stat1 = new UsageStats(); final UsageStats stat2 = new UsageStats(); stat1.mLastTimeUsed = System.currentTimeMillis(); stat1.mPackageName = "com.android.phone"; stats.add(stat1); stat2.mLastTimeUsed = System.currentTimeMillis(); stat2.mPackageName = "com.android.settings"; stats.add(stat2); // stat1, stat2 are not displayable when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())) .thenReturn(mock(ApplicationsState.AppEntry.class)); when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())) .thenReturn(mock(ApplicationsState.AppEntry.class)); when(mMockContext.getPackageManager().resolveActivity(any(Intent.class), anyInt())) .thenReturn(new ResolveInfo()); when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())) .thenReturn(stats); mController = new RecentAppsPreferenceController(mMockContext, mAppState, null); mController.displayPreference(mScreen); verify(mCategory, never()).addPreference(any(Preference.class)); verify(mCategory).setTitle(null); verify(mSeeAllPref).setTitle(R.string.applications_settings); verify(mSeeAllPref).setIcon(null); } } Loading
res/values/config.xml +1 −1 Original line number Diff line number Diff line Loading @@ -106,6 +106,6 @@ <bool name="config_tintSettingIcon">true</bool> <!-- Whether or not App & Notification screen should display recently used apps --> <bool name="config_display_recent_apps">false</bool> <bool name="config_display_recent_apps">true</bool> </resources>
src/com/android/settings/applications/RecentAppsPreferenceController.java +4 −12 Original line number Diff line number Diff line Loading @@ -153,8 +153,9 @@ public class RecentAppsPreferenceController extends PreferenceController @VisibleForTesting void refreshUi(Context prefContext) { reloadData(); if (shouldDisplayRecentApps()) { displayRecentApps(prefContext); final List<UsageStats> recentApps = getDisplayableRecentAppList(); if (recentApps != null && !recentApps.isEmpty()) { displayRecentApps(prefContext, recentApps); } else { displayOnlyAppInfo(); } Loading Loading @@ -182,11 +183,10 @@ public class RecentAppsPreferenceController extends PreferenceController } } private void displayRecentApps(Context prefContext) { private void displayRecentApps(Context prefContext, List<UsageStats> recentApps) { mCategory.setTitle(R.string.recent_app_category_title); mSeeAllPref.setTitle(R.string.see_all_apps_title); mSeeAllPref.setIcon(R.drawable.ic_chevron_right_24dp); final List<UsageStats> recentApps = getDisplayableRecentAppList(); // Rebind prefs/avoid adding new prefs if possible. Adding/removing prefs causes jank. // Build a cached preference pool Loading Loading @@ -276,14 +276,6 @@ public class RecentAppsPreferenceController extends PreferenceController return recentApps; } /** * Whether or not we should show a list of recent apps, and a see all link. */ @VisibleForTesting boolean shouldDisplayRecentApps() { return mContext.getResources().getBoolean(R.bool.config_display_recent_apps) && mApplicationsState != null && mStats != null && !mStats.isEmpty(); } /** * Whether or not the app should be included in recent list. Loading
tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java +33 −24 Original line number Diff line number Diff line Loading @@ -124,30 +124,6 @@ public class RecentAppsPreferenceControllerTest { verify(mController, times(2)).refreshUi(mContext); } @Test public void configOff_shouldNotDisplayRecentApps() { mController = new RecentAppsPreferenceController(mMockContext, (Application) null, null); when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps)) .thenReturn(false); assertThat(mController.shouldDisplayRecentApps()).isFalse(); } @Test public void configOn_shouldDisplayRecentAppsWhenHaveData() { final List<UsageStats> stats = new ArrayList<>(); stats.add(mock(UsageStats.class)); when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps)) .thenReturn(true); when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())) .thenReturn(stats); mController = new RecentAppsPreferenceController(mMockContext, mAppState, null); mController.reloadData(); assertThat(mController.shouldDisplayRecentApps()).isTrue(); } @Test public void display_shouldNotShowRecents_showAppInfoPreference() { mController = new RecentAppsPreferenceController(mMockContext, mAppState, null); Loading Loading @@ -206,4 +182,37 @@ public class RecentAppsPreferenceControllerTest { verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp); } @Test public void display_hasRecentButNoneDisplayable_showAppInfo() { when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps)) .thenReturn(true); final List<UsageStats> stats = new ArrayList<>(); final UsageStats stat1 = new UsageStats(); final UsageStats stat2 = new UsageStats(); stat1.mLastTimeUsed = System.currentTimeMillis(); stat1.mPackageName = "com.android.phone"; stats.add(stat1); stat2.mLastTimeUsed = System.currentTimeMillis(); stat2.mPackageName = "com.android.settings"; stats.add(stat2); // stat1, stat2 are not displayable when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())) .thenReturn(mock(ApplicationsState.AppEntry.class)); when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())) .thenReturn(mock(ApplicationsState.AppEntry.class)); when(mMockContext.getPackageManager().resolveActivity(any(Intent.class), anyInt())) .thenReturn(new ResolveInfo()); when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())) .thenReturn(stats); mController = new RecentAppsPreferenceController(mMockContext, mAppState, null); mController.displayPreference(mScreen); verify(mCategory, never()).addPreference(any(Preference.class)); verify(mCategory).setTitle(null); verify(mSeeAllPref).setTitle(R.string.applications_settings); verify(mSeeAllPref).setIcon(null); } }