Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52e64d01 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Give assistant ability to modify channels.

Test: cts on same topic
Change-Id: Ia0db73d4d81a89e0821ba6a06f12823605dbea73
parent 6ae13327
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -35171,8 +35171,12 @@ package android.service.notification {
    ctor public NotificationAssistantService();
    method public final void adjustNotification(android.service.notification.Adjustment);
    method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>);
    method public void createNotificationChannel(java.lang.String, android.app.NotificationChannel);
    method public void deleteNotificationChannel(java.lang.String, java.lang.String);
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public abstract android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
    method public void updateNotificationChannel(java.lang.String, android.app.NotificationChannel);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
  }
+4 −0
Original line number Diff line number Diff line
@@ -38008,8 +38008,12 @@ package android.service.notification {
    ctor public NotificationAssistantService();
    method public final void adjustNotification(android.service.notification.Adjustment);
    method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>);
    method public void createNotificationChannel(java.lang.String, android.app.NotificationChannel);
    method public void deleteNotificationChannel(java.lang.String, java.lang.String);
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public abstract android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
    method public void updateNotificationChannel(java.lang.String, android.app.NotificationChannel);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
  }
+4 −0
Original line number Diff line number Diff line
@@ -35268,8 +35268,12 @@ package android.service.notification {
    ctor public NotificationAssistantService();
    method public final void adjustNotification(android.service.notification.Adjustment);
    method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>);
    method public void createNotificationChannel(java.lang.String, android.app.NotificationChannel);
    method public void deleteNotificationChannel(java.lang.String, java.lang.String);
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public abstract android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
    method public void updateNotificationChannel(java.lang.String, android.app.NotificationChannel);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
  }
+6 −2
Original line number Diff line number Diff line
@@ -99,8 +99,12 @@ interface INotificationManager
    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);
+72 −2
Original line number Diff line number Diff line
@@ -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.os.RemoteException;
import android.util.Log;
import com.android.internal.os.SomeArgs;

import java.util.ArrayList;
import java.util.List;

/**
@@ -79,9 +83,10 @@ public abstract class NotificationAssistantService extends NotificationListenerS
    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 abstract class NotificationAssistantService extends NotificationListenerS
    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,
Loading