129 lines
4.2 KiB
Java
129 lines
4.2 KiB
Java
package androidx.lifecycle;
|
|
|
|
import java.lang.reflect.Constructor;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class Lifecycling {
|
|
private static Map<Class, Integer> a = new HashMap();
|
|
private static Map<Class, List<Constructor<? extends GeneratedAdapter>>> b = new HashMap();
|
|
|
|
static GenericLifecycleObserver a(Object obj) {
|
|
if (obj instanceof FullLifecycleObserver) {
|
|
return new FullLifecycleObserverAdapter((FullLifecycleObserver) obj);
|
|
}
|
|
if (obj instanceof GenericLifecycleObserver) {
|
|
return (GenericLifecycleObserver) obj;
|
|
}
|
|
Class<?> cls = obj.getClass();
|
|
if (b(cls) != 2) {
|
|
return new ReflectiveGenericLifecycleObserver(obj);
|
|
}
|
|
List<Constructor<? extends GeneratedAdapter>> list = b.get(cls);
|
|
if (list.size() == 1) {
|
|
return new SingleGeneratedAdapterObserver(a(list.get(0), obj));
|
|
}
|
|
GeneratedAdapter[] generatedAdapterArr = new GeneratedAdapter[list.size()];
|
|
for (int i = 0; i < list.size(); i++) {
|
|
generatedAdapterArr[i] = a(list.get(i), obj);
|
|
}
|
|
return new CompositeGeneratedAdaptersObserver(generatedAdapterArr);
|
|
}
|
|
|
|
private static int b(Class<?> cls) {
|
|
if (a.containsKey(cls)) {
|
|
return a.get(cls).intValue();
|
|
}
|
|
int d = d(cls);
|
|
a.put(cls, Integer.valueOf(d));
|
|
return d;
|
|
}
|
|
|
|
private static boolean c(Class<?> cls) {
|
|
return cls != null && LifecycleObserver.class.isAssignableFrom(cls);
|
|
}
|
|
|
|
private static int d(Class<?> cls) {
|
|
if (cls.getCanonicalName() == null) {
|
|
return 1;
|
|
}
|
|
Constructor<? extends GeneratedAdapter> a2 = a(cls);
|
|
if (a2 != null) {
|
|
b.put(cls, Collections.singletonList(a2));
|
|
return 2;
|
|
}
|
|
if (ClassesInfoCache.c.b(cls)) {
|
|
return 1;
|
|
}
|
|
Class<? super Object> superclass = cls.getSuperclass();
|
|
ArrayList arrayList = null;
|
|
if (c(superclass)) {
|
|
if (b(superclass) == 1) {
|
|
return 1;
|
|
}
|
|
arrayList = new ArrayList(b.get(superclass));
|
|
}
|
|
for (Class<?> cls2 : cls.getInterfaces()) {
|
|
if (c(cls2)) {
|
|
if (b(cls2) == 1) {
|
|
return 1;
|
|
}
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList();
|
|
}
|
|
arrayList.addAll(b.get(cls2));
|
|
}
|
|
}
|
|
if (arrayList == null) {
|
|
return 1;
|
|
}
|
|
b.put(cls, arrayList);
|
|
return 2;
|
|
}
|
|
|
|
private static GeneratedAdapter a(Constructor<? extends GeneratedAdapter> constructor, Object obj) {
|
|
try {
|
|
return constructor.newInstance(obj);
|
|
} catch (IllegalAccessException e) {
|
|
throw new RuntimeException(e);
|
|
} catch (InstantiationException e2) {
|
|
throw new RuntimeException(e2);
|
|
} catch (InvocationTargetException e3) {
|
|
throw new RuntimeException(e3);
|
|
}
|
|
}
|
|
|
|
private static Constructor<? extends GeneratedAdapter> a(Class<?> cls) {
|
|
try {
|
|
Package r0 = cls.getPackage();
|
|
String canonicalName = cls.getCanonicalName();
|
|
String name = r0 != null ? r0.getName() : "";
|
|
if (!name.isEmpty()) {
|
|
canonicalName = canonicalName.substring(name.length() + 1);
|
|
}
|
|
String a2 = a(canonicalName);
|
|
if (!name.isEmpty()) {
|
|
a2 = name + "." + a2;
|
|
}
|
|
Constructor declaredConstructor = Class.forName(a2).getDeclaredConstructor(cls);
|
|
if (!declaredConstructor.isAccessible()) {
|
|
declaredConstructor.setAccessible(true);
|
|
}
|
|
return declaredConstructor;
|
|
} catch (ClassNotFoundException unused) {
|
|
return null;
|
|
} catch (NoSuchMethodException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
|
|
public static String a(String str) {
|
|
return str.replace(".", "_") + "_LifecycleAdapter";
|
|
}
|
|
}
|