package androidx.lifecycle;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import n2.AbstractC2612c;

/* JADX INFO: renamed from: androidx.lifecycle.z, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC1116z {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final HashMap f12198a = new HashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final HashMap f12199b = new HashMap();

    public static void a(Constructor constructor, InterfaceC1112v interfaceC1112v) {
        try {
            kotlin.jvm.internal.o.e(constructor.newInstance(interfaceC1112v));
            throw new ClassCastException();
        } catch (IllegalAccessException e6) {
            throw new RuntimeException(e6);
        } catch (InstantiationException e7) {
            throw new RuntimeException(e7);
        } catch (InvocationTargetException e8) {
            throw new RuntimeException(e8);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:61:0x010f  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x0141 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int b(Class cls) {
        Constructor<?> declaredConstructor;
        boolean zBooleanValue;
        F1.I iK;
        HashMap map = f12198a;
        Integer num = (Integer) map.get(cls);
        if (num != null) {
            return num.intValue();
        }
        int i6 = 1;
        if (cls.getCanonicalName() != null) {
            ArrayList arrayList = null;
            try {
                Package r32 = cls.getPackage();
                String canonicalName = cls.getCanonicalName();
                String name = r32 != null ? r32.getName() : "";
                kotlin.jvm.internal.o.e(name);
                if (name.length() != 0) {
                    kotlin.jvm.internal.o.e(canonicalName);
                    canonicalName = canonicalName.substring(name.length() + 1);
                    kotlin.jvm.internal.o.g(canonicalName, "substring(...)");
                }
                kotlin.jvm.internal.o.e(canonicalName);
                String strConcat = S4.w.y0(canonicalName, ".", "_").concat("_LifecycleAdapter");
                if (name.length() != 0) {
                    strConcat = name + '.' + strConcat;
                }
                declaredConstructor = Class.forName(strConcat).getDeclaredConstructor(cls);
                if (!declaredConstructor.isAccessible()) {
                    declaredConstructor.setAccessible(true);
                }
            } catch (ClassNotFoundException unused) {
                declaredConstructor = null;
            } catch (NoSuchMethodException e6) {
                throw new RuntimeException(e6);
            }
            HashMap map2 = f12199b;
            if (declaredConstructor != null) {
                map2.put(cls, AbstractC2612c.q(declaredConstructor));
            } else {
                C1096e c1096e = C1096e.f12165c;
                HashMap map3 = c1096e.f12167b;
                Boolean bool = (Boolean) map3.get(cls);
                if (bool != null) {
                    zBooleanValue = bool.booleanValue();
                } else {
                    try {
                        Method[] declaredMethods = cls.getDeclaredMethods();
                        int length = declaredMethods.length;
                        int i7 = 0;
                        while (true) {
                            if (i7 >= length) {
                                map3.put(cls, Boolean.FALSE);
                                zBooleanValue = false;
                                break;
                            }
                            if (((H) declaredMethods[i7].getAnnotation(H.class)) != null) {
                                c1096e.a(cls, declaredMethods);
                                zBooleanValue = true;
                                break;
                            }
                            i7++;
                        }
                    } catch (NoClassDefFoundError e7) {
                        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.", e7);
                    }
                }
                if (!zBooleanValue) {
                    Class superclass = cls.getSuperclass();
                    if (superclass != null && InterfaceC1112v.class.isAssignableFrom(superclass)) {
                        kotlin.jvm.internal.o.e(superclass);
                        if (b(superclass) != 1) {
                            Object obj = map2.get(superclass);
                            kotlin.jvm.internal.o.e(obj);
                            arrayList = new ArrayList((Collection) obj);
                            iK = kotlin.jvm.internal.o.k(cls.getInterfaces());
                            while (true) {
                                if (!iK.hasNext()) {
                                    Class cls2 = (Class) iK.next();
                                    if (cls2 != null && InterfaceC1112v.class.isAssignableFrom(cls2)) {
                                        kotlin.jvm.internal.o.e(cls2);
                                        if (b(cls2) == 1) {
                                            break;
                                        }
                                        if (arrayList == null) {
                                            arrayList = new ArrayList();
                                        }
                                        Object obj2 = map2.get(cls2);
                                        kotlin.jvm.internal.o.e(obj2);
                                        arrayList.addAll((Collection) obj2);
                                    }
                                } else if (arrayList != null) {
                                    map2.put(cls, arrayList);
                                }
                            }
                        }
                    } else {
                        iK = kotlin.jvm.internal.o.k(cls.getInterfaces());
                        while (true) {
                            if (!iK.hasNext()) {
                            }
                        }
                    }
                }
            }
            i6 = 2;
        }
        map.put(cls, Integer.valueOf(i6));
        return i6;
    }
}
