package androidx.lifecycle;

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

/* JADX INFO: loaded from: classes.dex */
public abstract class s {

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

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

    public static void a(Constructor constructor, Object obj) {
        try {
            Object objNewInstance = constructor.newInstance(obj);
            nb.g.h(objNewInstance, "{\n            constructo…tance(`object`)\n        }");
            defpackage.e.y(objNewInstance);
            throw null;
        } catch (IllegalAccessException e10) {
            throw new RuntimeException(e10);
        } catch (InstantiationException e11) {
            throw new RuntimeException(e11);
        } catch (InvocationTargetException e12) {
            throw new RuntimeException(e12);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00e3  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x010f A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int b(Class cls) {
        Constructor declaredConstructor;
        int length;
        HashMap map = f2702a;
        Integer num = (Integer) map.get(cls);
        if (num != null) {
            return num.intValue();
        }
        int i10 = 1;
        if (cls.getCanonicalName() != null) {
            ArrayList arrayList = null;
            int i11 = 0;
            try {
                Package r42 = cls.getPackage();
                String canonicalName = cls.getCanonicalName();
                String name = r42 != null ? r42.getName() : "";
                nb.g.h(name, "fullPackage");
                if (name.length() != 0) {
                    nb.g.h(canonicalName, "name");
                    canonicalName = canonicalName.substring(name.length() + 1);
                    nb.g.h(canonicalName, "this as java.lang.String).substring(startIndex)");
                }
                nb.g.h(canonicalName, "if (fullPackage.isEmpty(…g(fullPackage.length + 1)");
                String strConcat = kotlin.text.h.h0(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 e10) {
                throw new RuntimeException(e10);
            }
            HashMap map2 = f2703b;
            if (declaredConstructor != null) {
                map2.put(cls, hb.a.l0(declaredConstructor));
            } else if (!c.f2641c.b(cls)) {
                Class superclass = cls.getSuperclass();
                if (superclass == null || !LifecycleObserver.class.isAssignableFrom(superclass)) {
                    Class<?>[] interfaces = cls.getInterfaces();
                    nb.g.h(interfaces, "klass.interfaces");
                    length = interfaces.length;
                    while (true) {
                        if (i11 < length) {
                            Class<?> cls2 = interfaces[i11];
                            if (cls2 != null && LifecycleObserver.class.isAssignableFrom(cls2)) {
                                nb.g.h(cls2, "intrface");
                                if (b(cls2) == 1) {
                                    break;
                                }
                                if (arrayList == null) {
                                    arrayList = new ArrayList();
                                }
                                Object obj = map2.get(cls2);
                                nb.g.f(obj);
                                arrayList.addAll((Collection) obj);
                            }
                            i11++;
                        } else if (arrayList != null) {
                            map2.put(cls, arrayList);
                        }
                    }
                } else {
                    nb.g.h(superclass, "superclass");
                    if (b(superclass) != 1) {
                        Object obj2 = map2.get(superclass);
                        nb.g.f(obj2);
                        arrayList = new ArrayList((Collection) obj2);
                        Class<?>[] interfaces2 = cls.getInterfaces();
                        nb.g.h(interfaces2, "klass.interfaces");
                        length = interfaces2.length;
                        while (true) {
                            if (i11 < length) {
                            }
                            i11++;
                        }
                    }
                }
            }
            i10 = 2;
        }
        map.put(cls, Integer.valueOf(i10));
        return i10;
    }
}
