jimu-decompiled/sources/retrofit2/Platform.java
2025-05-13 19:24:51 +02:00

103 lines
3.0 KiB
Java

package retrofit2;
import android.os.Build;
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.concurrent.Executor;
import retrofit2.CallAdapter;
/* loaded from: classes2.dex */
class Platform {
private static final Platform PLATFORM = findPlatform();
static class Android extends Platform {
static class MainThreadExecutor implements Executor {
private final Handler handler = new Handler(Looper.getMainLooper());
MainThreadExecutor() {
}
@Override // java.util.concurrent.Executor
public void execute(Runnable runnable) {
this.handler.post(runnable);
}
}
Android() {
}
@Override // retrofit2.Platform
CallAdapter.Factory defaultCallAdapterFactory(Executor executor) {
if (executor != null) {
return new ExecutorCallAdapterFactory(executor);
}
throw new AssertionError();
}
@Override // retrofit2.Platform
public Executor defaultCallbackExecutor() {
return new MainThreadExecutor();
}
}
static class Java8 extends Platform {
Java8() {
}
@Override // retrofit2.Platform
Object invokeDefaultMethod(Method method, Class<?> cls, Object obj, Object... objArr) throws Throwable {
Constructor declaredConstructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, Integer.TYPE);
declaredConstructor.setAccessible(true);
return ((MethodHandles.Lookup) declaredConstructor.newInstance(cls, -1)).unreflectSpecial(method, cls).bindTo(obj).invokeWithArguments(objArr);
}
@Override // retrofit2.Platform
boolean isDefaultMethod(Method method) {
return method.isDefault();
}
}
Platform() {
}
private static Platform findPlatform() {
try {
Class.forName("android.os.Build");
if (Build.VERSION.SDK_INT != 0) {
return new Android();
}
} catch (ClassNotFoundException unused) {
}
try {
Class.forName("java.util.Optional");
return new Java8();
} catch (ClassNotFoundException unused2) {
return new Platform();
}
}
static Platform get() {
return PLATFORM;
}
CallAdapter.Factory defaultCallAdapterFactory(Executor executor) {
return executor != null ? new ExecutorCallAdapterFactory(executor) : DefaultCallAdapterFactory.INSTANCE;
}
Executor defaultCallbackExecutor() {
return null;
}
Object invokeDefaultMethod(Method method, Class<?> cls, Object obj, Object... objArr) throws Throwable {
throw new UnsupportedOperationException();
}
boolean isDefaultMethod(Method method) {
return false;
}
}