diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 95ba523b3a49e..131245458bb2c 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -115,7 +115,6 @@ interface INotificationManager ParceledListSlice getNotificationChannelGroups(String pkg); boolean onlyHasDefaultChannel(String pkg, int uid); boolean areChannelsBypassingDnd(); - int getAppsBypassingDndCount(int uid); ParceledListSlice getNotificationChannelsBypassingDnd(String pkg, int userId); boolean isPackagePaused(String pkg); void deleteNotificationHistoryItem(String pkg, int uid, long postedTime); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index b880a61bbb0a4..95c26d902c94b 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -479,6 +479,7 @@ public class NotificationManagerService extends SystemService { private ActivityManagerInternal mAmi; private IPackageManager mPackageManager; private PackageManager mPackageManagerClient; + private PackageManagerInternal mPackageManagerInternal; AudioManager mAudioManager; AudioManagerInternal mAudioManagerInternal; // Can be null for wear @@ -2212,6 +2213,7 @@ public class NotificationManagerService extends SystemService { mUgmInternal = ugmInternal; mPackageManager = packageManager; mPackageManagerClient = packageManagerClient; + mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class); mAppOps = appOps; mAppOpsService = iAppOps; try { @@ -2292,10 +2294,12 @@ public class NotificationManagerService extends SystemService { }); } }); + mPermissionHelper = permissionHelper; mPreferencesHelper = new PreferencesHelper(getContext(), mPackageManagerClient, mRankingHandler, mZenModeHelper, + mPermissionHelper, new NotificationChannelLoggerImpl(), mAppOps, new SysUiStatsEvent.BuilderFactory()); @@ -2309,7 +2313,6 @@ public class NotificationManagerService extends SystemService { mGroupHelper = groupHelper; mVibratorHelper = new VibratorHelper(getContext()); mHistoryManager = historyManager; - mPermissionHelper = permissionHelper; // This is a ManagedServices object that keeps track of the listeners. mListeners = notificationListeners; @@ -3481,7 +3484,7 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.setEnabled(pkg, uid, enabled); // TODO (b/194833441): this is being ignored by app ops now that the permission - // exists + // exists, so send the broadcast manually mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg, enabled ? MODE_ALLOWED : AppOpsManager.MODE_IGNORED); @@ -4081,16 +4084,14 @@ public class NotificationManagerService extends SystemService { + " cannot read channels for " + targetPkg + " in " + userId); } - @Override - public int getAppsBypassingDndCount(int userId) { - checkCallerIsSystem(); - return mPreferencesHelper.getAppsBypassingDndCount(userId); - } - @Override public ParceledListSlice getNotificationChannelsBypassingDnd( String pkg, int userId) { checkCallerIsSystem(); + if (!areNotificationsEnabledForPackage(pkg, + mPackageManagerInternal.getPackageUid(pkg, 0, userId))) { + return ParceledListSlice.emptyList(); + } return mPreferencesHelper.getNotificationChannelsBypassingDnd(pkg, userId); } diff --git a/services/core/java/com/android/server/notification/PermissionHelper.java b/services/core/java/com/android/server/notification/PermissionHelper.java index 5e381ea6aedd2..a3c009a029644 100644 --- a/services/core/java/com/android/server/notification/PermissionHelper.java +++ b/services/core/java/com/android/server/notification/PermissionHelper.java @@ -58,6 +58,10 @@ public final class PermissionHelper { mMigrationEnabled = migrationEnabled; } + public boolean isMigrationEnabled() { + return mMigrationEnabled; + } + /** * Returns whether the given uid holds the notification permission. Must not be called * with a lock held. diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 6cf7d067f7807..b94721afee009 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -169,6 +169,7 @@ public class PreferencesHelper implements RankingConfig { private final PackageManager mPm; private final RankingHandler mRankingHandler; private final ZenModeHelper mZenModeHelper; + private final PermissionHelper mPermissionHelper; private final NotificationChannelLogger mNotificationChannelLogger; private final AppOpsManager mAppOps; @@ -187,12 +188,14 @@ public class PreferencesHelper implements RankingConfig { private int mCurrentUserId = UserHandle.USER_NULL; public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler, - ZenModeHelper zenHelper, NotificationChannelLogger notificationChannelLogger, + ZenModeHelper zenHelper, PermissionHelper permHelper, + NotificationChannelLogger notificationChannelLogger, AppOpsManager appOpsManager, SysUiStatsEvent.BuilderFactory statsEventBuilderFactory) { mContext = context; mZenModeHelper = zenHelper; mRankingHandler = rankingHandler; + mPermissionHelper = permHelper; mPm = pm; mNotificationChannelLogger = notificationChannelLogger; mAppOps = appOpsManager; @@ -791,6 +794,7 @@ public class PreferencesHelper implements RankingConfig { Objects.requireNonNull(group); Objects.requireNonNull(group.getId()); Objects.requireNonNull(!TextUtils.isEmpty(group.getName())); + boolean needsDndChange = false; synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); if (r == null) { @@ -809,7 +813,7 @@ public class PreferencesHelper implements RankingConfig { // but the system can if (group.isBlocked() != oldGroup.isBlocked()) { group.lockFields(NotificationChannelGroup.USER_LOCKED_BLOCKED_STATE); - updateChannelsBypassingDnd(); + needsDndChange = true; } } } @@ -822,6 +826,9 @@ public class PreferencesHelper implements RankingConfig { } r.groups.put(group.getId(), group); } + if (needsDndChange) { + updateChannelsBypassingDnd(); + } } @Override @@ -831,7 +838,7 @@ public class PreferencesHelper implements RankingConfig { Objects.requireNonNull(channel); Objects.requireNonNull(channel.getId()); Preconditions.checkArgument(!TextUtils.isEmpty(channel.getName())); - boolean needsPolicyFileChange = false, wasUndeleted = false; + boolean needsPolicyFileChange = false, wasUndeleted = false, needsDndChange = false; synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); if (r == null) { @@ -897,7 +904,7 @@ public class PreferencesHelper implements RankingConfig { if (bypassDnd != mAreChannelsBypassingDnd || previousExistingImportance != existing.getImportance()) { - updateChannelsBypassingDnd(); + needsDndChange = true; } } } @@ -912,60 +919,64 @@ public class PreferencesHelper implements RankingConfig { mNotificationChannelLogger.logNotificationChannelModified(existing, uid, pkg, previousLoggingImportance, false); } - return needsPolicyFileChange; - } - - if (r.channels.size() >= NOTIFICATION_CHANNEL_COUNT_LIMIT) { - throw new IllegalStateException("Limit exceed; cannot create more channels"); - } - - needsPolicyFileChange = true; - - if (channel.getImportance() < IMPORTANCE_NONE - || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) { - throw new IllegalArgumentException("Invalid importance level"); - } - - // Reset fields that apps aren't allowed to set. - if (fromTargetApp && !hasDndAccess) { - channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX); - } - if (fromTargetApp) { - channel.setLockscreenVisibility(r.visibility); - channel.setAllowBubbles(existing != null - ? existing.getAllowBubbles() - : NotificationChannel.DEFAULT_ALLOW_BUBBLE); - } - clearLockedFieldsLocked(channel); - channel.setImportanceLockedByOEM(r.oemLockedImportance); - if (!channel.isImportanceLockedByOEM()) { - if (r.oemLockedChannels.contains(channel.getId())) { - channel.setImportanceLockedByOEM(true); + } else { + if (r.channels.size() >= NOTIFICATION_CHANNEL_COUNT_LIMIT) { + throw new IllegalStateException("Limit exceed; cannot create more channels"); } - } - channel.setImportanceLockedByCriticalDeviceFunction(r.defaultAppLockedImportance); - if (channel.getLockscreenVisibility() == Notification.VISIBILITY_PUBLIC) { - channel.setLockscreenVisibility( - NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE); - } - if (!r.showBadge) { - channel.setShowBadge(false); - } - channel.setOriginalImportance(channel.getImportance()); - // validate parent - if (channel.getParentChannelId() != null) { - Preconditions.checkArgument(r.channels.containsKey(channel.getParentChannelId()), - "Tried to create a conversation channel without a preexisting parent"); - } + needsPolicyFileChange = true; - r.channels.put(channel.getId(), channel); - if (channel.canBypassDnd() != mAreChannelsBypassingDnd) { - updateChannelsBypassingDnd(); + if (channel.getImportance() < IMPORTANCE_NONE + || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) { + throw new IllegalArgumentException("Invalid importance level"); + } + + // Reset fields that apps aren't allowed to set. + if (fromTargetApp && !hasDndAccess) { + channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX); + } + if (fromTargetApp) { + channel.setLockscreenVisibility(r.visibility); + channel.setAllowBubbles(existing != null + ? existing.getAllowBubbles() + : NotificationChannel.DEFAULT_ALLOW_BUBBLE); + } + clearLockedFieldsLocked(channel); + channel.setImportanceLockedByOEM(r.oemLockedImportance); + if (!channel.isImportanceLockedByOEM()) { + if (r.oemLockedChannels.contains(channel.getId())) { + channel.setImportanceLockedByOEM(true); + } + } + channel.setImportanceLockedByCriticalDeviceFunction(r.defaultAppLockedImportance); + if (channel.getLockscreenVisibility() == Notification.VISIBILITY_PUBLIC) { + channel.setLockscreenVisibility( + NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE); + } + if (!r.showBadge) { + channel.setShowBadge(false); + } + channel.setOriginalImportance(channel.getImportance()); + + // validate parent + if (channel.getParentChannelId() != null) { + Preconditions.checkArgument( + r.channels.containsKey(channel.getParentChannelId()), + "Tried to create a conversation channel without a preexisting parent"); + } + + r.channels.put(channel.getId(), channel); + if (channel.canBypassDnd() != mAreChannelsBypassingDnd) { + needsDndChange = true; + } + MetricsLogger.action(getChannelLog(channel, pkg).setType( + com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_OPEN)); + mNotificationChannelLogger.logNotificationChannelCreated(channel, uid, pkg); } - MetricsLogger.action(getChannelLog(channel, pkg).setType( - com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_OPEN)); - mNotificationChannelLogger.logNotificationChannelCreated(channel, uid, pkg); + } + + if (needsDndChange) { + updateChannelsBypassingDnd(); } return needsPolicyFileChange; @@ -997,6 +1008,7 @@ public class PreferencesHelper implements RankingConfig { boolean fromUser) { Objects.requireNonNull(updatedChannel); Objects.requireNonNull(updatedChannel.getId()); + boolean needsDndChange = false; synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); if (r == null) { @@ -1050,9 +1062,12 @@ public class PreferencesHelper implements RankingConfig { if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd || channel.getImportance() != updatedChannel.getImportance()) { - updateChannelsBypassingDnd(); + needsDndChange = true; } } + if (needsDndChange) { + updateChannelsBypassingDnd(); + } updateConfig(); } @@ -1126,6 +1141,8 @@ public class PreferencesHelper implements RankingConfig { @Override public boolean deleteNotificationChannel(String pkg, int uid, String channelId) { + boolean deletedChannel = false; + boolean channelBypassedDnd = false; synchronized (mPackagePreferences) { PackagePreferences r = getPackagePreferencesLocked(pkg, uid); if (r == null) { @@ -1133,13 +1150,18 @@ public class PreferencesHelper implements RankingConfig { } NotificationChannel channel = r.channels.get(channelId); if (channel != null) { - return deleteNotificationChannelLocked(channel, pkg, uid); + channelBypassedDnd = channel.canBypassDnd(); + deletedChannel = deleteNotificationChannelLocked(channel, pkg, uid); } - return false; } + if (channelBypassedDnd) { + updateChannelsBypassingDnd(); + } + return deletedChannel; } - private boolean deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) { + private boolean deleteNotificationChannelLocked(NotificationChannel channel, String pkg, + int uid) { if (!channel.isDeleted()) { channel.setDeleted(true); channel.setDeletedTimeMs(System.currentTimeMillis()); @@ -1147,10 +1169,6 @@ public class PreferencesHelper implements RankingConfig { lm.setType(com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_CLOSE); MetricsLogger.action(lm); mNotificationChannelLogger.logNotificationChannelDeleted(channel, uid, pkg); - - if (mAreChannelsBypassingDnd && channel.canBypassDnd()) { - updateChannelsBypassingDnd(); - } return true; } return false; @@ -1352,6 +1370,7 @@ public class PreferencesHelper implements RankingConfig { public List deleteNotificationChannelGroup(String pkg, int uid, String groupId) { List deletedChannels = new ArrayList<>(); + boolean groupBypassedDnd = false; synchronized (mPackagePreferences) { PackagePreferences r = getPackagePreferencesLocked(pkg, uid); if (r == null || TextUtils.isEmpty(groupId)) { @@ -1368,11 +1387,15 @@ public class PreferencesHelper implements RankingConfig { for (int i = 0; i < N; i++) { final NotificationChannel nc = r.channels.valueAt(i); if (groupId.equals(nc.getGroup())) { + groupBypassedDnd |= nc.canBypassDnd(); deleteNotificationChannelLocked(nc, pkg, uid); deletedChannels.add(nc); } } } + if (groupBypassedDnd) { + updateChannelsBypassingDnd(); + } return deletedChannels; } @@ -1495,8 +1518,8 @@ public class PreferencesHelper implements RankingConfig { public @NonNull List deleteConversations(String pkg, int uid, Set conversationIds) { + List deletedChannelIds = new ArrayList<>(); synchronized (mPackagePreferences) { - List deletedChannelIds = new ArrayList<>(); PackagePreferences r = getPackagePreferencesLocked(pkg, uid); if (r == null) { return deletedChannelIds; @@ -1517,11 +1540,11 @@ public class PreferencesHelper implements RankingConfig { deletedChannelIds.add(nc.getId()); } } - if (!deletedChannelIds.isEmpty() && mAreChannelsBypassingDnd) { - updateChannelsBypassingDnd(); - } - return deletedChannelIds; } + if (!deletedChannelIds.isEmpty() && mAreChannelsBypassingDnd) { + updateChannelsBypassingDnd(); + } + return deletedChannelIds; } @Override @@ -1554,8 +1577,7 @@ public class PreferencesHelper implements RankingConfig { synchronized (mPackagePreferences) { final PackagePreferences r = mPackagePreferences.get( packagePreferencesKey(pkg, userId)); - // notifications from this package aren't blocked - if (r != null && r.importance != IMPORTANCE_NONE) { + if (r != null) { for (NotificationChannel channel : r.channels.values()) { if (channelIsLiveLocked(r, channel) && channel.canBypassDnd()) { channels.add(channel); @@ -1621,33 +1643,6 @@ public class PreferencesHelper implements RankingConfig { } } - /** - * Returns the number of apps that have at least one notification channel that can bypass DND - * for given particular user - */ - public int getAppsBypassingDndCount(int userId) { - int count = 0; - synchronized (mPackagePreferences) { - final int numPackagePreferences = mPackagePreferences.size(); - for (int i = 0; i < numPackagePreferences; i++) { - final PackagePreferences r = mPackagePreferences.valueAt(i); - // Package isn't associated with this userId or notifications from this package are - // blocked - if (userId != UserHandle.getUserId(r.uid) || r.importance == IMPORTANCE_NONE) { - continue; - } - - for (NotificationChannel channel : r.channels.values()) { - if (channelIsLiveLocked(r, channel) && channel.canBypassDnd()) { - count++; - break; - } - } - } - } - return count; - } - /** * Syncs {@link #mAreChannelsBypassingDnd} with the current user's notification policy before * updating @@ -1655,41 +1650,56 @@ public class PreferencesHelper implements RankingConfig { private void syncChannelsBypassingDnd() { mAreChannelsBypassingDnd = (mZenModeHelper.getNotificationPolicy().state & NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND) == 1; + updateChannelsBypassingDnd(); } /** * Updates the user's NotificationPolicy based on whether the current userId * has channels bypassing DND - * @param userId */ private void updateChannelsBypassingDnd() { + ArraySet> candidatePkgs = new ArraySet<>(); + synchronized (mPackagePreferences) { final int numPackagePreferences = mPackagePreferences.size(); for (int i = 0; i < numPackagePreferences; i++) { final PackagePreferences r = mPackagePreferences.valueAt(i); - // Package isn't associated with the current userId or notifications from this - // package are blocked - if (mCurrentUserId != UserHandle.getUserId(r.uid) - || r.importance == IMPORTANCE_NONE) { + // Package isn't associated with the current userId + if (mCurrentUserId != UserHandle.getUserId(r.uid)) { continue; } for (NotificationChannel channel : r.channels.values()) { if (channelIsLiveLocked(r, channel) && channel.canBypassDnd()) { - if (!mAreChannelsBypassingDnd) { - mAreChannelsBypassingDnd = true; - updateZenPolicy(true); - } - return; + candidatePkgs.add(new Pair(r.pkg, r.uid)); + break; } } } } - // If no channels bypass DND, update the zen policy once to disable DND bypass. - if (mAreChannelsBypassingDnd) { - mAreChannelsBypassingDnd = false; - updateZenPolicy(false); + for (int i = candidatePkgs.size() - 1; i >= 0; i--) { + Pair app = candidatePkgs.valueAt(i); + if (mPermissionHelper.isMigrationEnabled()) { + if (!mPermissionHelper.hasPermission(app.second)) { + candidatePkgs.removeAt(i); + } + } else { + synchronized (mPackagePreferences) { + PackagePreferences r = getPackagePreferencesLocked(app.first, app.second); + if (r == null) { + continue; + } + if (r.importance == IMPORTANCE_NONE) { + candidatePkgs.removeAt(i); + } + } + } + } + boolean haveBypassingApps = candidatePkgs.size() > 0; + if (mAreChannelsBypassingDnd != haveBypassingApps) { + mAreChannelsBypassingDnd = haveBypassingApps; + updateZenPolicy(mAreChannelsBypassingDnd); } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 16ee1e8a22285..2bd237b1e900c 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -132,6 +132,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.LauncherApps; import android.content.pm.PackageManager; +import android.content.pm.PackageManagerInternal; import android.content.pm.ParceledListSlice; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutServiceInternal; @@ -248,6 +249,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Mock private PackageManager mPackageManagerClient; @Mock + private PackageManagerInternal mPackageManagerInternal; + @Mock private WindowManagerInternal mWindowManagerInternal; @Mock private PermissionHelper mPermissionHelper; @@ -375,6 +378,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { LocalServices.addService(DeviceIdleInternal.class, deviceIdleInternal); LocalServices.removeServiceForTest(ActivityManagerInternal.class); LocalServices.addService(ActivityManagerInternal.class, mAmi); + LocalServices.removeServiceForTest(PackageManagerInternal.class); + LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternal); mContext.addMockSystemService(Context.ALARM_SERVICE, mAlarmManager); doNothing().when(mContext).sendBroadcastAsUser(any(), any(), any()); @@ -8307,4 +8312,15 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testMigrationDisabledByDefault() { assertThat(mService.mEnableAppSettingMigration).isFalse(); } + + @Test + public void testGetNotificationChannelsBypassingDnd_blocked() throws RemoteException { + mService.setPreferencesHelper(mPreferencesHelper); + when(mPreferencesHelper.getImportance(PKG, mUid)).thenReturn(IMPORTANCE_NONE); + + assertThat(mBinderService.getNotificationChannelsBypassingDnd(PKG, mUid).getList()) + .isEmpty(); + verify(mPermissionHelper, never()).hasPermission(anyInt()); + verify(mPreferencesHelper, never()).getNotificationChannelsBypassingDnd(PKG, mUid); + } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java index 36d6945e8c796..c36d7ad8909e1 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java @@ -76,6 +76,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.LauncherApps; import android.content.pm.PackageManager; +import android.content.pm.PackageManagerInternal; import android.content.pm.ParceledListSlice; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutServiceInternal; @@ -86,6 +87,7 @@ import android.os.Build; import android.os.IBinder; import android.os.Looper; import android.os.Process; +import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; @@ -159,6 +161,8 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { @Mock private PackageManager mPackageManagerClient; @Mock + private PackageManagerInternal mPackageManagerInternal; + @Mock private WindowManagerInternal mWindowManagerInternal; @Mock private PermissionHelper mPermissionHelper; @@ -279,6 +283,8 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { LocalServices.addService(DeviceIdleInternal.class, deviceIdleInternal); LocalServices.removeServiceForTest(ActivityManagerInternal.class); LocalServices.addService(ActivityManagerInternal.class, mAmi); + LocalServices.removeServiceForTest(PackageManagerInternal.class); + LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternal); mContext.addMockSystemService(Context.ALARM_SERVICE, mAlarmManager); doNothing().when(mContext).sendBroadcastAsUser(any(), any(), any()); @@ -612,4 +618,16 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { assertEquals(PKG, captor.getValue().getPackage()); assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); } + + @Test + public void testGetNotificationChannelsBypassingDnd_blocked() throws RemoteException { + mService.setPreferencesHelper(mPreferencesHelper); + + when(mPermissionHelper.hasPermission(mUid)).thenReturn(false); + + assertThat(mBinderService.getNotificationChannelsBypassingDnd(PKG, mUid).getList()) + .isEmpty(); + verify(mPreferencesHelper, never()).getImportance(anyString(), anyInt()); + verify(mPreferencesHelper, never()).getNotificationChannelsBypassingDnd(PKG, mUid); + } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PermissionHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PermissionHelperTest.java index f72d39a2e595d..55b12dd30b178 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PermissionHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PermissionHelperTest.java @@ -62,6 +62,7 @@ import java.lang.reflect.Parameter; import java.lang.reflect.Type; import java.util.List; import java.util.Map; +import java.util.Objects; @SmallTest @RunWith(AndroidJUnit4.class) @@ -91,7 +92,8 @@ public class PermissionHelperTest extends UiServiceTestCase { Method[] allMethods = PermissionHelper.class.getDeclaredMethods(); for (Method method : allMethods) { - if (Modifier.isPublic(method.getModifiers())) { + if (Modifier.isPublic(method.getModifiers()) && + !Objects.equals("isMigrationEnabled", method.getName())) { Parameter[] params = method.getParameters(); List args = Lists.newArrayListWithCapacity(params.length); for (int i = 0; i < params.length; i++) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index ea5de0c6e219f..5324ec5f900e9 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -153,7 +153,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { Uri.parse("content://" + TEST_AUTHORITY + "/internal/audio/media/10?title=Test&canonical=1"); - @Mock NotificationUsageStats mUsageStats; + @Mock PermissionHelper mPermissionHelper; @Mock RankingHandler mHandler; @Mock PackageManager mPm; IContentProvider mTestIContentProvider; @@ -269,8 +269,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mStatsEventBuilderFactory = new WrappedSysUiStatsEvent.WrappedBuilderFactory(); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, - mAppOpsManager, mStatsEventBuilderFactory); + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); resetZenModeHelper(); mAudioAttributes = new AudioAttributes.Builder() @@ -1393,16 +1393,6 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(3, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1, user).getList().size()); - // block notifications from this app - mHelper.setEnabled(PKG_N_MR1, user, false); - assertEquals(0, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1, - user).getList().size()); - - // re-enable notifications from this app - mHelper.setEnabled(PKG_N_MR1, user, true); - assertEquals(3, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1, - user).getList().size()); - // setBypassDnd false for some channels channel1.setBypassDnd(false); channel2.setBypassDnd(false); @@ -1416,78 +1406,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test - public void testGetAppsBypassingDndCount_noAppsBypassing() throws Exception { - assertEquals(0, mHelper.getAppsBypassingDndCount(USER.getIdentifier())); - } - - @Test - public void testGetAppsBypassingDndCount_noAppsForUserIdBypassing() throws Exception { - int user = 9; - NotificationChannel channel = new NotificationChannel("id", "name", - NotificationManager.IMPORTANCE_MAX); - channel.setBypassDnd(true); - mHelper.createNotificationChannel(PKG_N_MR1, 111, channel, true, true); - - assertEquals(0, mHelper.getAppsBypassingDndCount(user)); - } - - @Test - public void testGetAppsBypassingDndCount_oneChannelBypassing_groupBlocked() { - int user = USER.getIdentifier(); - NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1"); - NotificationChannel channel1 = new NotificationChannel("id1", "name1", - NotificationManager.IMPORTANCE_MAX); - channel1.setBypassDnd(true); - channel1.setGroup(ncg.getId()); - mHelper.createNotificationChannelGroup(PKG_N_MR1, user, ncg, /* fromTargetApp */ true); - mHelper.createNotificationChannel(PKG_N_MR1, user, channel1, true, /*has DND access*/ true); - - assertEquals(1, mHelper.getAppsBypassingDndCount(user)); - - // disable group - ncg.setBlocked(true); - mHelper.createNotificationChannelGroup(PKG_N_MR1, user, ncg, /* fromTargetApp */ false); - assertEquals(0, mHelper.getAppsBypassingDndCount(user)); - } - - @Test - public void testGetAppsBypassingDndCount_oneAppBypassing() { - int user = USER.getIdentifier(); - NotificationChannel channel1 = new NotificationChannel("id1", "name1", - NotificationManager.IMPORTANCE_MAX); - NotificationChannel channel2 = new NotificationChannel("id2", "name2", - NotificationManager.IMPORTANCE_MAX); - NotificationChannel channel3 = new NotificationChannel("id3", "name3", - NotificationManager.IMPORTANCE_MAX); - channel1.setBypassDnd(true); - channel2.setBypassDnd(true); - channel3.setBypassDnd(true); - // has DND access, so can set bypassDnd attribute - mHelper.createNotificationChannel(PKG_N_MR1, user, channel1, true, /*has DND access*/ true); - mHelper.createNotificationChannel(PKG_N_MR1, user, channel2, true, true); - mHelper.createNotificationChannel(PKG_N_MR1, user, channel3, true, true); - assertEquals(1, mHelper.getAppsBypassingDndCount(user)); - - // block notifications from this app - mHelper.setEnabled(PKG_N_MR1, user, false); - assertEquals(0, mHelper.getAppsBypassingDndCount(user)); // no apps can bypass dnd - - // re-enable notifications from this app - mHelper.setEnabled(PKG_N_MR1, user, true); - assertEquals(1, mHelper.getAppsBypassingDndCount(user)); - - // setBypassDnd false for some channels - channel1.setBypassDnd(false); - channel2.setBypassDnd(false); - assertEquals(1, mHelper.getAppsBypassingDndCount(user)); - - // setBypassDnd false for rest of the channels - channel3.setBypassDnd(false); - assertEquals(0, mHelper.getAppsBypassingDndCount(user)); - } - - @Test - public void testCreateAndDeleteCanChannelsBypassDnd() throws Exception { + public void testCreateAndDeleteCanChannelsBypassDnd_localSettings() throws Exception { int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1; // create notification channel that can't bypass dnd @@ -1501,6 +1420,70 @@ public class PreferencesHelperTest extends UiServiceTestCase { // create notification channel that can bypass dnd // expected result: areChannelsBypassingDnd = true + assertTrue(mHelper.getImportance(PKG_N_MR1, uid) != IMPORTANCE_NONE); + NotificationChannel channel2 = new NotificationChannel("id2", "name2", IMPORTANCE_LOW); + channel2.setBypassDnd(true); + mHelper.createNotificationChannel(PKG_N_MR1, uid, channel2, true, true); + assertTrue(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); + resetZenModeHelper(); + + // delete channels + mHelper.deleteNotificationChannel(PKG_N_MR1, uid, channel.getId()); + assertTrue(mHelper.areChannelsBypassingDnd()); // channel2 can still bypass DND + verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); + resetZenModeHelper(); + + mHelper.deleteNotificationChannel(PKG_N_MR1, uid, channel2.getId()); + assertFalse(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); + resetZenModeHelper(); + } + + @Test + public void testCreateAndUpdateChannelsBypassingDnd_permissionHelper() { + int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1; + + when(mPermissionHelper.isMigrationEnabled()).thenReturn(true); + when(mPermissionHelper.hasPermission(uid)).thenReturn(true); + + // create notification channel that can't bypass dnd + // expected result: areChannelsBypassingDnd = false + // setNotificationPolicy isn't called since areChannelsBypassingDnd was already false + NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW); + mHelper.createNotificationChannel(PKG_N_MR1, uid, channel, true, false); + assertFalse(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); + resetZenModeHelper(); + + // Recreate a channel & now the app has dnd access granted and can set the bypass dnd field + NotificationChannel update = new NotificationChannel("id1", "name1", IMPORTANCE_LOW); + update.setBypassDnd(true); + mHelper.createNotificationChannel(PKG_N_MR1, uid, update, true, true); + + assertTrue(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); + resetZenModeHelper(); + } + + @Test + public void testCreateAndDeleteCanChannelsBypassDnd_permissionHelper() throws Exception { + int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1; + + when(mPermissionHelper.isMigrationEnabled()).thenReturn(true); + when(mPermissionHelper.hasPermission(uid)).thenReturn(true); + + // create notification channel that can't bypass dnd + // expected result: areChannelsBypassingDnd = false + // setNotificationPolicy isn't called since areChannelsBypassingDnd was already false + NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW); + mHelper.createNotificationChannel(PKG_N_MR1, uid, channel, true, false); + assertFalse(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); + resetZenModeHelper(); + + // create notification channel that can bypass dnd, using local app level settings + // expected result: areChannelsBypassingDnd = true NotificationChannel channel2 = new NotificationChannel("id2", "name2", IMPORTANCE_LOW); channel2.setBypassDnd(true); mHelper.createNotificationChannel(PKG_N_MR1, uid, channel2, true, true); @@ -1520,6 +1503,79 @@ public class PreferencesHelperTest extends UiServiceTestCase { resetZenModeHelper(); } + @Test + public void testBlockedGroupDoesNotBypassDnd() throws Exception { + int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1; + + // start in a 'allowed to bypass dnd state' + mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, + NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND, 0); + when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, + mAppOpsManager, mStatsEventBuilderFactory); + + + // create notification channel that can bypass dnd, but app is blocked + // expected result: areChannelsBypassingDnd = false + NotificationChannelGroup group = new NotificationChannelGroup("group", "group"); + group.setBlocked(true); + mHelper.createNotificationChannelGroup(PKG_N_MR1, uid, group, false); + NotificationChannel channel2 = new NotificationChannel("id2", "name2", IMPORTANCE_LOW); + channel2.setGroup("group"); + channel2.setBypassDnd(true); + mHelper.createNotificationChannel(PKG_N_MR1, uid, channel2, true, true); + assertFalse(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); + resetZenModeHelper(); + } + + @Test + public void testBlockedAppsDoNotBypassDnd_localSettings() throws Exception { + int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1; + + // start in a 'allowed to bypass dnd state' + mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, + NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND, 0); + when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, + mAppOpsManager, mStatsEventBuilderFactory); + + mHelper.setImportance(PKG_N_MR1, uid, IMPORTANCE_NONE); + // create notification channel that can bypass dnd, but app is blocked + // expected result: areChannelsBypassingDnd = false + NotificationChannel channel2 = new NotificationChannel("id2", "name2", IMPORTANCE_LOW); + channel2.setBypassDnd(true); + mHelper.createNotificationChannel(PKG_N_MR1, uid, channel2, true, true); + assertFalse(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); + resetZenModeHelper(); + } + + @Test + public void testBlockedAppsDoNotBypassDnd_permissionHelper() throws Exception { + int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1; + when(mPermissionHelper.isMigrationEnabled()).thenReturn(true); + when(mPermissionHelper.hasPermission(uid)).thenReturn(false); + // start in a 'allowed to bypass dnd state' + mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, + NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND, 0); + when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, + mAppOpsManager, mStatsEventBuilderFactory); + + // create notification channel that can bypass dnd, but app is blocked + // expected result: areChannelsBypassingDnd = false + NotificationChannel channel2 = new NotificationChannel("id2", "name2", IMPORTANCE_LOW); + channel2.setBypassDnd(true); + mHelper.createNotificationChannel(PKG_N_MR1, uid, channel2, true, true); + assertFalse(mHelper.areChannelsBypassingDnd()); + verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); + resetZenModeHelper(); + } + @Test public void testUpdateCanChannelsBypassDnd() throws Exception { int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1; @@ -1557,7 +1613,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND, 0); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); @@ -1569,7 +1626,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { // start notification policy off with mAreChannelsBypassingDnd = false mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, 0, 0); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); @@ -2355,7 +2413,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "\n" + "\n"; - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadByteArrayXml(preQXml.getBytes(), true, UserHandle.USER_SYSTEM); @@ -2368,7 +2427,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.setHideSilentStatusIcons(!PreferencesHelper.DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2465,7 +2525,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_UNSPECIFIED); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2477,7 +2538,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2490,7 +2552,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.revokeNotificationDelegate(PKG_O, UID_O); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2503,7 +2566,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.toggleNotificationDelegate(PKG_O, UID_O, false); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2522,7 +2586,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.revokeNotificationDelegate(PKG_O, UID_O); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2541,7 +2606,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(BUBBLE_PREFERENCE_NONE, mHelper.getBubblePreference(PKG_O, UID_O)); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2596,7 +2662,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.getAppLockedFields(PKG_O, UID_O)); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -2633,7 +2700,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.getAppLockedFields(PKG_O, UID_O)); ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); loadStreamXml(baos, false, UserHandle.USER_ALL); @@ -3235,7 +3303,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testPlaceholderConversationId_shortcutRequired() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); final String xml = "\n" @@ -3254,7 +3323,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testNormalConversationId_shortcutRequired() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); final String xml = "\n" @@ -3273,7 +3343,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testNoConversationId_shortcutRequired() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); final String xml = "\n" @@ -3292,7 +3363,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testDeleted_noTime() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); final String xml = "\n" @@ -3311,7 +3383,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testDeleted_twice() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); mHelper.createNotificationChannel( @@ -3322,7 +3395,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testDeleted_recentTime() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); mHelper.createNotificationChannel( @@ -3339,7 +3413,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { parser.setInput(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())), null); parser.nextTag(); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); mHelper.readXml(parser, true, UserHandle.USER_SYSTEM); @@ -3350,7 +3425,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testUnDelete_time() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); mHelper.createNotificationChannel( @@ -3369,7 +3445,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testDeleted_longTime() throws Exception { - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, + mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, + mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); long time = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 30); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java index 8edd111477024..59d9a35c4471d 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java @@ -48,6 +48,7 @@ import android.companion.ICompanionDeviceManager; import android.content.Context; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; +import android.content.pm.PackageManagerInternal; import android.os.Looper; import android.os.UserHandle; import android.os.UserManager;