Skip to content

Commit

Permalink
safeparcel: Support short
Browse files Browse the repository at this point in the history
* 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.<init>(SafeParcelReflectionUtil.java:465)
	       at org.microg.safeparcel.SafeParcelReflectionUtil$ClassDescriptor.<init>(SafeParcelReflectionUtil.java:411)
	       at org.microg.safeparcel.ReflectedSafeParcelableCreatorAndWriter.<init>(ReflectedSafeParcelableCreatorAndWriter.java:18)
	       at org.microg.safeparcel.AutoSafeParcelable$AutoCreator.<init>(AutoSafeParcelable.java:45)
	       at com.google.android.gms.fido.fido2.api.common.UvmEntries.<clinit>(UvmEntries.java:80)
	       <snipped>
	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
  • Loading branch information
chirayudesai committed Aug 28, 2023
1 parent e00b985 commit 82296fd
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -364,6 +367,14 @@ private static void readField(AutoSafeParcelable object, Parcel parcel, int head
descriptor.field.set(object, l);
break;
}
case Short: {
short i = (short) 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;
Expand All @@ -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<T> {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 82296fd

Please sign in to comment.