diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java index 1fe7e7d1d8a..d5e17233a72 100644 --- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java +++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java @@ -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; @@ -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; @@ -177,7 +175,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC e.printStackTrace(); } if (events != null) { - ArrayMap aggregatedStats = new ArrayMap<>(); UsageEvents.Event event = new UsageEvents.Event(); @@ -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; } @@ -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); @@ -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()); @@ -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); @@ -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; diff --git a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java index d47d1257816..93bd8dca7bc 100644 --- a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java @@ -168,7 +168,6 @@ public class RecentNotifyingAppsPreferenceControllerTest { @Test public void display_showRecents() throws Exception { - List events = new ArrayList<>(); Event app = new Event(); app.mEventType = Event.NOTIFICATION_INTERRUPTION; @@ -262,8 +261,12 @@ public class RecentNotifyingAppsPreferenceControllerTest { ArgumentCaptor prefCaptor = ArgumentCaptor.forClass(Preference.class); verify(mCategory, times(2)).addPreference(prefCaptor.capture()); List 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