Loading core/java/android/util/IntArray.java +5 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,11 @@ public class IntArray implements Cloneable { return -1; } /** Returns {@code true} if this array contains the specified value. */ public boolean contains(int value) { return indexOf(value) != -1; } /** * Removes the value at the specified index from this array. */ Loading core/tests/utiltests/src/android/util/IntArrayTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -55,9 +55,11 @@ public class IntArrayTest { a.add(5, 20); assertThat(a.get(5)).isEqualTo(20); assertThat(a.indexOf(20)).isEqualTo(5); assertThat(a.contains(20)).isTrue(); verify(a, 1, 2, 0, 0, 0, 20, 10, 0, 0); assertThat(a.indexOf(99)).isEqualTo(-1); assertThat(a.contains(99)).isFalse(); a.resize(15); a.set(14, 30); Loading @@ -71,6 +73,7 @@ public class IntArrayTest { backingArray[2] = 30; verify(a, backingArray); assertThat(a.indexOf(30)).isEqualTo(2); assertThat(a.contains(30)).isTrue(); a.resize(2); assertThat(backingArray[2]).isEqualTo(0); Loading services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -1928,6 +1928,7 @@ public class NotificationManagerService extends SystemService { mConditionProviders.onUserRemoved(userId); mAssistants.onUserRemoved(userId); mHistoryManager.onUserRemoved(userId); mPreferencesHelper.syncChannelsBypassingDnd(); handleSavePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); Loading Loading @@ -2379,6 +2380,7 @@ public class NotificationManagerService extends SystemService { }); mPermissionHelper = permissionHelper; mNotificationChannelLogger = channelLogger; mUserProfiles.updateCache(getContext()); mPreferencesHelper = new PreferencesHelper(getContext(), mPackageManagerClient, mRankingHandler, Loading @@ -2387,6 +2389,7 @@ public class NotificationManagerService extends SystemService { mPermissionManager, mNotificationChannelLogger, mAppOps, mUserProfiles, new SysUiStatsEvent.BuilderFactory(), mShowReviewPermissionsNotification); mRankingHelper = new RankingHelper(getContext(), Loading Loading @@ -2442,8 +2445,6 @@ public class NotificationManagerService extends SystemService { mZenModeHelper.initZenMode(); mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter(); mUserProfiles.updateCache(getContext()); if (mPackageManagerClient.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { telephonyManager.listen(new PhoneStateListener() { @Override Loading services/core/java/com/android/server/notification/PreferencesHelper.java +12 −22 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.Notification; import android.app.NotificationChannel; Loading @@ -53,7 +52,6 @@ import android.content.pm.ParceledListSlice; import android.content.pm.UserInfo; import android.metrics.LogMaker; import android.net.Uri; import android.os.Binder; import android.os.Build; import android.os.Process; import android.os.UserHandle; Loading Loading @@ -114,7 +112,6 @@ public class PreferencesHelper implements RankingConfig { private static final int XML_VERSION_REVIEW_PERMISSIONS_NOTIFICATION = 4; @VisibleForTesting static final int UNKNOWN_UID = UserHandle.USER_NULL; private static final String NON_BLOCKABLE_CHANNEL_DELIM = ":"; @VisibleForTesting static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 5000; Loading Loading @@ -196,6 +193,7 @@ public class PreferencesHelper implements RankingConfig { private final PermissionManager mPermissionManager; private final NotificationChannelLogger mNotificationChannelLogger; private final AppOpsManager mAppOps; private final ManagedServices.UserProfiles mUserProfiles; private SparseBooleanArray mBadgingEnabled; private SparseBooleanArray mBubblesEnabled; Loading @@ -204,14 +202,12 @@ public class PreferencesHelper implements RankingConfig { private boolean mIsMediaNotificationFilteringEnabled = DEFAULT_MEDIA_NOTIFICATION_FILTERING; private boolean mCurrentUserHasChannelsBypassingDnd; private boolean mHideSilentStatusBarIcons = DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS; private boolean mShowReviewPermissionsNotification; private boolean mAllowInvalidShortcuts = false; private final boolean mShowReviewPermissionsNotification; public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler, ZenModeHelper zenHelper, PermissionHelper permHelper, PermissionManager permManager, NotificationChannelLogger notificationChannelLogger, AppOpsManager appOpsManager, AppOpsManager appOpsManager, ManagedServices.UserProfiles userProfiles, SysUiStatsEvent.BuilderFactory statsEventBuilderFactory, boolean showReviewPermissionsNotification) { mContext = context; Loading @@ -222,6 +218,7 @@ public class PreferencesHelper implements RankingConfig { mPm = pm; mNotificationChannelLogger = notificationChannelLogger; mAppOps = appOpsManager; mUserProfiles = userProfiles; mStatsEventBuilderFactory = statsEventBuilderFactory; mShowReviewPermissionsNotification = showReviewPermissionsNotification; Loading Loading @@ -435,7 +432,7 @@ public class PreferencesHelper implements RankingConfig { channel.getConversationId() != null && channel.getConversationId().contains( PLACEHOLDER_CONVERSATION_ID); return mAllowInvalidShortcuts || (!mAllowInvalidShortcuts && !isInvalidShortcutChannel); return !isInvalidShortcutChannel; } private boolean isDeletionOk(NotificationChannel nc) { Loading Loading @@ -1790,8 +1787,9 @@ public class PreferencesHelper implements RankingConfig { * Syncs {@link #mCurrentUserHasChannelsBypassingDnd} with the current user's notification * policy before updating. Must be called: * <ul> * <li>On system init, after channels and DND configurations are loaded.</li> * <li>When the current user changes, after the corresponding DND config is loaded.</li> * <li>On system init, after channels and DND configurations are loaded. * <li>When the current user is switched, after the corresponding DND config is loaded. * <li>If users are removed (the removed user could've been a profile of the current one). * </ul> */ void syncChannelsBypassingDnd() { Loading @@ -1805,20 +1803,19 @@ public class PreferencesHelper implements RankingConfig { /** * Updates the user's NotificationPolicy based on whether the current userId has channels * bypassing DND. It should be called whenever a channel is created, updated, or deleted, or * when the current user is switched. * when the current user (or its profiles) change. */ private void updateCurrentUserHasChannelsBypassingDnd(int callingUid, boolean fromSystemOrSystemUi) { ArraySet<Pair<String, Integer>> candidatePkgs = new ArraySet<>(); final int currentUserId = getCurrentUser(); final IntArray currentUserIds = mUserProfiles.getCurrentProfileIds(); 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 if (currentUserId != UserHandle.getUserId(r.uid)) { continue; if (!currentUserIds.contains(UserHandle.getUserId(r.uid))) { continue; // Package isn't associated with any profile of the current userId. } for (NotificationChannel channel : r.channels.values()) { Loading @@ -1842,13 +1839,6 @@ public class PreferencesHelper implements RankingConfig { } } private int getCurrentUser() { final long identity = Binder.clearCallingIdentity(); int currentUserId = ActivityManager.getCurrentUser(); Binder.restoreCallingIdentity(identity); return currentUserId; } private boolean channelIsLiveLocked(PackagePreferences pkgPref, NotificationChannel channel) { // Channel is in a group that's blocked if (isGroupBlocked(pkgPref.pkg, pkgPref.uid, channel.getGroup())) { Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +63 −101 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/util/IntArray.java +5 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,11 @@ public class IntArray implements Cloneable { return -1; } /** Returns {@code true} if this array contains the specified value. */ public boolean contains(int value) { return indexOf(value) != -1; } /** * Removes the value at the specified index from this array. */ Loading
core/tests/utiltests/src/android/util/IntArrayTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -55,9 +55,11 @@ public class IntArrayTest { a.add(5, 20); assertThat(a.get(5)).isEqualTo(20); assertThat(a.indexOf(20)).isEqualTo(5); assertThat(a.contains(20)).isTrue(); verify(a, 1, 2, 0, 0, 0, 20, 10, 0, 0); assertThat(a.indexOf(99)).isEqualTo(-1); assertThat(a.contains(99)).isFalse(); a.resize(15); a.set(14, 30); Loading @@ -71,6 +73,7 @@ public class IntArrayTest { backingArray[2] = 30; verify(a, backingArray); assertThat(a.indexOf(30)).isEqualTo(2); assertThat(a.contains(30)).isTrue(); a.resize(2); assertThat(backingArray[2]).isEqualTo(0); Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -1928,6 +1928,7 @@ public class NotificationManagerService extends SystemService { mConditionProviders.onUserRemoved(userId); mAssistants.onUserRemoved(userId); mHistoryManager.onUserRemoved(userId); mPreferencesHelper.syncChannelsBypassingDnd(); handleSavePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); Loading Loading @@ -2379,6 +2380,7 @@ public class NotificationManagerService extends SystemService { }); mPermissionHelper = permissionHelper; mNotificationChannelLogger = channelLogger; mUserProfiles.updateCache(getContext()); mPreferencesHelper = new PreferencesHelper(getContext(), mPackageManagerClient, mRankingHandler, Loading @@ -2387,6 +2389,7 @@ public class NotificationManagerService extends SystemService { mPermissionManager, mNotificationChannelLogger, mAppOps, mUserProfiles, new SysUiStatsEvent.BuilderFactory(), mShowReviewPermissionsNotification); mRankingHelper = new RankingHelper(getContext(), Loading Loading @@ -2442,8 +2445,6 @@ public class NotificationManagerService extends SystemService { mZenModeHelper.initZenMode(); mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter(); mUserProfiles.updateCache(getContext()); if (mPackageManagerClient.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { telephonyManager.listen(new PhoneStateListener() { @Override Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +12 −22 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.Notification; import android.app.NotificationChannel; Loading @@ -53,7 +52,6 @@ import android.content.pm.ParceledListSlice; import android.content.pm.UserInfo; import android.metrics.LogMaker; import android.net.Uri; import android.os.Binder; import android.os.Build; import android.os.Process; import android.os.UserHandle; Loading Loading @@ -114,7 +112,6 @@ public class PreferencesHelper implements RankingConfig { private static final int XML_VERSION_REVIEW_PERMISSIONS_NOTIFICATION = 4; @VisibleForTesting static final int UNKNOWN_UID = UserHandle.USER_NULL; private static final String NON_BLOCKABLE_CHANNEL_DELIM = ":"; @VisibleForTesting static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 5000; Loading Loading @@ -196,6 +193,7 @@ public class PreferencesHelper implements RankingConfig { private final PermissionManager mPermissionManager; private final NotificationChannelLogger mNotificationChannelLogger; private final AppOpsManager mAppOps; private final ManagedServices.UserProfiles mUserProfiles; private SparseBooleanArray mBadgingEnabled; private SparseBooleanArray mBubblesEnabled; Loading @@ -204,14 +202,12 @@ public class PreferencesHelper implements RankingConfig { private boolean mIsMediaNotificationFilteringEnabled = DEFAULT_MEDIA_NOTIFICATION_FILTERING; private boolean mCurrentUserHasChannelsBypassingDnd; private boolean mHideSilentStatusBarIcons = DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS; private boolean mShowReviewPermissionsNotification; private boolean mAllowInvalidShortcuts = false; private final boolean mShowReviewPermissionsNotification; public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler, ZenModeHelper zenHelper, PermissionHelper permHelper, PermissionManager permManager, NotificationChannelLogger notificationChannelLogger, AppOpsManager appOpsManager, AppOpsManager appOpsManager, ManagedServices.UserProfiles userProfiles, SysUiStatsEvent.BuilderFactory statsEventBuilderFactory, boolean showReviewPermissionsNotification) { mContext = context; Loading @@ -222,6 +218,7 @@ public class PreferencesHelper implements RankingConfig { mPm = pm; mNotificationChannelLogger = notificationChannelLogger; mAppOps = appOpsManager; mUserProfiles = userProfiles; mStatsEventBuilderFactory = statsEventBuilderFactory; mShowReviewPermissionsNotification = showReviewPermissionsNotification; Loading Loading @@ -435,7 +432,7 @@ public class PreferencesHelper implements RankingConfig { channel.getConversationId() != null && channel.getConversationId().contains( PLACEHOLDER_CONVERSATION_ID); return mAllowInvalidShortcuts || (!mAllowInvalidShortcuts && !isInvalidShortcutChannel); return !isInvalidShortcutChannel; } private boolean isDeletionOk(NotificationChannel nc) { Loading Loading @@ -1790,8 +1787,9 @@ public class PreferencesHelper implements RankingConfig { * Syncs {@link #mCurrentUserHasChannelsBypassingDnd} with the current user's notification * policy before updating. Must be called: * <ul> * <li>On system init, after channels and DND configurations are loaded.</li> * <li>When the current user changes, after the corresponding DND config is loaded.</li> * <li>On system init, after channels and DND configurations are loaded. * <li>When the current user is switched, after the corresponding DND config is loaded. * <li>If users are removed (the removed user could've been a profile of the current one). * </ul> */ void syncChannelsBypassingDnd() { Loading @@ -1805,20 +1803,19 @@ public class PreferencesHelper implements RankingConfig { /** * Updates the user's NotificationPolicy based on whether the current userId has channels * bypassing DND. It should be called whenever a channel is created, updated, or deleted, or * when the current user is switched. * when the current user (or its profiles) change. */ private void updateCurrentUserHasChannelsBypassingDnd(int callingUid, boolean fromSystemOrSystemUi) { ArraySet<Pair<String, Integer>> candidatePkgs = new ArraySet<>(); final int currentUserId = getCurrentUser(); final IntArray currentUserIds = mUserProfiles.getCurrentProfileIds(); 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 if (currentUserId != UserHandle.getUserId(r.uid)) { continue; if (!currentUserIds.contains(UserHandle.getUserId(r.uid))) { continue; // Package isn't associated with any profile of the current userId. } for (NotificationChannel channel : r.channels.values()) { Loading @@ -1842,13 +1839,6 @@ public class PreferencesHelper implements RankingConfig { } } private int getCurrentUser() { final long identity = Binder.clearCallingIdentity(); int currentUserId = ActivityManager.getCurrentUser(); Binder.restoreCallingIdentity(identity); return currentUserId; } private boolean channelIsLiveLocked(PackagePreferences pkgPref, NotificationChannel channel) { // Channel is in a group that's blocked if (isGroupBlocked(pkgPref.pkg, pkgPref.uid, channel.getGroup())) { Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +63 −101 File changed.Preview size limit exceeded, changes collapsed. Show changes