summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alexandru-Andrei Rotaru <rotaru@google.com> 2017-08-18 15:54:36 +0100
committer Andrew Scull <ascull@google.com> 2017-08-23 10:07:28 +0000
commitb7a79b47cbf3888745be2b0c33a77532dc0d2cf0 (patch)
treefd78629e04d0f786c4fcea59b2bc88e3a6550dae
parenta68cdbe7b193e2ac4ad47935bb06e5bf8bbd1693 (diff)
StringParceledListSlice throws exception when the IPC memory threshold is exceeded
Fixed the code such that list of strings that exceed the 256KB limit can be transfered. Bug: 64833731 Test: Added unit test in ParceledListSliceTest Change-Id: I4e16708010125a444baa8fcb0af6101dc643cd38 (cherry picked from commit 2682fa70678ec79131329a6071d70c3d84c23d41)
-rw-r--r--core/java/android/content/pm/BaseParceledListSlice.java2
-rw-r--r--core/tests/coretests/src/android/content/pm/ParceledListSliceTest.java31
2 files changed, 25 insertions, 8 deletions
diff --git a/core/java/android/content/pm/BaseParceledListSlice.java b/core/java/android/content/pm/BaseParceledListSlice.java
index aaa5f19c3fca..5877a09b7759 100644
--- a/core/java/android/content/pm/BaseParceledListSlice.java
+++ b/core/java/android/content/pm/BaseParceledListSlice.java
@@ -102,7 +102,7 @@ abstract class BaseParceledListSlice<T> implements Parcelable {
return;
}
while (i < N && reply.readInt() != 0) {
- final T parcelable = reply.readCreator(creator, loader);
+ final T parcelable = readCreator(creator, reply, loader);
verifySameType(listElementClass, parcelable.getClass());
mList.add(parcelable);
diff --git a/core/tests/coretests/src/android/content/pm/ParceledListSliceTest.java b/core/tests/coretests/src/android/content/pm/ParceledListSliceTest.java
index 5dd3c2ce6b5d..a9d19b4b295c 100644
--- a/core/tests/coretests/src/android/content/pm/ParceledListSliceTest.java
+++ b/core/tests/coretests/src/android/content/pm/ParceledListSliceTest.java
@@ -2,9 +2,11 @@ package android.content.pm;
import android.os.Parcel;
import android.os.Parcelable;
+
import junit.framework.TestCase;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
public class ParceledListSliceTest extends TestCase {
@@ -91,15 +93,10 @@ public class ParceledListSliceTest extends TestCase {
}
}
- public void testStringList() throws Exception {
- final int objectCount = 400;
- List<String> list = new ArrayList<String>();
- for (long i = 0; i < objectCount; i++) {
- list.add(Long.toString(i * (6 - i)));
- }
-
+ private void sendParcelStringList(List<String> list) {
StringParceledListSlice slice;
Parcel parcel = Parcel.obtain();
+
try {
parcel.writeParcelable(new StringParceledListSlice(list), 0);
parcel.setDataPosition(0);
@@ -113,6 +110,26 @@ public class ParceledListSliceTest extends TestCase {
assertEquals(list, slice.getList());
}
+ public void testStringList() throws Exception {
+ final int objectCount = 400;
+ List<String> list = new ArrayList<String>();
+ for (long i = 0; i < objectCount; i++) {
+ list.add(Long.toString(i * (6 - i)));
+ }
+
+ sendParcelStringList(list);
+ }
+
+ public void testLargeStringList() throws Exception {
+ final int thresholdBytes = 256 * 1024;
+ final String value = Long.toString(Long.MAX_VALUE);
+ final int objectCount = 2 * thresholdBytes / value.length();
+ final List<String> list = Collections.nCopies(objectCount, value);
+
+ sendParcelStringList(list);
+ }
+
+
/**
* Test that only homogeneous elements may be unparceled.
*/