mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-14 09:57:16 +01:00
203 lines
8.8 KiB
Java
203 lines
8.8 KiB
Java
package androidx.lifecycle;
|
|
|
|
import ai.onnxruntime.OnnxMap$$ExternalSyntheticBUOutline0;
|
|
import androidx.lifecycle.Lifecycle;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import okio.Buffer$$ExternalSyntheticBUOutline0;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@Deprecated
|
|
/* loaded from: classes14.dex */
|
|
final class ClassesInfoCache {
|
|
private static final int CALL_TYPE_NO_ARG = 0;
|
|
private static final int CALL_TYPE_PROVIDER = 1;
|
|
private static final int CALL_TYPE_PROVIDER_WITH_EVENT = 2;
|
|
static ClassesInfoCache sInstance = new ClassesInfoCache();
|
|
private final Map<Class<?>, CallbackInfo> mCallbackMap = new HashMap();
|
|
private final Map<Class<?>, Boolean> mHasLifecycleMethods = new HashMap();
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@Deprecated
|
|
public static class CallbackInfo {
|
|
final Map<Lifecycle.Event, List<MethodReference>> mEventToHandlers = new HashMap();
|
|
final Map<MethodReference, Lifecycle.Event> mHandlerToEvent;
|
|
|
|
public CallbackInfo(Map<MethodReference, Lifecycle.Event> map) {
|
|
this.mHandlerToEvent = map;
|
|
for (Map.Entry<MethodReference, Lifecycle.Event> entry : map.entrySet()) {
|
|
Lifecycle.Event value = entry.getValue();
|
|
List<MethodReference> list = this.mEventToHandlers.get(value);
|
|
if (list == null) {
|
|
list = new ArrayList<>();
|
|
this.mEventToHandlers.put(value, list);
|
|
}
|
|
list.add(entry.getKey());
|
|
}
|
|
}
|
|
|
|
private static void invokeMethodsForEvent(List<MethodReference> list, LifecycleOwner lifecycleOwner, Lifecycle.Event event, Object obj) {
|
|
if (list != null) {
|
|
for (int size = list.size() - 1; size >= 0; size--) {
|
|
list.get(size).invokeCallback(lifecycleOwner, event, obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void invokeCallbacks(LifecycleOwner lifecycleOwner, Lifecycle.Event event, Object obj) {
|
|
invokeMethodsForEvent(this.mEventToHandlers.get(event), lifecycleOwner, event, obj);
|
|
invokeMethodsForEvent(this.mEventToHandlers.get(Lifecycle.Event.ON_ANY), lifecycleOwner, event, obj);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@Deprecated
|
|
public static final class MethodReference {
|
|
final int mCallType;
|
|
final Method mMethod;
|
|
|
|
public MethodReference(int i, Method method) {
|
|
this.mCallType = i;
|
|
this.mMethod = method;
|
|
method.setAccessible(true);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof MethodReference)) {
|
|
return false;
|
|
}
|
|
MethodReference methodReference = (MethodReference) obj;
|
|
return this.mCallType == methodReference.mCallType && this.mMethod.getName().equals(methodReference.mMethod.getName());
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.mMethod.getName().hashCode() + (this.mCallType * 31);
|
|
}
|
|
|
|
public void invokeCallback(LifecycleOwner lifecycleOwner, Lifecycle.Event event, Object obj) {
|
|
try {
|
|
int i = this.mCallType;
|
|
if (i == 0) {
|
|
this.mMethod.invoke(obj, null);
|
|
} else if (i == 1) {
|
|
this.mMethod.invoke(obj, lifecycleOwner);
|
|
} else {
|
|
if (i != 2) {
|
|
return;
|
|
}
|
|
this.mMethod.invoke(obj, lifecycleOwner, event);
|
|
}
|
|
} catch (IllegalAccessException e) {
|
|
Buffer$$ExternalSyntheticBUOutline0.m((Throwable) e);
|
|
} catch (InvocationTargetException e2) {
|
|
OnnxMap$$ExternalSyntheticBUOutline0.m("Failed to call observer method", e2.getCause());
|
|
}
|
|
}
|
|
}
|
|
|
|
private CallbackInfo createInfo(Class<?> cls, Method[] methodArr) {
|
|
int i;
|
|
CallbackInfo info;
|
|
Class<?> superclass = cls.getSuperclass();
|
|
HashMap hashMap = new HashMap();
|
|
if (superclass != null && (info = getInfo(superclass)) != null) {
|
|
hashMap.putAll(info.mHandlerToEvent);
|
|
}
|
|
for (Class<?> cls2 : cls.getInterfaces()) {
|
|
for (Map.Entry<MethodReference, Lifecycle.Event> entry : getInfo(cls2).mHandlerToEvent.entrySet()) {
|
|
verifyAndPutHandler(hashMap, entry.getKey(), entry.getValue(), cls);
|
|
}
|
|
}
|
|
if (methodArr == null) {
|
|
methodArr = getDeclaredMethods(cls);
|
|
}
|
|
boolean z = false;
|
|
for (Method method : methodArr) {
|
|
OnLifecycleEvent onLifecycleEvent = (OnLifecycleEvent) method.getAnnotation(OnLifecycleEvent.class);
|
|
if (onLifecycleEvent != null) {
|
|
Class<?>[] parameterTypes = method.getParameterTypes();
|
|
if (parameterTypes.length <= 0) {
|
|
i = 0;
|
|
} else {
|
|
if (!LifecycleOwner.class.isAssignableFrom(parameterTypes[0])) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("invalid parameter type. Must be one and instanceof LifecycleOwner");
|
|
return null;
|
|
}
|
|
i = 1;
|
|
}
|
|
Lifecycle.Event value = onLifecycleEvent.value();
|
|
if (parameterTypes.length > 1) {
|
|
if (!Lifecycle.Event.class.isAssignableFrom(parameterTypes[1])) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("invalid parameter type. second arg must be an event");
|
|
return null;
|
|
}
|
|
if (value != Lifecycle.Event.ON_ANY) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Second arg is supported only for ON_ANY value");
|
|
return null;
|
|
}
|
|
i = 2;
|
|
}
|
|
if (parameterTypes.length > 2) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("cannot have more than 2 params");
|
|
return null;
|
|
}
|
|
verifyAndPutHandler(hashMap, new MethodReference(i, method), value, cls);
|
|
z = true;
|
|
}
|
|
}
|
|
CallbackInfo callbackInfo = new CallbackInfo(hashMap);
|
|
this.mCallbackMap.put(cls, callbackInfo);
|
|
this.mHasLifecycleMethods.put(cls, Boolean.valueOf(z));
|
|
return callbackInfo;
|
|
}
|
|
|
|
private Method[] getDeclaredMethods(Class<?> cls) {
|
|
try {
|
|
return cls.getDeclaredMethods();
|
|
} catch (NoClassDefFoundError e) {
|
|
Single$$ExternalSyntheticBUOutline0.m("The observer class has some methods that use newer APIs which are not available in the current OS version. Lifecycles cannot access even other methods so you should make sure that your observer classes only access framework classes that are available in your min API level OR use lifecycle:compiler annotation processor.", e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private void verifyAndPutHandler(Map<MethodReference, Lifecycle.Event> map, MethodReference methodReference, Lifecycle.Event event, Class<?> cls) {
|
|
Lifecycle.Event event2 = map.get(methodReference);
|
|
if (event2 == null || event == event2) {
|
|
if (event2 == null) {
|
|
map.put(methodReference, event);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Method " + methodReference.mMethod.getName() + " in " + cls.getName() + " already declared with different @OnLifecycleEvent value: previous value " + event2 + ", new value " + event);
|
|
}
|
|
|
|
public CallbackInfo getInfo(Class<?> cls) {
|
|
CallbackInfo callbackInfo = this.mCallbackMap.get(cls);
|
|
return callbackInfo != null ? callbackInfo : createInfo(cls, null);
|
|
}
|
|
|
|
public boolean hasLifecycleMethods(Class<?> cls) {
|
|
Boolean bool = this.mHasLifecycleMethods.get(cls);
|
|
if (bool != null) {
|
|
return bool.booleanValue();
|
|
}
|
|
Method[] declaredMethods = getDeclaredMethods(cls);
|
|
for (Method method : declaredMethods) {
|
|
if (((OnLifecycleEvent) method.getAnnotation(OnLifecycleEvent.class)) != null) {
|
|
createInfo(cls, declaredMethods);
|
|
return true;
|
|
}
|
|
}
|
|
this.mHasLifecycleMethods.put(cls, Boolean.FALSE);
|
|
return false;
|
|
}
|
|
}
|