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

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

Allow resid notification channel group labels.

Test: cts, runtest systemui, runtest systemui-notification, manual
Change-Id: I9e7b43c97fd04057e1a2614876af958cc2f40a99
parent 296417a9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5518,12 +5518,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 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;
  }
+2 −0
Original line number Diff line number Diff line
@@ -5711,6 +5711,7 @@ 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();
@@ -5718,6 +5719,7 @@ package android.app {
    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;
+2 −0
Original line number Diff line number Diff line
@@ -5528,12 +5528,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 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;
  }
+42 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package android.app;

import android.annotation.StringRes;
import android.annotation.SystemApi;
import android.net.Uri;
import android.os.Parcel;
@@ -40,23 +41,38 @@ 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.
     *
     * @param id The id of the group. Must be unique per package.
     * @param name The user visible name of the group.
     * @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.
     */
    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();
@@ -64,6 +80,7 @@ public final class NotificationChannelGroup implements Parcelable {
            mId = null;
        }
        mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mNameResId = in.readInt();
        in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader());
    }

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

@@ -93,6 +111,13 @@ 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
     *
@@ -119,7 +144,12 @@ public final class NotificationChannelGroup implements Parcelable {
        out.startTag(null, TAG_GROUP);

        out.attribute(null, ATT_ID, getId());
        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);
    }
@@ -132,6 +162,7 @@ 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;
    }

@@ -160,6 +191,7 @@ 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;
@@ -171,13 +203,18 @@ public final class NotificationChannelGroup implements Parcelable {

    @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;
    }
@@ -187,6 +224,8 @@ public final class NotificationChannelGroup implements Parcelable {
        return "NotificationChannelGroup{" +
                "mId='" + mId + '\'' +
                ", mName=" + mName +
                ", mNameResId=" + mNameResId +
                ", mChannels=" + mChannels +
                '}';
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -154,8 +154,13 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
                        iNotificationManager.getNotificationChannelGroupForPackage(
                                channel.getGroup(), pkg, appUid);
                if (notificationChannelGroup != null) {
                    if (info != null && notificationChannelGroup.getNameResId() != 0) {
                        groupName = pm.getText(pkg, notificationChannelGroup.getNameResId(), info);
                    }
                    if (notificationChannelGroup.getName() != null) {
                        groupName = notificationChannelGroup.getName();
                    }
                }
            } catch (RemoteException e) {
                Log.e(TAG, e.toString());
            }
Loading