diff options
5 files changed, 37 insertions, 24 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 5ea24804e0fd..43cad5b2f729 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -57,6 +57,7 @@ interface INotificationManager void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList); void createNotificationChannels(String pkg, in ParceledListSlice channelsList); + void createNotificationChannelsForPackage(String pkg, int uid, in ParceledListSlice channelsList); ParceledListSlice getNotificationChannelGroupsForPackage(String pkg, int uid, boolean includeDeleted); NotificationChannelGroup getNotificationChannelGroupForPackage(String groupId, String pkg, int uid); void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel); diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 097df31ac96e..75998f2eb36d 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -453,19 +453,6 @@ public class NotificationManager } /** - * @hide - */ - public void createNotificationChannelsForPackage(String pkg, - @NonNull List<NotificationChannel> channels) { - INotificationManager service = getService(); - try { - service.createNotificationChannels(pkg, new ParceledListSlice(channels)); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - - /** * Returns the notification channel settings for a given channel id. */ public NotificationChannel getNotificationChannel(String channelId) { diff --git a/core/java/com/android/internal/notification/SystemNotificationChannels.java b/core/java/com/android/internal/notification/SystemNotificationChannels.java index c840f26a0d53..ef20750cdb19 100644 --- a/core/java/com/android/internal/notification/SystemNotificationChannels.java +++ b/core/java/com/android/internal/notification/SystemNotificationChannels.java @@ -14,10 +14,13 @@ package com.android.internal.notification; +import android.app.INotificationManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; +import android.content.pm.ParceledListSlice; +import android.os.RemoteException; import android.provider.Settings; import com.android.internal.R; @@ -69,6 +72,8 @@ public class SystemNotificationChannels { context.getString(R.string.notification_channel_car_mode), NotificationManager.IMPORTANCE_LOW)); + channelsList.add(newAccountChannel(context)); + channelsList.add(new NotificationChannel( DEVELOPER, context.getString(R.string.notification_channel_developer), @@ -121,15 +126,23 @@ public class SystemNotificationChannels { NotificationManager.IMPORTANCE_MIN)); nm.createNotificationChannels(channelsList); - createAccountChannelForPackage(context.getPackageName(), context); } - public static void createAccountChannelForPackage(String pkg, Context context) { - final NotificationManager nm = context.getSystemService(NotificationManager.class); - nm.createNotificationChannelsForPackage(pkg, Arrays.asList(new NotificationChannel( + public static void createAccountChannelForPackage(String pkg, int uid, Context context) { + final INotificationManager iNotificationManager = NotificationManager.getService(); + try { + iNotificationManager.createNotificationChannelsForPackage(pkg, uid, + new ParceledListSlice(Arrays.asList(newAccountChannel(context)))); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + private static NotificationChannel newAccountChannel(Context context) { + return new NotificationChannel( ACCOUNT, context.getString(R.string.notification_channel_account), - NotificationManager.IMPORTANCE_LOW))); + NotificationManager.IMPORTANCE_LOW); } private SystemNotificationChannels() {} diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java index 490e63d29659..df292addb33f 100644 --- a/services/core/java/com/android/server/accounts/AccountManagerService.java +++ b/services/core/java/com/android/server/accounts/AccountManagerService.java @@ -5677,7 +5677,7 @@ public class AccountManagerService synchronized (mUsers) { userAccounts = mUsers.get(userId); } - SystemNotificationChannels.createAccountChannelForPackage(packageName, mContext); + SystemNotificationChannels.createAccountChannelForPackage(packageName, uid, mContext); doNotification(userAccounts, account, null, intent, packageName, userId); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 7e10a09eab4b..53a403603a5b 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1633,22 +1633,34 @@ public class NotificationManagerService extends SystemService { savePolicyFile(); } - @Override - public void createNotificationChannels(String pkg, - ParceledListSlice channelsList) throws RemoteException { - checkCallerIsSystemOrSameApp(pkg); + private void createNotificationChannelsImpl(String pkg, int uid, + ParceledListSlice channelsList) { List<NotificationChannel> channels = channelsList.getList(); final int channelsSize = channels.size(); for (int i = 0; i < channelsSize; i++) { final NotificationChannel channel = channels.get(i); Preconditions.checkNotNull(channel, "channel in list is null"); - mRankingHelper.createNotificationChannel(pkg, Binder.getCallingUid(), channel, + mRankingHelper.createNotificationChannel(pkg, uid, channel, true /* fromTargetApp */); } savePolicyFile(); } @Override + public void createNotificationChannels(String pkg, + ParceledListSlice channelsList) throws RemoteException { + checkCallerIsSystemOrSameApp(pkg); + createNotificationChannelsImpl(pkg, Binder.getCallingUid(), channelsList); + } + + @Override + public void createNotificationChannelsForPackage(String pkg, int uid, + ParceledListSlice channelsList) throws RemoteException { + checkCallerIsSystem(); + createNotificationChannelsImpl(pkg, uid, channelsList); + } + + @Override public NotificationChannel getNotificationChannel(String pkg, String channelId) { checkCallerIsSystemOrSameApp(pkg); return mRankingHelper.getNotificationChannel( |