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

Commit 2682fa70 authored by Alexandru-Andrei Rotaru's avatar Alexandru-Andrei Rotaru
Browse files

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 : b/64833731
Test: Added unit test in ParceledListSliceTest

Change-Id: I4e16708010125a444baa8fcb0af6101dc643cd38
parent 25b14a1a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+24 −7
Original line number Diff line number Diff line
@@ -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.
     */