446 lines
15 KiB
Java
446 lines
15 KiB
Java
package o;
|
|
|
|
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 o.InterfaceC15299gmn;
|
|
import org.greenrobot.eventbus.EventBusException;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
/* renamed from: o.gmk, reason: case insensitive filesystem */
|
|
/* loaded from: classes.dex */
|
|
public class C15296gmk {
|
|
private static volatile C15296gmk c;
|
|
final InterfaceC15299gmn b;
|
|
final ExecutorService d;
|
|
private final RunnableC15297gml f;
|
|
private final int g;
|
|
private final RunnableC15292gmg h;
|
|
private final ThreadLocal<LWm> i;
|
|
private final boolean j;
|
|
private final boolean k;
|
|
private final InterfaceC15303gmr l;
|
|
private final boolean m;
|
|
private final boolean n;
|
|
|
|
/* renamed from: o, reason: collision with root package name */
|
|
private final InterfaceC15304gms f9144o;
|
|
private final boolean p;
|
|
private final C15306gmu q;
|
|
private final Map<Class<?>, CopyOnWriteArrayList<C15310gmy>> r;
|
|
private final Map<Class<?>, Object> s;
|
|
private final boolean t;
|
|
private final Map<Object, List<Class<?>>> v;
|
|
private static final C15298gmm a = new C15298gmm();
|
|
private static final Map<Class<?>, List<Class<?>>> e = new HashMap();
|
|
|
|
public static C15296gmk b() {
|
|
C15296gmk c15296gmk;
|
|
C15296gmk c15296gmk2 = c;
|
|
if (c15296gmk2 != null) {
|
|
return c15296gmk2;
|
|
}
|
|
synchronized (C15296gmk.class) {
|
|
c15296gmk = c;
|
|
if (c15296gmk == null) {
|
|
c15296gmk = new C15296gmk();
|
|
c = c15296gmk;
|
|
}
|
|
}
|
|
return c15296gmk;
|
|
}
|
|
|
|
public C15296gmk() {
|
|
this(a);
|
|
}
|
|
|
|
private C15296gmk(C15298gmm c15298gmm) {
|
|
InterfaceC15299gmn hBt;
|
|
this.i = new ThreadLocal<LWm>(this) { // from class: o.gmk.5
|
|
private C15296gmk a;
|
|
|
|
{
|
|
this.a = this;
|
|
}
|
|
|
|
@Override // java.lang.ThreadLocal
|
|
protected final /* synthetic */ LWm initialValue() {
|
|
return new LWm();
|
|
}
|
|
};
|
|
InterfaceC15299gmn interfaceC15299gmn = c15298gmm.i;
|
|
if (gmB.b()) {
|
|
hBt = gmB.e().b;
|
|
} else {
|
|
hBt = new InterfaceC15299gmn.HBt();
|
|
}
|
|
this.b = hBt;
|
|
this.r = new HashMap();
|
|
this.v = new HashMap();
|
|
this.s = new ConcurrentHashMap();
|
|
InterfaceC15304gms interfaceC15304gms = c15298gmm.g;
|
|
InterfaceC15304gms interfaceC15304gms2 = gmB.b() ? gmB.e().e : null;
|
|
this.f9144o = interfaceC15304gms2;
|
|
this.l = interfaceC15304gms2 != null ? interfaceC15304gms2.e(this) : null;
|
|
this.f = new RunnableC15297gml(this);
|
|
this.h = new RunnableC15292gmg(this);
|
|
List<InterfaceC15275gmI> list = c15298gmm.k;
|
|
this.g = 0;
|
|
this.q = new C15306gmu(c15298gmm.k, c15298gmm.f, c15298gmm.d);
|
|
this.m = c15298gmm.e;
|
|
this.k = c15298gmm.b;
|
|
this.t = c15298gmm.j;
|
|
this.n = c15298gmm.h;
|
|
this.p = c15298gmm.m;
|
|
this.j = c15298gmm.c;
|
|
this.d = c15298gmm.a;
|
|
}
|
|
|
|
public final void a(Object obj) {
|
|
if (C15311gmz.a() && !C15311gmz.d()) {
|
|
throw new RuntimeException("It looks like you are using EventBus on Android, make sure to add the \"eventbus\" Android library to your dependencies.");
|
|
}
|
|
List<C15308gmw> d = this.q.d(obj.getClass());
|
|
synchronized (this) {
|
|
Iterator<C15308gmw> it = d.iterator();
|
|
while (it.hasNext()) {
|
|
b(obj, it.next());
|
|
}
|
|
}
|
|
}
|
|
|
|
private void b(Object obj, C15308gmw c15308gmw) {
|
|
Class<?> cls = c15308gmw.e;
|
|
C15310gmy c15310gmy = new C15310gmy(obj, c15308gmw);
|
|
CopyOnWriteArrayList<C15310gmy> copyOnWriteArrayList = this.r.get(cls);
|
|
if (copyOnWriteArrayList == null) {
|
|
copyOnWriteArrayList = new CopyOnWriteArrayList<>();
|
|
this.r.put(cls, copyOnWriteArrayList);
|
|
} else if (copyOnWriteArrayList.contains(c15310gmy)) {
|
|
StringBuilder sb = new StringBuilder("Subscriber ");
|
|
sb.append(obj.getClass());
|
|
sb.append(" already registered to event ");
|
|
sb.append(cls);
|
|
throw new EventBusException(sb.toString());
|
|
}
|
|
int size = copyOnWriteArrayList.size();
|
|
for (int i = 0; i <= size; i++) {
|
|
if (i == size || c15308gmw.c > copyOnWriteArrayList.get(i).a.c) {
|
|
copyOnWriteArrayList.add(i, c15310gmy);
|
|
break;
|
|
}
|
|
}
|
|
List<Class<?>> list = this.v.get(obj);
|
|
if (list == null) {
|
|
list = new ArrayList<>();
|
|
this.v.put(obj, list);
|
|
}
|
|
list.add(cls);
|
|
if (c15308gmw.d) {
|
|
if (this.j) {
|
|
for (Map.Entry<Class<?>, Object> entry : this.s.entrySet()) {
|
|
if (cls.isAssignableFrom(entry.getKey())) {
|
|
b(c15310gmy, entry.getValue());
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
b(c15310gmy, this.s.get(cls));
|
|
}
|
|
}
|
|
|
|
private void b(C15310gmy c15310gmy, Object obj) {
|
|
if (obj != null) {
|
|
InterfaceC15304gms interfaceC15304gms = this.f9144o;
|
|
d(c15310gmy, obj, interfaceC15304gms == null || interfaceC15304gms.a());
|
|
}
|
|
}
|
|
|
|
private void c(Object obj, Class<?> cls) {
|
|
CopyOnWriteArrayList<C15310gmy> copyOnWriteArrayList = this.r.get(cls);
|
|
if (copyOnWriteArrayList != null) {
|
|
int size = copyOnWriteArrayList.size();
|
|
int i = 0;
|
|
while (i < size) {
|
|
C15310gmy c15310gmy = copyOnWriteArrayList.get(i);
|
|
if (c15310gmy.b == obj) {
|
|
c15310gmy.d = false;
|
|
copyOnWriteArrayList.remove(i);
|
|
i--;
|
|
size--;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void b(Object obj) {
|
|
synchronized (this) {
|
|
List<Class<?>> list = this.v.get(obj);
|
|
if (list != null) {
|
|
Iterator<Class<?>> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
c(obj, it.next());
|
|
}
|
|
this.v.remove(obj);
|
|
} else {
|
|
InterfaceC15299gmn interfaceC15299gmn = this.b;
|
|
Level level = Level.WARNING;
|
|
StringBuilder sb = new StringBuilder("Subscriber to unregister was not registered before: ");
|
|
sb.append(obj.getClass());
|
|
interfaceC15299gmn.c(level, sb.toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void e(Object obj) {
|
|
LWm lWm = this.i.get();
|
|
List<Object> list = lWm.a;
|
|
list.add(obj);
|
|
if (lWm.b) {
|
|
return;
|
|
}
|
|
InterfaceC15304gms interfaceC15304gms = this.f9144o;
|
|
lWm.d = interfaceC15304gms == null || interfaceC15304gms.a();
|
|
lWm.b = true;
|
|
boolean z = lWm.e;
|
|
while (!list.isEmpty()) {
|
|
try {
|
|
e(list.remove(0), lWm);
|
|
} finally {
|
|
lWm.b = false;
|
|
lWm.d = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void e(Object obj, LWm lWm) throws Error {
|
|
boolean a2;
|
|
Class<?> cls = obj.getClass();
|
|
if (this.j) {
|
|
List<Class<?>> a3 = a(cls);
|
|
int size = a3.size();
|
|
a2 = false;
|
|
for (int i = 0; i < size; i++) {
|
|
a2 |= a(obj, lWm, a3.get(i));
|
|
}
|
|
} else {
|
|
a2 = a(obj, lWm, cls);
|
|
}
|
|
if (a2) {
|
|
return;
|
|
}
|
|
if (this.k) {
|
|
this.b.c(Level.FINE, "No subscribers registered for event ".concat(String.valueOf(cls)));
|
|
}
|
|
if (!this.n || cls == C15305gmt.class || cls == C15307gmv.class) {
|
|
return;
|
|
}
|
|
e(new C15305gmt(this, obj));
|
|
}
|
|
|
|
private boolean a(Object obj, LWm lWm, Class<?> cls) {
|
|
CopyOnWriteArrayList<C15310gmy> copyOnWriteArrayList;
|
|
synchronized (this) {
|
|
copyOnWriteArrayList = this.r.get(cls);
|
|
}
|
|
if (copyOnWriteArrayList == null || copyOnWriteArrayList.isEmpty()) {
|
|
return false;
|
|
}
|
|
Iterator<C15310gmy> it = copyOnWriteArrayList.iterator();
|
|
while (it.hasNext()) {
|
|
C15310gmy next = it.next();
|
|
lWm.c = obj;
|
|
lWm.g = next;
|
|
try {
|
|
d(next, obj, lWm.d);
|
|
boolean z = lWm.e;
|
|
} finally {
|
|
lWm.c = null;
|
|
lWm.g = null;
|
|
lWm.e = false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: o.gmk$1, reason: invalid class name */
|
|
/* loaded from: classes.dex */
|
|
public static /* synthetic */ class AnonymousClass1 {
|
|
static final int[] b;
|
|
|
|
static {
|
|
int[] iArr = new int[ThreadMode.values().length];
|
|
b = iArr;
|
|
try {
|
|
iArr[ThreadMode.POSTING.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
b[ThreadMode.MAIN.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
b[ThreadMode.MAIN_ORDERED.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
try {
|
|
b[ThreadMode.BACKGROUND.ordinal()] = 4;
|
|
} catch (NoSuchFieldError unused4) {
|
|
}
|
|
try {
|
|
b[ThreadMode.ASYNC.ordinal()] = 5;
|
|
} catch (NoSuchFieldError unused5) {
|
|
}
|
|
}
|
|
}
|
|
|
|
private void d(C15310gmy c15310gmy, Object obj, boolean z) {
|
|
int i = AnonymousClass1.b[c15310gmy.a.h.ordinal()];
|
|
if (i != 1) {
|
|
if (i != 2) {
|
|
if (i == 3) {
|
|
InterfaceC15303gmr interfaceC15303gmr = this.l;
|
|
if (interfaceC15303gmr != null) {
|
|
interfaceC15303gmr.a(c15310gmy, obj);
|
|
return;
|
|
} else {
|
|
a(c15310gmy, obj);
|
|
return;
|
|
}
|
|
}
|
|
if (i == 4) {
|
|
if (z) {
|
|
this.f.a(c15310gmy, obj);
|
|
return;
|
|
} else {
|
|
a(c15310gmy, obj);
|
|
return;
|
|
}
|
|
}
|
|
if (i != 5) {
|
|
StringBuilder sb = new StringBuilder("Unknown thread mode: ");
|
|
sb.append(c15310gmy.a.h);
|
|
throw new IllegalStateException(sb.toString());
|
|
}
|
|
RunnableC15292gmg runnableC15292gmg = this.h;
|
|
runnableC15292gmg.c.a(C15302gmq.c(c15310gmy, obj));
|
|
runnableC15292gmg.b.d.execute(runnableC15292gmg);
|
|
return;
|
|
}
|
|
if (!z) {
|
|
this.l.a(c15310gmy, obj);
|
|
return;
|
|
}
|
|
}
|
|
a(c15310gmy, obj);
|
|
}
|
|
|
|
private static List<Class<?>> a(Class<?> cls) {
|
|
List<Class<?>> list;
|
|
Map<Class<?>, List<Class<?>>> map = e;
|
|
synchronized (map) {
|
|
list = map.get(cls);
|
|
if (list == null) {
|
|
list = new ArrayList<>();
|
|
for (Class<?> cls2 = cls; cls2 != null; cls2 = cls2.getSuperclass()) {
|
|
list.add(cls2);
|
|
b(list, cls2.getInterfaces());
|
|
}
|
|
e.put(cls, list);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private static void b(List<Class<?>> list, Class<?>[] clsArr) {
|
|
for (Class<?> cls : clsArr) {
|
|
if (!list.contains(cls)) {
|
|
list.add(cls);
|
|
b(list, cls.getInterfaces());
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public final void a(C15310gmy c15310gmy, Object obj) {
|
|
try {
|
|
c15310gmy.a.a.invoke(c15310gmy.b, obj);
|
|
} catch (IllegalAccessException e2) {
|
|
throw new IllegalStateException("Unexpected exception", e2);
|
|
} catch (InvocationTargetException e3) {
|
|
c(c15310gmy, obj, e3.getCause());
|
|
}
|
|
}
|
|
|
|
private void c(C15310gmy c15310gmy, Object obj, Throwable th) {
|
|
if (!(obj instanceof C15307gmv)) {
|
|
if (this.p) {
|
|
throw new EventBusException("Invoking subscriber failed", th);
|
|
}
|
|
if (this.m) {
|
|
InterfaceC15299gmn interfaceC15299gmn = this.b;
|
|
Level level = Level.SEVERE;
|
|
StringBuilder sb = new StringBuilder("Could not dispatch event: ");
|
|
sb.append(obj.getClass());
|
|
sb.append(" to subscribing class ");
|
|
sb.append(c15310gmy.b.getClass());
|
|
interfaceC15299gmn.b(level, sb.toString(), th);
|
|
}
|
|
if (this.t) {
|
|
e(new C15307gmv(this, th, obj, c15310gmy.b));
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if (this.m) {
|
|
InterfaceC15299gmn interfaceC15299gmn2 = this.b;
|
|
Level level2 = Level.SEVERE;
|
|
StringBuilder sb2 = new StringBuilder("SubscriberExceptionEvent subscriber ");
|
|
sb2.append(c15310gmy.b.getClass());
|
|
sb2.append(" threw an exception");
|
|
interfaceC15299gmn2.b(level2, sb2.toString(), th);
|
|
C15307gmv c15307gmv = (C15307gmv) obj;
|
|
InterfaceC15299gmn interfaceC15299gmn3 = this.b;
|
|
Level level3 = Level.SEVERE;
|
|
StringBuilder sb3 = new StringBuilder("Initial event ");
|
|
sb3.append(c15307gmv.a);
|
|
sb3.append(" caused exception in ");
|
|
sb3.append(c15307gmv.b);
|
|
interfaceC15299gmn3.b(level3, sb3.toString(), c15307gmv.d);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: o.gmk$LWm */
|
|
/* loaded from: classes.dex */
|
|
public static final class LWm {
|
|
final List<Object> a = new ArrayList();
|
|
boolean b;
|
|
Object c;
|
|
boolean d;
|
|
boolean e;
|
|
C15310gmy g;
|
|
|
|
LWm() {
|
|
}
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder("EventBus[indexCount=");
|
|
sb.append(this.g);
|
|
sb.append(", eventInheritance=");
|
|
sb.append(this.j);
|
|
sb.append("]");
|
|
return sb.toString();
|
|
}
|
|
}
|