package O1;

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: loaded from: classes2.dex */
class p {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final Map f1541d = new ConcurrentHashMap();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final a[] f1542e = new a[4];

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private List f1543a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final boolean f1544b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final boolean f1545c;

    static class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final List f1546a = new ArrayList();

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final Map f1547b = new HashMap();

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final Map f1548c = new HashMap();

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final StringBuilder f1549d = new StringBuilder(128);

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        Class f1550e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        Class f1551f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        boolean f1552g;

        a() {
        }

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

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

        void c(Class cls) {
            this.f1551f = cls;
            this.f1550e = cls;
            this.f1552g = false;
        }

        void d() {
            if (this.f1552g) {
                this.f1551f = null;
                return;
            }
            Class superclass = this.f1551f.getSuperclass();
            this.f1551f = superclass;
            String name = superclass.getName();
            if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
                this.f1551f = null;
            }
        }

        void e() {
            this.f1546a.clear();
            this.f1547b.clear();
            this.f1548c.clear();
            this.f1549d.setLength(0);
            this.f1550e = null;
            this.f1551f = null;
            this.f1552g = false;
        }
    }

    p(List list, boolean z2, boolean z3) {
        this.f1543a = list;
        this.f1544b = z2;
        this.f1545c = z3;
    }

    private List b(Class cls) {
        a aVarG = g();
        aVarG.c(cls);
        while (aVarG.f1551f != null) {
            f(aVarG);
            d(aVarG);
            aVarG.d();
        }
        return e(aVarG);
    }

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

    private void d(a aVar) {
        Method[] methods;
        try {
            methods = aVar.f1551f.getDeclaredMethods();
        } catch (Throwable unused) {
            methods = aVar.f1551f.getMethods();
            aVar.f1552g = 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.f1546a.add(new o(method, cls, mVar.threadMode(), mVar.priority(), mVar.sticky()));
                        }
                    }
                } else if (this.f1544b && 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.f1544b && 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 e(a aVar) {
        ArrayList arrayList = new ArrayList(aVar.f1546a);
        aVar.e();
        synchronized (f1542e) {
            int i2 = 0;
            while (true) {
                if (i2 >= 4) {
                    break;
                }
                try {
                    a[] aVarArr = f1542e;
                    if (aVarArr[i2] == null) {
                        aVarArr[i2] = aVar;
                        break;
                    }
                    i2++;
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        return arrayList;
    }

    private P1.a f(a aVar) {
        aVar.getClass();
        List list = this.f1543a;
        if (list != null) {
            Iterator it = list.iterator();
            if (it.hasNext()) {
                android.support.v4.media.a.a(it.next());
                throw null;
            }
        }
        return null;
    }

    private a g() {
        synchronized (f1542e) {
            for (int i2 = 0; i2 < 4; i2++) {
                try {
                    a[] aVarArr = f1542e;
                    a aVar = aVarArr[i2];
                    if (aVar != null) {
                        aVarArr[i2] = null;
                        return aVar;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
            return new a();
        }
    }

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