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

Commit 1d97e6a0 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Remove resource id channel/group name fields

Apps can listen for the LOCALE_CHANGED broadcast to
change names if needed.

Fixes: 35336590
Test: runtest systemui-notification, cts, manual
Change-Id: I62d2778f61e99200692755a6f268828a374837e6
parent 87f0f834
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -5494,7 +5494,6 @@ package android.app {
  public final class NotificationChannel implements android.os.Parcelable {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence, int);
    ctor public NotificationChannel(java.lang.String, int, int);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public boolean canShowBadge();
@@ -5508,7 +5507,6 @@ package android.app {
    method public int getLightColor();
    method public int getLockscreenVisibility();
    method public java.lang.CharSequence getName();
    method public int getNameResId();
    method public android.net.Uri getSound();
    method public long[] getVibrationPattern();
    method public void setBypassDnd(boolean);
@@ -5516,6 +5514,7 @@ package android.app {
    method public void setImportance(int);
    method public void setLightColor(int);
    method public void setLockscreenVisibility(int);
    method public void setName(java.lang.CharSequence);
    method public void setShowBadge(boolean);
    method public void setSound(android.net.Uri, android.media.AudioAttributes);
    method public void setVibrationPattern(long[]);
@@ -5528,14 +5527,12 @@ package android.app {
  public final class NotificationChannelGroup implements android.os.Parcelable {
    ctor public NotificationChannelGroup(java.lang.String, java.lang.CharSequence);
    ctor public NotificationChannelGroup(java.lang.String, int);
    ctor protected NotificationChannelGroup(android.os.Parcel);
    method public android.app.NotificationChannelGroup clone();
    method public int describeContents();
    method public java.util.List<android.app.NotificationChannel> getChannels();
    method public java.lang.String getId();
    method public java.lang.CharSequence getName();
    method public int getNameResId();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannelGroup> CREATOR;
  }
+1 −8
Original line number Diff line number Diff line
@@ -5681,7 +5681,6 @@ package android.app {
  public final class NotificationChannel implements android.os.Parcelable {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence, int);
    ctor public NotificationChannel(java.lang.String, int, int);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public boolean canShowBadge();
@@ -5695,19 +5694,17 @@ package android.app {
    method public int getLightColor();
    method public int getLockscreenVisibility();
    method public java.lang.CharSequence getName();
    method public int getNameResId();
    method public android.net.Uri getSound();
    method public int getUserLockedFields();
    method public long[] getVibrationPattern();
    method public boolean isDeleted();
    method public void lockFields(int);
    method public void populateFromXml(org.xmlpull.v1.XmlPullParser);
    method public void setBypassDnd(boolean);
    method public void setDeleted(boolean);
    method public void setGroup(java.lang.String);
    method public void setImportance(int);
    method public void setLightColor(int);
    method public void setLockscreenVisibility(int);
    method public void setName(java.lang.CharSequence);
    method public void setShowBadge(boolean);
    method public void setSound(android.net.Uri, android.media.AudioAttributes);
    method public void setVibrationPattern(long[]);
@@ -5732,18 +5729,14 @@ package android.app {
  public final class NotificationChannelGroup implements android.os.Parcelable {
    ctor public NotificationChannelGroup(java.lang.String, java.lang.CharSequence);
    ctor public NotificationChannelGroup(java.lang.String, int);
    ctor protected NotificationChannelGroup(android.os.Parcel);
    method public void addChannel(android.app.NotificationChannel);
    method public android.app.NotificationChannelGroup clone();
    method public int describeContents();
    method public java.util.List<android.app.NotificationChannel> getChannels();
    method public java.lang.String getId();
    method public java.lang.CharSequence getName();
    method public int getNameResId();
    method public org.json.JSONObject toJson() throws org.json.JSONException;
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeXml(org.xmlpull.v1.XmlSerializer) throws java.io.IOException;
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannelGroup> CREATOR;
  }
+1 −4
Original line number Diff line number Diff line
@@ -5504,7 +5504,6 @@ package android.app {
  public final class NotificationChannel implements android.os.Parcelable {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence, int);
    ctor public NotificationChannel(java.lang.String, int, int);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public boolean canShowBadge();
@@ -5518,7 +5517,6 @@ package android.app {
    method public int getLightColor();
    method public int getLockscreenVisibility();
    method public java.lang.CharSequence getName();
    method public int getNameResId();
    method public android.net.Uri getSound();
    method public long[] getVibrationPattern();
    method public void setBypassDnd(boolean);
@@ -5526,6 +5524,7 @@ package android.app {
    method public void setImportance(int);
    method public void setLightColor(int);
    method public void setLockscreenVisibility(int);
    method public void setName(java.lang.CharSequence);
    method public void setShowBadge(boolean);
    method public void setSound(android.net.Uri, android.media.AudioAttributes);
    method public void setVibrationPattern(long[]);
@@ -5538,14 +5537,12 @@ package android.app {
  public final class NotificationChannelGroup implements android.os.Parcelable {
    ctor public NotificationChannelGroup(java.lang.String, java.lang.CharSequence);
    ctor public NotificationChannelGroup(java.lang.String, int);
    ctor protected NotificationChannelGroup(android.os.Parcel);
    method public android.app.NotificationChannelGroup clone();
    method public int describeContents();
    method public java.util.List<android.app.NotificationChannel> getChannels();
    method public java.lang.String getId();
    method public java.lang.CharSequence getName();
    method public int getNameResId();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannelGroup> CREATOR;
  }
+7 −37
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.annotation.SystemApi;
import android.content.Intent;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Parcel;
@@ -47,7 +48,6 @@ public final class NotificationChannel implements Parcelable {

    private static final String TAG_CHANNEL = "channel";
    private static final String ATT_NAME = "name";
    private static final String ATT_NAME_RES_ID = "name_res_id";
    private static final String ATT_ID = "id";
    private static final String ATT_DELETED = "deleted";
    private static final String ATT_PRIORITY = "priority";
@@ -141,7 +141,6 @@ public final class NotificationChannel implements Parcelable {

    private final String mId;
    private CharSequence mName;
    private int mNameResId = 0;
    private int mImportance = DEFAULT_IMPORTANCE;
    private boolean mBypassDnd;
    private int mLockscreenVisibility = DEFAULT_VISIBILITY;
@@ -162,7 +161,9 @@ public final class NotificationChannel implements Parcelable {
     * @param id The id of the channel. Must be unique per package.
     * @param name The user visible name of the channel. Unchangeable once created; use this
     *             constructor if the channel represents a user-defined category that does not
     *             need to be translated.
     *             need to be translated. You can rename this channel when the system
     *             locale changes by listening for the {@link Intent#ACTION_LOCALE_CHANGED}
     *             broadcast.
     * @param importance The importance of the channel. This controls how interruptive notifications
     *                   posted to this channel are. See e.g.
     *                   {@link NotificationManager#IMPORTANCE_DEFAULT}.
@@ -173,21 +174,6 @@ public final class NotificationChannel implements Parcelable {
        this.mImportance = importance;
    }

    /**
     * Creates a notification channel.
     *
     * @param id The id of the channel. Must be unique per package.
     * @param nameResId The resource id of the string containing the channel name.
     * @param importance The importance of the channel. This controls how interruptive notifications
     *                   posted to this channel are. See e.g.
     *                   {@link NotificationManager#IMPORTANCE_DEFAULT}.
     */
    public NotificationChannel(String id, @StringRes int nameResId, int importance) {
        this.mId = id;
        this.mNameResId = nameResId;
        this.mImportance = importance;
    }

    protected NotificationChannel(Parcel in) {
        if (in.readByte() != 0) {
            mId = in.readString();
@@ -195,7 +181,6 @@ public final class NotificationChannel implements Parcelable {
            mId = null;
        }
        mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mNameResId = in.readInt();
        mImportance = in.readInt();
        mBypassDnd = in.readByte() != 0;
        mLockscreenVisibility = in.readInt();
@@ -228,7 +213,6 @@ public final class NotificationChannel implements Parcelable {
            dest.writeByte((byte) 0);
        }
        TextUtils.writeToParcel(mName, dest, flags);
        dest.writeInt(mNameResId);
        dest.writeInt(mImportance);
        dest.writeByte(mBypassDnd ? (byte) 1 : (byte) 0);
        dest.writeInt(mLockscreenVisibility);
@@ -262,7 +246,6 @@ public final class NotificationChannel implements Parcelable {
    /**
     * @hide
     */
    @SystemApi
    public void lockFields(int field) {
        mUserLockedFields |= field;
    }
@@ -270,16 +253,15 @@ public final class NotificationChannel implements Parcelable {
    /**
     * @hide
     */
    @SystemApi
    public void setDeleted(boolean deleted) {
        mDeleted = deleted;
    }

    /**
     * @hide
     * Sets the name of this channel.
     */
    public void setNameResId(@StringRes int nameResId) {
        this.mNameResId = nameResId;
    public void setName(CharSequence name) {
        mName = name;
    }

    // Modifiable by a notification ranker.
@@ -416,13 +398,6 @@ public final class NotificationChannel implements Parcelable {
        return mName;
    }

    /**
     * Returns the resource id of the user visible name of this channel.
     */
    public int getNameResId() {
        return mNameResId;
    }

    /**
     * Returns the user specified importance {e.g. @link NotificationManager#IMPORTANCE_LOW} for
     * notifications posted to this channel.
@@ -556,7 +531,6 @@ public final class NotificationChannel implements Parcelable {
        if (getName() != null) {
            out.attribute(null, ATT_NAME, getName().toString());
        }
        out.attribute(null, ATT_NAME_RES_ID, Integer.toString(getNameResId()));
        if (getImportance() != DEFAULT_IMPORTANCE) {
            out.attribute(
                    null, ATT_IMPORTANCE, Integer.toString(getImportance()));
@@ -614,7 +588,6 @@ public final class NotificationChannel implements Parcelable {
        JSONObject record = new JSONObject();
        record.put(ATT_ID, getId());
        record.put(ATT_NAME, getName());
        record.put(ATT_NAME_RES_ID, getNameResId());
        if (getImportance() != DEFAULT_IMPORTANCE) {
            record.put(ATT_IMPORTANCE,
                    NotificationListenerService.Ranking.importanceToString(getImportance()));
@@ -732,7 +705,6 @@ public final class NotificationChannel implements Parcelable {

        NotificationChannel that = (NotificationChannel) o;

        if (getNameResId() != that.getNameResId()) return false;
        if (getImportance() != that.getImportance()) return false;
        if (mBypassDnd != that.mBypassDnd) return false;
        if (getLockscreenVisibility() != that.getLockscreenVisibility()) return false;
@@ -762,7 +734,6 @@ public final class NotificationChannel implements Parcelable {
    public int hashCode() {
        int result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getName() != null ? getName().hashCode() : 0);
        result = 31 * result + getNameResId();
        result = 31 * result + getImportance();
        result = 31 * result + (mBypassDnd ? 1 : 0);
        result = 31 * result + getLockscreenVisibility();
@@ -784,7 +755,6 @@ public final class NotificationChannel implements Parcelable {
        return "NotificationChannel{" +
                "mId='" + mId + '\'' +
                ", mName=" + mName +
                ", mNameResId=" + mNameResId +
                ", mImportance=" + mImportance +
                ", mBypassDnd=" + mBypassDnd +
                ", mLockscreenVisibility=" + mLockscreenVisibility +
+7 −45
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package android.app;

import android.annotation.StringRes;
import android.annotation.SystemApi;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
@@ -41,38 +42,25 @@ public final class NotificationChannelGroup implements Parcelable {

    private static final String TAG_GROUP = "channelGroup";
    private static final String ATT_NAME = "name";
    private static final String ATT_NAME_RES_ID = "name_res_id";
    private static final String ATT_ID = "id";

    private final String mId;
    private CharSequence mName;
    private int mNameResId = 0;
    private List<NotificationChannel> mChannels = new ArrayList<>();

    /**
     * Creates a notification channel.
     * Creates a notification channel group.
     *
     * @param id The id of the group. Must be unique per package.
     * @param name The user visible name of the group. Unchangeable once created; use this
     *             constructor if the group represents something user-defined that does not
     *             need to be translated.
     * @param name The user visible name of the group. You can rename this group when the system
     *             locale changes by listening for the {@link Intent#ACTION_LOCALE_CHANGED}
     *             broadcast.
     */
    public NotificationChannelGroup(String id, CharSequence name) {
        this.mId = id;
        this.mName = name;
    }

    /**
     * Creates a notification channel.
     *
     * @param id The id of the group. Must be unique per package.
     * @param nameResId String resource id of the user visible name of the group.
     */
    public NotificationChannelGroup(String id, @StringRes int nameResId) {
        this.mId = id;
        this.mNameResId = nameResId;
    }

    protected NotificationChannelGroup(Parcel in) {
        if (in.readByte() != 0) {
            mId = in.readString();
@@ -80,7 +68,6 @@ public final class NotificationChannelGroup implements Parcelable {
            mId = null;
        }
        mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mNameResId = in.readInt();
        in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader());
    }

@@ -93,7 +80,6 @@ public final class NotificationChannelGroup implements Parcelable {
            dest.writeByte((byte) 0);
        }
        TextUtils.writeToParcel(mName, dest, flags);
        dest.writeInt(mNameResId);
        dest.writeParcelableList(mChannels, flags);
    }

@@ -111,19 +97,11 @@ public final class NotificationChannelGroup implements Parcelable {
        return mName;
    }

    /**
     * Returns the resource id of the user visible name of this group.
     */
    public @StringRes int getNameResId() {
        return mNameResId;
    }

    /*
     * Returns the list of channels that belong to this group
     *
     * @hide
     */
    @SystemApi
    public List<NotificationChannel> getChannels() {
        return mChannels;
    }
@@ -131,7 +109,6 @@ public final class NotificationChannelGroup implements Parcelable {
    /**
     * @hide
     */
    @SystemApi
    public void addChannel(NotificationChannel channel) {
        mChannels.add(channel);
    }
@@ -139,7 +116,6 @@ public final class NotificationChannelGroup implements Parcelable {
    /**
     * @hide
     */
    @SystemApi
    public void writeXml(XmlSerializer out) throws IOException {
        out.startTag(null, TAG_GROUP);

@@ -147,9 +123,6 @@ public final class NotificationChannelGroup implements Parcelable {
        if (getName() != null) {
            out.attribute(null, ATT_NAME, getName().toString());
        }
        if (getNameResId() != 0) {
            out.attribute(null, ATT_NAME_RES_ID, Integer.toString(getNameResId()));
        }

        out.endTag(null, TAG_GROUP);
    }
@@ -162,7 +135,6 @@ public final class NotificationChannelGroup implements Parcelable {
        JSONObject record = new JSONObject();
        record.put(ATT_ID, getId());
        record.put(ATT_NAME, getName());
        record.put(ATT_NAME_RES_ID, getNameResId());
        return record;
    }

@@ -191,31 +163,22 @@ public final class NotificationChannelGroup implements Parcelable {

        NotificationChannelGroup that = (NotificationChannelGroup) o;

        if (getNameResId() != that.getNameResId()) return false;
        if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false;
        if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) {
            return false;
        }
        return getChannels() != null ? getChannels().equals(that.getChannels())
                : that.getChannels() == null;

        return true;
    }

    @Override
    public NotificationChannelGroup clone() {
        if (getName() != null) {
        return new NotificationChannelGroup(getId(), getName());
        } else {
            return new NotificationChannelGroup(getId(), getNameResId());
        }
    }

    @Override
    public int hashCode() {
        int result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getName() != null ? getName().hashCode() : 0);
        result = 31 * result + getNameResId();
        result = 31 * result + (getChannels() != null ? getChannels().hashCode() : 0);
        return result;
    }

@@ -224,7 +187,6 @@ public final class NotificationChannelGroup implements Parcelable {
        return "NotificationChannelGroup{" +
                "mId='" + mId + '\'' +
                ", mName=" + mName +
                ", mNameResId=" + mNameResId +
                ", mChannels=" + mChannels +
                '}';
    }
Loading