AccountManagerService send pkg uid when creating notification channel

AccountManager needs to pass the app's uid explicitly in order for the
channel lookup to not fail. Requires separate API that only system can
call.

Bug: 36511867
Test: Install Clankium and reboot device, observe Notification
Change-Id: I6ddd87d755b4b2129565dd275e799b0349a80936
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 5ea2480..43cad5b 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -57,6 +57,7 @@
 
     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 097df31..75998f2 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -453,19 +453,6 @@
     }
 
     /**
-     * @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 c840f26..ef20750 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 @@
                 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 @@
                 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 490e63d..df292ad 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 @@
             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 7e10a09..53a4036 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 @@
             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(