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

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

Add badging support for channels.

In this iteration badges are a user opt in feature.
Known issue: all listeners will receive 'badge only' notifications.

Test: runtest systemui-notification

Change-Id: Ic7450bf4de5351cfdc72bd96ec946fe6e035035c
parent 059a60b8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -5381,6 +5381,7 @@ package android.app {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence, int);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public boolean canShowBadge();
    method public int describeContents();
    method public void enableVibration(boolean);
    method public java.lang.String getId();
@@ -5389,10 +5390,13 @@ package android.app {
    method public java.lang.CharSequence getName();
    method public android.net.Uri getSound();
    method public long[] getVibrationPattern();
    method public boolean isAllowed();
    method public void setAllowed(boolean);
    method public void setBypassDnd(boolean);
    method public void setImportance(int);
    method public void setLights(boolean);
    method public void setLockscreenVisibility(int);
    method public void setShowBadge(boolean);
    method public void setSound(android.net.Uri);
    method public void setVibrationPattern(long[]);
    method public boolean shouldShowLights();
+7 −0
Original line number Diff line number Diff line
@@ -5538,6 +5538,7 @@ package android.app {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence, int);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public boolean canShowBadge();
    method public int describeContents();
    method public void enableVibration(boolean);
    method public java.lang.String getId();
@@ -5547,12 +5548,15 @@ package android.app {
    method public android.net.Uri getSound();
    method public int getUserLockedFields();
    method public long[] getVibrationPattern();
    method public boolean isAllowed();
    method public void lockFields(int);
    method public void populateFromXml(org.xmlpull.v1.XmlPullParser);
    method public void setAllowed(boolean);
    method public void setBypassDnd(boolean);
    method public void setImportance(int);
    method public void setLights(boolean);
    method public void setLockscreenVisibility(int);
    method public void setShowBadge(boolean);
    method public void setSound(android.net.Uri);
    method public void setVibrationPattern(long[]);
    method public boolean shouldShowLights();
@@ -5562,9 +5566,12 @@ package android.app {
    method public void writeXml(org.xmlpull.v1.XmlSerializer) throws java.io.IOException;
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannel> CREATOR;
    field public static final java.lang.String DEFAULT_CHANNEL_ID = "miscellaneous";
    field public static final int[] LOCKABLE_FIELDS;
    field public static final int USER_LOCKED_ALLOWED = 64; // 0x40
    field public static final int USER_LOCKED_IMPORTANCE = 4; // 0x4
    field public static final int USER_LOCKED_LIGHTS = 8; // 0x8
    field public static final int USER_LOCKED_PRIORITY = 1; // 0x1
    field public static final int USER_LOCKED_SHOW_BADGE = 128; // 0x80
    field public static final int USER_LOCKED_SOUND = 32; // 0x20
    field public static final int USER_LOCKED_VIBRATION = 16; // 0x10
    field public static final int USER_LOCKED_VISIBILITY = 2; // 0x2
+4 −0
Original line number Diff line number Diff line
@@ -5391,6 +5391,7 @@ package android.app {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence, int);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public boolean canShowBadge();
    method public int describeContents();
    method public void enableVibration(boolean);
    method public java.lang.String getId();
@@ -5399,10 +5400,13 @@ package android.app {
    method public java.lang.CharSequence getName();
    method public android.net.Uri getSound();
    method public long[] getVibrationPattern();
    method public boolean isAllowed();
    method public void setAllowed(boolean);
    method public void setBypassDnd(boolean);
    method public void setImportance(int);
    method public void setLights(boolean);
    method public void setLockscreenVisibility(int);
    method public void setShowBadge(boolean);
    method public void setSound(android.net.Uri);
    method public void setVibrationPattern(long[]);
    method public boolean shouldShowLights();
+0 −7
Original line number Diff line number Diff line
@@ -50,13 +50,6 @@ interface INotificationManager
    void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled);
    boolean areNotificationsEnabledForPackage(String pkg, int uid);
    boolean areNotificationsEnabled(String pkg);

    void setVisibilityOverride(String pkg, int uid, int visibility);
    int getVisibilityOverride(String pkg, int uid);
    void setPriority(String pkg, int uid, int priority);
    int getPriority(String pkg, int uid);
    void setImportance(String pkg, int uid, int importance);
    int getImportance(String pkg, int uid);
    int getPackageImportance(String pkg);

    void createNotificationChannel(String pkg, in NotificationChannel channel,
+100 −9
Original line number Diff line number Diff line
@@ -53,7 +53,9 @@ public final class NotificationChannel implements Parcelable {
    private static final String ATT_SOUND = "sound";
    //TODO: add audio attributes support
    private static final String ATT_AUDIO_ATTRIBUTES = "audio_attributes";
    private static final String ATT_SHOW_BADGE = "show_badge";
    private static final String ATT_USER_LOCKED = "locked";
    private static final String ATT_ALLOWED = "allowed";
    private static final String DELIMITER = ",";

    /**
@@ -87,10 +89,39 @@ public final class NotificationChannel implements Parcelable {
    @SystemApi
    public static final int USER_LOCKED_SOUND = 0x00000020;

    /**
     * @hide
     */
    @SystemApi
    public static final int USER_LOCKED_ALLOWED = 0x00000040;

    /**
     * @hide
     */
    @SystemApi
    public static final int USER_LOCKED_SHOW_BADGE = 0x00000080;

    /**
     * @hide
     */
    @SystemApi
    public static final int[] LOCKABLE_FIELDS = new int[] {
            USER_LOCKED_PRIORITY,
            USER_LOCKED_VISIBILITY,
            USER_LOCKED_IMPORTANCE,
            USER_LOCKED_LIGHTS,
            USER_LOCKED_VIBRATION,
            USER_LOCKED_SOUND,
            USER_LOCKED_ALLOWED,
            USER_LOCKED_SHOW_BADGE
    };


    private static final int DEFAULT_VISIBILITY =
            NotificationManager.VISIBILITY_NO_OVERRIDE;
    private static final int DEFAULT_IMPORTANCE =
            NotificationManager.IMPORTANCE_UNSPECIFIED;
    private static final boolean DEFAULT_ALLOWED = true;

    private final String mId;
    private CharSequence mName;
@@ -102,6 +133,8 @@ public final class NotificationChannel implements Parcelable {
    private long[] mVibration;
    private int mUserLockedFields;
    private boolean mVibrationEnabled;
    private boolean mShowBadge;
    private boolean mAllowed = DEFAULT_ALLOWED;

    /**
     * Creates a notification channel.
@@ -137,6 +170,8 @@ public final class NotificationChannel implements Parcelable {
        mVibration = in.createLongArray();
        mUserLockedFields = in.readInt();
        mVibrationEnabled = in.readByte() != 0;
        mShowBadge = in.readByte() != 0;
        mAllowed = in.readByte() != 0;
    }

    @Override
@@ -161,6 +196,8 @@ public final class NotificationChannel implements Parcelable {
        dest.writeLongArray(mVibration);
        dest.writeInt(mUserLockedFields);
        dest.writeByte(mVibrationEnabled ? (byte) 1 : (byte) 0);
        dest.writeByte(mShowBadge ? (byte) 1 : (byte) 0);
        dest.writeByte(mAllowed ? (byte) 1 : (byte) 0);
    }

    /**
@@ -174,30 +211,30 @@ public final class NotificationChannel implements Parcelable {
    // Modifiable by a notification ranker.

    /**
     * Only modifiable by the system and notification ranker.
     *
     * Sets whether or not this notification can interrupt the user in
     * Sets whether or not notifications posted to this channel can interrupt the user in
     * {@link android.app.NotificationManager.Policy#INTERRUPTION_FILTER_PRIORITY} mode.
     *
     * Only modifiable by the system and notification ranker.
     */
    public void setBypassDnd(boolean bypassDnd) {
        this.mBypassDnd = bypassDnd;
    }

    /**
     * Only modifiable by the system and notification ranker.
     * Sets whether notifications posted to this channel appear on the lockscreen or not, and if so,
     * whether they appear in a redacted form. See e.g. {@link Notification#VISIBILITY_SECRET}.
     *
     * Sets whether this notification appears on the lockscreen or not, and if so, whether it
     * appears in a redacted form. See e.g. {@link Notification#VISIBILITY_SECRET}.
     * Only modifiable by the system and notification ranker.
     */
    public void setLockscreenVisibility(int lockscreenVisibility) {
        this.mLockscreenVisibility = lockscreenVisibility;
    }

    /**
     * Only modifiable by the system and notification ranker.
     *
     * Sets the level of interruption of this notification channel.
     *
     * Only modifiable by the system and notification ranker.
     *
     * @param importance the amount the user should be interrupted by notifications from this
     *                   channel. See e.g.
     *                   {@link android.app.NotificationManager#IMPORTANCE_DEFAULT}.
@@ -206,6 +243,30 @@ public final class NotificationChannel implements Parcelable {
        this.mImportance = importance;
    }

    /**
     * Sets whether notifications posted to this channel can appear as application icon badges
     * in a Launcher.
     *
     * Only modifiable by the system and notification ranker.
     *
     * @param showBadge true if badges should be allowed to be shown.
     */
    public void setShowBadge(boolean showBadge) {
        this.mShowBadge = showBadge;
    }

    /**
     * Sets whether notifications are allowed to be posted to this channel.
     *
     * Only modifiable by the system and notification ranker.
     *
     * @param allowed true if notifications are not allowed from this channel.
     */
    public void setAllowed(boolean allowed) {
        this.mAllowed = allowed;
    }


    // Modifiable by apps on channel creation.

    /**
@@ -310,6 +371,21 @@ public final class NotificationChannel implements Parcelable {
        return mLockscreenVisibility;
    }

    /**
     * Returns whether notifications posted to this channel can appear as badges in a Launcher
     * application.
     */
    public boolean canShowBadge() {
        return mShowBadge;
    }

    /**
     * Returns whether notifications are allowed to post to this channel.
     */
    public boolean isAllowed() {
        return mAllowed;
    }

    /**
     * @hide
     */
@@ -331,6 +407,8 @@ public final class NotificationChannel implements Parcelable {
        setLights(safeBool(parser, ATT_LIGHTS, false));
        enableVibration(safeBool(parser, ATT_VIBRATION_ENABLED, false));
        setVibrationPattern(safeLongArray(parser, ATT_VIBRATION, null));
        setShowBadge(safeBool(parser, ATT_SHOW_BADGE, false));
        setAllowed(safeBool(parser, ATT_ALLOWED, true));
        lockFields(safeInt(parser, ATT_USER_LOCKED, 0));
    }

@@ -369,6 +447,12 @@ public final class NotificationChannel implements Parcelable {
        if (getUserLockedFields() != 0) {
            out.attribute(null, ATT_USER_LOCKED, Integer.toString(getUserLockedFields()));
        }
        if (canShowBadge()) {
            out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(canShowBadge()));
        }
        if (!isAllowed()) {
            out.attribute(null, ATT_ALLOWED, Boolean.toString(isAllowed()));
        }

        out.endTag(null, TAG_CHANNEL);
    }
@@ -398,6 +482,8 @@ public final class NotificationChannel implements Parcelable {
        record.put(ATT_VIBRATION_ENABLED, Boolean.toString(shouldVibrate()));
        record.put(ATT_USER_LOCKED, Integer.toString(getUserLockedFields()));
        record.put(ATT_VIBRATION, longArrayToString(getVibrationPattern()));
        record.put(ATT_SHOW_BADGE, Boolean.toString(canShowBadge()));
        record.put(ATT_ALLOWED, Boolean.toString(isAllowed()));

        return record;
    }
@@ -481,6 +567,8 @@ public final class NotificationChannel implements Parcelable {
        if (mLights != that.mLights) return false;
        if (mUserLockedFields != that.mUserLockedFields) return false;
        if (mVibrationEnabled != that.mVibrationEnabled) return false;
        if (mShowBadge != that.mShowBadge) return false;
        if (mAllowed != that.mAllowed) return false;
        if (mId != null ? !mId.equals(that.mId) : that.mId != null) return false;
        if (mName != null ? !mName.equals(that.mName) : that.mName != null) return false;
        if (mSound != null ? !mSound.equals(that.mSound) : that.mSound != null) return false;
@@ -500,10 +588,11 @@ public final class NotificationChannel implements Parcelable {
        result = 31 * result + Arrays.hashCode(mVibration);
        result = 31 * result + mUserLockedFields;
        result = 31 * result + (mVibrationEnabled ? 1 : 0);
        result = 31 * result + (mShowBadge ? 1 : 0);
        result = 31 * result + (mAllowed ? 1 : 0);
        return result;
    }


    @Override
    public String toString() {
        return "NotificationChannel{" +
@@ -517,6 +606,8 @@ public final class NotificationChannel implements Parcelable {
                ", mVibration=" + Arrays.toString(mVibration) +
                ", mUserLockedFields=" + mUserLockedFields +
                ", mVibrationEnabled=" + mVibrationEnabled +
                ", mShowBadge=" + mShowBadge +
                ", mAllowed=" + mAllowed +
                '}';
    }
}
Loading