Merge "Copy lists to ensure deep immutability in RoutingSessionInfo"
This commit is contained in:
@@ -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<>();
|
||||
|
||||
Reference in New Issue
Block a user