Loading src/com/android/settings/notification/NotificationBackend.java +19 −32 Original line number Diff line number Diff line Loading @@ -115,8 +115,7 @@ 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); Loading @@ -138,18 +137,6 @@ public class NotificationBackend { row.lockedImportance = true; } } } else { row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app); List<String> roles = rm.getHeldRolesFromController(app.packageName); if (roles.contains(RoleManager.ROLE_DIALER) || roles.contains(RoleManager.ROLE_EMERGENCY)) { row.systemApp = true; } final String[] nonBlockablePkgs = context.getResources().getStringArray( com.android.internal.R.array.config_nonBlockableNotificationPackages); markAppRowWithBlockables(nonBlockablePkgs, row, app.packageName); } } @VisibleForTesting static void markAppRowWithBlockables(String[] nonBlockablePkgs, AppRow row, Loading src/com/android/settings/notification/app/NotificationPreferenceController.java +2 −8 Original line number Diff line number Diff line Loading @@ -64,7 +64,6 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc @Nullable protected ShortcutInfo mConversationInfo; protected List<String> mPreferenceFilter; boolean mMigratedPermission; boolean overrideCanBlock; boolean overrideCanConfigure; Loading @@ -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; } /** Loading Loading @@ -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; } Loading Loading @@ -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; Loading tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java +0 −20 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java +0 −71 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading Loading @@ -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(); Loading Loading
src/com/android/settings/notification/NotificationBackend.java +19 −32 Original line number Diff line number Diff line Loading @@ -115,8 +115,7 @@ 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); Loading @@ -138,18 +137,6 @@ public class NotificationBackend { row.lockedImportance = true; } } } else { row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app); List<String> roles = rm.getHeldRolesFromController(app.packageName); if (roles.contains(RoleManager.ROLE_DIALER) || roles.contains(RoleManager.ROLE_EMERGENCY)) { row.systemApp = true; } final String[] nonBlockablePkgs = context.getResources().getStringArray( com.android.internal.R.array.config_nonBlockableNotificationPackages); markAppRowWithBlockables(nonBlockablePkgs, row, app.packageName); } } @VisibleForTesting static void markAppRowWithBlockables(String[] nonBlockablePkgs, AppRow row, Loading
src/com/android/settings/notification/app/NotificationPreferenceController.java +2 −8 Original line number Diff line number Diff line Loading @@ -64,7 +64,6 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc @Nullable protected ShortcutInfo mConversationInfo; protected List<String> mPreferenceFilter; boolean mMigratedPermission; boolean overrideCanBlock; boolean overrideCanConfigure; Loading @@ -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; } /** Loading Loading @@ -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; } Loading Loading @@ -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; Loading
tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java +0 −20 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading
tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java +0 −71 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading @@ -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(); Loading Loading @@ -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(); Loading