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 C0297d {

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

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

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

    public static void b(HashMap map, C0296c c0296c, EnumC0307n enumC0307n, Class cls) {
        EnumC0307n enumC0307n2 = (EnumC0307n) map.get(c0296c);
        if (enumC0307n2 == null || enumC0307n == enumC0307n2) {
            if (enumC0307n2 == null) {
                map.put(c0296c, enumC0307n);
                return;
            }
            return;
        }
        throw new IllegalArgumentException("Method " + c0296c.f4465b.getName() + " in " + cls.getName() + " already declared with different @OnLifecycleEvent value: previous value " + enumC0307n2 + ", new value " + enumC0307n);
    }

    public final C0295b a(Class cls, Method[] methodArr) {
        int i;
        Class superclass = cls.getSuperclass();
        HashMap map = new HashMap();
        HashMap map2 = this.f4468a;
        if (superclass != null) {
            C0295b c0295bA = (C0295b) map2.get(superclass);
            if (c0295bA == null) {
                c0295bA = a(superclass, null);
            }
            map.putAll(c0295bA.f4462b);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            C0295b c0295bA2 = (C0295b) map2.get(cls2);
            if (c0295bA2 == null) {
                c0295bA2 = a(cls2, null);
            }
            for (Map.Entry entry : c0295bA2.f4462b.entrySet()) {
                b(map, (C0296c) entry.getKey(), (EnumC0307n) entry.getValue(), cls);
            }
        }
        if (methodArr == null) {
            try {
                methodArr = cls.getDeclaredMethods();
            } catch (NoClassDefFoundError e2) {
                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.", e2);
            }
        }
        boolean z5 = false;
        for (Method method : methodArr) {
            F f6 = (F) method.getAnnotation(F.class);
            if (f6 != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i = 0;
                } else {
                    if (!InterfaceC0313u.class.isAssignableFrom(parameterTypes[0])) {
                        throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                    }
                    i = 1;
                }
                EnumC0307n enumC0307nValue = f6.value();
                if (parameterTypes.length > 1) {
                    if (!EnumC0307n.class.isAssignableFrom(parameterTypes[1])) {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    }
                    if (enumC0307nValue != EnumC0307n.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 C0296c(i, method), enumC0307nValue, cls);
                z5 = true;
            }
        }
        C0295b c0295b = new C0295b(map);
        map2.put(cls, c0295b);
        this.f4469b.put(cls, Boolean.valueOf(z5));
        return c0295b;
    }
}
