+ @Override
+ public NotificationChannel getNotificationChannelForPackage(String pkg, int uid,
+ String channelId, boolean includeDeleted) {
+ checkCallerIsSystem();
+ return mRankingHelper.getNotificationChannel(pkg, uid, channelId, includeDeleted);
+ }
+
+ @Override
+ public void deleteNotificationChannel(String pkg, String channelId) {
+ checkCallerIsSystemOrSameApp(pkg);
+ final int callingUid = Binder.getCallingUid();
+ if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(channelId)) {
+ throw new IllegalArgumentException("Cannot delete default channel");
+ }
+ cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true,
+ UserHandle.getUserId(callingUid), REASON_CHANNEL_BANNED, null);
+ mRankingHelper.deleteNotificationChannel(pkg, callingUid, channelId);
+ mListeners.notifyNotificationChannelChanged(pkg,
+ UserHandle.getUserHandleForUid(callingUid),
+ mRankingHelper.getNotificationChannel(pkg, callingUid, channelId, true),
+ NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
+ savePolicyFile();
+ }
+
+ @Override
+ public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(
+ String pkg) {
+ checkCallerIsSystemOrSameApp(pkg);
+ return new ParceledListSlice<>(new ArrayList(
+ mRankingHelper.getNotificationChannelGroups(pkg, Binder.getCallingUid())));
+ }
+
+ @Override
+ public void deleteNotificationChannelGroup(String pkg, String groupId) {
+ checkCallerIsSystemOrSameApp(pkg);
+
+ final int callingUid = Binder.getCallingUid();
+ NotificationChannelGroup groupToDelete =
+ mRankingHelper.getNotificationChannelGroup(groupId, pkg, callingUid);
+ if (groupToDelete != null) {
+ List<NotificationChannel> deletedChannels =
+ mRankingHelper.deleteNotificationChannelGroup(pkg, callingUid, groupId);
+ for (int i = 0; i < deletedChannels.size(); i++) {
+ final NotificationChannel deletedChannel = deletedChannels.get(i);
+ cancelAllNotificationsInt(MY_UID, MY_PID, pkg, deletedChannel.getId(), 0, 0,
+ true,
+ UserHandle.getUserId(Binder.getCallingUid()), REASON_CHANNEL_BANNED,
+ null);
+ mListeners.notifyNotificationChannelChanged(pkg,
+ UserHandle.getUserHandleForUid(callingUid),
+ deletedChannel,
+ NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
+ }
+ mListeners.notifyNotificationChannelGroupChanged(
+ pkg, UserHandle.getUserHandleForUid(callingUid), groupToDelete,
+ NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
+ savePolicyFile();
+ }
+ }
+
+ @Override
+ public void updateNotificationChannelForPackage(String pkg, int uid,
+ NotificationChannel channel) {
+ enforceSystemOrSystemUI("Caller not system or systemui");
+ Preconditions.checkNotNull(channel);
+ updateNotificationChannelInt(pkg, uid, channel, false);
+ }
+
+ @Override
+ public ParceledListSlice<NotificationChannel> getNotificationChannelsForPackage(String pkg,
+ int uid, boolean includeDeleted) {
+ enforceSystemOrSystemUI("getNotificationChannelsForPackage");
+ return mRankingHelper.getNotificationChannels(pkg, uid, includeDeleted);
+ }
+
+ @Override
+ public int getNumNotificationChannelsForPackage(String pkg, int uid,
+ boolean includeDeleted) {
+ enforceSystemOrSystemUI("getNumNotificationChannelsForPackage");
+ return mRankingHelper.getNotificationChannels(pkg, uid, includeDeleted)
+ .getList().size();
+ }
+
+ @Override
+ public boolean onlyHasDefaultChannel(String pkg, int uid) {
+ enforceSystemOrSystemUI("onlyHasDefaultChannel");
+ return mRankingHelper.onlyHasDefaultChannel(pkg, uid);
+ }
+
+ @Override
+ public int getDeletedChannelCount(String pkg, int uid) {
+ enforceSystemOrSystemUI("getDeletedChannelCount");
+ return mRankingHelper.getDeletedChannelCount(pkg, uid);
+ }
+
+ @Override
+ public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage(
+ String pkg, int uid, boolean includeDeleted) {
+ checkCallerIsSystem();
+ return mRankingHelper.getNotificationChannelGroups(pkg, uid, includeDeleted);
+ }
+
+ @Override
+ public NotificationChannelGroup getNotificationChannelGroupForPackage(
+ String groupId, String pkg, int uid) {
+ enforceSystemOrSystemUI("getNotificationChannelGroupForPackage");
+ return mRankingHelper.getNotificationChannelGroup(groupId, pkg, uid);
+ }
+
+ @Override
+ public ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg) {
+ checkCallerIsSystemOrSameApp(pkg);
+ return mRankingHelper.getNotificationChannels(
+ pkg, Binder.getCallingUid(), false /* includeDeleted */);
+ }
+
+ @Override
+ public void clearData(String packageName, int uid, boolean fromApp) throws RemoteException {
+ checkCallerIsSystem();
+
+ // Cancel posted notifications
+ cancelAllNotificationsInt(MY_UID, MY_PID, packageName, null, 0, 0, true,
+ UserHandle.getUserId(Binder.getCallingUid()), REASON_CHANNEL_BANNED, null);
+
+ final String[] packages = new String[] {packageName};
+ final int[] uids = new int[] {uid};
+
+ // Listener & assistant
+ mListeners.onPackagesChanged(true, packages, uids);
+ mAssistants.onPackagesChanged(true, packages, uids);
+
+ // Zen
+ mConditionProviders.onPackagesChanged(true, packages, uids);
+
+ // Reset notification preferences
+ if (!fromApp) {
+ mRankingHelper.onPackagesChanged(
+ true, UserHandle.getCallingUserId(), packages, uids);
+ }
+
+ savePolicyFile();
+ }
+
+
+ /**
+ * System-only API for getting a list of current (i.e. not cleared) notifications.
+ *
+ * Requires ACCESS_NOTIFICATIONS which is signature|system.
+ * @returns A list of all the notifications, in natural order.
+ */
+ @Override
+ public StatusBarNotification[] getActiveNotifications(String callingPkg) {
+ // enforce() will ensure the calling uid has the correct permission
+ getContext().enforceCallingOrSelfPermission(
+ android.Manifest.permission.ACCESS_NOTIFICATIONS,
+ "NotificationManagerService.getActiveNotifications");
+
+ StatusBarNotification[] tmp = null;
+ int uid = Binder.getCallingUid();