Add "name" to RoutingSessionInfo
The name of dynamic group can be set by providers.
Bug: 150249359
Test: cts tests
Change-Id: I1b74fe5b7976eb0ad6a52fd29203446dde480de8
diff --git a/api/current.txt b/api/current.txt
index a2f2c06..12fbbe4 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -27479,6 +27479,7 @@
method @Nullable public android.os.Bundle getControlHints();
method @NonNull public java.util.List<java.lang.String> getDeselectableRoutes();
method @NonNull public String getId();
+ method @Nullable public CharSequence getName();
method @NonNull public java.util.List<java.lang.String> getSelectableRoutes();
method @NonNull public java.util.List<java.lang.String> getSelectedRoutes();
method @NonNull public java.util.List<java.lang.String> getTransferableRoutes();
@@ -27506,6 +27507,7 @@
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 19a46ce..9d81fbb 100644
--- a/media/java/android/media/RoutingSessionInfo.java
+++ b/media/java/android/media/RoutingSessionInfo.java
@@ -49,6 +49,7 @@
private static final String TAG = "RoutingSessionInfo";
final String mId;
+ final CharSequence mName;
final String mClientPackageName;
@Nullable
final String mProviderId;
@@ -69,6 +70,7 @@
Objects.requireNonNull(builder, "builder must not be null.");
mId = builder.mId;
+ mName = builder.mName;
mClientPackageName = builder.mClientPackageName;
mProviderId = builder.mProviderId;
@@ -94,6 +96,7 @@
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 @@
}
private static String ensureString(String str) {
- if (str != null) {
- return str;
- }
- return "";
+ return str != null ? str : "";
}
private static <T> List<T> ensureList(List<? extends T> list) {
@@ -143,6 +143,14 @@
}
/**
+ * 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 @@
}
/**
- * 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<String> getSelectedRoutes() {
@@ -177,7 +185,7 @@
}
/**
- * 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<String> getSelectableRoutes() {
@@ -185,7 +193,7 @@
}
/**
- * 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<String> getDeselectableRoutes() {
@@ -193,7 +201,7 @@
}
/**
- * 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<String> getTransferableRoutes() {
@@ -255,6 +263,7 @@
@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 @@
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 @@
@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 @@
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 static final class Builder {
// TODO: Reorder these (important ones first)
final String mId;
+ CharSequence mName;
final String mClientPackageName;
String mProviderId;
final List<String> mSelectedRoutes;
@@ -357,6 +369,7 @@
Bundle mControlHints;
boolean mIsSystemSession;
+ //TODO: Remove this.
/**
* Constructor for builder to create {@link RoutingSessionInfo}.
* <p>
@@ -374,10 +387,10 @@
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 @@
Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
mId = sessionInfo.mId;
+ mName = sessionInfo.mName;
mClientPackageName = sessionInfo.mClientPackageName;
mProviderId = sessionInfo.mProviderId;
@@ -411,6 +425,15 @@
}
/**
+ * 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.
*
* @hide