51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
|
package com.google.android.gms.dynamic;
|
||
|
|
||
|
import android.os.IBinder;
|
||
|
import com.google.android.gms.common.internal.Preconditions;
|
||
|
import com.google.android.gms.dynamic.IObjectWrapper;
|
||
|
import java.lang.reflect.Field;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public final class ObjectWrapper<T> extends IObjectWrapper.Stub {
|
||
|
private final Object zza;
|
||
|
|
||
|
private ObjectWrapper(Object obj) {
|
||
|
this.zza = obj;
|
||
|
}
|
||
|
|
||
|
public static <T> T unwrap(IObjectWrapper iObjectWrapper) {
|
||
|
if (iObjectWrapper instanceof ObjectWrapper) {
|
||
|
return (T) ((ObjectWrapper) iObjectWrapper).zza;
|
||
|
}
|
||
|
IBinder asBinder = iObjectWrapper.asBinder();
|
||
|
Field[] declaredFields = asBinder.getClass().getDeclaredFields();
|
||
|
Field field = null;
|
||
|
int i = 0;
|
||
|
for (Field field2 : declaredFields) {
|
||
|
if (!field2.isSynthetic()) {
|
||
|
i++;
|
||
|
field = field2;
|
||
|
}
|
||
|
}
|
||
|
if (i == 1) {
|
||
|
Preconditions.checkNotNull(field);
|
||
|
if (!field.isAccessible()) {
|
||
|
field.setAccessible(true);
|
||
|
try {
|
||
|
return (T) field.get(asBinder);
|
||
|
} catch (IllegalAccessException e) {
|
||
|
throw new IllegalArgumentException("Could not access the field in remoteBinder.", e);
|
||
|
} catch (NullPointerException e2) {
|
||
|
throw new IllegalArgumentException("Binder object is null.", e2);
|
||
|
}
|
||
|
}
|
||
|
throw new IllegalArgumentException("IObjectWrapper declared field not private!");
|
||
|
}
|
||
|
throw new IllegalArgumentException("Unexpected number of IObjectWrapper declared fields: " + declaredFields.length);
|
||
|
}
|
||
|
|
||
|
public static <T> IObjectWrapper wrap(T t) {
|
||
|
return new ObjectWrapper(t);
|
||
|
}
|
||
|
}
|