Swiggy v4.51.1版本的 MD5 值为:5af7ec91512a0a8c1510e3f8bac20b8b
以下内容为反编译后的 Dispatcher.java 源代码,内容仅作参考
package in.swiggy.swiggylytics.core.impl;
import android.content.Context;
import in.swiggy.swiggylytics.core.interfaces.IConfigManager;
import in.swiggy.swiggylytics.core.interfaces.IDispatcher;
import in.swiggy.swiggylytics.core.interfaces.ILogger;
import in.swiggy.swiggylytics.core.models.Batch;
import in.swiggy.swiggylytics.core.models.Constants;
import in.swiggy.swiggylytics.core.models.Event;
import in.swiggy.swiggylytics.core.models.NetworkResponse;
import in.swiggy.swiggylytics.core.utils.NonConfigEventTransformer;
import in.swiggy.swiggylytics.core.utils.NonConfigOkHttpUtils;
import in.swiggy.swiggylytics.core.utils.OkHttpUtils;
import io.reactivex.subjects.PublishSubject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.Pair;
import okhttp3.OkHttpClient;
public class Dispatcher implements IDispatcher {
private static final String r = "Dispatcher";
private static IDispatcher s;
private final ILogger a;
private final IConfigManager b;
private final OkHttpClient c;
private final Context d;
private long e = 15000;
private boolean f = false;
private final PublishSubject<Event> g = PublishSubject.b();
private final PublishSubject<Batch> h = PublishSubject.b();
private final PublishSubject<Batch> i = PublishSubject.b();
private PublishSubject<Batch> j = PublishSubject.b();
private PublishSubject<Batch> k = PublishSubject.b();
private PublishSubject<Batch> l = PublishSubject.b();
private Event m = null;
private Batch n = null;
private Batch o = null;
private Batch p = null;
private HashMap<String, Event> q = new HashMap<>();
private Dispatcher(OkHttpClient okHttpClient, ILogger iLogger, IConfigManager iConfigManager, Context context) {
this.c = okHttpClient;
this.a = iLogger;
this.b = iConfigManager;
this.d = context;
}
private void n(Batch batch) {
for (Event event : batch.a()) {
if (!this.q.containsKey(event.j())) {
this.q.put(event.j(), event);
}
}
}
public static IDispatcher p(OkHttpClient okHttpClient, ILogger iLogger, IConfigManager iConfigManager, Context context) {
if (s == null) {
s = new Dispatcher(okHttpClient, iLogger, iConfigManager, context);
}
return s;
}
private boolean q(String str) {
try {
NetworkResponse j = OkHttpUtils.d(this.c, this.b, this.a).j("https://analytics.swiggy.com/message-set", str);
if (j == null) {
return false;
}
if (!j.a()) {
return false;
}
return true;
} catch (Exception e) {
this.a.a("Sending failed", e);
return false;
}
}
private boolean r(String str) {
try {
NetworkResponse g = NonConfigOkHttpUtils.b(NonConfigOkHttpUtils.d(this.b), this.b, this.a).g("https://analytics.swiggy.com/message-set", str);
if (g == null) {
return false;
}
if (!g.a()) {
return false;
}
return true;
} catch (Exception e) {
this.a.a("Sending failed", e);
return false;
}
}
@Override
public io.reactivex.l<Batch> a() {
PublishSubject<Batch> b = PublishSubject.b();
this.l = b;
return b.hide();
}
@Override
public io.reactivex.l<Batch> b() {
return this.i.hide();
}
@Override
public Batch c() {
return this.n;
}
@Override
public Batch d() {
return this.p;
}
@Override
public Event e() {
return this.m;
}
@Override
public Batch f() {
return this.o;
}
@Override
public io.reactivex.l<Batch> g() {
PublishSubject<Batch> b = PublishSubject.b();
this.j = b;
return b.hide();
}
@Override
public void h(Batch batch) {
if (batch.a().size() == 0) {
return;
}
this.a.d(r, "Dispatching batch");
this.p = batch;
n(batch);
batch.e(true);
if (!q(batch.b())) {
batch.f(false);
this.h.onNext(batch);
} else {
batch.f(true);
}
this.p = null;
batch.e(false);
this.k.onNext(batch);
}
@Override
public io.reactivex.l<Event> i() {
return this.g.hide();
}
@Override
public void j(Batch batch) {
if (batch.a().size() == 0) {
return;
}
this.a.d(r, "Dispatching batch");
this.n = batch;
n(batch);
batch.e(true);
if (!q(batch.b())) {
batch.f(false);
this.h.onNext(batch);
} else {
batch.f(true);
}
this.n = null;
batch.e(false);
this.j.onNext(batch);
}
@Override
public void k(Batch batch) {
if (batch.a().size() == 0) {
return;
}
this.a.d(r, "Dispatching non-config batch");
this.o = batch;
n(batch);
batch.e(true);
for (int i = 0; i < batch.a().size(); i++) {
Event event = batch.a().get(i);
Pair<Map<String, Object>, Map<String, Object>> c = NonConfigEventTransformer.c(event.b(), event.d());
batch.a().get(i).l(c.d());
batch.a().get(i).m(c.e());
}
if (!r(new Batch(o(batch)).b())) {
batch.f(false);
this.i.onNext(batch);
} else {
batch.f(true);
}
this.o = null;
batch.e(false);
this.l.onNext(batch);
}
@Override
public io.reactivex.l<Batch> l() {
return this.h.hide();
}
@Override
public io.reactivex.l<Batch> m() {
PublishSubject<Batch> b = PublishSubject.b();
this.k = b;
return b.hide();
}
public List<Event> o(Batch batch) {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < batch.a().size(); i++) {
Event event = batch.a().get(i);
try {
if (System.currentTimeMillis() - ((Long) event.b().get("client_timestamp")).longValue() <= Constants.b.longValue() * this.b.m()) {
arrayList.add(event);
}
} catch (Exception unused) {
arrayList.add(event);
}
}
return arrayList;
}
@Override
public void purge() {
this.m = null;
this.n = null;
this.p = null;
this.o = null;
}
}