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

Commit 97449fa3 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Lists returned from OS aren't mutable.

Data returned via ParceledListSlice is a snapshot of data from the
system, and should not be mutated directly.

In particular, this can cause developer confusion if they call
Collection.remove(), which doesn't actually mutate the value in the
system.  There are other mutation APIs that developers should be
using instead, such as JobScheduler.cancel().

Test: builds, boots, common operations work
Bug: 27856974
Change-Id: I72528dee4d79e483aa295bd91d1ed80d0d72d21c
parent 29993074
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -17,12 +17,15 @@
package android.content.pm;

import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.util.Log;

import dalvik.system.VMRuntime;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -127,8 +130,12 @@ public class ParceledListSlice<T extends Parcelable> implements Parcelable {
    }

    public List<T> getList() {
        if (VMRuntime.getRuntime().getTargetSdkVersion() > Build.VERSION_CODES.N_MR1) {
            return Collections.unmodifiableList(mList);
        } else {
            return mList;
        }
    }

    @Override
    public int describeContents() {
+2 −2
Original line number Diff line number Diff line
@@ -104,8 +104,8 @@ public class RecentsTaskLoadPlan {
        int currentUserId = UserHandle.USER_CURRENT;
        updateCurrentQuietProfilesCache(currentUserId);
        SystemServicesProxy ssp = Recents.getSystemServices();
        mRawTasks = ssp.getRecentTasks(ActivityManager.getMaxRecentTasksStatic(),
                currentUserId, includeFrontMostExcludedTask, mCurrentQuietProfiles);
        mRawTasks = new ArrayList<>(ssp.getRecentTasks(ActivityManager.getMaxRecentTasksStatic(),
                currentUserId, includeFrontMostExcludedTask, mCurrentQuietProfiles));

        // Since the raw tasks are given in most-recent to least-recent order, we need to reverse it
        Collections.reverse(mRawTasks);