package X6FRs_4.KNBe_11;

import X6FRs_4.KNBe_11.IFxWkV_5;
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;
/* compiled from: ClassesInfoCache.java */
/* loaded from: classes.dex */
public class KQgRr5e_0 {
    public static KQgRr5e_0 KQgRr5e_0 = new KQgRr5e_0();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Map<Class, C0052KQgRr5e_0> f610KQgRr5e_0 = new HashMap();
    public final Map<Class, Boolean> QxJ9d_1 = new HashMap();

    /* compiled from: ClassesInfoCache.java */
    /* loaded from: classes.dex */
    public static class QxJ9d_1 {
        public final int KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final Method f611KQgRr5e_0;

        public QxJ9d_1(int i, Method method) {
            this.KQgRr5e_0 = i;
            this.f611KQgRr5e_0 = method;
            method.setAccessible(true);
        }

        public void KQgRr5e_0(Xgtqvk_8 xgtqvk_8, IFxWkV_5.KQgRr5e_0 kQgRr5e_0, Object obj) {
            try {
                int i = this.KQgRr5e_0;
                if (i == 0) {
                    this.f611KQgRr5e_0.invoke(obj, new Object[0]);
                } else if (i == 1) {
                    this.f611KQgRr5e_0.invoke(obj, xgtqvk_8);
                } else if (i != 2) {
                } else {
                    this.f611KQgRr5e_0.invoke(obj, xgtqvk_8, kQgRr5e_0);
                }
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e2) {
                throw new RuntimeException("Failed to call observer method", e2.getCause());
            }
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null || QxJ9d_1.class != obj.getClass()) {
                return false;
            }
            QxJ9d_1 qxJ9d_1 = (QxJ9d_1) obj;
            return this.KQgRr5e_0 == qxJ9d_1.KQgRr5e_0 && this.f611KQgRr5e_0.getName().equals(qxJ9d_1.f611KQgRr5e_0.getName());
        }

