package androidx.lifecycle;

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

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

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

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

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

    public static void b(HashMap map, C0498c c0498c, EnumC0509n enumC0509n, Class cls) {
        EnumC0509n enumC0509n2 = (EnumC0509n) map.get(c0498c);
        if (enumC0509n2 == null || enumC0509n == enumC0509n2) {
            if (enumC0509n2 == null) {
                map.put(c0498c, enumC0509n);
                return;
            }
            return;
        }
        throw new IllegalArgumentException("Method " + c0498c.f8825b.getName() + " in " + cls.getName() + " already declared with different @OnLifecycleEvent value: previous value " + enumC0509n2 + ", new value " + enumC0509n);
    }

    public final C0497b a(Class cls, Method[] methodArr) {
        int i;
        Class superclass = cls.getSuperclass();
        HashMap map = new HashMap();
        HashMap map2 = this.f8827a;
        if (superclass != null) {
            C0497b c0497bA = (C0497b) map2.get(superclass);
            if (c0497bA == null) {
                c0497bA = a(superclass, null);
            }
            map.putAll(c0497bA.f8823b);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            C0497b c0497bA2 = (C0497b) map2.get(cls2);
            if (c0497bA2 == null) {
                c0497bA2 = a(cls2, null);
            }
            for (Map.Entry entry : c0497bA2.f8823b.entrySet()) {
                b(map, (C0498c) entry.getKey(), (EnumC0509n) entry.getValue(), cls);
            }
        }
        if (methodArr == null) {
            try {
                methodArr = cls.getDeclaredMethods();
            } catch (NoClassDefFoundError e8) {
                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.", e8);
            }
        }
        boolean z8 = false;
        for (Method method : methodArr) {
            B b8 = (B) method.getAnnotation(B.class);
            if (b8 != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i = 0;
                } else {
                    if (!InterfaceC0516v.class.isAssignableFrom(parameterTypes[0])) {
                        throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                    }
                    i = 1;
                }
                EnumC0509n enumC0509nValue = b8.value();
                if (parameterTypes.length > 1) {
                    if (!EnumC0509n.class.isAssignableFrom(parameterTypes[1])) {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    }
                    if (enumC0509nValue != EnumC0509n.ON_ANY) {
                        throw new IllegalArgumentException("Second arg is supported only for ON_ANY value");
                    }
                    i = 2;
                }
                if (parameterTypes.length > 2) {
                    throw new IllegalArgumentException("cannot have more than 2 params");
                }
                b(map, new C0498c(method, i), enumC0509nValue, cls);
                z8 = true;
            }
        }
        C0497b c0497b = new C0497b(map);
        map2.put(cls, c0497b);
        this.f8828b.put(cls, Boolean.valueOf(z8));
        return c0497b;
    }
}
