package 㳳.ῲ.K;

import android.os.Looper;
import java.lang.reflect.InvocationTargetException;
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;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import org.greenrobot.eventbus.EventBusException;
import ඓ.K.K.K.C1293;
import 㳳.ῲ.K.AbstractC2410;
import 㳳.ῲ.K.AbstractC2417;
import 㳳.ῲ.K.ᓣ.AbstractC2405;

/* renamed from: 㳳.ῲ.K.ʬ  reason: contains not printable characters */
/* compiled from: EventBus */
public class C2399 {

    /* renamed from: Ԛ  reason: contains not printable characters */
    public static final Map<Class<?>, List<Class<?>>> f8287 = new HashMap();

    /* renamed from: ݜ  reason: contains not printable characters */
    public static volatile C2399 f8288;

    /* renamed from: 䀟  reason: contains not printable characters */
    public static final C2420 f8289 = new C2420();

    /* renamed from: ʬ  reason: contains not printable characters */
    public final Map<Class<?>, Object> f8290;

    /* renamed from: Ԕ  reason: contains not printable characters */
    public final boolean f8291;

    /* renamed from: ؿ  reason: contains not printable characters */
    public final boolean f8292;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final AbstractC2410 f8293;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public final int f8294;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public final boolean f8295;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final C2414 f8296;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final Map<Object, List<Class<?>>> f8297;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final RunnableC2409 f8298;

    /* renamed from: K  reason: contains not printable characters */
    public final Map<Class<?>, CopyOnWriteArrayList<C2403>> f8299;

    /* renamed from: 㑃  reason: contains not printable characters */
    public final boolean f8300;

    /* renamed from: 㗗  reason: contains not printable characters */
    public final boolean f8301;

    /* renamed from: 㗽  reason: contains not printable characters */
    public final AbstractC2417 f8302;

    /* renamed from: 㳳  reason: contains not printable characters */
    public final ExecutorService f8303;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final AbstractC2407 f8304;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final ThreadLocal<C2400> f8305 = new C2401(this);

    /* renamed from: 㿎  reason: contains not printable characters */
    public final RunnableC2412 f8306;

    /* renamed from: 䁗  reason: contains not printable characters */
    public final boolean f8307;

    /* renamed from: 㳳.ῲ.K.ʬ$ῲ  reason: contains not printable characters */
    /* compiled from: EventBus */
    public static final class C2400 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public boolean f8308;

        /* renamed from: ඓ  reason: contains not printable characters */
        public Object f8309;

        /* renamed from: ῲ  reason: contains not printable characters */
        public boolean f8310;

        /* renamed from: K  reason: contains not printable characters */
        public final List<Object> f8311 = new ArrayList();

        /* renamed from: 㴹  reason: contains not printable characters */
        public boolean f8312;

