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

Commit d3e53c5e authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

MediaRouter: Allow empty name for routes

I thought that routes with empty name are invalid and providers
shouldn't publish those.

BT devices seem to be able to have empty name, however, so we have
to choose between
 a) ignoring empty named bluetooth routes
 b) allowing empty named routes

If a BT device was invalid, BT or Audio should hide the device.
So even the name is empty, the route may be valid and we choose b).

Test: atest mediaroutertest
   && atest A2dpServiceTest

Change-Id: I9b4866711bc4f4c2c13e790519ea1f4d408fa5d1
parent 0332e9a2
Loading
Loading
Loading
Loading
+13 −21
Original line number Diff line number Diff line
@@ -66,9 +66,9 @@ public final class MediaRoute2Info implements Parcelable {
    @Nullable
    final String mProviderId;
    @NonNull
    final String mName;
    final CharSequence mName;
    @Nullable
    final String mDescription;
    final CharSequence mDescription;
    @Nullable
    final String mClientPackageName;
    @NonNull
@@ -98,8 +98,8 @@ public final class MediaRoute2Info implements Parcelable {
    MediaRoute2Info(@NonNull Parcel in) {
        mId = in.readString();
        mProviderId = in.readString();
        mName = in.readString();
        mDescription = in.readString();
        mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mClientPackageName = in.readString();
        mSupportedCategories = in.createStringArrayList();
        mVolume = in.readInt();
@@ -194,12 +194,12 @@ public final class MediaRoute2Info implements Parcelable {
    }

    @NonNull
    public String getName() {
    public CharSequence getName() {
        return mName;
    }

    @Nullable
    public String getDescription() {
    public CharSequence getDescription() {
        return mDescription;
    }

@@ -277,8 +277,8 @@ public final class MediaRoute2Info implements Parcelable {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString(mId);
        dest.writeString(mProviderId);
        dest.writeString(mName);
        dest.writeString(mDescription);
        TextUtils.writeToParcel(mName, dest, flags);
        TextUtils.writeToParcel(mDescription, dest, flags);
        dest.writeString(mClientPackageName);
        dest.writeStringList(mSupportedCategories);
        dest.writeInt(mVolume);
@@ -308,8 +308,8 @@ public final class MediaRoute2Info implements Parcelable {
    public static final class Builder {
        String mId;
        String mProviderId;
        String mName;
        String mDescription;
        CharSequence mName;
        CharSequence mDescription;
        String mClientPackageName;
        List<String> mSupportedCategories;
        int mVolume;
@@ -317,13 +317,7 @@ public final class MediaRoute2Info implements Parcelable {
        int mVolumeHandling = PLAYBACK_VOLUME_FIXED;
        Bundle mExtras;

        public Builder(@NonNull String id, @NonNull String name) {
            if (TextUtils.isEmpty(id)) {
                throw new IllegalArgumentException("id must not be null or empty");
            }
            if (TextUtils.isEmpty(name)) {
                throw new IllegalArgumentException("name must not be null or empty");
            }
        public Builder(@NonNull String id, @NonNull CharSequence name) {
            setId(id);
            setName(name);
            mSupportedCategories = new ArrayList<>();
@@ -379,10 +373,8 @@ public final class MediaRoute2Info implements Parcelable {
         * Sets the user-visible name of the route.
         */
        @NonNull
        public Builder setName(@NonNull String name) {
            if (TextUtils.isEmpty(name)) {
                throw new IllegalArgumentException("name must not be null or empty");
            }
        public Builder setName(@NonNull CharSequence name) {
            Objects.requireNonNull(name, "name must not be null");
            mName = name;
            return this;
        }
+2 −2
Original line number Diff line number Diff line
@@ -179,12 +179,12 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
            if (mCurAudioRoutesInfo.bluetoothName != null) {
                //TODO: mark as bluetooth once MediaRoute2Info has device type
                mBluetoothA2dpRoute = new MediaRoute2Info.Builder(BLUETOOTH_ROUTE_ID,
                        mCurAudioRoutesInfo.bluetoothName.toString())
                        mCurAudioRoutesInfo.bluetoothName)
                        .setDescription(mContext.getResources().getText(
                                R.string.bluetooth_a2dp_audio_route_name).toString())
                        .addSupportedCategory(CATEGORY_LIVE_AUDIO)
                        .build();
            } else if (mBluetoothA2dpRoute != null) {
            } else {
                mBluetoothA2dpRoute = null;
            }
        }