From 4138b6f68a19fa2734be294ba44176794833d2a2 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 4 May 2022 16:24:23 -0400 Subject: [PATCH] Remove notification permission feature flag Tes: Settings notification robotests Bug: 231344755 Change-Id: I3e35eede94ea88bee4c2e7fc03ce998ed68b4f81 --- .../notification/NotificationBackend.java | 51 +++++-------- .../app/NotificationPreferenceController.java | 10 +-- .../notification/NotificationBackendTest.java | 20 ------ .../NotificationPreferenceControllerTest.java | 71 ------------------- 4 files changed, 21 insertions(+), 131 deletions(-) diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index 2ae91e21b44..5215a33fcc4 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -115,40 +115,27 @@ public class NotificationBackend { void recordCanBeBlocked(Context context, PackageManager pm, RoleManager rm, PackageInfo app, AppRow row) { - if (Settings.Secure.getIntForUser(context.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 0, USER_SYSTEM) != 0) { - try { - row.systemApp = row.lockedImportance = - sINM.isPermissionFixed(app.packageName, row.userId); - } catch (RemoteException e) { - Log.w(TAG, "Error calling NMS", e); - } - // The permission system cannot make role permissions 'fixed', so check for these - // roles explicitly - List roles = rm.getHeldRolesFromController(app.packageName); - if (roles.contains(RoleManager.ROLE_DIALER) - || roles.contains(RoleManager.ROLE_EMERGENCY)) { - row.systemApp = row.lockedImportance = true; - } - // if the app targets T but has not requested the permission, we cannot change the - // permission state - if (app.applicationInfo.targetSdkVersion > Build.VERSION_CODES.S_V2) { - if (app.requestedPermissions == null || Arrays.stream(app.requestedPermissions) - .noneMatch(p -> p.equals(android.Manifest.permission.POST_NOTIFICATIONS))) { - row.lockedImportance = true; - } - } - } else { - row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app); - List roles = rm.getHeldRolesFromController(app.packageName); - if (roles.contains(RoleManager.ROLE_DIALER) - || roles.contains(RoleManager.ROLE_EMERGENCY)) { - row.systemApp = true; + try { + row.systemApp = row.lockedImportance = + sINM.isPermissionFixed(app.packageName, row.userId); + } catch (RemoteException e) { + Log.w(TAG, "Error calling NMS", e); + } + // The permission system cannot make role permissions 'fixed', so check for these + // roles explicitly + List roles = rm.getHeldRolesFromController(app.packageName); + if (roles.contains(RoleManager.ROLE_DIALER) + || roles.contains(RoleManager.ROLE_EMERGENCY)) { + row.systemApp = row.lockedImportance = true; + } + // if the app targets T but has not requested the permission, we cannot change the + // permission state + if (app.applicationInfo.targetSdkVersion > Build.VERSION_CODES.S_V2) { + if (app.requestedPermissions == null || Arrays.stream(app.requestedPermissions) + .noneMatch(p -> p.equals(android.Manifest.permission.POST_NOTIFICATIONS))) { + row.lockedImportance = true; } - final String[] nonBlockablePkgs = context.getResources().getStringArray( - com.android.internal.R.array.config_nonBlockableNotificationPackages); - markAppRowWithBlockables(nonBlockablePkgs, row, app.packageName); } } diff --git a/src/com/android/settings/notification/app/NotificationPreferenceController.java b/src/com/android/settings/notification/app/NotificationPreferenceController.java index 289f1edfc3c..9d339f02737 100644 --- a/src/com/android/settings/notification/app/NotificationPreferenceController.java +++ b/src/com/android/settings/notification/app/NotificationPreferenceController.java @@ -64,7 +64,6 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc @Nullable protected ShortcutInfo mConversationInfo; protected List mPreferenceFilter; - boolean mMigratedPermission; boolean overrideCanBlock; boolean overrideCanConfigure; @@ -78,8 +77,6 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc mBackend = backend; mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mPm = mContext.getPackageManager(); - mMigratedPermission = Settings.Secure.getIntForUser(context.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 0, USER_SYSTEM) != 0; } /** @@ -155,9 +152,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc return overrideCanConfigureValue; } if (channel != null && mAppRow != null) { - boolean locked = mMigratedPermission ? mAppRow.lockedImportance - : channel.isImportanceLockedByCriticalDeviceFunction() - || channel.isImportanceLockedByOEM(); + boolean locked = mAppRow.lockedImportance; if (locked) { return channel.isBlockable() || channel.getImportance() == IMPORTANCE_NONE; } @@ -186,8 +181,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc return overrideCanConfigureValue; } if (channel != null && mAppRow != null) { - boolean locked = mMigratedPermission ? mAppRow.lockedImportance - : channel.isImportanceLockedByOEM(); + boolean locked = mAppRow.lockedImportance; return !locked || channel.isBlockable(); } return false; diff --git a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java index a7ddec3c552..5745aa0718d 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java @@ -16,9 +16,6 @@ package com.android.settings.notification; -import static android.os.UserHandle.USER_SYSTEM; -import static android.provider.Settings.*; - import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertFalse; @@ -37,11 +34,9 @@ import android.content.ComponentName; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import android.content.pm.PermissionInfo; import android.net.MacAddress; import android.os.Build; import android.os.Parcel; -import android.provider.Settings; import com.android.settings.notification.NotificationBackend.AppRow; import com.android.settingslib.bluetooth.CachedBluetoothDevice; @@ -117,9 +112,6 @@ public class NotificationBackendTest { @Test public void testMarkAppRow_fixedPermission_withRole() throws Exception { - Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - PackageInfo pi = new PackageInfo(); pi.packageName = "test"; pi.applicationInfo = new ApplicationInfo(); @@ -141,9 +133,6 @@ public class NotificationBackendTest { @Test public void testMarkAppRow_fixedPermission() throws Exception { - Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - PackageInfo pi = new PackageInfo(); pi.packageName = "test"; pi.applicationInfo = new ApplicationInfo(); @@ -161,9 +150,6 @@ public class NotificationBackendTest { @Test public void testMarkAppRow_notFixedPermission() throws Exception { - Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - PackageInfo pi = new PackageInfo(); pi.packageName = "test"; pi.applicationInfo = new ApplicationInfo(); @@ -181,9 +167,6 @@ public class NotificationBackendTest { @Test public void testMarkAppRow_targetsT_noPermissionRequest() throws Exception { - Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - PackageInfo pi = new PackageInfo(); pi.packageName = "test"; pi.applicationInfo = new ApplicationInfo(); @@ -203,9 +186,6 @@ public class NotificationBackendTest { @Test public void testMarkAppRow_targetsT_permissionRequest() throws Exception { - Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - PackageInfo pi = new PackageInfo(); pi.packageName = "test"; pi.applicationInfo = new ApplicationInfo(); diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java index 8d31fe53354..4ba5fe7f644 100644 --- a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java @@ -225,9 +225,6 @@ public class NotificationPreferenceControllerTest { @Test public void testIsChannelBlockable_postMigration_locked() { - Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - mController = new TestPreferenceController(mContext, mBackend); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -240,9 +237,6 @@ public class NotificationPreferenceControllerTest { @Test public void testIsChannelBlockable_postMigration_locked_butChannelOff() { - Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - mController = new TestPreferenceController(mContext, mBackend); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -255,9 +249,6 @@ public class NotificationPreferenceControllerTest { @Test public void testIsChannelBlockable_postMigration_locked_butChannelBlockable() { - Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - mController = new TestPreferenceController(mContext, mBackend); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -271,9 +262,6 @@ public class NotificationPreferenceControllerTest { @Test public void testIsChannelGroupBlockable_postMigration_locked() { - Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - mController = new TestPreferenceController(mContext, mBackend); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -285,9 +273,6 @@ public class NotificationPreferenceControllerTest { @Test public void testIsChannelGroupBlockable_postMigration_locked_butChannelGroupOff() { - Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - mController = new TestPreferenceController(mContext, mBackend); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -300,9 +285,6 @@ public class NotificationPreferenceControllerTest { @Test public void testIsAppBlockable_postMigration_locked() { - Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - mController = new TestPreferenceController(mContext, mBackend); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -314,9 +296,6 @@ public class NotificationPreferenceControllerTest { @Test public void testIsAppBlockable_postMigration_locked_butAppOff() { - Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), - Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); - mController = new TestPreferenceController(mContext, mBackend); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -326,32 +305,6 @@ public class NotificationPreferenceControllerTest { assertFalse(mController.isAppBlockable()); } - @Test - public void testIsBlockable_oemAllowlist() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); - when(channel.getImportance()).thenReturn(IMPORTANCE_LOW); - - mController.onResume(appRow, channel, null, null, null, null, null); - assertFalse(mController.isChannelBlockable()); - - when(channel.isImportanceLockedByOEM()).thenReturn(false); - mController.onResume(appRow, channel, null, null, null, null, null); - assertTrue(mController.isChannelBlockable()); - } - - @Test - public void testIsBlockable_defaultApp() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.getImportance()).thenReturn(IMPORTANCE_LOW); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); - - mController.onResume(appRow, channel, null, null, null, null, null); - assertFalse(mController.isChannelBlockable()); - } - @Test public void testIsChannelBlockable_nonSystemAppsBlockable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); @@ -409,30 +362,6 @@ public class NotificationPreferenceControllerTest { assertTrue(mController.isChannelGroupBlockable()); } - @Test - public void testIsChannelBlockable_oemLocked() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = false; - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); - when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT); - - mController.onResume(appRow, channel, null, null, null, null, null); - assertFalse(mController.isChannelBlockable()); - } - - @Test - public void testIsChannelBlockable_criticalDeviceFunction() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = false; - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); - when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT); - - mController.onResume(appRow, channel, null, null, null, null, null); - assertFalse(mController.isChannelBlockable()); - } - @Test public void testIsChannelGroupBlockable_SystemNotBlockable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();