Loading services/core/java/com/android/server/notification/NotificationManagerService.java +54 −46 Original line number Diff line number Diff line Loading @@ -207,7 +207,6 @@ import com.android.internal.util.Preconditions; import com.android.internal.util.XmlUtils; import com.android.server.DeviceIdleController; import com.android.server.EventLogTags; import com.android.server.IoThread; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.lights.Light; Loading Loading @@ -266,7 +265,7 @@ public class NotificationManagerService extends SystemService { // message codes static final int MESSAGE_DURATION_REACHED = 2; // 3: removed to a different handler static final int MESSAGE_SAVE_POLICY_FILE = 3; static final int MESSAGE_SEND_RANKING_UPDATE = 4; static final int MESSAGE_LISTENER_HINTS_CHANGED = 5; static final int MESSAGE_LISTENER_NOTIFICATION_FILTER_CHANGED = 6; Loading Loading @@ -574,7 +573,7 @@ public class NotificationManagerService extends SystemService { mListeners.migrateToXml(); mAssistants.migrateToXml(); mConditionProviders.migrateToXml(); handleSavePolicyFile(); savePolicyFile(); } mAssistants.ensureAssistant(); Loading Loading @@ -604,8 +603,15 @@ public class NotificationManagerService extends SystemService { } } /** * Saves notification policy */ public void savePolicyFile() { mHandler.removeMessages(MESSAGE_SAVE_POLICY_FILE); mHandler.sendEmptyMessage(MESSAGE_SAVE_POLICY_FILE); } private void handleSavePolicyFile() { IoThread.getHandler().post(() -> { if (DBG) Slog.d(TAG, "handleSavePolicyFile"); synchronized (mPolicyFile) { final FileOutputStream stream; Loading @@ -625,7 +631,6 @@ public class NotificationManagerService extends SystemService { } } BackupManager.dataChanged(getContext().getPackageName()); }); } private void writePolicyXml(OutputStream stream, boolean forBackup) throws IOException { Loading Loading @@ -1133,8 +1138,8 @@ public class NotificationManagerService extends SystemService { } } mHandler.scheduleOnPackageChanged(removingPackage, changeUserId, pkgList, uidList); savePolicyFile(); } } }; Loading Loading @@ -1201,7 +1206,7 @@ public class NotificationManagerService extends SystemService { mListeners.onUserRemoved(userId); mConditionProviders.onUserRemoved(userId); mAssistants.onUserRemoved(userId); handleSavePolicyFile(); savePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); mUserProfiles.updateCache(context); Loading Loading @@ -1457,7 +1462,7 @@ public class NotificationManagerService extends SystemService { mZenModeHelper.addCallback(new ZenModeHelper.Callback() { @Override public void onConfigChanged() { handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -1759,7 +1764,7 @@ public class NotificationManagerService extends SystemService { modifiedChannel, NOTIFICATION_CHANNEL_OR_GROUP_UPDATED); } handleSavePolicyFile(); savePolicyFile(); } private void maybeNotifyChannelOwner(String pkg, int uid, NotificationChannel preUpdate, Loading Loading @@ -2227,7 +2232,7 @@ public class NotificationManagerService extends SystemService { Slog.w(TAG, "Can't notify app about app block change", e); } handleSavePolicyFile(); savePolicyFile(); } /** Loading Loading @@ -2284,7 +2289,7 @@ public class NotificationManagerService extends SystemService { public void setShowBadge(String pkg, int uid, boolean showBadge) { checkCallerIsSystem(); mPreferencesHelper.setShowBadge(pkg, uid, showBadge); handleSavePolicyFile(); savePolicyFile(); } @Override Loading @@ -2300,7 +2305,7 @@ public class NotificationManagerService extends SystemService { if (info != null) { mPreferencesHelper.setNotificationDelegate( callingPkg, callingUid, delegate, info.uid); handleSavePolicyFile(); savePolicyFile(); } } catch (RemoteException e) { // :( Loading @@ -2311,7 +2316,7 @@ public class NotificationManagerService extends SystemService { public void revokeNotificationDelegate(String callingPkg) { checkCallerIsSameApp(callingPkg); mPreferencesHelper.revokeNotificationDelegate(callingPkg, Binder.getCallingUid()); handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -2346,7 +2351,7 @@ public class NotificationManagerService extends SystemService { NotificationChannelGroup group) throws RemoteException { enforceSystemOrSystemUI("Caller not system or systemui"); createNotificationChannelGroup(pkg, uid, group, false, false); handleSavePolicyFile(); savePolicyFile(); } @Override Loading @@ -2359,7 +2364,7 @@ public class NotificationManagerService extends SystemService { final NotificationChannelGroup group = groups.get(i); createNotificationChannelGroup(pkg, Binder.getCallingUid(), group, true, false); } handleSavePolicyFile(); savePolicyFile(); } private void createNotificationChannelsImpl(String pkg, int uid, Loading @@ -2377,7 +2382,7 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.getNotificationChannel(pkg, uid, channel.getId(), false), NOTIFICATION_CHANNEL_OR_GROUP_ADDED); } handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -2422,7 +2427,7 @@ public class NotificationManagerService extends SystemService { UserHandle.getUserHandleForUid(callingUid), mPreferencesHelper.getNotificationChannel(pkg, callingUid, channelId, true), NOTIFICATION_CHANNEL_OR_GROUP_DELETED); handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -2464,7 +2469,7 @@ public class NotificationManagerService extends SystemService { mListeners.notifyNotificationChannelGroupChanged( pkg, UserHandle.getUserHandleForUid(callingUid), groupToDelete, NOTIFICATION_CHANNEL_OR_GROUP_DELETED); handleSavePolicyFile(); savePolicyFile(); } } Loading Loading @@ -2597,7 +2602,7 @@ public class NotificationManagerService extends SystemService { true, UserHandle.getCallingUserId(), packages, uids); } handleSavePolicyFile(); savePolicyFile(); } Loading Loading @@ -3385,7 +3390,7 @@ public class NotificationManagerService extends SystemService { final ByteArrayInputStream bais = new ByteArrayInputStream(payload); try { readPolicyXml(bais, true /*forRestore*/); handleSavePolicyFile(); savePolicyFile(); } catch (NumberFormatException | XmlPullParserException | IOException e) { Slog.w(TAG, "applyRestore: error reading payload", e); } Loading Loading @@ -3426,7 +3431,7 @@ public class NotificationManagerService extends SystemService { .setPackage(pkg) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); handleSavePolicyFile(); savePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3570,7 +3575,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); handleSavePolicyFile(); savePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading @@ -3596,7 +3601,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); handleSavePolicyFile(); savePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3679,7 +3684,7 @@ public class NotificationManagerService extends SystemService { verifyPrivilegedListener(token, user, false); createNotificationChannelGroup( pkg, getUidForPackageAndUser(pkg, user), group, false, true); handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -3728,7 +3733,7 @@ public class NotificationManagerService extends SystemService { } if (allow != mLockScreenAllowSecureNotifications) { mLockScreenAllowSecureNotifications = allow; handleSavePolicyFile(); savePolicyFile(); } } Loading Loading @@ -4487,7 +4492,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, "Ignored enqueue for snoozed notification " + r.getKey()); } mSnoozeHelper.update(userId, r); handleSavePolicyFile(); savePolicyFile(); return false; } Loading Loading @@ -4618,7 +4623,7 @@ public class NotificationManagerService extends SystemService { mSnoozeHelper.snooze(r, mDuration); } r.recordSnoozed(); handleSavePolicyFile(); savePolicyFile(); } } Loading Loading @@ -4696,7 +4701,7 @@ public class NotificationManagerService extends SystemService { if (mReason != REASON_SNOOZED) { final boolean wasSnoozed = mSnoozeHelper.cancel(mUserId, mPkg, mTag, mId); if (wasSnoozed) { handleSavePolicyFile(); savePolicyFile(); } } } Loading Loading @@ -5740,6 +5745,9 @@ public class NotificationManagerService extends SystemService { case MESSAGE_FINISH_TOKEN_TIMEOUT: handleKillTokenTimeout((ToastRecord) msg.obj); break; case MESSAGE_SAVE_POLICY_FILE: handleSavePolicyFile(); break; case MESSAGE_SEND_RANKING_UPDATE: handleSendRankingUpdate(); break; Loading Loading @@ -6257,7 +6265,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, String.format("unsnooze event(%s, %s)", key, listenerName)); } mSnoozeHelper.repost(key); handleSavePolicyFile(); savePolicyFile(); } @GuardedBy("mNotificationLock") Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +54 −46 Original line number Diff line number Diff line Loading @@ -207,7 +207,6 @@ import com.android.internal.util.Preconditions; import com.android.internal.util.XmlUtils; import com.android.server.DeviceIdleController; import com.android.server.EventLogTags; import com.android.server.IoThread; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.lights.Light; Loading Loading @@ -266,7 +265,7 @@ public class NotificationManagerService extends SystemService { // message codes static final int MESSAGE_DURATION_REACHED = 2; // 3: removed to a different handler static final int MESSAGE_SAVE_POLICY_FILE = 3; static final int MESSAGE_SEND_RANKING_UPDATE = 4; static final int MESSAGE_LISTENER_HINTS_CHANGED = 5; static final int MESSAGE_LISTENER_NOTIFICATION_FILTER_CHANGED = 6; Loading Loading @@ -574,7 +573,7 @@ public class NotificationManagerService extends SystemService { mListeners.migrateToXml(); mAssistants.migrateToXml(); mConditionProviders.migrateToXml(); handleSavePolicyFile(); savePolicyFile(); } mAssistants.ensureAssistant(); Loading Loading @@ -604,8 +603,15 @@ public class NotificationManagerService extends SystemService { } } /** * Saves notification policy */ public void savePolicyFile() { mHandler.removeMessages(MESSAGE_SAVE_POLICY_FILE); mHandler.sendEmptyMessage(MESSAGE_SAVE_POLICY_FILE); } private void handleSavePolicyFile() { IoThread.getHandler().post(() -> { if (DBG) Slog.d(TAG, "handleSavePolicyFile"); synchronized (mPolicyFile) { final FileOutputStream stream; Loading @@ -625,7 +631,6 @@ public class NotificationManagerService extends SystemService { } } BackupManager.dataChanged(getContext().getPackageName()); }); } private void writePolicyXml(OutputStream stream, boolean forBackup) throws IOException { Loading Loading @@ -1133,8 +1138,8 @@ public class NotificationManagerService extends SystemService { } } mHandler.scheduleOnPackageChanged(removingPackage, changeUserId, pkgList, uidList); savePolicyFile(); } } }; Loading Loading @@ -1201,7 +1206,7 @@ public class NotificationManagerService extends SystemService { mListeners.onUserRemoved(userId); mConditionProviders.onUserRemoved(userId); mAssistants.onUserRemoved(userId); handleSavePolicyFile(); savePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); mUserProfiles.updateCache(context); Loading Loading @@ -1457,7 +1462,7 @@ public class NotificationManagerService extends SystemService { mZenModeHelper.addCallback(new ZenModeHelper.Callback() { @Override public void onConfigChanged() { handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -1759,7 +1764,7 @@ public class NotificationManagerService extends SystemService { modifiedChannel, NOTIFICATION_CHANNEL_OR_GROUP_UPDATED); } handleSavePolicyFile(); savePolicyFile(); } private void maybeNotifyChannelOwner(String pkg, int uid, NotificationChannel preUpdate, Loading Loading @@ -2227,7 +2232,7 @@ public class NotificationManagerService extends SystemService { Slog.w(TAG, "Can't notify app about app block change", e); } handleSavePolicyFile(); savePolicyFile(); } /** Loading Loading @@ -2284,7 +2289,7 @@ public class NotificationManagerService extends SystemService { public void setShowBadge(String pkg, int uid, boolean showBadge) { checkCallerIsSystem(); mPreferencesHelper.setShowBadge(pkg, uid, showBadge); handleSavePolicyFile(); savePolicyFile(); } @Override Loading @@ -2300,7 +2305,7 @@ public class NotificationManagerService extends SystemService { if (info != null) { mPreferencesHelper.setNotificationDelegate( callingPkg, callingUid, delegate, info.uid); handleSavePolicyFile(); savePolicyFile(); } } catch (RemoteException e) { // :( Loading @@ -2311,7 +2316,7 @@ public class NotificationManagerService extends SystemService { public void revokeNotificationDelegate(String callingPkg) { checkCallerIsSameApp(callingPkg); mPreferencesHelper.revokeNotificationDelegate(callingPkg, Binder.getCallingUid()); handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -2346,7 +2351,7 @@ public class NotificationManagerService extends SystemService { NotificationChannelGroup group) throws RemoteException { enforceSystemOrSystemUI("Caller not system or systemui"); createNotificationChannelGroup(pkg, uid, group, false, false); handleSavePolicyFile(); savePolicyFile(); } @Override Loading @@ -2359,7 +2364,7 @@ public class NotificationManagerService extends SystemService { final NotificationChannelGroup group = groups.get(i); createNotificationChannelGroup(pkg, Binder.getCallingUid(), group, true, false); } handleSavePolicyFile(); savePolicyFile(); } private void createNotificationChannelsImpl(String pkg, int uid, Loading @@ -2377,7 +2382,7 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.getNotificationChannel(pkg, uid, channel.getId(), false), NOTIFICATION_CHANNEL_OR_GROUP_ADDED); } handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -2422,7 +2427,7 @@ public class NotificationManagerService extends SystemService { UserHandle.getUserHandleForUid(callingUid), mPreferencesHelper.getNotificationChannel(pkg, callingUid, channelId, true), NOTIFICATION_CHANNEL_OR_GROUP_DELETED); handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -2464,7 +2469,7 @@ public class NotificationManagerService extends SystemService { mListeners.notifyNotificationChannelGroupChanged( pkg, UserHandle.getUserHandleForUid(callingUid), groupToDelete, NOTIFICATION_CHANNEL_OR_GROUP_DELETED); handleSavePolicyFile(); savePolicyFile(); } } Loading Loading @@ -2597,7 +2602,7 @@ public class NotificationManagerService extends SystemService { true, UserHandle.getCallingUserId(), packages, uids); } handleSavePolicyFile(); savePolicyFile(); } Loading Loading @@ -3385,7 +3390,7 @@ public class NotificationManagerService extends SystemService { final ByteArrayInputStream bais = new ByteArrayInputStream(payload); try { readPolicyXml(bais, true /*forRestore*/); handleSavePolicyFile(); savePolicyFile(); } catch (NumberFormatException | XmlPullParserException | IOException e) { Slog.w(TAG, "applyRestore: error reading payload", e); } Loading Loading @@ -3426,7 +3431,7 @@ public class NotificationManagerService extends SystemService { .setPackage(pkg) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); handleSavePolicyFile(); savePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3570,7 +3575,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); handleSavePolicyFile(); savePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading @@ -3596,7 +3601,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); handleSavePolicyFile(); savePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3679,7 +3684,7 @@ public class NotificationManagerService extends SystemService { verifyPrivilegedListener(token, user, false); createNotificationChannelGroup( pkg, getUidForPackageAndUser(pkg, user), group, false, true); handleSavePolicyFile(); savePolicyFile(); } @Override Loading Loading @@ -3728,7 +3733,7 @@ public class NotificationManagerService extends SystemService { } if (allow != mLockScreenAllowSecureNotifications) { mLockScreenAllowSecureNotifications = allow; handleSavePolicyFile(); savePolicyFile(); } } Loading Loading @@ -4487,7 +4492,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, "Ignored enqueue for snoozed notification " + r.getKey()); } mSnoozeHelper.update(userId, r); handleSavePolicyFile(); savePolicyFile(); return false; } Loading Loading @@ -4618,7 +4623,7 @@ public class NotificationManagerService extends SystemService { mSnoozeHelper.snooze(r, mDuration); } r.recordSnoozed(); handleSavePolicyFile(); savePolicyFile(); } } Loading Loading @@ -4696,7 +4701,7 @@ public class NotificationManagerService extends SystemService { if (mReason != REASON_SNOOZED) { final boolean wasSnoozed = mSnoozeHelper.cancel(mUserId, mPkg, mTag, mId); if (wasSnoozed) { handleSavePolicyFile(); savePolicyFile(); } } } Loading Loading @@ -5740,6 +5745,9 @@ public class NotificationManagerService extends SystemService { case MESSAGE_FINISH_TOKEN_TIMEOUT: handleKillTokenTimeout((ToastRecord) msg.obj); break; case MESSAGE_SAVE_POLICY_FILE: handleSavePolicyFile(); break; case MESSAGE_SEND_RANKING_UPDATE: handleSendRankingUpdate(); break; Loading Loading @@ -6257,7 +6265,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, String.format("unsnooze event(%s, %s)", key, listenerName)); } mSnoozeHelper.repost(key); handleSavePolicyFile(); savePolicyFile(); } @GuardedBy("mNotificationLock") Loading