Allow synthetic field(s) in ObjectWrapper bc6bc583b9
This commit is contained in:
parent
8e98efdf09
commit
5f278780e1
1 changed files with 36 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ package com.google.android.gms.dynamic;
|
|||
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -34,10 +35,13 @@ public class ObjectWrapper<T> extends IObjectWrapper.Stub {
|
|||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (obj instanceof ObjectWrapper) {
|
||||
return ((ObjectWrapper<?>) obj).t;
|
||||
}
|
||||
|
||||
IBinder binder = obj.asBinder();
|
||||
<<<<<<< HEAD
|
||||
Field[] fields = binder.getClass().getDeclaredFields();
|
||||
|
||||
if (fields.length < 1) {
|
||||
|
|
@ -65,6 +69,9 @@ public class ObjectWrapper<T> extends IObjectWrapper.Stub {
|
|||
if (field == null) {
|
||||
throw new IllegalArgumentException("No non-synthetic fields were found");
|
||||
}
|
||||
=======
|
||||
Field field = getField(binder);
|
||||
>>>>>>> 42253b04 (Allow synthetic field(s) in ObjectWrapper https://github.com/microg/GmsCore/commit/bc6bc583b9ebce160faab449cb62d947b5d791b9)
|
||||
|
||||
if (!field.isAccessible()) {
|
||||
field.setAccessible(true);
|
||||
|
|
@ -85,6 +92,35 @@ public class ObjectWrapper<T> extends IObjectWrapper.Stub {
|
|||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Field getField(IBinder binder) {
|
||||
Field[] fields = binder.getClass().getDeclaredFields();
|
||||
|
||||
if (fields.length < 1) {
|
||||
throw new IllegalArgumentException("No fields were found");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Field field = null;
|
||||
|
||||
for (Field currentField : fields) {
|
||||
if (currentField.isSynthetic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (field == null) {
|
||||
field = currentField;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Too many non-synthetic fields were found");
|
||||
}
|
||||
}
|
||||
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("No non-synthetic fields were found");
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T unwrapTyped(IObjectWrapper obj, Class<T> clazz) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue