Loading services/core/java/com/android/server/notification/NotificationManagerService.java +49 −55 Original line number Diff line number Diff line Loading @@ -207,6 +207,7 @@ 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 @@ -265,7 +266,7 @@ public class NotificationManagerService extends SystemService { // message codes static final int MESSAGE_DURATION_REACHED = 2; static final int MESSAGE_SAVE_POLICY_FILE = 3; // 3: removed to a different handler 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 @@ -573,7 +574,7 @@ public class NotificationManagerService extends SystemService { mListeners.migrateToXml(); mAssistants.migrateToXml(); mConditionProviders.migrateToXml(); savePolicyFile(); handleSavePolicyFile(); } mAssistants.ensureAssistant(); Loading Loading @@ -603,15 +604,9 @@ 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() { @VisibleForTesting protected void handleSavePolicyFile() { IoThread.getHandler().post(() -> { if (DBG) Slog.d(TAG, "handleSavePolicyFile"); synchronized (mPolicyFile) { final FileOutputStream stream; Loading @@ -631,6 +626,7 @@ public class NotificationManagerService extends SystemService { } } BackupManager.dataChanged(getContext().getPackageName()); }); } private void writePolicyXml(OutputStream stream, boolean forBackup) throws IOException { Loading Loading @@ -1138,8 +1134,9 @@ public class NotificationManagerService extends SystemService { } } mHandler.scheduleOnPackageChanged(removingPackage, changeUserId, pkgList, uidList); savePolicyFile(); handleSavePolicyFile(); } } }; Loading Loading @@ -1206,7 +1203,7 @@ public class NotificationManagerService extends SystemService { mListeners.onUserRemoved(userId); mConditionProviders.onUserRemoved(userId); mAssistants.onUserRemoved(userId); savePolicyFile(); handleSavePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); mUserProfiles.updateCache(context); Loading Loading @@ -1462,7 +1459,7 @@ public class NotificationManagerService extends SystemService { mZenModeHelper.addCallback(new ZenModeHelper.Callback() { @Override public void onConfigChanged() { savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -1764,7 +1761,7 @@ public class NotificationManagerService extends SystemService { modifiedChannel, NOTIFICATION_CHANNEL_OR_GROUP_UPDATED); } savePolicyFile(); handleSavePolicyFile(); } private void maybeNotifyChannelOwner(String pkg, int uid, NotificationChannel preUpdate, Loading Loading @@ -2232,7 +2229,7 @@ public class NotificationManagerService extends SystemService { Slog.w(TAG, "Can't notify app about app block change", e); } savePolicyFile(); handleSavePolicyFile(); } /** Loading Loading @@ -2289,7 +2286,7 @@ public class NotificationManagerService extends SystemService { public void setShowBadge(String pkg, int uid, boolean showBadge) { checkCallerIsSystem(); mPreferencesHelper.setShowBadge(pkg, uid, showBadge); savePolicyFile(); handleSavePolicyFile(); } @Override Loading @@ -2305,7 +2302,7 @@ public class NotificationManagerService extends SystemService { if (info != null) { mPreferencesHelper.setNotificationDelegate( callingPkg, callingUid, delegate, info.uid); savePolicyFile(); handleSavePolicyFile(); } } catch (RemoteException e) { // :( Loading @@ -2316,7 +2313,7 @@ public class NotificationManagerService extends SystemService { public void revokeNotificationDelegate(String callingPkg) { checkCallerIsSameApp(callingPkg); mPreferencesHelper.revokeNotificationDelegate(callingPkg, Binder.getCallingUid()); savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -2351,7 +2348,7 @@ public class NotificationManagerService extends SystemService { NotificationChannelGroup group) throws RemoteException { enforceSystemOrSystemUI("Caller not system or systemui"); createNotificationChannelGroup(pkg, uid, group, false, false); savePolicyFile(); handleSavePolicyFile(); } @Override Loading @@ -2364,7 +2361,7 @@ public class NotificationManagerService extends SystemService { final NotificationChannelGroup group = groups.get(i); createNotificationChannelGroup(pkg, Binder.getCallingUid(), group, true, false); } savePolicyFile(); handleSavePolicyFile(); } private void createNotificationChannelsImpl(String pkg, int uid, Loading @@ -2382,7 +2379,7 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.getNotificationChannel(pkg, uid, channel.getId(), false), NOTIFICATION_CHANNEL_OR_GROUP_ADDED); } savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -2427,7 +2424,7 @@ public class NotificationManagerService extends SystemService { UserHandle.getUserHandleForUid(callingUid), mPreferencesHelper.getNotificationChannel(pkg, callingUid, channelId, true), NOTIFICATION_CHANNEL_OR_GROUP_DELETED); savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -2469,7 +2466,7 @@ public class NotificationManagerService extends SystemService { mListeners.notifyNotificationChannelGroupChanged( pkg, UserHandle.getUserHandleForUid(callingUid), groupToDelete, NOTIFICATION_CHANNEL_OR_GROUP_DELETED); savePolicyFile(); handleSavePolicyFile(); } } Loading Loading @@ -2602,7 +2599,7 @@ public class NotificationManagerService extends SystemService { true, UserHandle.getCallingUserId(), packages, uids); } savePolicyFile(); handleSavePolicyFile(); } Loading Loading @@ -3390,7 +3387,7 @@ public class NotificationManagerService extends SystemService { final ByteArrayInputStream bais = new ByteArrayInputStream(payload); try { readPolicyXml(bais, true /*forRestore*/); savePolicyFile(); handleSavePolicyFile(); } catch (NumberFormatException | XmlPullParserException | IOException e) { Slog.w(TAG, "applyRestore: error reading payload", e); } Loading Loading @@ -3431,7 +3428,7 @@ public class NotificationManagerService extends SystemService { .setPackage(pkg) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); savePolicyFile(); handleSavePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3575,7 +3572,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); savePolicyFile(); handleSavePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading @@ -3601,7 +3598,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); savePolicyFile(); handleSavePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3684,7 +3681,7 @@ public class NotificationManagerService extends SystemService { verifyPrivilegedListener(token, user, false); createNotificationChannelGroup( pkg, getUidForPackageAndUser(pkg, user), group, false, true); savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -3733,7 +3730,7 @@ public class NotificationManagerService extends SystemService { } if (allow != mLockScreenAllowSecureNotifications) { mLockScreenAllowSecureNotifications = allow; savePolicyFile(); handleSavePolicyFile(); } } Loading Loading @@ -4492,7 +4489,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, "Ignored enqueue for snoozed notification " + r.getKey()); } mSnoozeHelper.update(userId, r); savePolicyFile(); handleSavePolicyFile(); return false; } Loading Loading @@ -4623,7 +4620,7 @@ public class NotificationManagerService extends SystemService { mSnoozeHelper.snooze(r, mDuration); } r.recordSnoozed(); savePolicyFile(); handleSavePolicyFile(); } } Loading Loading @@ -4701,7 +4698,7 @@ public class NotificationManagerService extends SystemService { if (mReason != REASON_SNOOZED) { final boolean wasSnoozed = mSnoozeHelper.cancel(mUserId, mPkg, mTag, mId); if (wasSnoozed) { savePolicyFile(); handleSavePolicyFile(); } } } Loading Loading @@ -5750,9 +5747,6 @@ 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 @@ -6270,7 +6264,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, String.format("unsnooze event(%s, %s)", key, listenerName)); } mSnoozeHelper.repost(key); savePolicyFile(); handleSavePolicyFile(); } @GuardedBy("mNotificationLock") Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -238,6 +238,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { protected void reportUserInteraction(NotificationRecord r) { return; } @Override protected void handleSavePolicyFile() { return; } } private class TestableToastCallback extends ITransientNotification.Stub { Loading Loading @@ -1809,7 +1814,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mListener = mock(ManagedServices.ManagedServiceInfo.class); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); try { mBinderService.getNotificationChannelGroupsFromPrivilegedListener( null, PKG, Process.myUserHandle()); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +49 −55 Original line number Diff line number Diff line Loading @@ -207,6 +207,7 @@ 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 @@ -265,7 +266,7 @@ public class NotificationManagerService extends SystemService { // message codes static final int MESSAGE_DURATION_REACHED = 2; static final int MESSAGE_SAVE_POLICY_FILE = 3; // 3: removed to a different handler 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 @@ -573,7 +574,7 @@ public class NotificationManagerService extends SystemService { mListeners.migrateToXml(); mAssistants.migrateToXml(); mConditionProviders.migrateToXml(); savePolicyFile(); handleSavePolicyFile(); } mAssistants.ensureAssistant(); Loading Loading @@ -603,15 +604,9 @@ 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() { @VisibleForTesting protected void handleSavePolicyFile() { IoThread.getHandler().post(() -> { if (DBG) Slog.d(TAG, "handleSavePolicyFile"); synchronized (mPolicyFile) { final FileOutputStream stream; Loading @@ -631,6 +626,7 @@ public class NotificationManagerService extends SystemService { } } BackupManager.dataChanged(getContext().getPackageName()); }); } private void writePolicyXml(OutputStream stream, boolean forBackup) throws IOException { Loading Loading @@ -1138,8 +1134,9 @@ public class NotificationManagerService extends SystemService { } } mHandler.scheduleOnPackageChanged(removingPackage, changeUserId, pkgList, uidList); savePolicyFile(); handleSavePolicyFile(); } } }; Loading Loading @@ -1206,7 +1203,7 @@ public class NotificationManagerService extends SystemService { mListeners.onUserRemoved(userId); mConditionProviders.onUserRemoved(userId); mAssistants.onUserRemoved(userId); savePolicyFile(); handleSavePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); mUserProfiles.updateCache(context); Loading Loading @@ -1462,7 +1459,7 @@ public class NotificationManagerService extends SystemService { mZenModeHelper.addCallback(new ZenModeHelper.Callback() { @Override public void onConfigChanged() { savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -1764,7 +1761,7 @@ public class NotificationManagerService extends SystemService { modifiedChannel, NOTIFICATION_CHANNEL_OR_GROUP_UPDATED); } savePolicyFile(); handleSavePolicyFile(); } private void maybeNotifyChannelOwner(String pkg, int uid, NotificationChannel preUpdate, Loading Loading @@ -2232,7 +2229,7 @@ public class NotificationManagerService extends SystemService { Slog.w(TAG, "Can't notify app about app block change", e); } savePolicyFile(); handleSavePolicyFile(); } /** Loading Loading @@ -2289,7 +2286,7 @@ public class NotificationManagerService extends SystemService { public void setShowBadge(String pkg, int uid, boolean showBadge) { checkCallerIsSystem(); mPreferencesHelper.setShowBadge(pkg, uid, showBadge); savePolicyFile(); handleSavePolicyFile(); } @Override Loading @@ -2305,7 +2302,7 @@ public class NotificationManagerService extends SystemService { if (info != null) { mPreferencesHelper.setNotificationDelegate( callingPkg, callingUid, delegate, info.uid); savePolicyFile(); handleSavePolicyFile(); } } catch (RemoteException e) { // :( Loading @@ -2316,7 +2313,7 @@ public class NotificationManagerService extends SystemService { public void revokeNotificationDelegate(String callingPkg) { checkCallerIsSameApp(callingPkg); mPreferencesHelper.revokeNotificationDelegate(callingPkg, Binder.getCallingUid()); savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -2351,7 +2348,7 @@ public class NotificationManagerService extends SystemService { NotificationChannelGroup group) throws RemoteException { enforceSystemOrSystemUI("Caller not system or systemui"); createNotificationChannelGroup(pkg, uid, group, false, false); savePolicyFile(); handleSavePolicyFile(); } @Override Loading @@ -2364,7 +2361,7 @@ public class NotificationManagerService extends SystemService { final NotificationChannelGroup group = groups.get(i); createNotificationChannelGroup(pkg, Binder.getCallingUid(), group, true, false); } savePolicyFile(); handleSavePolicyFile(); } private void createNotificationChannelsImpl(String pkg, int uid, Loading @@ -2382,7 +2379,7 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.getNotificationChannel(pkg, uid, channel.getId(), false), NOTIFICATION_CHANNEL_OR_GROUP_ADDED); } savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -2427,7 +2424,7 @@ public class NotificationManagerService extends SystemService { UserHandle.getUserHandleForUid(callingUid), mPreferencesHelper.getNotificationChannel(pkg, callingUid, channelId, true), NOTIFICATION_CHANNEL_OR_GROUP_DELETED); savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -2469,7 +2466,7 @@ public class NotificationManagerService extends SystemService { mListeners.notifyNotificationChannelGroupChanged( pkg, UserHandle.getUserHandleForUid(callingUid), groupToDelete, NOTIFICATION_CHANNEL_OR_GROUP_DELETED); savePolicyFile(); handleSavePolicyFile(); } } Loading Loading @@ -2602,7 +2599,7 @@ public class NotificationManagerService extends SystemService { true, UserHandle.getCallingUserId(), packages, uids); } savePolicyFile(); handleSavePolicyFile(); } Loading Loading @@ -3390,7 +3387,7 @@ public class NotificationManagerService extends SystemService { final ByteArrayInputStream bais = new ByteArrayInputStream(payload); try { readPolicyXml(bais, true /*forRestore*/); savePolicyFile(); handleSavePolicyFile(); } catch (NumberFormatException | XmlPullParserException | IOException e) { Slog.w(TAG, "applyRestore: error reading payload", e); } Loading Loading @@ -3431,7 +3428,7 @@ public class NotificationManagerService extends SystemService { .setPackage(pkg) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); savePolicyFile(); handleSavePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3575,7 +3572,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); savePolicyFile(); handleSavePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading @@ -3601,7 +3598,7 @@ public class NotificationManagerService extends SystemService { .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.of(userId), null); savePolicyFile(); handleSavePolicyFile(); } } finally { Binder.restoreCallingIdentity(identity); Loading Loading @@ -3684,7 +3681,7 @@ public class NotificationManagerService extends SystemService { verifyPrivilegedListener(token, user, false); createNotificationChannelGroup( pkg, getUidForPackageAndUser(pkg, user), group, false, true); savePolicyFile(); handleSavePolicyFile(); } @Override Loading Loading @@ -3733,7 +3730,7 @@ public class NotificationManagerService extends SystemService { } if (allow != mLockScreenAllowSecureNotifications) { mLockScreenAllowSecureNotifications = allow; savePolicyFile(); handleSavePolicyFile(); } } Loading Loading @@ -4492,7 +4489,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, "Ignored enqueue for snoozed notification " + r.getKey()); } mSnoozeHelper.update(userId, r); savePolicyFile(); handleSavePolicyFile(); return false; } Loading Loading @@ -4623,7 +4620,7 @@ public class NotificationManagerService extends SystemService { mSnoozeHelper.snooze(r, mDuration); } r.recordSnoozed(); savePolicyFile(); handleSavePolicyFile(); } } Loading Loading @@ -4701,7 +4698,7 @@ public class NotificationManagerService extends SystemService { if (mReason != REASON_SNOOZED) { final boolean wasSnoozed = mSnoozeHelper.cancel(mUserId, mPkg, mTag, mId); if (wasSnoozed) { savePolicyFile(); handleSavePolicyFile(); } } } Loading Loading @@ -5750,9 +5747,6 @@ 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 @@ -6270,7 +6264,7 @@ public class NotificationManagerService extends SystemService { Slog.d(TAG, String.format("unsnooze event(%s, %s)", key, listenerName)); } mSnoozeHelper.repost(key); savePolicyFile(); handleSavePolicyFile(); } @GuardedBy("mNotificationLock") Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -238,6 +238,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { protected void reportUserInteraction(NotificationRecord r) { return; } @Override protected void handleSavePolicyFile() { return; } } private class TestableToastCallback extends ITransientNotification.Stub { Loading Loading @@ -1809,7 +1814,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mListener = mock(ManagedServices.ManagedServiceInfo.class); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); try { mBinderService.getNotificationChannelGroupsFromPrivilegedListener( null, PKG, Process.myUserHandle()); Loading