        public int hashCode() {
            return (this.KQgRr5e_0 * 31) + this.f611KQgRr5e_0.getName().hashCode();
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public boolean m358KQgRr5e_0(Class cls) {
        if (this.QxJ9d_1.containsKey(cls)) {
            return this.QxJ9d_1.get(cls).booleanValue();
        }
        Method[] m359KQgRr5e_0 = m359KQgRr5e_0(cls);
        for (Method method : m359KQgRr5e_0) {
            if (((LGe8pk_15) method.getAnnotation(LGe8pk_15.class)) != null) {
                KQgRr5e_0(cls, m359KQgRr5e_0);
                return true;
            }
        }
        this.QxJ9d_1.put(cls, false);
        return false;
    }

    /* compiled from: ClassesInfoCache.java */
    /* renamed from: X6FRs_4.KNBe_11.KQgRr5e_0$KQgRr5e_0  reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static class C0052KQgRr5e_0 {
        public final Map<IFxWkV_5.KQgRr5e_0, List<QxJ9d_1>> KQgRr5e_0 = new HashMap();
        public final Map<QxJ9d_1, IFxWkV_5.KQgRr5e_0> QxJ9d_1;

        public C0052KQgRr5e_0(Map<QxJ9d_1, IFxWkV_5.KQgRr5e_0> map) {
            this.QxJ9d_1 = map;
            for (Map.Entry<QxJ9d_1, IFxWkV_5.KQgRr5e_0> entry : map.entrySet()) {
                IFxWkV_5.KQgRr5e_0 value = entry.getValue();
                List<QxJ9d_1> list = this.KQgRr5e_0.get(value);
                if (list == null) {
                    list = new ArrayList<>();
                    this.KQgRr5e_0.put(value, list);
                }
                list.add(entry.getKey());
            }
        }

        public void KQgRr5e_0(Xgtqvk_8 xgtqvk_8, IFxWkV_5.KQgRr5e_0 kQgRr5e_0, Object obj) {
            KQgRr5e_0(this.KQgRr5e_0.get(kQgRr5e_0), xgtqvk_8, kQgRr5e_0, obj);
            KQgRr5e_0(this.KQgRr5e_0.get(IFxWkV_5.KQgRr5e_0.ON_ANY), xgtqvk_8, kQgRr5e_0, obj);
        }

        public static void KQgRr5e_0(List<QxJ9d_1> list, Xgtqvk_8 xgtqvk_8, IFxWkV_5.KQgRr5e_0 kQgRr5e_0, Object obj) {
            if (list != null) {
                for (int size = list.size() - 1; size >= 0; size--) {
                    list.get(size).KQgRr5e_0(xgtqvk_8, kQgRr5e_0, obj);
                }
            }
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final Method[] m359KQgRr5e_0(Class cls) {
        try {
            return 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);
        }
    }

    public C0052KQgRr5e_0 KQgRr5e_0(Class cls) {
        C0052KQgRr5e_0 c0052KQgRr5e_0 = this.f610KQgRr5e_0.get(cls);
        return c0052KQgRr5e_0 != null ? c0052KQgRr5e_0 : KQgRr5e_0(cls, null);
    }

    public final void KQgRr5e_0(Map<QxJ9d_1, IFxWkV_5.KQgRr5e_0> map, QxJ9d_1 qxJ9d_1, IFxWkV_5.KQgRr5e_0 kQgRr5e_0, Class cls) {
        IFxWkV_5.KQgRr5e_0 kQgRr5e_02 = map.get(qxJ9d_1);
        if (kQgRr5e_02 == null || kQgRr5e_0 == kQgRr5e_02) {
            if (kQgRr5e_02 == null) {
                map.put(qxJ9d_1, kQgRr5e_0);
                return;
            }
            return;
        }
        Method method = qxJ9d_1.f611KQgRr5e_0;
        throw new IllegalArgumentException("Method " + method.getName() + " in " + cls.getName() + " already declared with different @OnLifecycleEvent value: previous value " + kQgRr5e_02 + ", new value " + kQgRr5e_0);
    }

    public final C0052KQgRr5e_0 KQgRr5e_0(Class cls, Method[] methodArr) {
        int i;
        C0052KQgRr5e_0 KQgRr5e_02;
        Class superclass = cls.getSuperclass();
        HashMap hashMap = new HashMap();
        if (superclass != null && (KQgRr5e_02 = KQgRr5e_0(superclass)) != null) {
            hashMap.putAll(KQgRr5e_02.QxJ9d_1);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            for (Map.Entry<QxJ9d_1, IFxWkV_5.KQgRr5e_0> entry : KQgRr5e_0((Class) cls2).QxJ9d_1.entrySet()) {
                KQgRr5e_0(hashMap, entry.getKey(), entry.getValue(), cls);
            }
        }
        if (methodArr == null) {
            methodArr = m359KQgRr5e_0(cls);
        }
        boolean z = false;
        for (Method method : methodArr) {
            LGe8pk_15 lGe8pk_15 = (LGe8pk_15) method.getAnnotation(LGe8pk_15.class);
            if (lGe8pk_15 != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i = 0;
                } else if (!parameterTypes[0].isAssignableFrom(Xgtqvk_8.class)) {
                    throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                } else {
                    i = 1;
                }
                IFxWkV_5.KQgRr5e_0 value = lGe8pk_15.value();
                if (parameterTypes.length > 1) {
                    if (parameterTypes[1].isAssignableFrom(IFxWkV_5.KQgRr5e_0.class)) {
                        if (value != IFxWkV_5.KQgRr5e_0.ON_ANY) {
                            throw new IllegalArgumentException("Second arg is supported only for ON_ANY value");
                        }
                        i = 2;
                    } else {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    }
                }
                if (parameterTypes.length <= 2) {
                    KQgRr5e_0(hashMap, new QxJ9d_1(i, method), value, cls);
                    z = true;
                } else {
                    throw new IllegalArgumentException("cannot have more than 2 params");
                }
            }
        }
        C0052KQgRr5e_0 c0052KQgRr5e_0 = new C0052KQgRr5e_0(hashMap);
        this.f610KQgRr5e_0.put(cls, c0052KQgRr5e_0);
        this.QxJ9d_1.put(cls, Boolean.valueOf(z));
        return c0052KQgRr5e_0;
    }
}
