From 5cefb5dadf2f453a24503d9d875d804537936bc3 Mon Sep 17 00:00:00 2001 From: Justson Date: Fri, 3 Jul 2020 17:25:02 +0800 Subject: [PATCH] fix(pigeon): fix data loat in transmission --- .../com/flyingpigeon/sample/RemoteService.java | 2 +- .../java/com/flyingpigeon/library/Utils.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/flyingpigeon/sample/RemoteService.java b/app/src/main/java/com/flyingpigeon/sample/RemoteService.java index 967a2cb..e95b441 100644 --- a/app/src/main/java/com/flyingpigeon/sample/RemoteService.java +++ b/app/src/main/java/com/flyingpigeon/sample/RemoteService.java @@ -109,7 +109,7 @@ public void submitBitmap(String key, byte[] data, int length) { @RequestLarge @route(value = "/submit/bitmap2") public int submitBitmap2(String key, byte[] data, int length) { - Log.e(TAG, "IPC by route,submitBitmap:" + key + " data length:" + data.length + " length:" + length); + Log.e(TAG, "IPC by route,submitBitmap2:" + key + " data length:" + data.length + " length:" + length); return 1; } diff --git a/library/src/main/java/com/flyingpigeon/library/Utils.java b/library/src/main/java/com/flyingpigeon/library/Utils.java index 28cc995..bdb1b69 100644 --- a/library/src/main/java/com/flyingpigeon/library/Utils.java +++ b/library/src/main/java/com/flyingpigeon/library/Utils.java @@ -10,6 +10,7 @@ import java.io.Serializable; import java.lang.reflect.Type; +import static com.flyingpigeon.library.PigeonConstant.PIGEON_KEY_ARRAY_LENGTH; import static com.flyingpigeon.library.PigeonConstant.map; @@ -288,7 +289,21 @@ static void convert(String key, Bundle bundle, Type type, Object arg) { byte[] array = (byte[]) arg; if (array.length > 8 * 1024) { ParcelFileDescriptor parcelFileDescriptor = Ashmem.byteArrayToFileDescriptor(array); - bundle.putInt(key + "key_array_length", array.length); + bundle.putInt(key + PIGEON_KEY_ARRAY_LENGTH, array.length); + ParameterHandler.ParcelableHandler handler = (ParameterHandler.ParcelableHandler) map.get(Parcelable.class); + assert handler != null; + handler.apply(parcelFileDescriptor, key, bundle); + Parcelable parcelable = bundle.getParcelable(key); + } else { + ParameterHandler.ByteArrayHandler byteArrayHandler = (ParameterHandler.ByteArrayHandler) map.get(byte[].class); + byteArrayHandler.apply(array, byte[].class.getName(), bundle); + } + + } else if (Byte[].class.isAssignableFrom(typeClazz)) { + byte[] array = Utils.toPrimitives((Byte[]) arg); + if (array.length > 8 * 1024) { + ParcelFileDescriptor parcelFileDescriptor = Ashmem.byteArrayToFileDescriptor(array); + bundle.putInt(key + PIGEON_KEY_ARRAY_LENGTH, array.length); ParameterHandler.ParcelableHandler handler = (ParameterHandler.ParcelableHandler) map.get(Parcelable.class); assert handler != null; handler.apply(parcelFileDescriptor, key, bundle);