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

Commit ae74c912 authored by Iván Budnik's avatar Iván Budnik
Browse files

Copy lists to ensure deep immutability in RoutingSessionInfo

This avoids lists in RoutingSessionInfo being modified from the original
builder after creation. This change also removes redundant code.

Test: atest CtsMediaBetterTogetherTestCases
Bug: 265064892
Change-Id: Id4a3fb65f78c1f6f9374450a06c4071dbacb9b47
parent bac13cfa
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.util.Preconditions;

@@ -117,6 +116,8 @@ public final class RoutingSessionInfo implements Parcelable {
        mProviderId = src.readString();

        mSelectedRoutes = ensureList(src.createStringArrayList());
        Preconditions.checkArgument(!mSelectedRoutes.isEmpty());

        mSelectableRoutes = ensureList(src.createStringArrayList());
        mDeselectableRoutes = ensureList(src.createStringArrayList());
        mTransferableRoutes = ensureList(src.createStringArrayList());
@@ -416,15 +417,21 @@ public final class RoutingSessionInfo implements Parcelable {
        return result.toString();
    }

    /**
     * Provides a new list with unique route IDs if {@link #mProviderId} is set, or the original IDs
     * otherwise.
     *
     * @param routeIds list of route IDs to convert
     * @return new list with unique IDs or original IDs
     */

    @NonNull
    private List<String> convertToUniqueRouteIds(@NonNull List<String> routeIds) {
        if (routeIds == null) {
            Log.w(TAG, "routeIds is null. Returning an empty list");
            return Collections.emptyList();
        }
        Objects.requireNonNull(routeIds, "RouteIds cannot be null.");

        // mProviderId can be null if not set. Return the original list for this case.
        if (TextUtils.isEmpty(mProviderId)) {
            return routeIds;
            return new ArrayList<>(routeIds);
        }

        List<String> result = new ArrayList<>();