Loading src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java +10 −11 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC private final PackageManager mPm; private final NotificationBackend mNotificationBackend; private IUsageStatsManager mUsageStatsManager; private final int mUserId; private final IconDrawableFactory mIconDrawableFactory; private Calendar mCal; Loading @@ -104,7 +103,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC ApplicationsState appState, Fragment host) { super(context); mIconDrawableFactory = IconDrawableFactory.newInstance(context); mUserId = UserHandle.myUserId(); mPm = context.getPackageManager(); mHost = host; mApplicationsState = appState; Loading Loading @@ -177,7 +175,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC e.printStackTrace(); } if (events != null) { ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>(); UsageEvents.Event event = new UsageEvents.Event(); Loading Loading @@ -205,7 +202,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC } } private static String getKey(int userId, String pkg) { @VisibleForTesting static String getKey(int userId, String pkg) { return userId + "|" + pkg; } Loading Loading @@ -252,12 +250,13 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC } boolean rebindPref = true; NotificationAppPreference pref = appPreferences.remove(pkgName); NotificationAppPreference pref = appPreferences.remove(getKey(app.getUserId(), pkgName)); if (pref == null) { pref = new NotificationAppPreference(prefContext); rebindPref = false; } pref.setKey(pkgName); pref.setKey(getKey(app.getUserId(), pkgName)); pref.setTitle(appEntry.label); pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info)); pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL); Loading @@ -267,11 +266,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC Bundle args = new Bundle(); args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName); args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid); pref.setIntent(new SubSettingLauncher(mHost.getActivity()) .setDestination(AppNotificationSettings.class.getName()) .setTitleRes(R.string.notifications_title) .setArguments(args) .setUserHandle(new UserHandle(UserHandle.getUserId(appEntry.info.uid))) .setSourceMetricsCategory( SettingsEnums.MANAGE_APPLICATIONS_NOTIFICATIONS) .toIntent()); Loading Loading @@ -301,11 +300,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC int count = 0; for (NotifyingApp app : mApps) { final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry( app.getPackage(), mUserId); app.getPackage(), app.getUserId()); if (appEntry == null) { continue; } if (!shouldIncludePkgInRecents(app.getPackage())) { if (!shouldIncludePkgInRecents(app.getPackage(), app.getUserId())) { continue; } displayableApps.add(app); Loading @@ -321,14 +320,14 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC /** * Whether or not the app should be included in recent list. */ private boolean shouldIncludePkgInRecents(String pkgName) { private boolean shouldIncludePkgInRecents(String pkgName, int userId) { final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER) .setPackage(pkgName); if (mPm.resolveActivity(launchIntent, 0) == null) { // Not visible on launcher -> likely not a user visible app, skip if non-instant. final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(pkgName, mUserId); mApplicationsState.getEntry(pkgName, userId); if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) { Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName); return false; Loading tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java +6 −3 Original line number Diff line number Diff line Loading @@ -168,7 +168,6 @@ public class RecentNotifyingAppsPreferenceControllerTest { @Test public void display_showRecents() throws Exception { List<Event> events = new ArrayList<>(); Event app = new Event(); app.mEventType = Event.NOTIFICATION_INTERRUPTION; Loading Loading @@ -262,8 +261,12 @@ public class RecentNotifyingAppsPreferenceControllerTest { ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class); verify(mCategory, times(2)).addPreference(prefCaptor.capture()); List<Preference> prefs = prefCaptor.getAllValues(); assertThat(prefs.get(1).getKey()).isEqualTo(app.getPackageName()); assertThat(prefs.get(0).getKey()).isEqualTo(app1.getPackageName()); assertThat(prefs.get(1).getKey()).isEqualTo( RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app.getPackageName())); assertThat(prefs.get(0).getKey()).isEqualTo( RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app1.getPackageName())); } @Test Loading Loading
src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java +10 −11 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC private final PackageManager mPm; private final NotificationBackend mNotificationBackend; private IUsageStatsManager mUsageStatsManager; private final int mUserId; private final IconDrawableFactory mIconDrawableFactory; private Calendar mCal; Loading @@ -104,7 +103,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC ApplicationsState appState, Fragment host) { super(context); mIconDrawableFactory = IconDrawableFactory.newInstance(context); mUserId = UserHandle.myUserId(); mPm = context.getPackageManager(); mHost = host; mApplicationsState = appState; Loading Loading @@ -177,7 +175,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC e.printStackTrace(); } if (events != null) { ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>(); UsageEvents.Event event = new UsageEvents.Event(); Loading Loading @@ -205,7 +202,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC } } private static String getKey(int userId, String pkg) { @VisibleForTesting static String getKey(int userId, String pkg) { return userId + "|" + pkg; } Loading Loading @@ -252,12 +250,13 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC } boolean rebindPref = true; NotificationAppPreference pref = appPreferences.remove(pkgName); NotificationAppPreference pref = appPreferences.remove(getKey(app.getUserId(), pkgName)); if (pref == null) { pref = new NotificationAppPreference(prefContext); rebindPref = false; } pref.setKey(pkgName); pref.setKey(getKey(app.getUserId(), pkgName)); pref.setTitle(appEntry.label); pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info)); pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL); Loading @@ -267,11 +266,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC Bundle args = new Bundle(); args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName); args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid); pref.setIntent(new SubSettingLauncher(mHost.getActivity()) .setDestination(AppNotificationSettings.class.getName()) .setTitleRes(R.string.notifications_title) .setArguments(args) .setUserHandle(new UserHandle(UserHandle.getUserId(appEntry.info.uid))) .setSourceMetricsCategory( SettingsEnums.MANAGE_APPLICATIONS_NOTIFICATIONS) .toIntent()); Loading Loading @@ -301,11 +300,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC int count = 0; for (NotifyingApp app : mApps) { final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry( app.getPackage(), mUserId); app.getPackage(), app.getUserId()); if (appEntry == null) { continue; } if (!shouldIncludePkgInRecents(app.getPackage())) { if (!shouldIncludePkgInRecents(app.getPackage(), app.getUserId())) { continue; } displayableApps.add(app); Loading @@ -321,14 +320,14 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC /** * Whether or not the app should be included in recent list. */ private boolean shouldIncludePkgInRecents(String pkgName) { private boolean shouldIncludePkgInRecents(String pkgName, int userId) { final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER) .setPackage(pkgName); if (mPm.resolveActivity(launchIntent, 0) == null) { // Not visible on launcher -> likely not a user visible app, skip if non-instant. final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(pkgName, mUserId); mApplicationsState.getEntry(pkgName, userId); if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) { Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName); return false; Loading
tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java +6 −3 Original line number Diff line number Diff line Loading @@ -168,7 +168,6 @@ public class RecentNotifyingAppsPreferenceControllerTest { @Test public void display_showRecents() throws Exception { List<Event> events = new ArrayList<>(); Event app = new Event(); app.mEventType = Event.NOTIFICATION_INTERRUPTION; Loading Loading @@ -262,8 +261,12 @@ public class RecentNotifyingAppsPreferenceControllerTest { ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class); verify(mCategory, times(2)).addPreference(prefCaptor.capture()); List<Preference> prefs = prefCaptor.getAllValues(); assertThat(prefs.get(1).getKey()).isEqualTo(app.getPackageName()); assertThat(prefs.get(0).getKey()).isEqualTo(app1.getPackageName()); assertThat(prefs.get(1).getKey()).isEqualTo( RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app.getPackageName())); assertThat(prefs.get(0).getKey()).isEqualTo( RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app1.getPackageName())); } @Test Loading