506 lines
22 KiB
Java
506 lines
22 KiB
Java
package o;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.net.ConnectivityManager;
|
|
import android.net.NetworkInfo;
|
|
import android.os.Handler;
|
|
import android.os.HandlerThread;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import com.huawei.hms.support.api.entity.common.CommonConstant;
|
|
import com.squareup.picasso.Picasso;
|
|
import java.lang.ref.Reference;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.WeakHashMap;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Future;
|
|
import o.fNN;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class fNH {
|
|
final Context a;
|
|
final fNB b;
|
|
public final fNJ c;
|
|
final List<RunnableC13011fNx> d;
|
|
boolean e;
|
|
final Map<Object, AbstractC13013fNz> f;
|
|
public final Handler g;
|
|
final Map<String, RunnableC13011fNx> h;
|
|
final Map<Object, AbstractC13013fNz> i;
|
|
final Handler j;
|
|
final boolean k;
|
|
final Set<Object> l;
|
|
private IeS m;
|
|
final ExecutorService n;
|
|
|
|
/* renamed from: o, reason: collision with root package name */
|
|
private HBt f9097o;
|
|
private C13022fOc t;
|
|
|
|
public fNH(Context context, ExecutorService executorService, Handler handler, fNJ fnj, fNB fnb, C13022fOc c13022fOc) {
|
|
IeS ieS = new IeS();
|
|
this.m = ieS;
|
|
ieS.start();
|
|
C13025fOf.aBF_(ieS.getLooper());
|
|
this.a = context;
|
|
this.n = executorService;
|
|
this.h = new LinkedHashMap();
|
|
this.f = new WeakHashMap();
|
|
this.i = new WeakHashMap();
|
|
this.l = new LinkedHashSet();
|
|
this.g = new RVV(ieS.getLooper(), this);
|
|
this.c = fnj;
|
|
this.j = handler;
|
|
this.b = fnb;
|
|
this.t = c13022fOc;
|
|
this.d = new ArrayList(4);
|
|
this.e = C13025fOf.a(context);
|
|
this.k = C13025fOf.d(context, "android.permission.ACCESS_NETWORK_STATE");
|
|
HBt hBt = new HBt(this);
|
|
this.f9097o = hBt;
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
intentFilter.addAction("android.intent.action.AIRPLANE_MODE");
|
|
if (hBt.b.k) {
|
|
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
|
|
}
|
|
hBt.b.a.registerReceiver(hBt, intentFilter);
|
|
}
|
|
|
|
final void a(AbstractC13013fNz abstractC13013fNz) {
|
|
Reference reference = abstractC13013fNz.n;
|
|
Object obj = reference == null ? null : reference.get();
|
|
if (obj != null) {
|
|
abstractC13013fNz.l = true;
|
|
this.f.put(obj, abstractC13013fNz);
|
|
}
|
|
}
|
|
|
|
final void a(RunnableC13011fNx runnableC13011fNx) {
|
|
Future<?> future = runnableC13011fNx.b;
|
|
if (future == null || !future.isCancelled()) {
|
|
if (runnableC13011fNx.m != null) {
|
|
runnableC13011fNx.m.prepareToDraw();
|
|
}
|
|
this.d.add(runnableC13011fNx);
|
|
if (this.g.hasMessages(7)) {
|
|
return;
|
|
}
|
|
this.g.sendEmptyMessageDelayed(7, 200L);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
static class RVV extends Handler {
|
|
private final fNH a;
|
|
|
|
RVV(Looper looper, fNH fnh) {
|
|
super(looper);
|
|
this.a = fnh;
|
|
}
|
|
|
|
@Override // android.os.Handler
|
|
public final void handleMessage(Message message) {
|
|
switch (message.what) {
|
|
case 1:
|
|
this.a.d((AbstractC13013fNz) message.obj, true);
|
|
return;
|
|
case 2:
|
|
AbstractC13013fNz abstractC13013fNz = (AbstractC13013fNz) message.obj;
|
|
fNH fnh = this.a;
|
|
String str = abstractC13013fNz.c;
|
|
RunnableC13011fNx runnableC13011fNx = fnh.h.get(str);
|
|
if (runnableC13011fNx != null) {
|
|
runnableC13011fNx.c(abstractC13013fNz);
|
|
if (runnableC13011fNx.b()) {
|
|
fnh.h.remove(str);
|
|
if (abstractC13013fNz.h.f) {
|
|
C13025fOf.d("Dispatcher", "canceled", abstractC13013fNz.g.c());
|
|
}
|
|
}
|
|
}
|
|
if (fnh.l.contains(abstractC13013fNz.j)) {
|
|
Map<Object, AbstractC13013fNz> map = fnh.i;
|
|
Reference reference = abstractC13013fNz.n;
|
|
map.remove(reference == null ? null : reference.get());
|
|
if (abstractC13013fNz.h.f) {
|
|
C13025fOf.d("Dispatcher", "canceled", abstractC13013fNz.g.c(), "because paused request got canceled");
|
|
}
|
|
}
|
|
Map<Object, AbstractC13013fNz> map2 = fnh.f;
|
|
Reference reference2 = abstractC13013fNz.n;
|
|
AbstractC13013fNz remove = map2.remove(reference2 == null ? null : reference2.get());
|
|
if (remove == null || !remove.h.f) {
|
|
return;
|
|
}
|
|
C13025fOf.d("Dispatcher", "canceled", remove.g.c(), "from replaying");
|
|
return;
|
|
case 3:
|
|
case 8:
|
|
default:
|
|
Picasso.d.post(new Runnable(this, message) { // from class: o.fNH.RVV.2
|
|
private Message b;
|
|
private RVV c;
|
|
|
|
{
|
|
this.c = this;
|
|
this.b = message;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
StringBuilder sb = new StringBuilder("Unknown handler message received: ");
|
|
sb.append(this.b.what);
|
|
throw new AssertionError(sb.toString());
|
|
}
|
|
});
|
|
return;
|
|
case 4:
|
|
RunnableC13011fNx runnableC13011fNx2 = (RunnableC13011fNx) message.obj;
|
|
fNH fnh2 = this.a;
|
|
if (EnumC12984fNP.d(runnableC13011fNx2.i)) {
|
|
fnh2.b.aBk_(runnableC13011fNx2.h, runnableC13011fNx2.m);
|
|
}
|
|
fnh2.h.remove(runnableC13011fNx2.h);
|
|
fnh2.a(runnableC13011fNx2);
|
|
if (runnableC13011fNx2.j.f) {
|
|
C13025fOf.d("Dispatcher", "batched", C13025fOf.e(runnableC13011fNx2), "for completion");
|
|
return;
|
|
}
|
|
return;
|
|
case 5:
|
|
RunnableC13011fNx runnableC13011fNx3 = (RunnableC13011fNx) message.obj;
|
|
fNH fnh3 = this.a;
|
|
Future<?> future = runnableC13011fNx3.b;
|
|
if (future == null || !future.isCancelled()) {
|
|
if (fnh3.n.isShutdown()) {
|
|
fnh3.a(runnableC13011fNx3, false);
|
|
return;
|
|
}
|
|
NetworkInfo activeNetworkInfo = fnh3.k ? ((ConnectivityManager) C13025fOf.b(fnh3.a, "connectivity")).getActiveNetworkInfo() : null;
|
|
boolean z = fnh3.e;
|
|
int i = runnableC13011fNx3.n;
|
|
if (i > 0) {
|
|
runnableC13011fNx3.n = i - 1;
|
|
if (runnableC13011fNx3.l.aBy_(activeNetworkInfo)) {
|
|
if (runnableC13011fNx3.j.f) {
|
|
C13025fOf.d("Dispatcher", "retrying", C13025fOf.e(runnableC13011fNx3));
|
|
}
|
|
if (runnableC13011fNx3.d instanceof fNN.HBt) {
|
|
runnableC13011fNx3.f |= fNO.NO_CACHE.index;
|
|
}
|
|
runnableC13011fNx3.b = fnh3.n.submit(runnableC13011fNx3);
|
|
return;
|
|
}
|
|
}
|
|
boolean z2 = fnh3.k && runnableC13011fNx3.l.c();
|
|
fnh3.a(runnableC13011fNx3, z2);
|
|
if (z2) {
|
|
AbstractC13013fNz abstractC13013fNz2 = runnableC13011fNx3.e;
|
|
if (abstractC13013fNz2 != null) {
|
|
fnh3.a(abstractC13013fNz2);
|
|
}
|
|
List<AbstractC13013fNz> list = runnableC13011fNx3.a;
|
|
if (list != null) {
|
|
int size = list.size();
|
|
for (int i2 = 0; i2 < size; i2++) {
|
|
fnh3.a(list.get(i2));
|
|
}
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
return;
|
|
case 6:
|
|
this.a.a((RunnableC13011fNx) message.obj, false);
|
|
return;
|
|
case 7:
|
|
fNH fnh4 = this.a;
|
|
ArrayList<RunnableC13011fNx> arrayList = new ArrayList(fnh4.d);
|
|
fnh4.d.clear();
|
|
Handler handler = fnh4.j;
|
|
handler.sendMessage(handler.obtainMessage(8, arrayList));
|
|
if (arrayList.isEmpty() || !((RunnableC13011fNx) arrayList.get(0)).j.f) {
|
|
return;
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
for (RunnableC13011fNx runnableC13011fNx4 : arrayList) {
|
|
if (sb.length() > 0) {
|
|
sb.append(", ");
|
|
}
|
|
sb.append(C13025fOf.e(runnableC13011fNx4));
|
|
}
|
|
C13025fOf.d("Dispatcher", "delivered", sb.toString());
|
|
return;
|
|
case 9:
|
|
NetworkInfo networkInfo = (NetworkInfo) message.obj;
|
|
fNH fnh5 = this.a;
|
|
ExecutorService executorService = fnh5.n;
|
|
if (executorService instanceof fNU) {
|
|
fNU fnu = (fNU) executorService;
|
|
if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
|
|
int type = networkInfo.getType();
|
|
if (type == 0) {
|
|
int subtype = networkInfo.getSubtype();
|
|
switch (subtype) {
|
|
case 1:
|
|
case 2:
|
|
fnu.setCorePoolSize(1);
|
|
fnu.setMaximumPoolSize(1);
|
|
break;
|
|
default:
|
|
switch (subtype) {
|
|
case 12:
|
|
break;
|
|
case 13:
|
|
case 14:
|
|
case 15:
|
|
fnu.setCorePoolSize(3);
|
|
fnu.setMaximumPoolSize(3);
|
|
break;
|
|
default:
|
|
fnu.setCorePoolSize(3);
|
|
fnu.setMaximumPoolSize(3);
|
|
break;
|
|
}
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
fnu.setCorePoolSize(2);
|
|
fnu.setMaximumPoolSize(2);
|
|
break;
|
|
}
|
|
} else if (type == 1 || type == 6 || type == 9) {
|
|
fnu.setCorePoolSize(4);
|
|
fnu.setMaximumPoolSize(4);
|
|
}
|
|
}
|
|
fnu.setCorePoolSize(3);
|
|
fnu.setMaximumPoolSize(3);
|
|
}
|
|
if (networkInfo == null || !networkInfo.isConnected() || fnh5.f.isEmpty()) {
|
|
return;
|
|
}
|
|
Iterator<AbstractC13013fNz> it = fnh5.f.values().iterator();
|
|
while (it.hasNext()) {
|
|
AbstractC13013fNz next = it.next();
|
|
it.remove();
|
|
if (next.h.f) {
|
|
C13025fOf.d("Dispatcher", "replaying", next.g.c());
|
|
}
|
|
fnh5.d(next, false);
|
|
}
|
|
return;
|
|
case 10:
|
|
this.a.e = message.arg1 == 1;
|
|
return;
|
|
case 11:
|
|
Object obj = message.obj;
|
|
fNH fnh6 = this.a;
|
|
if (fnh6.l.add(obj)) {
|
|
Iterator<RunnableC13011fNx> it2 = fnh6.h.values().iterator();
|
|
while (it2.hasNext()) {
|
|
RunnableC13011fNx next2 = it2.next();
|
|
boolean z3 = next2.j.f;
|
|
AbstractC13013fNz abstractC13013fNz3 = next2.e;
|
|
List<AbstractC13013fNz> list2 = next2.a;
|
|
boolean z4 = (list2 == null || list2.isEmpty()) ? false : true;
|
|
if (abstractC13013fNz3 != null || z4) {
|
|
if (abstractC13013fNz3 != null && abstractC13013fNz3.j.equals(obj)) {
|
|
next2.c(abstractC13013fNz3);
|
|
Map<Object, AbstractC13013fNz> map3 = fnh6.i;
|
|
Reference reference3 = abstractC13013fNz3.n;
|
|
map3.put(reference3 == null ? null : reference3.get(), abstractC13013fNz3);
|
|
if (z3) {
|
|
String c = abstractC13013fNz3.g.c();
|
|
StringBuilder sb2 = new StringBuilder("because tag '");
|
|
sb2.append(obj);
|
|
sb2.append("' was paused");
|
|
C13025fOf.d("Dispatcher", "paused", c, sb2.toString());
|
|
}
|
|
}
|
|
if (z4) {
|
|
for (int size2 = list2.size() - 1; size2 >= 0; size2--) {
|
|
AbstractC13013fNz abstractC13013fNz4 = list2.get(size2);
|
|
if (abstractC13013fNz4.j.equals(obj)) {
|
|
next2.c(abstractC13013fNz4);
|
|
Map<Object, AbstractC13013fNz> map4 = fnh6.i;
|
|
Reference reference4 = abstractC13013fNz4.n;
|
|
map4.put(reference4 == null ? null : reference4.get(), abstractC13013fNz4);
|
|
if (z3) {
|
|
String c2 = abstractC13013fNz4.g.c();
|
|
StringBuilder sb3 = new StringBuilder("because tag '");
|
|
sb3.append(obj);
|
|
sb3.append("' was paused");
|
|
C13025fOf.d("Dispatcher", "paused", c2, sb3.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (next2.b()) {
|
|
it2.remove();
|
|
if (z3) {
|
|
C13025fOf.d("Dispatcher", "canceled", C13025fOf.e(next2), "all actions paused");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
return;
|
|
case 12:
|
|
Object obj2 = message.obj;
|
|
fNH fnh7 = this.a;
|
|
if (fnh7.l.remove(obj2)) {
|
|
Iterator<AbstractC13013fNz> it3 = fnh7.i.values().iterator();
|
|
ArrayList arrayList2 = null;
|
|
while (it3.hasNext()) {
|
|
AbstractC13013fNz next3 = it3.next();
|
|
if (next3.j.equals(obj2)) {
|
|
if (arrayList2 == null) {
|
|
arrayList2 = new ArrayList();
|
|
}
|
|
arrayList2.add(next3);
|
|
it3.remove();
|
|
}
|
|
}
|
|
if (arrayList2 != null) {
|
|
Handler handler2 = fnh7.j;
|
|
handler2.sendMessage(handler2.obtainMessage(13, arrayList2));
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
static class IeS extends HandlerThread {
|
|
IeS() {
|
|
super("Picasso-Dispatcher", 10);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
static class HBt extends BroadcastReceiver {
|
|
final fNH b;
|
|
|
|
HBt(fNH fnh) {
|
|
this.b = fnh;
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public final void onReceive(Context context, Intent intent) {
|
|
if (intent == null) {
|
|
return;
|
|
}
|
|
String action = intent.getAction();
|
|
if ("android.intent.action.AIRPLANE_MODE".equals(action)) {
|
|
if (intent.hasExtra(CommonConstant.ReqAccessTokenParam.STATE_LABEL)) {
|
|
fNH fnh = this.b;
|
|
boolean booleanExtra = intent.getBooleanExtra(CommonConstant.ReqAccessTokenParam.STATE_LABEL, false);
|
|
Handler handler = fnh.g;
|
|
handler.sendMessage(handler.obtainMessage(10, booleanExtra ? 1 : 0, 0));
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
|
|
ConnectivityManager connectivityManager = (ConnectivityManager) C13025fOf.b(context, "connectivity");
|
|
fNH fnh2 = this.b;
|
|
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
|
Handler handler2 = fnh2.g;
|
|
handler2.sendMessage(handler2.obtainMessage(9, activeNetworkInfo));
|
|
}
|
|
}
|
|
}
|
|
|
|
final void a(RunnableC13011fNx runnableC13011fNx, boolean z) {
|
|
if (runnableC13011fNx.j.f) {
|
|
C13025fOf.d("Dispatcher", "batched", C13025fOf.e(runnableC13011fNx), "for error".concat(z ? " (will replay)" : ""));
|
|
}
|
|
this.h.remove(runnableC13011fNx.h);
|
|
a(runnableC13011fNx);
|
|
}
|
|
|
|
final void d(AbstractC13013fNz abstractC13013fNz, boolean z) {
|
|
if (this.l.contains(abstractC13013fNz.j)) {
|
|
Map<Object, AbstractC13013fNz> map = this.i;
|
|
Reference reference = abstractC13013fNz.n;
|
|
map.put(reference != null ? reference.get() : null, abstractC13013fNz);
|
|
if (abstractC13013fNz.h.f) {
|
|
String c = abstractC13013fNz.g.c();
|
|
StringBuilder sb = new StringBuilder("because tag '");
|
|
sb.append(abstractC13013fNz.j);
|
|
sb.append("' is paused");
|
|
C13025fOf.d("Dispatcher", "paused", c, sb.toString());
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
RunnableC13011fNx runnableC13011fNx = this.h.get(abstractC13013fNz.c);
|
|
if (runnableC13011fNx == null) {
|
|
if (this.n.isShutdown()) {
|
|
if (abstractC13013fNz.h.f) {
|
|
C13025fOf.d("Dispatcher", "ignored", abstractC13013fNz.g.c(), "because shut down");
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
RunnableC13011fNx d = RunnableC13011fNx.d(abstractC13013fNz.h, this, this.b, this.t, abstractC13013fNz);
|
|
d.b = this.n.submit(d);
|
|
this.h.put(abstractC13013fNz.c, d);
|
|
if (z) {
|
|
Map<Object, AbstractC13013fNz> map2 = this.f;
|
|
Reference reference2 = abstractC13013fNz.n;
|
|
map2.remove(reference2 != null ? reference2.get() : null);
|
|
}
|
|
if (abstractC13013fNz.h.f) {
|
|
C13025fOf.d("Dispatcher", "enqueued", abstractC13013fNz.g.c());
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
boolean z2 = runnableC13011fNx.j.f;
|
|
fNW fnw = abstractC13013fNz.g;
|
|
if (runnableC13011fNx.e == null) {
|
|
runnableC13011fNx.e = abstractC13013fNz;
|
|
if (z2) {
|
|
List<AbstractC13013fNz> list = runnableC13011fNx.a;
|
|
if (list == null || list.isEmpty()) {
|
|
C13025fOf.d("Hunter", "joined", fnw.c(), "to empty hunter");
|
|
return;
|
|
} else {
|
|
C13025fOf.d("Hunter", "joined", fnw.c(), C13025fOf.e(runnableC13011fNx, "to "));
|
|
return;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (runnableC13011fNx.a == null) {
|
|
runnableC13011fNx.a = new ArrayList(3);
|
|
}
|
|
runnableC13011fNx.a.add(abstractC13013fNz);
|
|
if (z2) {
|
|
C13025fOf.d("Hunter", "joined", fnw.c(), C13025fOf.e(runnableC13011fNx, "to "));
|
|
}
|
|
Picasso.LWm lWm = abstractC13013fNz.g.j;
|
|
if (lWm.ordinal() > runnableC13011fNx.k.ordinal()) {
|
|
runnableC13011fNx.k = lWm;
|
|
}
|
|
}
|
|
}
|