package p037.p099;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import p037.p099.AbstractC2210;
import p138.p139.p143.p144.C2803;

/* JADX INFO: renamed from: މ.ދ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C2201 {

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static C2201 f7141 = new C2201();

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Map<Class<?>, C2202> f7142 = new HashMap();

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Map<Class<?>, Boolean> f7143 = new HashMap();

    /* JADX INFO: renamed from: މ.ދ.ؠ$֏, reason: contains not printable characters */
    public static class C2202 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final Map<AbstractC2210.EnumC2211, List<C2203>> f7144 = new HashMap();

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final Map<C2203, AbstractC2210.EnumC2211> f7145;

        public C2202(Map<C2203, AbstractC2210.EnumC2211> map) {
            this.f7145 = map;
            for (Map.Entry<C2203, AbstractC2210.EnumC2211> entry : map.entrySet()) {
                AbstractC2210.EnumC2211 value = entry.getValue();
                List<C2203> arrayList = this.f7144.get(value);
                if (arrayList == null) {
                    arrayList = new ArrayList<>();
                    this.f7144.put(value, arrayList);
                }
                arrayList.add(entry.getKey());
            }
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public static void m4265(List<C2203> list, InterfaceC2219 interfaceC2219, AbstractC2210.EnumC2211 enumC2211, Object obj) {
            if (list != null) {
                for (int size = list.size() - 1; size >= 0; size--) {
                    C2203 c2203 = list.get(size);
                    if (c2203 == null) {
                        throw null;
                    }
                    try {
                        int i = c2203.f7146;
                        if (i == 0) {
                            c2203.f7147.invoke(obj, new Object[0]);
                        } else if (i == 1) {
                            c2203.f7147.invoke(obj, interfaceC2219);
                        } else if (i == 2) {
                            c2203.f7147.invoke(obj, interfaceC2219, enumC2211);
                        }
                    } catch (IllegalAccessException e) {
                        throw new RuntimeException(e);
                    } catch (InvocationTargetException e2) {
                        throw new RuntimeException("Failed to call observer method", e2.getCause());
                    }
                }
            }
        }
    }

    /* JADX INFO: renamed from: މ.ދ.ؠ$ؠ, reason: contains not printable characters */
    public static final class C2203 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final int f7146;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final Method f7147;

        public C2203(int i, Method method) {
            this.f7146 = i;
            this.f7147 = method;
            method.setAccessible(true);
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof C2203)) {
                return false;
            }
            C2203 c2203 = (C2203) obj;
            return this.f7146 == c2203.f7146 && this.f7147.getName().equals(c2203.f7147.getName());
        }

        public int hashCode() {
            return this.f7147.getName().hashCode() + (this.f7146 * 31);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C2202 m4262(Class<?> cls) {
        C2202 c2202 = this.f7142.get(cls);
        return c2202 != null ? c2202 : m4263(cls, null);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C2202 m4263(Class<?> cls, Method[] methodArr) {
        int i;
        C2202 c2202M4262;
        Class<?> superclass = cls.getSuperclass();
        HashMap map = new HashMap();
        if (superclass != null && (c2202M4262 = m4262(superclass)) != null) {
            map.putAll(c2202M4262.f7145);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            for (Map.Entry<C2203, AbstractC2210.EnumC2211> entry : m4262(cls2).f7145.entrySet()) {
                m4264(map, entry.getKey(), 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) {
            InterfaceC2231 interfaceC2231 = (InterfaceC2231) method.getAnnotation(InterfaceC2231.class);
            if (interfaceC2231 != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i = 0;
                } else {
                    if (!parameterTypes[0].isAssignableFrom(InterfaceC2219.class)) {
                        throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                    }
                    i = 1;
                }
                AbstractC2210.EnumC2211 enumC2211Value = interfaceC2231.value();
                if (parameterTypes.length > 1) {
                    if (!parameterTypes[1].isAssignableFrom(AbstractC2210.EnumC2211.class)) {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    }
                    if (enumC2211Value != AbstractC2210.EnumC2211.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");
                }
                m4264(map, new C2203(i, method), enumC2211Value, cls);
                z = true;
            }
        }
        C2202 c2202 = new C2202(map);
        this.f7142.put(cls, c2202);
        this.f7143.put(cls, Boolean.valueOf(z));
        return c2202;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m4264(Map<C2203, AbstractC2210.EnumC2211> map, C2203 c2203, AbstractC2210.EnumC2211 enumC2211, Class<?> cls) {
        AbstractC2210.EnumC2211 enumC22112 = map.get(c2203);
        if (enumC22112 == null || enumC2211 == enumC22112) {
            if (enumC22112 == null) {
                map.put(c2203, enumC2211);
                return;
            }
            return;
        }
        Method method = c2203.f7147;
        StringBuilder sbM4889 = C2803.m4889("Method ");
        sbM4889.append(method.getName());
        sbM4889.append(" in ");
        sbM4889.append(cls.getName());
        sbM4889.append(" already declared with different @OnLifecycleEvent value: previous value ");
        sbM4889.append(enumC22112);
        sbM4889.append(", new value ");
        sbM4889.append(enumC2211);
        throw new IllegalArgumentException(sbM4889.toString());
    }
}
