diff --git a/api/current.txt b/api/current.txt index 13af1d47cf4eb..8477754d9095e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -27477,6 +27477,7 @@ package android.media { method @Nullable public android.os.Bundle getControlHints(); method @NonNull public java.util.List getDeselectableRoutes(); method @NonNull public String getId(); + method @Nullable public CharSequence getName(); method @NonNull public java.util.List getSelectableRoutes(); method @NonNull public java.util.List getSelectedRoutes(); method @NonNull public java.util.List getTransferableRoutes(); @@ -27504,6 +27505,7 @@ package android.media { method @NonNull public android.media.RoutingSessionInfo.Builder removeSelectedRoute(@NonNull String); method @NonNull public android.media.RoutingSessionInfo.Builder removeTransferableRoute(@NonNull String); method @NonNull public android.media.RoutingSessionInfo.Builder setControlHints(@Nullable android.os.Bundle); + method @NonNull public android.media.RoutingSessionInfo.Builder setName(@Nullable CharSequence); method @NonNull public android.media.RoutingSessionInfo.Builder setVolume(int); method @NonNull public android.media.RoutingSessionInfo.Builder setVolumeHandling(int); method @NonNull public android.media.RoutingSessionInfo.Builder setVolumeMax(int); diff --git a/media/java/android/media/RoutingSessionInfo.java b/media/java/android/media/RoutingSessionInfo.java index 19a46ce6570d8..9d81fbbb793a8 100644 --- a/media/java/android/media/RoutingSessionInfo.java +++ b/media/java/android/media/RoutingSessionInfo.java @@ -49,6 +49,7 @@ public final class RoutingSessionInfo implements Parcelable { private static final String TAG = "RoutingSessionInfo"; final String mId; + final CharSequence mName; final String mClientPackageName; @Nullable final String mProviderId; @@ -69,6 +70,7 @@ public final class RoutingSessionInfo implements Parcelable { Objects.requireNonNull(builder, "builder must not be null."); mId = builder.mId; + mName = builder.mName; mClientPackageName = builder.mClientPackageName; mProviderId = builder.mProviderId; @@ -94,6 +96,7 @@ public final class RoutingSessionInfo implements Parcelable { Objects.requireNonNull(src, "src must not be null."); mId = ensureString(src.readString()); + mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(src); mClientPackageName = ensureString(src.readString()); mProviderId = src.readString(); @@ -111,10 +114,7 @@ public final class RoutingSessionInfo implements Parcelable { } private static String ensureString(String str) { - if (str != null) { - return str; - } - return ""; + return str != null ? str : ""; } private static List ensureList(List list) { @@ -142,6 +142,14 @@ public final class RoutingSessionInfo implements Parcelable { } } + /** + * Gets the user-visible name of the session. It may be {@code null}. + */ + @Nullable + public CharSequence getName() { + return mName; + } + /** * Gets the original id set by {@link Builder#Builder(String, String)}. * @hide @@ -169,7 +177,7 @@ public final class RoutingSessionInfo implements Parcelable { } /** - * Gets the list of ids of selected routes for the session. It shouldn't be empty. + * Gets the list of IDs of selected routes for the session. It shouldn't be empty. */ @NonNull public List getSelectedRoutes() { @@ -177,7 +185,7 @@ public final class RoutingSessionInfo implements Parcelable { } /** - * Gets the list of ids of selectable routes for the session. + * Gets the list of IDs of selectable routes for the session. */ @NonNull public List getSelectableRoutes() { @@ -185,7 +193,7 @@ public final class RoutingSessionInfo implements Parcelable { } /** - * Gets the list of ids of deselectable routes for the session. + * Gets the list of IDs of deselectable routes for the session. */ @NonNull public List getDeselectableRoutes() { @@ -193,7 +201,7 @@ public final class RoutingSessionInfo implements Parcelable { } /** - * Gets the list of ids of transferable routes for the session. + * Gets the list of IDs of transferable routes for the session. */ @NonNull public List getTransferableRoutes() { @@ -255,6 +263,7 @@ public final class RoutingSessionInfo implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeString(mId); + dest.writeCharSequence(mName); dest.writeString(mClientPackageName); dest.writeString(mProviderId); dest.writeStringList(mSelectedRoutes); @@ -279,6 +288,7 @@ public final class RoutingSessionInfo implements Parcelable { RoutingSessionInfo other = (RoutingSessionInfo) obj; return Objects.equals(mId, other.mId) + && Objects.equals(mName, other.mName) && Objects.equals(mClientPackageName, other.mClientPackageName) && Objects.equals(mProviderId, other.mProviderId) && Objects.equals(mSelectedRoutes, other.mSelectedRoutes) @@ -292,7 +302,7 @@ public final class RoutingSessionInfo implements Parcelable { @Override public int hashCode() { - return Objects.hash(mId, mClientPackageName, mProviderId, + return Objects.hash(mId, mName, mClientPackageName, mProviderId, mSelectedRoutes, mSelectableRoutes, mDeselectableRoutes, mTransferableRoutes, mVolumeMax, mVolumeHandling, mVolume); } @@ -302,6 +312,7 @@ public final class RoutingSessionInfo implements Parcelable { StringBuilder result = new StringBuilder() .append("RoutingSessionInfo{ ") .append("sessionId=").append(mId) + .append(", name=").append(mName) .append(", selectedRoutes={") .append(String.join(",", mSelectedRoutes)) .append("}") @@ -345,6 +356,7 @@ public final class RoutingSessionInfo implements Parcelable { public static final class Builder { // TODO: Reorder these (important ones first) final String mId; + CharSequence mName; final String mClientPackageName; String mProviderId; final List mSelectedRoutes; @@ -357,6 +369,7 @@ public final class RoutingSessionInfo implements Parcelable { Bundle mControlHints; boolean mIsSystemSession; + //TODO: Remove this. /** * Constructor for builder to create {@link RoutingSessionInfo}. *

@@ -374,10 +387,10 @@ public final class RoutingSessionInfo implements Parcelable { if (TextUtils.isEmpty(id)) { throw new IllegalArgumentException("id must not be empty"); } - Objects.requireNonNull(clientPackageName, "clientPackageName must not be null"); mId = id; - mClientPackageName = clientPackageName; + mClientPackageName = + Objects.requireNonNull(clientPackageName, "clientPackageName must not be null"); mSelectedRoutes = new ArrayList<>(); mSelectableRoutes = new ArrayList<>(); mDeselectableRoutes = new ArrayList<>(); @@ -394,6 +407,7 @@ public final class RoutingSessionInfo implements Parcelable { Objects.requireNonNull(sessionInfo, "sessionInfo must not be null"); mId = sessionInfo.mId; + mName = sessionInfo.mName; mClientPackageName = sessionInfo.mClientPackageName; mProviderId = sessionInfo.mProviderId; @@ -410,6 +424,15 @@ public final class RoutingSessionInfo implements Parcelable { mIsSystemSession = sessionInfo.mIsSystemSession; } + /** + * Sets the user-visible name of the session. + */ + @NonNull + public Builder setName(@Nullable CharSequence name) { + mName = name; + return this; + } + /** * Sets the provider ID of the session. *