Skip to content

Commit

Permalink
fix(pigeon): fix data loat in transmission
Browse files Browse the repository at this point in the history
  • Loading branch information
Justson committed Jul 3, 2020
1 parent 5a81fba commit 5cefb5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 16 additions & 1 deletion library/src/main/java/com/flyingpigeon/library/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5cefb5d

Please sign in to comment.