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

Commit ff708383 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Allow the NAS to set a type for notifications.

Some of the types will redirect a notification to a new, reserved,
silent-by-default channel.

Fixes: 344013362
Fixes: 344015982
Fixes: 344015984

Test: NotificationAssistantServiceTest
Test: NotificationRecordTest
Test: PreferencesHelperTest
Change-Id: I1173dd9600164621b2e9ce08527d90a3177297d2
parent adefe413
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -12886,7 +12886,14 @@ package android.service.notification {
    field public static final String KEY_SENSITIVE_CONTENT = "key_sensitive_content";
    field public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria";
    field public static final String KEY_TEXT_REPLIES = "key_text_replies";
    field @FlaggedApi("android.service.notification.notification_classification") public static final String KEY_TYPE = "key_type";
    field public static final String KEY_USER_SENTIMENT = "key_user_sentiment";
    field @FlaggedApi("android.service.notification.notification_classification") public static final int TYPE_CONTENT_RECOMMENDATION = 4; // 0x4
    field @FlaggedApi("android.service.notification.notification_classification") public static final int TYPE_NEWS = 3; // 0x3
    field @FlaggedApi("android.service.notification.notification_classification") public static final int TYPE_OTHER = 0; // 0x0
    field @FlaggedApi("android.service.notification.notification_classification") public static final int TYPE_PROMOTION = 1; // 0x1
    field @FlaggedApi("android.service.notification.notification_classification") public static final int TYPE_SOCIAL_MEDIA = 2; // 0x2
    field @FlaggedApi("android.service.notification.notification_classification") public static final int TYPE_UNKNOWN = -1; // 0xffffffff
  }
  public abstract class NotificationAssistantService extends android.service.notification.NotificationListenerService {
+4 −0
Original line number Diff line number Diff line
@@ -379,6 +379,10 @@ package android.app {
    method public void setImportantConversation(boolean);
    method public void setOriginalImportance(int);
    method public void setUserVisibleTaskShown(boolean);
    field @FlaggedApi("android.service.notification.notification_classification") public static final String NEWS_ID = "android.app.news";
    field @FlaggedApi("android.service.notification.notification_classification") public static final String PROMOTIONS_ID = "android.app.promotions";
    field @FlaggedApi("android.service.notification.notification_classification") public static final String RECS_ID = "android.app.recs";
    field @FlaggedApi("android.service.notification.notification_classification") public static final String SOCIAL_MEDIA_ID = "android.app.social";
  }

  public final class NotificationChannelGroup implements android.os.Parcelable {
+29 −0
Original line number Diff line number Diff line
@@ -71,6 +71,35 @@ public final class NotificationChannel implements Parcelable {
     */
    public static final String DEFAULT_CHANNEL_ID = "miscellaneous";

    /**
     * A reserved id for a system channel reserved for promotional notifications.
     *  @hide
     */
    @TestApi
    @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final String PROMOTIONS_ID = "android.app.promotions";
    /**
     * A reserved id for a system channel reserved for non-conversation social media notifications.
     *  @hide
     */
    @TestApi
    @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final String SOCIAL_MEDIA_ID = "android.app.social";
    /**
     * A reserved id for a system channel reserved for news notifications.
     *  @hide
     */
    @TestApi
    @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final String NEWS_ID = "android.app.news";
    /**
     * A reserved id for a system channel reserved for content recommendation notifications.
     *  @hide
     */
    @TestApi
    @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final String RECS_ID = "android.app.recs";

    /**
     * The formatter used by the system to create an id for notification
     * channels when it automatically creates conversation channels on behalf of an app. The format
+57 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package android.service.notification;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
@@ -62,7 +64,8 @@ public final class Adjustment implements Parcelable {
            KEY_IMPORTANCE_PROPOSAL,
            KEY_SENSITIVE_CONTENT,
            KEY_RANKING_SCORE,
            KEY_NOT_CONVERSATION
            KEY_NOT_CONVERSATION,
            KEY_TYPE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Keys {}
@@ -171,6 +174,59 @@ public final class Adjustment implements Parcelable {
    @SystemApi
    public static final String KEY_NOT_CONVERSATION = "key_not_conversation";

    /**
     * Data type: int, the classification type of this notification. The OS may display
     * notifications differently depending on the type, and may change the alerting level of the
     * notification.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final String KEY_TYPE = "key_type";

    /** @hide */
    @IntDef(prefix = { "TYPE_" }, value = {
            TYPE_UNKNOWN,
            TYPE_OTHER,
            TYPE_PROMOTION,
            TYPE_SOCIAL_MEDIA,
            TYPE_NEWS,
            TYPE_CONTENT_RECOMMENDATION
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Types {}

    /**
     * The type of this notification is unknown.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final int TYPE_UNKNOWN = -1;
    /**
     * The type of this notification is not one of ones known to the NotificationAssistantService.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final int TYPE_OTHER = 0;
    /**
     * The type of this notification is a promotion/deal.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final int TYPE_PROMOTION = 1;
    /**
     * The type of this notification is social media content that isn't a
     * {@link Notification.Builder#setShortcutId(String) conversation}.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final int TYPE_SOCIAL_MEDIA = 2;
    /**
     * The type of this notification is news.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final int TYPE_NEWS = 3;
    /**
     * The type of this notification is content recommendation, for example new videos or books the
     * user may be interested in.
     */
    @FlaggedApi(Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public static final int TYPE_CONTENT_RECOMMENDATION = 4;

    /**
     * Create a notification adjustment.
     *
+8 −0
Original line number Diff line number Diff line
@@ -36,3 +36,11 @@ flag {
  bug: "305095040"
  is_fixed_read_only: true
}

flag {
    name: "notification_classification"
    is_exported: true
    namespace: "systemui"
    description: "Allows the NAS to classify notifications"
    bug: "343988084"
}
 No newline at end of file
Loading