From ebbb0ce80098f34905cc483a2022a616c30427e1 Mon Sep 17 00:00:00 2001 From: Jayant Chowdhary Date: Tue, 8 Jun 2021 09:41:40 -0700 Subject: [PATCH] OutputConfiguration: fix CREATOR readList for sensor pixel modes. OutputConfiguration uses writeIntArray in writeToParcel. It must use readIntArray in createFromParcel instead of readList. Bug: 188675581 Test: Sample app which tries to write invalid data into an OutputConfiguration parcel. When read again, the exception is thrown and not swallowed. Test: create OutputConfiguration; add certain sensorPixelModes; writeToParcel; set parcel's data position to 0; create OutputConfiguration from same parcel and read sensor pixel modes. They match. Change-Id: Id50396d328ba6fc830012a1c359934cf82249764 Signed-off-by: Jayant Chowdhary --- .../camera2/params/OutputConfiguration.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/core/java/android/hardware/camera2/params/OutputConfiguration.java b/core/java/android/hardware/camera2/params/OutputConfiguration.java index 1124b26654578..5bb7201eff65e 100644 --- a/core/java/android/hardware/camera2/params/OutputConfiguration.java +++ b/core/java/android/hardware/camera2/params/OutputConfiguration.java @@ -735,8 +735,7 @@ public final class OutputConfiguration implements Parcelable { source.readTypedList(surfaces, Surface.CREATOR); String physicalCameraId = source.readString(); boolean isMultiResolutionOutput = source.readInt() == 1; - ArrayList sensorPixelModesUsed = new ArrayList(); - source.readList(sensorPixelModesUsed, Integer.class.getClassLoader()); + int[] sensorPixelModesUsed = source.createIntArray(); checkArgumentInRange(rotation, ROTATION_0, ROTATION_270, "Rotation constant"); mSurfaceGroupId = surfaceSetId; @@ -760,7 +759,7 @@ public final class OutputConfiguration implements Parcelable { } mPhysicalCameraId = physicalCameraId; mIsMultiResolution = isMultiResolutionOutput; - mSensorPixelModesUsed = sensorPixelModesUsed; + mSensorPixelModesUsed = convertIntArrayToIntegerList(sensorPixelModesUsed); } /** @@ -848,6 +847,17 @@ public final class OutputConfiguration implements Parcelable { return integerArray; } + private static ArrayList convertIntArrayToIntegerList(int[] intArray) { + ArrayList integerList = new ArrayList(); + if (intArray == null) { + return integerList; + } + for (int i = 0; i < intArray.length; i++) { + integerList.add(intArray[i]); + } + return integerList; + } + @Override public void writeToParcel(Parcel dest, int flags) { if (dest == null) { @@ -865,7 +875,6 @@ public final class OutputConfiguration implements Parcelable { dest.writeInt(mIsMultiResolution ? 1 : 0); // writeList doesn't seem to work well with Integer list. dest.writeIntArray(convertIntegerToIntList(mSensorPixelModesUsed)); - //dest.writeArray(mSensorPixelModesUsed.toArray()); } /**