Merge "Fix app_block_state broadcast" into tm-dev

This commit is contained in:
Julia Reynolds
2022-03-08 21:11:47 +00:00
committed by Android (Google) Code Review
3 changed files with 9 additions and 30 deletions

View File

@@ -1623,18 +1623,6 @@ public class NotificationManagerService extends SystemService {
}
};
@VisibleForTesting
final IAppOpsCallback mAppOpsCallback = new IAppOpsCallback.Stub() {
@Override public void opChanged(int op, int uid, String packageName) {
if (mEnableAppSettingMigration) {
int opValue = mAppOps.checkOpNoThrow(
AppOpsManager.OP_POST_NOTIFICATION, uid, packageName);
boolean blocked = op != MODE_ALLOWED;
sendAppBlockStateChangedBroadcast(packageName, uid, blocked);
}
}
};
private final BroadcastReceiver mPackageIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -2133,12 +2121,6 @@ public class NotificationManagerService extends SystemService {
mUsageStatsManagerInternal = usageStatsManagerInternal;
mAppOps = appOps;
mAppOpsService = iAppOps;
try {
mAppOpsService.startWatchingMode(
AppOpsManager.OP_POST_NOTIFICATION, null, mAppOpsCallback);
} catch (RemoteException e) {
Slog.e(TAG, "Could not register OP_POST_NOTIFICATION listener");
}
mAppUsageStats = appUsageStats;
mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
mCompanionManager = companionManager;
@@ -3409,6 +3391,7 @@ public class NotificationManagerService extends SystemService {
}
mPermissionHelper.setNotificationPermission(
pkg, UserHandle.getUserId(uid), enabled, true);
sendAppBlockStateChangedBroadcast(pkg, uid, !enabled);
} else {
synchronized (mNotificationLock) {
boolean wasEnabled = mPreferencesHelper.getImportance(pkg, uid)

View File

@@ -2705,13 +2705,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
@Test
public void testUpdateAppNotifyCreatorBlock() throws Exception {
mService.setPreferencesHelper(mPreferencesHelper);
// should not trigger a broadcast
when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_IGNORED);
mService.mAppOpsCallback.opChanged(0, mUid, PKG);
when(mPreferencesHelper.getImportance(PKG, mUid)).thenReturn(IMPORTANCE_DEFAULT);
// should trigger a broadcast
mBinderService.setNotificationsEnabledForPackage(PKG, 0, true);
mBinderService.setNotificationsEnabledForPackage(PKG, mUid, false);
Thread.sleep(500);
waitForIdle();
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
@@ -2720,7 +2717,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED,
captor.getValue().getAction());
assertEquals(PKG, captor.getValue().getPackage());
assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true));
assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true));
}
@Test
@@ -2737,7 +2734,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// should not trigger a broadcast
when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_ALLOWED);
mService.mAppOpsCallback.opChanged(0, mUid, PKG);
// should trigger a broadcast
mBinderService.setNotificationsEnabledForPackage(PKG, 0, true);

View File

@@ -606,9 +606,9 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {
@Test
public void testUpdateAppNotifyCreatorBlock() throws Exception {
when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_IGNORED);
when(mPermissionHelper.hasPermission(mUid)).thenReturn(true);
mService.mAppOpsCallback.opChanged(0, mUid, PKG);
mBinderService.setNotificationsEnabledForPackage(PKG, mUid, false);
Thread.sleep(500);
waitForIdle();
@@ -618,14 +618,14 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {
assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED,
captor.getValue().getAction());
assertEquals(PKG, captor.getValue().getPackage());
assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true));
assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true));
}
@Test
public void testUpdateAppNotifyCreatorUnblock() throws Exception {
when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_ALLOWED);
when(mPermissionHelper.hasPermission(mUid)).thenReturn(false);
mService.mAppOpsCallback.opChanged(0, mUid, PKG);
mBinderService.setNotificationsEnabledForPackage(PKG, mUid, true);
Thread.sleep(500);
waitForIdle();