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

Commit 0bd3685b authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add API for NAS to tell us it doesn't support some adjustments

Test: NotificationAssistantTest
Test: NotificationAssistantsTest
Flag: android.service.notification.notification_classification
Bug: 369371269
Change-Id: Icf6397119afccd5a2742b5a3355d20cd1f2b2292
parent bce7071f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13018,6 +13018,7 @@ package android.service.notification {
    method public void onPanelHidden();
    method public void onPanelRevealed(int);
    method public void onSuggestedReplySent(@NonNull String, @NonNull CharSequence, int);
    method @FlaggedApi("android.service.notification.notification_classification") public final void setAdjustmentTypeSupportedState(@NonNull String, boolean);
    method public final void unsnoozeNotification(@NonNull String);
    field public static final String ACTION_NOTIFICATION_ASSISTANT_DETAIL_SETTINGS = "android.service.notification.action.NOTIFICATION_ASSISTANT_DETAIL_SETTINGS";
    field public static final String FEEDBACK_RATING = "feedback.rating";
+1 −0
Original line number Diff line number Diff line
@@ -396,6 +396,7 @@ package android.app {
    method public void cleanUpCallersAfter(long);
    method @FlaggedApi("android.app.modes_api") @NonNull public android.service.notification.ZenPolicy getDefaultZenPolicy();
    method public android.content.ComponentName getEffectsSuppressor();
    method @FlaggedApi("android.service.notification.notification_classification") @NonNull public java.util.Set<java.lang.String> getUnsupportedAdjustmentTypes();
    method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String);
    method @FlaggedApi("android.app.modes_api") public boolean removeAutomaticZenRule(@NonNull String, boolean);
    method @FlaggedApi("android.app.api_rich_ongoing") public void setCanPostPromotedNotifications(@NonNull String, int, boolean);
+4 −1
Original line number Diff line number Diff line
@@ -160,8 +160,8 @@ interface INotificationManager
    void requestBindProvider(in ComponentName component);
    void requestUnbindProvider(in IConditionProvider token);

    void setNotificationsShownFromListener(in INotificationListener token, in String[] keys);

    void setNotificationsShownFromListener(in INotificationListener token, in String[] keys);
    ParceledListSlice getActiveNotificationsFromListener(in INotificationListener token, in String[] keys, int trim);
    ParceledListSlice getSnoozedNotificationsFromListener(in INotificationListener token, int trim);
    void clearRequestedListenerHints(in INotificationListener token);
@@ -261,4 +261,7 @@ interface INotificationManager
    void setCanBePromoted(String pkg, int uid, boolean promote);
    boolean appCanBePromoted(String pkg, int uid);
    boolean canBePromoted(String pkg);

    void setAdjustmentTypeSupportedState(in INotificationListener token, String key, boolean supported);
    List<String> getUnsupportedAdjustmentTypes();
}
+17 −0
Original line number Diff line number Diff line
@@ -68,9 +68,11 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;

/**
@@ -3094,4 +3096,19 @@ public class NotificationManager {
        }
    }

    /**
     * Returns the list of {@link Adjustment} keys that the current approved
     * {@link android.service.notification.NotificationAssistantService} does not support.
     * @hide
     */
    @TestApi
    @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public @NonNull Set<String> getUnsupportedAdjustmentTypes() {
        INotificationManager service = getService();
        try {
            return new HashSet<>(service.getUnsupportedAdjustmentTypes());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.service.notification;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -367,6 +368,23 @@ public abstract class NotificationAssistantService extends NotificationListenerS
        }
    }

    /**
     * Informs the notification manager about what {@link Adjustment Adjustments} are supported by
     * this NAS.
     *
     * For backwards compatibility, we assume all Adjustment types are supported by the NAS.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public final void setAdjustmentTypeSupportedState(@NonNull @Adjustment.Keys String key,
            boolean supported) {
        if (!isBound()) return;
        try {
            getNotificationInterface().setAdjustmentTypeSupportedState(mWrapper, key, supported);
        } catch (android.os.RemoteException ex) {
            Log.v(TAG, "Unable to contact notification manager", ex);
        }
    }

    private class NotificationAssistantServiceWrapper extends NotificationListenerWrapper {
        @Override
        public void onNotificationEnqueuedWithChannel(IStatusBarNotificationHolder sbnHolder,
Loading