From 7217c4421f27ac7cf1339947d9a0d7c039c03c38 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 7 Sep 2018 15:00:49 -0400 Subject: [PATCH] Prevent non-blockable app from being blocked In the recent notifications display. Test: manual Change-Id: I0b14dfbcb8c4a971bb028def7751d083d37958de Fixes: 111863327 --- .../notification/NotificationBackend.java | 6 ++++ ...centNotifyingAppsPreferenceController.java | 16 +-------- ...NotifyingAppsPreferenceControllerTest.java | 34 ++----------------- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index 01f12283773..03b4ec30264 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -78,6 +78,12 @@ public class NotificationBackend { return row; } + public boolean isBlockable(Context context, ApplicationInfo info) { + final boolean blocked = getNotificationsBanned(info.packageName, info.uid); + final boolean systemApp = isSystemApp(context, info); + return !systemApp || (systemApp && blocked); + } + public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) { final AppRow row = loadAppRow(context, pm, app.applicationInfo); recordCanBeBlocked(context, pm, app, row); diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java index a027aec7e1c..bbc01f50104 100644 --- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java +++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java @@ -82,17 +82,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC private Preference mSeeAllPref; private Preference mDivider; - static { - SKIP_SYSTEM_PACKAGES.addAll(Arrays.asList( - "android", - "com.android.phone", - "com.android.settings", - "com.android.systemui", - "com.android.providers.calendar", - "com.android.providers.media" - )); - } - public RecentNotifyingAppsPreferenceController(Context context, NotificationBackend backend, Application app, Fragment host) { this(context, backend, app == null ? null : ApplicationsState.getInstance(app), host); @@ -226,6 +215,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC .setSourceMetricsCategory( MetricsProto.MetricsEvent.MANAGE_APPLICATIONS_NOTIFICATIONS) .toIntent()); + pref.setEnabled(mNotificationBackend.isBlockable(mContext, appEntry.info)); pref.setOnPreferenceChangeListener((preference, newValue) -> { boolean blocked = !(Boolean) newValue; mNotificationBackend.setNotificationsEnabledForPackage( @@ -272,10 +262,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC * Whether or not the app should be included in recent list. */ private boolean shouldIncludePkgInRecents(String pkgName) { - if (SKIP_SYSTEM_PACKAGES.contains(pkgName)) { - Log.d(TAG, "System package, skipping " + pkgName); - return false; - } final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER) .setPackage(pkgName); diff --git a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java index cbc51a99769..e222b20551c 100644 --- a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java @@ -189,9 +189,8 @@ public class RecentNotifyingAppsPreferenceControllerTest { mController.displayPreference(mScreen); verify(mCategory).setTitle(R.string.recent_notifications); - // Only add app1. app2 is skipped because of the package name, app3 skipped because - // it's invalid app. - verify(mCategory, times(1)).addPreference(any(Preference.class)); + // Only add app1 & app2. app3 skipped because it's invalid app. + verify(mCategory, times(2)).addPreference(any(Preference.class)); verify(mSeeAllPref).setSummary(null); verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp); @@ -246,35 +245,6 @@ public class RecentNotifyingAppsPreferenceControllerTest { assertThat(prefs.get(0).getKey()).isEqualTo(app2.getPackage()); } - @Test - public void display_hasRecentButNoneDisplayable_showAppInfo() { - final List apps = new ArrayList<>(); - final NotifyingApp app1 = new NotifyingApp() - .setPackage("com.android.phone") - .setLastNotified(System.currentTimeMillis()); - final NotifyingApp app2 = new NotifyingApp() - .setPackage("com.android.settings") - .setLastNotified(System.currentTimeMillis()); - apps.add(app1); - apps.add(app2); - - // app1, app2 are not displayable - when(mAppState.getEntry(app1.getPackage(), UserHandle.myUserId())) - .thenReturn(mock(ApplicationsState.AppEntry.class)); - when(mAppState.getEntry(app2.getPackage(), UserHandle.myUserId())) - .thenReturn(mock(ApplicationsState.AppEntry.class)); - when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn( - new ResolveInfo()); - when(mBackend.getRecentApps()).thenReturn(apps); - - mController.displayPreference(mScreen); - - verify(mCategory, never()).addPreference(any(Preference.class)); - verify(mCategory).setTitle(null); - verify(mSeeAllPref).setTitle(R.string.notifications_title); - verify(mSeeAllPref).setIcon(null); - } - @Test public void display_showRecents_formatSummary() { final List apps = new ArrayList<>();