From 3b7feb3b1534e04b8225992ad479176d93cfecba Mon Sep 17 00:00:00 2001 From: Chirayu Desai Date: Mon, 28 Aug 2023 23:32:21 +0530 Subject: [PATCH] safeparcel: Support short * Fixes crash with certain USB security keys, exception: FATAL EXCEPTION: main Process: com.google.android.gms:ui, PID: 6301 java.lang.ExceptionInInitializerError at java.lang.reflect.Field.get(Native Method) at org.microg.safeparcel.SafeParcelReflectionUtil.getCreator(SafeParcelReflectionUtil.java:123) at org.microg.safeparcel.SafeParcelReflectionUtil$ClassDescriptor$FieldDescriptor.(SafeParcelReflectionUtil.java:465) at org.microg.safeparcel.SafeParcelReflectionUtil$ClassDescriptor.(SafeParcelReflectionUtil.java:411) at org.microg.safeparcel.ReflectedSafeParcelableCreatorAndWriter.(ReflectedSafeParcelableCreatorAndWriter.java:18) at org.microg.safeparcel.AutoSafeParcelable$AutoCreator.(AutoSafeParcelable.java:45) at com.google.android.gms.fido.fido2.api.common.UvmEntries.(UvmEntries.java:80) Caused by: java.lang.RuntimeException: Type is not yet usable with SafeParcelReflectionUtil: short at org.microg.safeparcel.SafeParcelReflectionUtil$ClassDescriptor$FieldDescriptor.getType(SafeParcelReflectionUtil.java:521) Change-Id: Ie1c523d932ac213c531edf1e227c6ddcb72916bd --- .../safeparcel/SafeParcelReflectionUtil.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/play-services-basement/src/main/java/org/microg/safeparcel/SafeParcelReflectionUtil.java b/play-services-basement/src/main/java/org/microg/safeparcel/SafeParcelReflectionUtil.java index d0cf738285..4fdd1d2dd8 100644 --- a/play-services-basement/src/main/java/org/microg/safeparcel/SafeParcelReflectionUtil.java +++ b/play-services-basement/src/main/java/org/microg/safeparcel/SafeParcelReflectionUtil.java @@ -243,6 +243,9 @@ private static void writeField(AutoSafeParcelable object, Parcel parcel, int fla case Long: SafeParcelWriter.write(parcel, descriptor.id, (Long) descriptor.field.get(object)); break; + case Short: + SafeParcelWriter.write(parcel, descriptor.id, (Short) descriptor.field.get(object)); + break; case Boolean: SafeParcelWriter.write(parcel, descriptor.id, (Boolean) descriptor.field.get(object)); break; @@ -364,6 +367,14 @@ private static void readField(AutoSafeParcelable object, Parcel parcel, int head descriptor.field.set(object, l); break; } + case Short: { + short i = SafeParcelReader.readShort(parcel, header); + if (descriptor.versionCode != -1 && i > descriptor.versionCode) { + Log.d(TAG, String.format("Version code of %s (%d) is older than object read (%d).", descriptor.field.getDeclaringClass().getName(), descriptor.versionCode, i)); + } + descriptor.field.set(object, i); + break; + } case Boolean: descriptor.field.set(object, SafeParcelReader.readBool(parcel, header)); break; @@ -388,7 +399,7 @@ private enum SafeParcelType { Parcelable, Binder, Interface, Bundle, StringList, IntegerList, BooleanList, LongList, FloatList, DoubleList, List, Map, ParcelableArray, StringArray, ByteArray, ByteArrayArray, FloatArray, IntArray, - Integer, Long, Boolean, Float, Double, String, Byte; + Integer, Long, Short, Boolean, Float, Double, String, Byte; } public static class ClassDescriptor { @@ -506,6 +517,8 @@ private SafeParcelType getType() { return SafeParcelType.Map; if (clazz == int.class || clazz == Integer.class) return SafeParcelType.Integer; + if (clazz == short.class || clazz == Short.class) + return SafeParcelType.Short; if (clazz == boolean.class || clazz == Boolean.class) return SafeParcelType.Boolean; if (clazz == long.class || clazz == Long.class)