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

Commit 7e9ad046 authored by Alisa Hung's avatar Alisa Hung
Browse files

Add a new API to create conversation notification channels from the NAS.

This API is guarded by a new flag, FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT.

Design doc: go/nas-25q2-blue

Bug: 374245127
Bug: 373599715
Change-Id: I79b4a864ebf044baf0912b7eef992c071cd4c573
Test: NotificationManagerServiceTest
Flag: android.service.notification.notification_conversation_channel_management
parent 64a3dbc8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41481,6 +41481,7 @@ package android.service.notification {
    method public final void cancelNotification(String);
    method public final void cancelNotifications(String[]);
    method public final void clearRequestedListenerHints();
    method @FlaggedApi("android.service.notification.notification_conversation_channel_management") @Nullable public final android.app.NotificationChannel createConversationNotificationChannelForPackage(@NonNull String, @NonNull android.os.UserHandle, @NonNull String, @NonNull String);
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.service.notification.StatusBarNotification[] getActiveNotifications(String[]);
    method public final int getCurrentInterruptionFilter();
+1 −0
Original line number Diff line number Diff line
@@ -369,6 +369,7 @@ package android.app {
  }

  public final class NotificationChannel implements android.os.Parcelable {
    method @FlaggedApi("android.service.notification.notification_conversation_channel_management") @NonNull public android.app.NotificationChannel copy();
    method public int getOriginalImportance();
    method public boolean isImportanceLockedByCriticalDeviceFunction();
    method public void lockFields(int);
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ interface INotificationManager
    void setOnNotificationPostedTrimFromListener(in INotificationListener token, int trim);
    void setInterruptionFilter(String pkg, int interruptionFilter, boolean fromUser);

    NotificationChannel createConversationNotificationChannelForPackageFromPrivilegedListener(in INotificationListener token, String pkg, in UserHandle user, String parentChannelId, String conversationId);
    void updateNotificationChannelGroupFromPrivilegedListener(in INotificationListener token, String pkg, in UserHandle user, in NotificationChannelGroup group);
    void updateNotificationChannelFromPrivilegedListener(in INotificationListener token, String pkg, in UserHandle user, in NotificationChannel channel);
    ParceledListSlice getNotificationChannelsFromPrivilegedListener(in INotificationListener token, String pkg, in UserHandle user);
+6 −3
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package android.app;

import static android.service.notification.Flags.FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -475,9 +477,10 @@ public final class NotificationChannel implements Parcelable {
        dest.writeBoolean(mImportanceLockedDefaultApp);
    }

    /**
     * @hide
     */
    /** @hide */
    @TestApi
    @NonNull
    @FlaggedApi(FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT)
    public NotificationChannel copy() {
        NotificationChannel copy = new NotificationChannel(mId, mName, mImportance);
        copy.setDescription(mDesc);
+30 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.service.notification;

import android.annotation.CurrentTimeMillisLong;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -882,6 +883,35 @@ public abstract class NotificationListenerService extends Service {
        }
    }

    /**
     * Creates a conversation notification channel for a given package for a given user.
     *
     * <p>This method will throw a security exception if you don't have access to notifications
     * for the given user.</p>
     * <p>The caller must have {@link CompanionDeviceManager#getAssociations() an associated
     * device} or be the notification assistant in order to use this method.
     *
     * @param pkg The package the channel belongs to.
     * @param user The user the channel belongs to.
     * @param parentChannelId The parent channel id of the conversation channel belongs to.
     * @param conversationId The conversation id of the conversation channel.
     *
     * @return The created conversation channel.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT)
    public final @Nullable NotificationChannel createConversationNotificationChannelForPackage(
        @NonNull String pkg, @NonNull UserHandle user, @NonNull String parentChannelId,
        @NonNull String conversationId) {
        if (!isBound()) return null;
        try {
            return getNotificationInterface()
                    .createConversationNotificationChannelForPackageFromPrivilegedListener(
                            mWrapper, pkg, user, parentChannelId, conversationId);
        } catch (RemoteException e) {
            Log.v(TAG, "Unable to contact notification manager", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Updates a notification channel for a given package for a given user. This should only be used
Loading