Give assistant ability to modify channels.

Test: cts on same topic
Change-Id: Ia0db73d4d81a89e0821ba6a06f12823605dbea73
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 927ef6c..2c4e7a0 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -99,8 +99,12 @@
     void setOnNotificationPostedTrimFromListener(in INotificationListener token, int trim);
     void setInterruptionFilter(String pkg, int interruptionFilter);
 
-    void applyAdjustmentFromAssistantService(in INotificationListener token, in Adjustment adjustment);
-    void applyAdjustmentsFromAssistantService(in INotificationListener token, in List<Adjustment> adjustments);
+    void applyAdjustmentFromAssistant(in INotificationListener token, in Adjustment adjustment);
+    void applyAdjustmentsFromAssistant(in INotificationListener token, in List<Adjustment> adjustments);
+    void createNotificationChannelFromAssistant(in INotificationListener token, String pkg, in NotificationChannel channel);
+    void updateNotificationChannelFromAssistant(in INotificationListener token, String pkg, in NotificationChannel channel);
+    void deleteNotificationChannelFromAssistant(in INotificationListener token, String pkg, String channelId);
+    ParceledListSlice getNotificationChannelsFromAssistant(in INotificationListener token, String pkg);
 
     ComponentName getEffectsSuppressor();
     boolean matchesCallFilter(in Bundle extras);
diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java
index 4e00c64..51ba8c72 100644
--- a/core/java/android/service/notification/NotificationAssistantService.java
+++ b/core/java/android/service/notification/NotificationAssistantService.java
@@ -16,7 +16,10 @@
 
 package android.service.notification;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.annotation.SdkConstant;
+import android.app.NotificationChannel;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Handler;
@@ -27,6 +30,7 @@
 import android.util.Log;
 import com.android.internal.os.SomeArgs;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -79,9 +83,10 @@
     public final void adjustNotification(Adjustment adjustment) {
         if (!isBound()) return;
         try {
-            getNotificationInterface().applyAdjustmentFromAssistantService(mWrapper, adjustment);
+            getNotificationInterface().applyAdjustmentFromAssistant(mWrapper, adjustment);
         } catch (android.os.RemoteException ex) {
             Log.v(TAG, "Unable to contact notification manager", ex);
+            throw ex.rethrowFromSystemServer();
         }
     }
 
@@ -95,12 +100,77 @@
     public final void adjustNotifications(List<Adjustment> adjustments) {
         if (!isBound()) return;
         try {
-            getNotificationInterface().applyAdjustmentsFromAssistantService(mWrapper, adjustments);
+            getNotificationInterface().applyAdjustmentsFromAssistant(mWrapper, adjustments);
         } catch (android.os.RemoteException ex) {
             Log.v(TAG, "Unable to contact notification manager", ex);
+            throw ex.rethrowFromSystemServer();
         }
     }
 
+    /**
+     * Creates a notification channel that notifications can be posted to for a given package.
+     *
+     * @param pkg The package to create a channel for.
+     * @param channel  the channel to attempt to create.
+     */
+    public void createNotificationChannel(@NonNull String pkg,
+            @NonNull NotificationChannel channel) {
+        if (!isBound()) return;
+        try {
+            getNotificationInterface().createNotificationChannelFromAssistant(
+                    mWrapper, pkg, channel);
+        } catch (RemoteException e) {
+            Log.v(TAG, "Unable to contact notification manager", e);
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Updates a notification channel for a given package.
+     *
+     * @param pkg The package to the channel belongs to.
+     * @param channel the channel to attempt to update.
+     */
+    public void updateNotificationChannel(@NonNull String pkg,
+            @NonNull NotificationChannel channel) {
+        if (!isBound()) return;
+        try {
+            getNotificationInterface().updateNotificationChannelFromAssistant(
+                    mWrapper, pkg, channel);
+        } catch (RemoteException e) {
+            Log.v(TAG, "Unable to contact notification manager", e);
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Returns all notification channels belonging to the given package.
+     */
+    public List<NotificationChannel> getNotificationChannels(@NonNull String pkg) {
+        if (!isBound()) return null;
+        try {
+            return getNotificationInterface().getNotificationChannelsFromAssistant(
+                    mWrapper, pkg).getList();
+        } catch (RemoteException e) {
+            Log.v(TAG, "Unable to contact notification manager", e);
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Deletes the given notification channel.
+     */
+    public void deleteNotificationChannel(@NonNull String pkg, @NonNull String channelId) {
+        if (!isBound()) return;
+        try {
+            getNotificationInterface().deleteNotificationChannelFromAssistant(
+                    mWrapper, pkg, channelId);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+
     private class NotificationAssistantServiceWrapper extends NotificationListenerWrapper {
         @Override
         public void onNotificationEnqueued(IStatusBarNotificationHolder sbnHolder,