package o;

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

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Vh, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0552Vh {
    public static final C0552Vh c = new C0552Vh();
    public final HashMap a = new HashMap();
    public final HashMap b = new HashMap();

    public static void b(HashMap map, C0526Uh c0526Uh, UK uk, Class cls) {
        UK uk2 = (UK) map.get(c0526Uh);
        if (uk2 == null || uk == uk2) {
            if (uk2 == null) {
                map.put(c0526Uh, uk);
                return;
            }
            return;
        }
        throw new IllegalArgumentException("Method " + c0526Uh.b.getName() + " in " + cls.getName() + " already declared with different @OnLifecycleEvent value: previous value " + uk2 + ", new value " + uk);
    }

    public final C0500Th a(Class cls, Method[] methodArr) throws SecurityException {
        int i;
        Class superclass = cls.getSuperclass();
        HashMap map = new HashMap();
        HashMap map2 = this.a;
        if (superclass != null) {
            C0500Th c0500ThA = (C0500Th) map2.get(superclass);
            if (c0500ThA == null) {
                c0500ThA = a(superclass, null);
            }
            map.putAll(c0500ThA.b);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            C0500Th c0500ThA2 = (C0500Th) map2.get(cls2);
            if (c0500ThA2 == null) {
                c0500ThA2 = a(cls2, null);
            }
            for (Map.Entry entry : c0500ThA2.b.entrySet()) {
                b(map, (C0526Uh) entry.getKey(), (UK) entry.getValue(), cls);
            }
        }
        if (methodArr == null) {
            try {
                methodArr = cls.getDeclaredMethods();
            } catch (NoClassDefFoundError e) {
                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.", e);
            }
        }
        boolean z = false;
        for (Method method : methodArr) {
            NT nt = (NT) method.getAnnotation(NT.class);
            if (nt != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i = 0;
                } else {
                    if (!InterfaceC0898cL.class.isAssignableFrom(parameterTypes[0])) {
                        throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                    }
                    i = 1;
                }
                UK ukValue = nt.value();
                if (parameterTypes.length > 1) {
                    if (!UK.class.isAssignableFrom(parameterTypes[1])) {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    }
                    if (ukValue != UK.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 C0526Uh(i, method), ukValue, cls);
                z = true;
            }
        }
        C0500Th c0500Th = new C0500Th(map);
        map2.put(cls, c0500Th);
        this.b.put(cls, Boolean.valueOf(z));
        return c0500Th;
    }
}
