package androidx.lifecycle;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: renamed from: androidx.lifecycle.e, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1096e {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final C1096e f12165c = new C1096e();

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

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

    public static void b(HashMap map, C1095d c1095d, EnumC1107p enumC1107p, Class cls) {
        EnumC1107p enumC1107p2 = (EnumC1107p) map.get(c1095d);
        if (enumC1107p2 == null || enumC1107p == enumC1107p2) {
            if (enumC1107p2 == null) {
                map.put(c1095d, enumC1107p);
                return;
            }
            return;
        }
        throw new IllegalArgumentException("Method " + c1095d.f12164b.getName() + " in " + cls.getName() + " already declared with different @OnLifecycleEvent value: previous value " + enumC1107p2 + ", new value " + enumC1107p);
    }

    public final C1094c a(Class cls, Method[] methodArr) {
        int i6;
        Class superclass = cls.getSuperclass();
        HashMap map = new HashMap();
        HashMap map2 = this.f12166a;
        if (superclass != null) {
            C1094c c1094cA = (C1094c) map2.get(superclass);
            if (c1094cA == null) {
                c1094cA = a(superclass, null);
            }
            map.putAll(c1094cA.f12159b);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            C1094c c1094cA2 = (C1094c) map2.get(cls2);
            if (c1094cA2 == null) {
                c1094cA2 = a(cls2, null);
            }
            for (Map.Entry entry : c1094cA2.f12159b.entrySet()) {
                b(map, (C1095d) entry.getKey(), (EnumC1107p) entry.getValue(), cls);
            }
        }
        if (methodArr == null) {
            try {
                methodArr = cls.getDeclaredMethods();
            } catch (NoClassDefFoundError e6) {
                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.", e6);
            }
        }
        boolean z6 = false;
        for (Method method : methodArr) {
            H h5 = (H) method.getAnnotation(H.class);
            if (h5 != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i6 = 0;
                } else {
                    if (!InterfaceC1113w.class.isAssignableFrom(parameterTypes[0])) {
                        throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                    }
                    i6 = 1;
                }
                EnumC1107p enumC1107pValue = h5.value();
                if (parameterTypes.length > 1) {
                    if (!EnumC1107p.class.isAssignableFrom(parameterTypes[1])) {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    }
                    if (enumC1107pValue != EnumC1107p.ON_ANY) {
                        throw new IllegalArgumentException("Second arg is supported only for ON_ANY value");
                    }
                    i6 = 2;
                }
                if (parameterTypes.length > 2) {
                    throw new IllegalArgumentException("cannot have more than 2 params");
                }
                b(map, new C1095d(i6, method), enumC1107pValue, cls);
                z6 = true;
            }
        }
        C1094c c1094c = new C1094c(map);
        map2.put(cls, c1094c);
        this.f12167b.put(cls, Boolean.valueOf(z6));
        return c1094c;
    }
}
