package c.l;

import c.l.j;
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 java.util.Objects;

/* JADX INFO: compiled from: ClassesInfoCache.java */
/* JADX INFO: loaded from: classes.dex */
@Deprecated
public final class c {
    public static c a = new c();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Map<Class<?>, a> f1759b = new HashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Map<Class<?>, Boolean> f1760c = new HashMap();

    /* JADX INFO: compiled from: ClassesInfoCache.java */
    @Deprecated
    public static class a {
        public final Map<j.a, List<b>> a = new HashMap();

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final Map<b, j.a> f1761b;

        public a(Map<b, j.a> map) {
            this.f1761b = map;
            for (Map.Entry<b, j.a> entry : map.entrySet()) {
                j.a value = entry.getValue();
                List<b> arrayList = this.a.get(value);
                if (arrayList == null) {
                    arrayList = new ArrayList<>();
                    this.a.put(value, arrayList);
                }
                arrayList.add(entry.getKey());
            }
        }

        public static void a(List<b> list, n nVar, j.a aVar, Object obj) {
            if (list != null) {
                for (int size = list.size() - 1; size >= 0; size--) {
                    b bVar = list.get(size);
                    Objects.requireNonNull(bVar);
                    try {
                        int i2 = bVar.a;
                        if (i2 == 0) {
                            bVar.f1762b.invoke(obj, new Object[0]);
                        } else if (i2 == 1) {
                            bVar.f1762b.invoke(obj, nVar);
                        } else if (i2 == 2) {
                            bVar.f1762b.invoke(obj, nVar, aVar);
                        }
                    } catch (IllegalAccessException e2) {
                        throw new RuntimeException(e2);
                    } catch (InvocationTargetException e3) {
                        throw new RuntimeException("Failed to call observer method", e3.getCause());
                    }
                }
            }
        }
    }

    /* JADX INFO: compiled from: ClassesInfoCache.java */
    @Deprecated
    public static final class b {
        public final int a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final Method f1762b;

        public b(int i2, Method method) {
            this.a = i2;
            this.f1762b = method;
            method.setAccessible(true);
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof b)) {
                return false;
            }
            b bVar = (b) obj;
            return this.a == bVar.a && this.f1762b.getName().equals(bVar.f1762b.getName());
        }

        public int hashCode() {
            return this.f1762b.getName().hashCode() + (this.a * 31);
        }
    }

    public final a a(Class<?> cls, Method[] methodArr) {
        int i2;
        a aVarB;
        Class<?> superclass = cls.getSuperclass();
        HashMap map = new HashMap();
        if (superclass != null && (aVarB = b(superclass)) != null) {
            map.putAll(aVarB.f1761b);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            for (Map.Entry<b, j.a> entry : b(cls2).f1761b.entrySet()) {
                c(map, entry.getKey(), 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 z = false;
        for (Method method : methodArr) {
            u uVar = (u) method.getAnnotation(u.class);
            if (uVar != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i2 = 0;
                } else {
                    if (!parameterTypes[0].isAssignableFrom(n.class)) {
                        throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                    }
                    i2 = 1;
                }
                j.a aVarValue = uVar.value();
                if (parameterTypes.length > 1) {
                    if (!parameterTypes[1].isAssignableFrom(j.a.class)) {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    }
                    if (aVarValue != j.a.ON_ANY) {
                        throw new IllegalArgumentException("Second arg is supported only for ON_ANY value");
                    }
                    i2 = 2;
                }
                if (parameterTypes.length > 2) {
                    throw new IllegalArgumentException("cannot have more than 2 params");
                }
                c(map, new b(i2, method), aVarValue, cls);
                z = true;
            }
        }
        a aVar = new a(map);
        this.f1759b.put(cls, aVar);
        this.f1760c.put(cls, Boolean.valueOf(z));
        return aVar;
    }

    public a b(Class<?> cls) {
        a aVar = this.f1759b.get(cls);
        return aVar != null ? aVar : a(cls, null);
    }

    public final void c(Map<b, j.a> map, b bVar, j.a aVar, Class<?> cls) {
        j.a aVar2 = map.get(bVar);
        if (aVar2 == null || aVar == aVar2) {
            if (aVar2 == null) {
                map.put(bVar, aVar);
                return;
            }
            return;
        }
        Method method = bVar.f1762b;
        StringBuilder sbB = d.b.a.a.a.B("Method ");
        sbB.append(method.getName());
        sbB.append(" in ");
        sbB.append(cls.getName());
        sbB.append(" already declared with different @OnLifecycleEvent value: previous value ");
        sbB.append(aVar2);
        sbB.append(", new value ");
        sbB.append(aVar);
        throw new IllegalArgumentException(sbB.toString());
    }
}
