Loading services/core/java/com/android/server/notification/PreferencesHelper.java +25 −20 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ 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 Loading @@ -73,7 +74,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.PrintWriter; Loading Loading @@ -184,6 +184,8 @@ public class PreferencesHelper implements RankingConfig { private Map<String, List<String>> mOemLockedApps = new HashMap(); private int mCurrentUserId = UserHandle.USER_NULL; public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler, ZenModeHelper zenHelper, NotificationChannelLogger notificationChannelLogger, AppOpsManager appOpsManager, Loading @@ -199,7 +201,8 @@ public class PreferencesHelper implements RankingConfig { updateBadgingEnabled(); updateBubblesEnabled(); updateMediaNotificationFilteringEnabled(); syncChannelsBypassingDnd(mContext.getUserId()); mCurrentUserId = ActivityManager.getCurrentUser(); syncChannelsBypassingDnd(); } public void readXml(TypedXmlPullParser parser, boolean forRestore, int userId) Loading Loading @@ -806,7 +809,7 @@ public class PreferencesHelper implements RankingConfig { // but the system can if (group.isBlocked() != oldGroup.isBlocked()) { group.lockFields(NotificationChannelGroup.USER_LOCKED_BLOCKED_STATE); updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } } Loading Loading @@ -888,13 +891,13 @@ public class PreferencesHelper implements RankingConfig { // fields on the channel yet if (existing.getUserLockedFields() == 0 && hasDndAccess) { boolean bypassDnd = channel.canBypassDnd(); if (bypassDnd != existing.canBypassDnd()) { if (bypassDnd != existing.canBypassDnd() || wasUndeleted) { existing.setBypassDnd(bypassDnd); needsPolicyFileChange = true; if (bypassDnd != mAreChannelsBypassingDnd || previousExistingImportance != existing.getImportance()) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } } Loading Loading @@ -958,7 +961,7 @@ public class PreferencesHelper implements RankingConfig { r.channels.put(channel.getId(), channel); if (channel.canBypassDnd() != mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } MetricsLogger.action(getChannelLog(channel, pkg).setType( com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_OPEN)); Loading Loading @@ -1047,7 +1050,7 @@ public class PreferencesHelper implements RankingConfig { if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd || channel.getImportance() != updatedChannel.getImportance()) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } updateConfig(); Loading Loading @@ -1145,7 +1148,7 @@ public class PreferencesHelper implements RankingConfig { mNotificationChannelLogger.logNotificationChannelDeleted(channel, uid, pkg); if (mAreChannelsBypassingDnd && channel.canBypassDnd()) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } } Loading Loading @@ -1512,7 +1515,7 @@ public class PreferencesHelper implements RankingConfig { } } if (!deletedChannelIds.isEmpty() && mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } return deletedChannelIds; } Loading Loading @@ -1658,29 +1661,29 @@ public class PreferencesHelper implements RankingConfig { } /** * Syncs {@link #mAreChannelsBypassingDnd} with the user's notification policy before * Syncs {@link #mAreChannelsBypassingDnd} with the current user's notification policy before * updating * @param userId */ private void syncChannelsBypassingDnd(int userId) { private void syncChannelsBypassingDnd() { mAreChannelsBypassingDnd = (mZenModeHelper.getNotificationPolicy().state & NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND) == 1; updateChannelsBypassingDnd(userId); updateChannelsBypassingDnd(); } /** * Updates the user's NotificationPolicy based on whether the given userId * Updates the user's NotificationPolicy based on whether the current userId * has channels bypassing DND * @param userId */ private void updateChannelsBypassingDnd(int userId) { private void updateChannelsBypassingDnd() { 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) { // 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) { continue; } Loading Loading @@ -2226,14 +2229,16 @@ public class PreferencesHelper implements RankingConfig { * Called when user switches */ public void onUserSwitched(int userId) { syncChannelsBypassingDnd(userId); mCurrentUserId = userId; syncChannelsBypassingDnd(); } /** * Called when user is unlocked */ public void onUserUnlocked(int userId) { syncChannelsBypassingDnd(userId); mCurrentUserId = userId; syncChannelsBypassingDnd(); } public void onUserRemoved(int userId) { Loading Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +25 −20 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ 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 Loading @@ -73,7 +74,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.PrintWriter; Loading Loading @@ -184,6 +184,8 @@ public class PreferencesHelper implements RankingConfig { private Map<String, List<String>> mOemLockedApps = new HashMap(); private int mCurrentUserId = UserHandle.USER_NULL; public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler, ZenModeHelper zenHelper, NotificationChannelLogger notificationChannelLogger, AppOpsManager appOpsManager, Loading @@ -199,7 +201,8 @@ public class PreferencesHelper implements RankingConfig { updateBadgingEnabled(); updateBubblesEnabled(); updateMediaNotificationFilteringEnabled(); syncChannelsBypassingDnd(mContext.getUserId()); mCurrentUserId = ActivityManager.getCurrentUser(); syncChannelsBypassingDnd(); } public void readXml(TypedXmlPullParser parser, boolean forRestore, int userId) Loading Loading @@ -806,7 +809,7 @@ public class PreferencesHelper implements RankingConfig { // but the system can if (group.isBlocked() != oldGroup.isBlocked()) { group.lockFields(NotificationChannelGroup.USER_LOCKED_BLOCKED_STATE); updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } } Loading Loading @@ -888,13 +891,13 @@ public class PreferencesHelper implements RankingConfig { // fields on the channel yet if (existing.getUserLockedFields() == 0 && hasDndAccess) { boolean bypassDnd = channel.canBypassDnd(); if (bypassDnd != existing.canBypassDnd()) { if (bypassDnd != existing.canBypassDnd() || wasUndeleted) { existing.setBypassDnd(bypassDnd); needsPolicyFileChange = true; if (bypassDnd != mAreChannelsBypassingDnd || previousExistingImportance != existing.getImportance()) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } } Loading Loading @@ -958,7 +961,7 @@ public class PreferencesHelper implements RankingConfig { r.channels.put(channel.getId(), channel); if (channel.canBypassDnd() != mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } MetricsLogger.action(getChannelLog(channel, pkg).setType( com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_OPEN)); Loading Loading @@ -1047,7 +1050,7 @@ public class PreferencesHelper implements RankingConfig { if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd || channel.getImportance() != updatedChannel.getImportance()) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } updateConfig(); Loading Loading @@ -1145,7 +1148,7 @@ public class PreferencesHelper implements RankingConfig { mNotificationChannelLogger.logNotificationChannelDeleted(channel, uid, pkg); if (mAreChannelsBypassingDnd && channel.canBypassDnd()) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } } } Loading Loading @@ -1512,7 +1515,7 @@ public class PreferencesHelper implements RankingConfig { } } if (!deletedChannelIds.isEmpty() && mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(mContext.getUserId()); updateChannelsBypassingDnd(); } return deletedChannelIds; } Loading Loading @@ -1658,29 +1661,29 @@ public class PreferencesHelper implements RankingConfig { } /** * Syncs {@link #mAreChannelsBypassingDnd} with the user's notification policy before * Syncs {@link #mAreChannelsBypassingDnd} with the current user's notification policy before * updating * @param userId */ private void syncChannelsBypassingDnd(int userId) { private void syncChannelsBypassingDnd() { mAreChannelsBypassingDnd = (mZenModeHelper.getNotificationPolicy().state & NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND) == 1; updateChannelsBypassingDnd(userId); updateChannelsBypassingDnd(); } /** * Updates the user's NotificationPolicy based on whether the given userId * Updates the user's NotificationPolicy based on whether the current userId * has channels bypassing DND * @param userId */ private void updateChannelsBypassingDnd(int userId) { private void updateChannelsBypassingDnd() { 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) { // 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) { continue; } Loading Loading @@ -2226,14 +2229,16 @@ public class PreferencesHelper implements RankingConfig { * Called when user switches */ public void onUserSwitched(int userId) { syncChannelsBypassingDnd(userId); mCurrentUserId = userId; syncChannelsBypassingDnd(); } /** * Called when user is unlocked */ public void onUserUnlocked(int userId) { syncChannelsBypassingDnd(userId); mCurrentUserId = userId; syncChannelsBypassingDnd(); } public void onUserRemoved(int userId) { Loading