From 97449fa389dbc1ab872d63fde001bae7a659991b Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 18 Nov 2016 11:05:18 -0700 Subject: [PATCH] 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 --- core/java/android/content/pm/ParceledListSlice.java | 9 ++++++++- .../systemui/recents/model/RecentsTaskLoadPlan.java | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/java/android/content/pm/ParceledListSlice.java b/core/java/android/content/pm/ParceledListSlice.java index 945858e6d3c65..29ea5a07ee9b9 100644 --- a/core/java/android/content/pm/ParceledListSlice.java +++ b/core/java/android/content/pm/ParceledListSlice.java @@ -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,7 +130,11 @@ public class ParceledListSlice implements Parcelable { } public List getList() { - return mList; + if (VMRuntime.getRuntime().getTargetSdkVersion() > Build.VERSION_CODES.N_MR1) { + return Collections.unmodifiableList(mList); + } else { + return mList; + } } @Override diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java index 9b48e4d02623c..5bfc17fcaaf96 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java +++ b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java @@ -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);