package com.tapjoy.internal; import android.content.Context; import com.tapjoy.TJConnectListener; import com.tapjoy.TapjoyLog; import com.tapjoy.TapjoyUtil; import java.util.Hashtable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; /* loaded from: classes4.dex */ public abstract class z2 { public final ReentrantLock a; public final Condition b; public final ExecutorService c; public volatile int d; public TJConnectListener e; public y2 f; public long g; public v2 h; public v2 i; public String j; public boolean k; public z2() { ReentrantLock reentrantLock = new ReentrantLock(); this.a = reentrantLock; this.b = reentrantLock.newCondition(); this.c = Executors.newSingleThreadExecutor(); this.d = 1; this.g = 1000L; } public final boolean a(Context context, String str, Hashtable hashtable, TJConnectListener tJConnectListener) { boolean a; this.a.lock(); this.k = false; try { if (this.e == null) { this.e = tJConnectListener; } v2 v2Var = new v2((q2) this, context, str, hashtable); int a2 = h0.a(this.d); if (a2 == 0) { this.h = v2Var; y.b.addObserver(new t2((q2) this)); Context context2 = v2Var.a; u2 u2Var = new u2((q2) this); r2 r2Var = ((q2) this).l; int i = r2Var.d; if (i <= 5) { r2Var.d = i + 1; a = super/*com.tapjoy.m1*/.a(context2, str, hashtable, u2Var); if (a) { a(2); return true; } } return false; } if (a2 == 1 || a2 == 2) { this.i = v2Var; return true; } if (a2 == 3) { this.i = v2Var; this.a.lock(); try { this.g = 1000L; this.b.signal(); this.a.unlock(); return true; } finally { this.a.unlock(); } } if (a2 == 4) { c(); return true; } if (a2 != 5) { a(1); return false; } String str2 = this.j; if (str2 == null || str2.isEmpty()) { c(); } else { b(-1, this.j); } return true; } finally { } } public final void c() { TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.internal.z2$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { z2.this.b(); } }); } public final /* synthetic */ void b() { TJConnectListener tJConnectListener = this.e; if (tJConnectListener != null) { tJConnectListener.onConnectSuccess(); this.e = null; } } public final void b(final int i, final String str) { TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.internal.z2$$ExternalSyntheticLambda2 @Override // java.lang.Runnable public final void run() { z2.this.a(str, i); } }); } public final void c(final int i, final String str) { if (this.d == 3 && this.k) { return; } this.k = true; TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.internal.z2$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { z2.this.a(i, str); } }); } public final void a(int i) { this.a.lock(); try { this.d = i; } finally { this.a.unlock(); } } public final v2 a() { this.a.lock(); try { v2 v2Var = this.i; if (v2Var != null) { this.h = v2Var; this.i = null; } v2 v2Var2 = this.h; this.a.unlock(); return v2Var2; } catch (Throwable th) { this.a.unlock(); throw th; } } public final /* synthetic */ void a(int i, String str) { TJConnectListener tJConnectListener = this.e; if (tJConnectListener != null) { tJConnectListener.onConnectFailure(i, str); } } public final /* synthetic */ void a(String str, int i) { if (this.e != null && str != null && !str.isEmpty()) { this.e.onConnectSuccess(); this.e.onConnectWarning(i, str); } else { TJConnectListener tJConnectListener = this.e; if (tJConnectListener != null) { tJConnectListener.onConnectSuccess(); } } } public final void a(long j) { this.a.lock(); try { a(4); if (this.b.await(j, TimeUnit.MILLISECONDS)) { this.g = 1000L; } } catch (InterruptedException e) { TapjoyLog.d("TapjoyConnectAutoRetry", e.getMessage()); } finally { a(3); this.a.unlock(); } } }