what-the-bank/sources/retrofit2/Platform.java

121 lines
4.3 KiB
Java

package retrofit2;
import android.os.Handler;
import android.os.Looper;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
import retrofit2.CallAdapter;
import retrofit2.Converter;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class Platform {
private static final Platform PLATFORM = findPlatform();
private final boolean hasJava8Types;
private final Constructor<MethodHandles.Lookup> lookupConstructor;
/* JADX INFO: Access modifiers changed from: package-private */
public Executor defaultCallbackExecutor() {
return null;
}
private static Platform findPlatform() {
if ("Dalvik".equals(System.getProperty("java.vm.name"))) {
return new Android();
}
return new Platform(true);
}
Platform(boolean z) {
this.hasJava8Types = z;
Constructor<MethodHandles.Lookup> constructor = null;
if (z) {
try {
constructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, Integer.TYPE);
constructor.setAccessible(true);
} catch (NoClassDefFoundError | NoSuchMethodException unused) {
}
}
this.lookupConstructor = constructor;
}
/* JADX INFO: Access modifiers changed from: package-private */
public List<? extends CallAdapter.Factory> defaultCallAdapterFactories(Executor executor) {
DefaultCallAdapterFactory defaultCallAdapterFactory = new DefaultCallAdapterFactory(executor);
return this.hasJava8Types ? Arrays.asList(CompletableFutureCallAdapterFactory.INSTANCE, defaultCallAdapterFactory) : Collections.singletonList(defaultCallAdapterFactory);
}
/* JADX INFO: Access modifiers changed from: package-private */
public List<? extends Converter.Factory> defaultConverterFactories() {
return this.hasJava8Types ? Collections.singletonList(OptionalConverterFactory.INSTANCE) : Collections.emptyList();
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean isDefaultMethod(Method method) {
return this.hasJava8Types && method.isDefault();
}
/* JADX INFO: Access modifiers changed from: package-private */
public Object invokeDefaultMethod(Method method, Class<?> cls, Object obj, Object... objArr) throws Throwable {
MethodHandles.Lookup lookup;
Constructor<MethodHandles.Lookup> constructor = this.lookupConstructor;
if (constructor != null) {
lookup = constructor.newInstance(cls, -1);
} else {
lookup = MethodHandles.lookup();
}
return lookup.unreflectSpecial(method, cls).bindTo(obj).invokeWithArguments(objArr);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static final class Android extends Platform {
Android() {
super(true);
}
@Override // retrofit2.Platform
public final Executor defaultCallbackExecutor() {
return new MainThreadExecutor();
}
@Override // retrofit2.Platform
final Object invokeDefaultMethod(Method method, Class<?> cls, Object obj, Object... objArr) throws Throwable {
return super.invokeDefaultMethod(method, cls, obj, objArr);
}
/* loaded from: classes.dex */
static final class MainThreadExecutor implements Executor {
private final Handler handler = new Handler(Looper.getMainLooper());
MainThreadExecutor() {
}
@Override // java.util.concurrent.Executor
public final void execute(Runnable runnable) {
this.handler.post(runnable);
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public int defaultConverterFactoriesSize() {
return this.hasJava8Types ? 1 : 0;
}
/* JADX INFO: Access modifiers changed from: package-private */
public int defaultCallAdapterFactoriesSize() {
return this.hasJava8Types ? 2 : 1;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static Platform get() {
return PLATFORM;
}
}