package com.applovin.impl.sdk.network; import android.content.Intent; import android.content.IntentFilter; import android.text.TextUtils; import com.applovin.impl.gc; import com.applovin.impl.jn; import com.applovin.impl.sdk.AppLovinBroadcastManager; import com.applovin.impl.sdk.SessionTracker; import com.applovin.impl.sdk.j; import com.applovin.impl.sdk.n; import com.applovin.impl.sj; import com.applovin.impl.tm; import com.applovin.impl.yl; import com.applovin.impl.yp; import com.applovin.sdk.AppLovinPostbackListener; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import org.json.JSONObject; /* loaded from: classes2.dex */ public class b implements AppLovinBroadcastManager.Receiver { private final j a; private final n b; private final int c; private final c d; private final Object f = new Object(); private final List g; private final Set h; private final List i; public class a implements AppLovinPostbackListener { final /* synthetic */ d a; final /* synthetic */ AppLovinPostbackListener b; public a(d dVar, AppLovinPostbackListener appLovinPostbackListener) { this.a = dVar; this.b = appLovinPostbackListener; } @Override // com.applovin.sdk.AppLovinPostbackListener public void onPostbackFailure(String str, int i) { n unused = b.this.b; if (n.a()) { b.this.b.d("PersistentPostbackManager", "Failed to submit postback: " + this.a + " with error code: " + i + "; will retry later..."); } b.this.d(this.a); gc.a(this.b, str, i); if (this.a.c() == 1) { b.this.a.E().a("dispatchPostback", str, i); } } @Override // com.applovin.sdk.AppLovinPostbackListener public void onPostbackSuccess(String str) { b.this.a(this.a); n unused = b.this.b; if (n.a()) { b.this.b.a("PersistentPostbackManager", "Successfully submit postback: " + this.a); } b.this.c(); gc.a(this.b, str); } } public b(j jVar) { ArrayList arrayList = new ArrayList(); this.g = arrayList; this.h = new HashSet(); this.i = new ArrayList(); if (jVar == null) { throw new IllegalArgumentException("No sdk specified"); } this.a = jVar; this.b = jVar.J(); int intValue = ((Integer) jVar.a(sj.c3)).intValue(); this.c = intValue; if (!((Boolean) jVar.a(sj.f3)).booleanValue()) { this.d = null; return; } c cVar = new c(this, jVar); this.d = cVar; if (yp.a(sj.m1, jVar) && yp.h()) { a(new Runnable() { // from class: com.applovin.impl.sdk.network.b$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { b.this.f(); } }, true, true); } else { arrayList.addAll(cVar.a(intValue)); } AppLovinBroadcastManager.registerReceiver(this, new IntentFilter(SessionTracker.ACTION_APPLICATION_PAUSED)); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void f() { synchronized (this.f) { this.g.addAll(0, this.d.a(this.c)); } } public List d() { ArrayList arrayList = new ArrayList(); synchronized (this.f) { try { if (((Boolean) this.a.a(sj.e3)).booleanValue()) { arrayList.ensureCapacity(this.i.size()); arrayList.addAll(this.i); } else { arrayList.ensureCapacity(this.g.size()); arrayList.addAll(this.g); } } catch (Throwable th) { throw th; } } return arrayList; } public void e(d dVar) { a(dVar, true); } @Override // com.applovin.impl.sdk.AppLovinBroadcastManager.Receiver public void onReceive(Intent intent, Map map) { this.a.j0().a((yl) this.d, tm.b.OTHER); } private void c(d dVar) { synchronized (this.f) { while (this.g.size() > this.c) { try { this.g.remove(0); } catch (Throwable th) { throw th; } } this.g.add(dVar); } if (n.a()) { this.b.a("PersistentPostbackManager", "Enqueued postback: " + dVar); } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void e() { synchronized (this.f) { try { Iterator it = new ArrayList(this.g).iterator(); while (it.hasNext()) { b((d) it.next()); } } catch (Throwable th) { throw th; } } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void b(d dVar, AppLovinPostbackListener appLovinPostbackListener) { synchronized (this.f) { c(dVar); a(dVar, appLovinPostbackListener); } } public void a(d dVar, boolean z) { a(dVar, z, (AppLovinPostbackListener) null); } public void a(final d dVar, boolean z, final AppLovinPostbackListener appLovinPostbackListener) { if (TextUtils.isEmpty(dVar.k())) { if (n.a()) { this.b.b("PersistentPostbackManager", "Requested a postback dispatch for empty URL; nothing to do..."); } } else { if (z) { dVar.a(); } a(new Runnable() { // from class: com.applovin.impl.sdk.network.b$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { b.this.b(dVar, appLovinPostbackListener); } }, yp.h(), dVar.m()); } } public void b() { a(new Runnable() { // from class: com.applovin.impl.sdk.network.b$$ExternalSyntheticLambda2 @Override // java.lang.Runnable public final void run() { b.this.e(); } }, true, false); } private void b(d dVar) { a(dVar, (AppLovinPostbackListener) null); } /* JADX INFO: Access modifiers changed from: private */ public void c() { synchronized (this.f) { try { Iterator it = this.i.iterator(); while (it.hasNext()) { b((d) it.next()); } this.i.clear(); } catch (Throwable th) { throw th; } } } /* JADX INFO: Access modifiers changed from: private */ public void d(d dVar) { synchronized (this.f) { this.h.remove(dVar); this.i.add(dVar); } } public void a() { synchronized (this.f) { this.g.clear(); this.i.clear(); } this.a.j0().a((yl) this.d, tm.b.OTHER); } private void a(d dVar, AppLovinPostbackListener appLovinPostbackListener) { if (n.a()) { this.b.a("PersistentPostbackManager", "Preparing to submit postback: " + dVar); } if (this.a.x0() && !dVar.m()) { if (n.a()) { this.b.a("PersistentPostbackManager", "Skipping postback dispatch because SDK is still initializing - postback will be dispatched afterwards"); return; } return; } if (TextUtils.isEmpty(dVar.k())) { if (n.a()) { this.b.b("PersistentPostbackManager", "Skipping empty postback dispatch..."); return; } return; } synchronized (this.f) { try { if (this.h.contains(dVar)) { if (n.a()) { this.b.a("PersistentPostbackManager", "Skipping in progress postback: " + dVar.k()); } return; } dVar.l(); Integer num = (Integer) this.a.a(sj.b3); if (dVar.c() > num.intValue()) { if (n.a()) { this.b.k("PersistentPostbackManager", "Exceeded maximum persisted attempt count of " + num + ". Dequeuing postback: " + dVar); } a(dVar); return; } synchronized (this.f) { this.h.add(dVar); } e a2 = e.b(this.a).b(dVar.k()).a(dVar.d()).b(dVar.i()).c(dVar.h()).a(dVar.g()).a(dVar.j() != null ? new JSONObject(dVar.j()) : null).b(dVar.o()).a(dVar.n()).a(dVar.f()).h(dVar.p()).e(dVar.e()).a(); if (n.a()) { this.b.a("PersistentPostbackManager", "Submitting postback: " + dVar); } this.a.Y().dispatchPostbackRequest(a2, new a(dVar, appLovinPostbackListener)); } catch (Throwable th) { throw th; } } } /* JADX INFO: Access modifiers changed from: private */ public void a(d dVar) { synchronized (this.f) { this.h.remove(dVar); this.g.remove(dVar); } if (n.a()) { this.b.a("PersistentPostbackManager", "Dequeued postback: " + dVar); } } private void a(Runnable runnable, boolean z, boolean z2) { if (z) { this.a.j0().a((yl) new jn(this.a, z2, "runPostbackTask", runnable), tm.b.OTHER); } else { runnable.run(); } } }