package androidx.lifecycle;

import com.google.android.gms.internal.measurement.C1;
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;

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

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

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

    public static void a(Constructor constructor, InterfaceC0515u interfaceC0515u) {
        try {
            P6.g.b(constructor.newInstance(interfaceC0515u));
            throw new ClassCastException();
        } catch (IllegalAccessException e8) {
            throw new RuntimeException(e8);
        } catch (InstantiationException e9) {
            throw new RuntimeException(e9);
        } catch (InvocationTargetException e10) {
            throw new RuntimeException(e10);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:61:0x010e  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x0140 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int b(Class cls) {
        Constructor declaredConstructor;
        boolean zBooleanValue;
        B6.b bVarD;
        int i = 1;
        HashMap map = f8856a;
        Integer num = (Integer) map.get(cls);
        if (num != null) {
            return num.intValue();
        }
        if (cls.getCanonicalName() != null) {
            ArrayList arrayList = null;
            try {
                Package r42 = cls.getPackage();
                String canonicalName = cls.getCanonicalName();
                String name = r42 != null ? r42.getName() : "";
                P6.g.b(name);
                if (name.length() != 0) {
                    P6.g.b(canonicalName);
                    canonicalName = canonicalName.substring(name.length() + 1);
                    P6.g.d(canonicalName, "substring(...)");
                }
                P6.g.b(canonicalName);
                String strConcat = X6.n.K(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 e8) {
                throw new RuntimeException(e8);
            }
            HashMap map2 = f8857b;
            if (declaredConstructor != null) {
                map2.put(cls, C1.C(declaredConstructor));
            } else {
                C0499d c0499d = C0499d.f8826c;
                HashMap map3 = c0499d.f8828b;
                Boolean bool = (Boolean) map3.get(cls);
                if (bool != null) {
                    zBooleanValue = bool.booleanValue();
                } else {
                    try {
                        Method[] declaredMethods = cls.getDeclaredMethods();
                        int length = declaredMethods.length;
                        int i5 = 0;
                        while (true) {
                            if (i5 >= length) {
                                map3.put(cls, Boolean.FALSE);
                                zBooleanValue = false;
                                break;
                            }
                            if (((B) declaredMethods[i5].getAnnotation(B.class)) != null) {
                                c0499d.a(cls, declaredMethods);
                                zBooleanValue = true;
                                break;
                            }
                            i5++;
                        }
                    } catch (NoClassDefFoundError e9) {
                        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.", e9);
                    }
                }
                if (!zBooleanValue) {
                    Class superclass = cls.getSuperclass();
                    if (superclass != null && InterfaceC0515u.class.isAssignableFrom(superclass)) {
                        P6.g.b(superclass);
                        if (b(superclass) != 1) {
                            Object obj = map2.get(superclass);
                            P6.g.b(obj);
                            arrayList = new ArrayList((Collection) obj);
                            bVarD = P6.p.d(cls.getInterfaces());
                            while (true) {
                                if (!bVarD.hasNext()) {
                                    Class cls2 = (Class) bVarD.next();
                                    if (cls2 != null && InterfaceC0515u.class.isAssignableFrom(cls2)) {
                                        P6.g.b(cls2);
                                        if (b(cls2) == 1) {
                                            break;
                                        }
                                        if (arrayList == null) {
                                            arrayList = new ArrayList();
                                        }
                                        Object obj2 = map2.get(cls2);
                                        P6.g.b(obj2);
                                        arrayList.addAll((Collection) obj2);
                                    }
                                } else if (arrayList != null) {
                                    map2.put(cls, arrayList);
                                }
                            }
                        }
                    } else {
                        bVarD = P6.p.d(cls.getInterfaces());
                        while (true) {
                            if (!bVarD.hasNext()) {
                            }
                        }
                    }
                }
            }
            i = 2;
        }
        map.put(cls, Integer.valueOf(i));
        return i;
    }
}