        /* renamed from: 㸾  reason: contains not printable characters */
        public C2403 f8313;
    }

    /* renamed from: 㳳.ῲ.K.ʬ$K  reason: contains not printable characters */
    /* compiled from: EventBus */
    public class C2401 extends ThreadLocal<C2400> {
        public C2401(C2399 r1) {
        }

        /* Return type fixed from 'java.lang.Object' to match base method */
        @Override // java.lang.ThreadLocal
        public C2400 initialValue() {
            return new C2400();
        }
    }

    public C2399() {
        Object r1;
        C2420 r0 = f8289;
        AbstractC2417 r12 = r0.f8356;
        this.f8302 = r12 == null ? (!AbstractC2417.C2419.m6477() || r0.m6481() == null) ? new AbstractC2417.C2418() : new AbstractC2417.C2419("EventBus") : r12;
        this.f8299 = new HashMap();
        this.f8297 = new HashMap();
        this.f8290 = new ConcurrentHashMap();
        AbstractC2410 r13 = r0.f8361;
        AbstractC2407 r2 = null;
        this.f8293 = r13 == null ? (!AbstractC2417.C2419.m6477() || (r1 = r0.m6481()) == null) ? null : new AbstractC2410.C2411((Looper) r1) : r13;
        AbstractC2410 r14 = this.f8293;
        this.f8304 = r14 != null ? ((AbstractC2410.C2411) r14).m6460(this) : r2;
        this.f8298 = new RunnableC2409(this);
        this.f8306 = new RunnableC2412(this);
        List<AbstractC2405> list = r0.f8362;
        this.f8294 = list != null ? list.size() : 0;
        this.f8296 = new C2414(r0.f8362, r0.f8365, r0.f8359);
        this.f8300 = r0.f8360;
        this.f8307 = r0.f8358;
        this.f8291 = r0.f8354;
        this.f8301 = r0.f8364;
        this.f8295 = r0.f8355;
        this.f8292 = r0.f8363;
        this.f8303 = r0.f8357;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static C2399 m6437() {
        if (f8288 == null) {
            synchronized (C2399.class) {
                if (f8288 == null) {
                    f8288 = new C2399();
                }
            }
        }
        return f8288;
    }

    public String toString() {
        StringBuilder r0 = C1293.m3416("EventBus[indexCount=");
        r0.append(this.f8294);
        r0.append(", eventInheritance=");
        r0.append(this.f8292);
        r0.append("]");
        return r0.toString();
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public synchronized void m6440(Object obj) {
        List<Class<?>> list = this.f8297.get(obj);
        if (list != null) {
            for (Class<?> cls : list) {
                CopyOnWriteArrayList<C2403> copyOnWriteArrayList = this.f8299.get(cls);
                if (copyOnWriteArrayList != null) {
                    int size = copyOnWriteArrayList.size();
                    int i = 0;
                    while (i < size) {
                        C2403 r5 = copyOnWriteArrayList.get(i);
                        if (r5.f8322 == obj) {
                            r5.f8320 = false;
                            copyOnWriteArrayList.remove(i);
                            i--;
                            size--;
                        }
                        i++;
                    }
                }
            }
            this.f8297.remove(obj);
        } else {
            this.f8302.m6473(Level.WARNING, "Subscriber to unregister was not registered before: " + obj.getClass());
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m6444(Object obj, C2402 r9) {
        Object value;
        Class<?> cls = r9.f8314;
        C2403 r1 = new C2403(obj, r9);
        CopyOnWriteArrayList<C2403> copyOnWriteArrayList = this.f8299.get(cls);
        if (copyOnWriteArrayList == null) {
            copyOnWriteArrayList = new CopyOnWriteArrayList<>();
            this.f8299.put(cls, copyOnWriteArrayList);
        } else if (copyOnWriteArrayList.contains(r1)) {
            StringBuilder r12 = C1293.m3416("Subscriber ");
            r12.append(obj.getClass());
            r12.append(" already registered to event ");
            r12.append(cls);
            throw new EventBusException(r12.toString());
        }
        int size = copyOnWriteArrayList.size();
        int i = 0;
        while (true) {
            if (i > size) {
                break;
            } else if (i == size || r9.f8319 > copyOnWriteArrayList.get(i).f8321.f8319) {
                copyOnWriteArrayList.add(i, r1);
            } else {
                i++;
            }
        }
        copyOnWriteArrayList.add(i, r1);
        List<Class<?>> list = this.f8297.get(obj);
        if (list == null) {
            list = new ArrayList<>();
            this.f8297.put(obj, list);
        }
        list.add(cls);
        if (!r9.f8315) {
            return;
        }
        if (this.f8292) {
            for (Map.Entry<Class<?>, Object> entry : this.f8290.entrySet()) {
                if (cls.isAssignableFrom(entry.getKey()) && (value = entry.getValue()) != null) {
                    m6446(r1, value, m6448());
                }
            }
            return;
        }
        Object obj2 = this.f8290.get(cls);
        if (obj2 != null) {
            m6446(r1, obj2, m6448());
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m6441(Object obj) {
        List<C2402> r0 = this.f8296.m6463(obj.getClass());
        synchronized (this) {
            for (C2402 r1 : r0) {
                m6444(obj, r1);
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final boolean m6448() {
        AbstractC2410 r0 = this.f8293;
        if (r0 == null || ((AbstractC2410.C2411) r0).f8334 == Looper.myLooper()) {
            return true;
        }
        return false;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6442(Object obj) {
        C2400 r0 = this.f8305.get();
        List<Object> list = r0.f8311;
        list.add(obj);
        if (!r0.f8310) {
            r0.f8308 = m6448();
            r0.f8310 = true;
            if (!r0.f8312) {
                while (!list.isEmpty()) {
                    try {
                        m6443(list.remove(0), r0);
                    } finally {
                        r0.f8310 = false;
                        r0.f8308 = false;
                    }
                }
                return;
            }
            throw new EventBusException("Internal error. Abort state was not reset");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m6443(Object obj, C2400 r8) throws Error {
        boolean z;
        Class<?> cls = obj.getClass();
        if (this.f8292) {
            List<Class<?>> r1 = m6438(cls);
            int size = r1.size();
            z = false;
            for (int i = 0; i < size; i++) {
                z |= m6449(obj, r8, r1.get(i));
            }
        } else {
            z = m6449(obj, r8, cls);
        }
        if (!z) {
            if (this.f8307) {
                AbstractC2417 r82 = this.f8302;
                Level level = Level.FINE;
                r82.m6473(level, "No subscribers registered for event " + cls);
            }
            if (!(!this.f8301 || cls == C2421.class || cls == C2422.class)) {
                m6442(new C2421(this, obj));
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final boolean m6449(Object obj, C2400 r6, Class<?> cls) {
        CopyOnWriteArrayList<C2403> copyOnWriteArrayList;
        synchronized (this) {
            copyOnWriteArrayList = this.f8299.get(cls);
        }
        if (copyOnWriteArrayList == null || copyOnWriteArrayList.isEmpty()) {
            return false;
        }
        Iterator<C2403> it2 = copyOnWriteArrayList.iterator();
        while (it2.hasNext()) {
            C2403 next = it2.next();
            r6.f8309 = obj;
            r6.f8313 = next;
            try {
                m6446(next, obj, r6.f8308);
                if (r6.f8312) {
                    return true;
                }
            } finally {
                r6.f8309 = null;
                r6.f8313 = null;
                r6.f8312 = false;
            }
        }
        return true;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m6446(C2403 r3, Object obj, boolean z) {
        int ordinal = r3.f8321.f8316.ordinal();
        if (ordinal == 0) {
            m6445(r3, obj);
        } else if (ordinal != 1) {
            if (ordinal == 2) {
                AbstractC2407 r5 = this.f8304;
                if (r5 != null) {
                    r5.m6456(r3, obj);
                } else {
                    m6445(r3, obj);
                }
            } else if (ordinal != 3) {
                if (ordinal == 4) {
                    this.f8306.m6461(r3, obj);
                    return;
                }
                StringBuilder r52 = C1293.m3416("Unknown thread mode: ");
                r52.append(r3.f8321.f8316);
                throw new IllegalStateException(r52.toString());
            } else if (z) {
                this.f8298.m6459(r3, obj);
            } else {
                m6445(r3, obj);
            }
        } else if (z) {
            m6445(r3, obj);
        } else {
            this.f8304.m6456(r3, obj);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static List<Class<?>> m6438(Class<?> cls) {
        List<Class<?>> list;
        synchronized (f8287) {
            list = f8287.get(cls);
            if (list == null) {
                list = new ArrayList<>();
                for (Class<?> cls2 = cls; cls2 != null; cls2 = cls2.getSuperclass()) {
                    list.add(cls2);
                    m6439(list, cls2.getInterfaces());
                }
                f8287.put(cls, list);
            }
        }
        return list;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m6439(List<Class<?>> list, Class<?>[] clsArr) {
        for (Class<?> cls : clsArr) {
            if (!list.contains(cls)) {
                list.add(cls);
                m6439(list, cls.getInterfaces());
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6447(C2408 r3) {
        Object obj = r3.f8330;
        C2403 r1 = r3.f8329;
        C2408.m6458(r3);
        if (r1.f8320) {
            m6445(r1, obj);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6445(C2403 r6, Object obj) {
        try {
            r6.f8321.f8317.invoke(r6.f8322, obj);
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (obj instanceof C2422) {
                if (this.f8300) {
                    AbstractC2417 r1 = this.f8302;
                    Level level = Level.SEVERE;
                    StringBuilder r3 = C1293.m3416("SubscriberExceptionEvent subscriber ");
                    r3.append(r6.f8322.getClass());
                    r3.append(" threw an exception");
                    r1.m6474(level, r3.toString(), cause);
                    C2422 r7 = (C2422) obj;
                    AbstractC2417 r62 = this.f8302;
                    Level level2 = Level.SEVERE;
                    StringBuilder r12 = C1293.m3416("Initial event ");
                    r12.append(r7.f8367);
                    r12.append(" caused exception in ");
                    r12.append(r7.f8366);
                    r62.m6474(level2, r12.toString(), r7.f8368);
                }
            } else if (!this.f8295) {
                if (this.f8300) {
                    AbstractC2417 r13 = this.f8302;
                    Level level3 = Level.SEVERE;
                    StringBuilder r32 = C1293.m3416("Could not dispatch event: ");
                    r32.append(obj.getClass());
                    r32.append(" to subscribing class ");
                    r32.append(r6.f8322.getClass());
                    r13.m6474(level3, r32.toString(), cause);
                }
                if (this.f8291) {
                    m6442(new C2422(this, cause, obj, r6.f8322));
                }
            } else {
                throw new EventBusException("Invoking subscriber failed", cause);
            }
        } catch (IllegalAccessException e2) {
            throw new IllegalStateException("Unexpected exception", e2);
        }
    }
}
