package org.greenrobot.eventbus;

import com.cvte.vman.instance.InvokeCmd;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/* JADX INFO: compiled from: SubscriberMethodFinder.java */
/* JADX INFO: loaded from: classes.dex */
class p {
    private static final Map<Class<?>, List<o>> d = new ConcurrentHashMap();
    private static final a[] e = new a[4];
    private List<org.greenrobot.eventbus.r.b> a;
    private final boolean b;
    private final boolean c;

    /* JADX INFO: compiled from: SubscriberMethodFinder.java */
    static class a {
        final List<o> a = new ArrayList();
        final Map<Class, Object> b = new HashMap();
        final Map<String, Class> c = new HashMap();
        final StringBuilder d = new StringBuilder(128);
        Class<?> e;
        boolean f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        org.greenrobot.eventbus.r.a f1111g;

        a() {
        }

        private boolean b(Method method, Class<?> cls) {
            this.d.setLength(0);
            this.d.append(method.getName());
            StringBuilder sb = this.d;
            sb.append('>');
            sb.append(cls.getName());
            String string = this.d.toString();
            Class<?> declaringClass = method.getDeclaringClass();
            Class clsPut = this.c.put(string, declaringClass);
            if (clsPut == null || clsPut.isAssignableFrom(declaringClass)) {
                return true;
            }
            this.c.put(string, clsPut);
            return false;
        }

        boolean a(Method method, Class<?> cls) {
            Object objPut = this.b.put(cls, method);
            if (objPut == null) {
                return true;
            }
            if (objPut instanceof Method) {
                if (!b((Method) objPut, cls)) {
                    throw new IllegalStateException();
                }
                this.b.put(cls, this);
            }
            return b(method, cls);
        }

        void c(Class<?> cls) {
            this.e = cls;
            this.f = false;
            this.f1111g = null;
        }

        void d() {
            if (this.f) {
                this.e = null;
                return;
            }
            Class<? super Object> superclass = this.e.getSuperclass();
            this.e = superclass;
            String name = superclass.getName();
            if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
                this.e = null;
            }
        }

        void e() {
            this.a.clear();
            this.b.clear();
            this.c.clear();
            this.d.setLength(0);
            this.e = null;
            this.f = false;
            this.f1111g = null;
        }
    }

    p(List<org.greenrobot.eventbus.r.b> list, boolean z, boolean z2) {
        this.a = list;
        this.b = z;
        this.c = z2;
    }

    private List<o> b(Class<?> cls) {
        a aVarG = g();
        aVarG.c(cls);
        while (aVarG.e != null) {
            org.greenrobot.eventbus.r.a aVarF = f(aVarG);
            aVarG.f1111g = aVarF;
            if (aVarF != null) {
                for (o oVar : aVarF.a()) {
                    if (aVarG.a(oVar.a, oVar.c)) {
                        aVarG.a.add(oVar);
                    }
                }
            } else {
                d(aVarG);
            }
            aVarG.d();
        }
        return e(aVarG);
    }

    private List<o> c(Class<?> cls) {
        a aVarG = g();
        aVarG.c(cls);
        while (aVarG.e != null) {
            d(aVarG);
            aVarG.d();
        }
        return e(aVarG);
    }

    private void d(a aVar) {
        Method[] methods;
        try {
            methods = aVar.e.getDeclaredMethods();
        } catch (Throwable unused) {
            methods = aVar.e.getMethods();
            aVar.f = true;
        }
        for (Method method : methods) {
            int modifiers = method.getModifiers();
            if ((modifiers & 1) != 0 && (modifiers & InvokeCmd.CMD_AUDIO_SET_MIC_POWER_DOWN) == 0) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length == 1) {
                    m mVar = (m) method.getAnnotation(m.class);
                    if (mVar != null) {
                        Class<?> cls = parameterTypes[0];
                        if (aVar.a(method, cls)) {
                            aVar.a.add(new o(method, cls, mVar.threadMode(), mVar.priority(), mVar.sticky()));
                        }
                    }
                } else if (this.b && method.isAnnotationPresent(m.class)) {
                    throw new e("@Subscribe method " + (method.getDeclaringClass().getName() + "." + method.getName()) + "must have exactly 1 parameter but has " + parameterTypes.length);
                }
            } else if (this.b && method.isAnnotationPresent(m.class)) {
                throw new e((method.getDeclaringClass().getName() + "." + method.getName()) + " is a illegal @Subscribe method: must be public, non-static, and non-abstract");
            }
        }
    }

    private List<o> e(a aVar) {
        ArrayList arrayList = new ArrayList(aVar.a);
        aVar.e();
        synchronized (e) {
            int i2 = 0;
            while (true) {
                if (i2 >= 4) {
                    break;
                }
                if (e[i2] == null) {
                    e[i2] = aVar;
                    break;
                }
                i2++;
            }
        }
        return arrayList;
    }

    private org.greenrobot.eventbus.r.a f(a aVar) {
        org.greenrobot.eventbus.r.a aVar2 = aVar.f1111g;
        if (aVar2 != null && aVar2.c() != null) {
            org.greenrobot.eventbus.r.a aVarC = aVar.f1111g.c();
            if (aVar.e == aVarC.b()) {
                return aVarC;
            }
        }
        List<org.greenrobot.eventbus.r.b> list = this.a;
        if (list == null) {
            return null;
        }
        Iterator<org.greenrobot.eventbus.r.b> it = list.iterator();
        while (it.hasNext()) {
            org.greenrobot.eventbus.r.a aVarA = it.next().a(aVar.e);
            if (aVarA != null) {
                return aVarA;
            }
        }
        return null;
    }

    private a g() {
        synchronized (e) {
            for (int i2 = 0; i2 < 4; i2++) {
                a aVar = e[i2];
                if (aVar != null) {
                    e[i2] = null;
                    return aVar;
                }
            }
            return new a();
        }
    }

    List<o> a(Class<?> cls) {
        List<o> list = d.get(cls);
        if (list != null) {
            return list;
        }
        List<o> listC = this.c ? c(cls) : b(cls);
        if (!listC.isEmpty()) {
            d.put(cls, listC);
            return listC;
        }
        throw new e("Subscriber " + cls + " and its super classes have no public methods with the @Subscribe annotation");
    }
}
