package p037.p099;

import androidx.lifecycle.CompositeGeneratedAdaptersObserver;
import androidx.lifecycle.FullLifecycleObserverAdapter;
import androidx.lifecycle.ReflectiveGenericLifecycleObserver;
import androidx.lifecycle.SingleGeneratedAdapterObserver;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* JADX INFO: renamed from: މ.ދ.ޑ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C2225 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Map<Class<?>, Integer> f7169 = new HashMap();

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static Map<Class<?>, List<Constructor<? extends InterfaceC2207>>> f7170 = new HashMap();

    /* JADX WARN: Removed duplicated region for block: B:60:0x00f0  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x011c A[SYNTHETIC] */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int m4285(Class<?> cls) {
        Constructor<?> declaredConstructor;
        boolean zBooleanValue;
        int length;
        int i;
        Integer num = f7169.get(cls);
        if (num != null) {
            return num.intValue();
        }
        int i2 = 1;
        if (cls.getCanonicalName() != null) {
            ArrayList arrayList = null;
            try {
                Package r4 = cls.getPackage();
                String canonicalName = cls.getCanonicalName();
                String name = r4 != null ? r4.getName() : "";
                if (!name.isEmpty()) {
                    canonicalName = canonicalName.substring(name.length() + 1);
                }
                String strM4286 = m4286(canonicalName);
                if (!name.isEmpty()) {
                    strM4286 = name + "." + strM4286;
                }
                declaredConstructor = Class.forName(strM4286).getDeclaredConstructor(cls);
                if (!declaredConstructor.isAccessible()) {
                    declaredConstructor.setAccessible(true);
                }
            } catch (ClassNotFoundException unused) {
                declaredConstructor = null;
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
            if (declaredConstructor != null) {
                f7170.put(cls, Collections.singletonList(declaredConstructor));
            } else {
                C2201 c2201 = C2201.f7141;
                Boolean bool = c2201.f7143.get(cls);
                if (bool != null) {
                    zBooleanValue = bool.booleanValue();
                } else {
                    try {
                        Method[] declaredMethods = cls.getDeclaredMethods();
                        int length2 = declaredMethods.length;
                        int i3 = 0;
                        while (true) {
                            if (i3 >= length2) {
                                c2201.f7143.put(cls, false);
                                zBooleanValue = false;
                                break;
                            }
                            if (((InterfaceC2231) declaredMethods[i3].getAnnotation(InterfaceC2231.class)) != null) {
                                c2201.m4263(cls, declaredMethods);
                                zBooleanValue = true;
                                break;
                            }
                            i3++;
                        }
                    } catch (NoClassDefFoundError e2) {
                        throw new IllegalArgumentException("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.", e2);
                    }
                }
                if (!zBooleanValue) {
                    Class<? super Object> superclass = cls.getSuperclass();
                    if (!(superclass != null && InterfaceC2218.class.isAssignableFrom(superclass))) {
                        Class<?>[] interfaces = cls.getInterfaces();
                        length = interfaces.length;
                        i = 0;
                        while (true) {
                            if (i < length) {
                                Class<?> cls2 = interfaces[i];
                                if (cls2 != null && InterfaceC2218.class.isAssignableFrom(cls2)) {
                                    if (m4285(cls2) == 1) {
                                        break;
                                    }
                                    if (arrayList == null) {
                                        arrayList = new ArrayList();
                                    }
                                    arrayList.addAll(f7170.get(cls2));
                                }
                                i++;
                            } else if (arrayList != null) {
                                f7170.put(cls, arrayList);
                            }
                        }
                    } else if (m4285((Class<?>) superclass) != 1) {
                        arrayList = new ArrayList(f7170.get(superclass));
                        Class<?>[] interfaces2 = cls.getInterfaces();
                        length = interfaces2.length;
                        i = 0;
                        while (true) {
                            if (i < length) {
                            }
                            i++;
                        }
                    }
                }
            }
            i2 = 2;
        }
        f7169.put(cls, Integer.valueOf(i2));
        return i2;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static String m4286(String str) {
        return str.replace(".", "_") + "_LifecycleAdapter";
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static InterfaceC2207 m4287(Constructor<? extends InterfaceC2207> 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);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static InterfaceC2217 m4288(Object obj) {
        boolean z = obj instanceof InterfaceC2217;
        boolean z2 = obj instanceof InterfaceC2206;
        if (z && z2) {
            return new FullLifecycleObserverAdapter((InterfaceC2206) obj, (InterfaceC2217) obj);
        }
        if (z2) {
            return new FullLifecycleObserverAdapter((InterfaceC2206) obj, null);
        }
        if (z) {
            return (InterfaceC2217) obj;
        }
        Class<?> cls = obj.getClass();
        if (m4285(cls) != 2) {
            return new ReflectiveGenericLifecycleObserver(obj);
        }
        List<Constructor<? extends InterfaceC2207>> list = f7170.get(cls);
        if (list.size() == 1) {
            return new SingleGeneratedAdapterObserver(m4287(list.get(0), obj));
        }
        InterfaceC2207[] interfaceC2207Arr = new InterfaceC2207[list.size()];
        for (int i = 0; i < list.size(); i++) {
            interfaceC2207Arr[i] = m4287(list.get(i), obj);
        }
        return new CompositeGeneratedAdaptersObserver(interfaceC2207Arr);
    }
}
