package com.vungle.warren.utility; import android.app.Activity; import android.app.Application; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.util.Log; import java.lang.ref.WeakReference; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; import l8.f; /* loaded from: classes2.dex */ public class a implements Application.ActivityLifecycleCallbacks { /* renamed from: j, reason: collision with root package name */ public static final String f8562j = "a"; /* renamed from: k, reason: collision with root package name */ private static final a f8563k = new a(); /* renamed from: a, reason: collision with root package name */ private boolean f8564a; /* renamed from: b, reason: collision with root package name */ private int f8565b; /* renamed from: c, reason: collision with root package name */ private int f8566c; /* renamed from: f, reason: collision with root package name */ private Handler f8569f; /* renamed from: d, reason: collision with root package name */ private CopyOnWriteArraySet f8567d = new CopyOnWriteArraySet(); /* renamed from: e, reason: collision with root package name */ private ConcurrentHashMap f8568e = new ConcurrentHashMap(); /* renamed from: g, reason: collision with root package name */ private boolean f8570g = true; /* renamed from: h, reason: collision with root package name */ private boolean f8571h = true; /* renamed from: i, reason: collision with root package name */ private Runnable f8572i = new RunnableC0128a(); /* renamed from: com.vungle.warren.utility.a$a, reason: collision with other inner class name */ class RunnableC0128a implements Runnable { RunnableC0128a() { } @Override // java.lang.Runnable public void run() { if (a.this.f8566c == 0 && !a.this.f8570g) { a.this.f8570g = true; Iterator it = a.this.f8567d.iterator(); while (it.hasNext()) { ((g) it.next()).a(); } } if (a.this.f8565b == 0 && a.this.f8570g && !a.this.f8571h) { a.this.f8571h = true; Iterator it2 = a.this.f8567d.iterator(); while (it2.hasNext()) { ((g) it2.next()).d(); } } } } class b extends g { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ WeakReference f8574a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ Intent f8575b; /* renamed from: c, reason: collision with root package name */ final /* synthetic */ Intent f8576c; /* renamed from: d, reason: collision with root package name */ final /* synthetic */ l8.f f8577d; /* renamed from: e, reason: collision with root package name */ final /* synthetic */ f f8578e; b(WeakReference weakReference, Intent intent, Intent intent2, l8.f fVar, f fVar2) { this.f8574a = weakReference; this.f8575b = intent; this.f8576c = intent2; this.f8577d = fVar; this.f8578e = fVar2; } @Override // com.vungle.warren.utility.a.g public void c() { super.c(); a.f8563k.t(this); Context context = (Context) this.f8574a.get(); if (context == null || !a.v(context, this.f8575b, this.f8576c, this.f8577d)) { return; } a.f8563k.o(this.f8578e); } } class c implements Runnable { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ WeakReference f8579a; c(WeakReference weakReference) { this.f8579a = weakReference; } @Override // java.lang.Runnable public void run() { a.this.f8569f.removeCallbacks(this); a.this.u((f) this.f8579a.get()); } } class d extends g { /* renamed from: a, reason: collision with root package name */ boolean f8581a = false; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ WeakReference f8582b; /* renamed from: c, reason: collision with root package name */ final /* synthetic */ Runnable f8583c; d(WeakReference weakReference, Runnable runnable) { this.f8582b = weakReference; this.f8583c = runnable; } @Override // com.vungle.warren.utility.a.g public void a() { super.a(); this.f8581a = true; a.this.f8569f.removeCallbacks(this.f8583c); } @Override // com.vungle.warren.utility.a.g public void b() { super.b(); a.this.f8569f.postDelayed(this.f8583c, 1400L); } @Override // com.vungle.warren.utility.a.g public void d() { super.d(); f fVar = (f) this.f8582b.get(); if (this.f8581a && fVar != null && a.this.f8568e.containsKey(fVar)) { fVar.a(); } a.this.u(fVar); a.this.f8569f.removeCallbacks(this.f8583c); } } class e extends g { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ WeakReference f8585a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ Runnable f8586b; e(WeakReference weakReference, Runnable runnable) { this.f8585a = weakReference; this.f8586b = runnable; } @Override // com.vungle.warren.utility.a.g public void c() { a.f8563k.t(this); g gVar = (g) a.this.f8568e.get(this.f8585a.get()); if (gVar != null) { a.this.f8569f.postDelayed(this.f8586b, 3000L); a.this.n(gVar); } } } public interface f { void a(); } public static class g { public void a() { } public void b() { } public void c() { } public void d() { } } private a() { } public static a p() { return f8563k; } /* JADX INFO: Access modifiers changed from: private */ public void t(g gVar) { this.f8567d.remove(gVar); } /* JADX INFO: Access modifiers changed from: private */ public void u(f fVar) { g gVar; if (fVar == null || (gVar = (g) this.f8568e.remove(fVar)) == null) { return; } t(gVar); } /* JADX INFO: Access modifiers changed from: private */ public static boolean v(Context context, Intent intent, Intent intent2, l8.f fVar) { if (intent == null && intent2 == null) { return false; } try { if (intent != null) { context.startActivity(intent); } else { context.startActivity(intent2); } if (fVar != null) { fVar.a(intent != null ? f.a.DEEP_LINK : f.a.DEFAULT); } return true; } catch (ActivityNotFoundException e10) { Log.e(f8562j, "Cannot find activity to handle the Implicit intent: " + e10.getLocalizedMessage()); if (intent != null && intent2 != null) { try { context.startActivity(intent2); if (fVar != null) { fVar.a(f.a.DEFAULT); } return true; } catch (ActivityNotFoundException unused) { return false; } } return false; } } public static void w(Context context, Intent intent, Intent intent2, f fVar) { x(context, intent, intent2, fVar, null); } public static void x(Context context, Intent intent, Intent intent2, f fVar, l8.f fVar2) { WeakReference weakReference = new WeakReference(context); a aVar = f8563k; if (!aVar.q()) { aVar.n(new b(weakReference, intent, intent2, fVar2, fVar)); } else if (v(context, intent, intent2, fVar2)) { aVar.o(fVar); } } public void n(g gVar) { this.f8567d.add(gVar); } public void o(f fVar) { if (fVar == null) { return; } if (!this.f8564a) { fVar.a(); return; } WeakReference weakReference = new WeakReference(fVar); c cVar = new c(weakReference); d dVar = new d(weakReference, cVar); this.f8568e.put(fVar, dVar); if (!q()) { p().n(new e(weakReference, cVar)); } else { this.f8569f.postDelayed(cVar, 3000L); n(dVar); } } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityCreated(Activity activity, Bundle bundle) { } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityDestroyed(Activity activity) { } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityPaused(Activity activity) { this.f8566c = Math.max(0, this.f8566c - 1); this.f8569f.postDelayed(this.f8572i, 700L); } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityResumed(Activity activity) { int i10 = this.f8566c + 1; this.f8566c = i10; if (i10 == 1) { if (!this.f8570g) { this.f8569f.removeCallbacks(this.f8572i); return; } this.f8570g = false; Iterator it = this.f8567d.iterator(); while (it.hasNext()) { ((g) it.next()).b(); } } } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityStarted(Activity activity) { int i10 = this.f8565b + 1; this.f8565b = i10; if (i10 == 1 && this.f8571h) { this.f8571h = false; Iterator it = this.f8567d.iterator(); while (it.hasNext()) { ((g) it.next()).c(); } } } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityStopped(Activity activity) { this.f8565b = Math.max(0, this.f8565b - 1); this.f8569f.postDelayed(this.f8572i, 700L); } protected boolean q() { return !this.f8564a || this.f8565b > 0; } public void r(Context context) { if (this.f8564a) { return; } this.f8569f = new Handler(Looper.getMainLooper()); ((Application) context.getApplicationContext()).registerActivityLifecycleCallbacks(this); this.f8564a = true; } public boolean s() { return this.f8564a; } }