package com.vungle.warren; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.util.Pair; import com.vungle.warren.ui.VungleActivity; import com.vungle.warren.y; import java.util.concurrent.atomic.AtomicBoolean; import m8.b; /* loaded from: classes2.dex */ public abstract class a extends Activity { /* renamed from: j, reason: collision with root package name */ private static b.a f7931j; /* renamed from: a, reason: collision with root package name */ private m8.b f7932a; /* renamed from: b, reason: collision with root package name */ private BroadcastReceiver f7933b; /* renamed from: c, reason: collision with root package name */ private com.vungle.warren.d f7934c; /* renamed from: d, reason: collision with root package name */ private y f7935d; /* renamed from: e, reason: collision with root package name */ private o8.b f7936e; /* renamed from: f, reason: collision with root package name */ private AtomicBoolean f7937f = new AtomicBoolean(false); /* renamed from: g, reason: collision with root package name */ private boolean f7938g = false; /* renamed from: h, reason: collision with root package name */ private boolean f7939h = false; /* renamed from: i, reason: collision with root package name */ private y.a f7940i = new d(); /* renamed from: com.vungle.warren.a$a, reason: collision with other inner class name */ class C0116a implements l8.a { C0116a() { } @Override // l8.a public void close() { a.this.finish(); } } class b implements l8.e { b() { } @Override // l8.e public void setOrientation(int i10) { a.this.setRequestedOrientation(i10); } } class c extends BroadcastReceiver { c() { } @Override // android.content.BroadcastReceiver public void onReceive(Context context, Intent intent) { String stringExtra = intent.getStringExtra("command"); stringExtra.hashCode(); if (stringExtra.equals("stopAll")) { a.this.finish(); return; } VungleLogger.j(a.class.getSimpleName() + "#connectBroadcastReceiver", String.format("Receiving Invalid Broadcast: %1$s", stringExtra)); } } class d implements y.a { d() { } @Override // com.vungle.warren.y.a public void a(Pair pair, com.vungle.warren.error.a aVar) { if (aVar != null) { a.this.f7935d = null; a.this.m(aVar.a(), a.this.f7934c); a.this.finish(); return; } a.this.f7932a = (m8.b) pair.second; a.this.f7932a.o(a.f7931j); a.this.f7932a.f((m8.a) pair.first, a.this.f7936e); if (a.this.f7937f.getAndSet(false)) { a.this.p(); } } } private void k() { this.f7933b = new c(); k0.a.b(getApplicationContext()).c(this.f7933b, new IntentFilter("AdvertisementBus")); } public static Intent l(Context context, com.vungle.warren.d dVar) { Intent intent = new Intent(context, (Class) VungleActivity.class); intent.addFlags(268435456); Bundle bundle = new Bundle(); bundle.putSerializable("request", dVar); intent.putExtras(bundle); return intent; } /* JADX INFO: Access modifiers changed from: private */ public void m(int i10, com.vungle.warren.d dVar) { com.vungle.warren.error.a aVar = new com.vungle.warren.error.a(i10); b.a aVar2 = f7931j; if (aVar2 != null) { aVar2.b(aVar, dVar.f()); } VungleLogger.c(a.class.getSimpleName() + "#deliverError", aVar.getLocalizedMessage()); } static com.vungle.warren.d n(Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { return (com.vungle.warren.d) extras.getSerializable("request"); } return null; } public static void o(b.a aVar) { f7931j = aVar; } /* JADX INFO: Access modifiers changed from: private */ public void p() { if (this.f7932a == null) { this.f7937f.set(true); } else if (!this.f7938g && this.f7939h && hasWindowFocus()) { this.f7932a.start(); this.f7938g = true; } } private void q() { if (this.f7932a != null && this.f7938g) { this.f7932a.i((isChangingConfigurations() ? 1 : 0) | (isFinishing() ? 2 : 0)); this.f7938g = false; } this.f7937f.set(false); } protected abstract boolean j(); @Override // android.app.Activity public void onBackPressed() { m8.b bVar = this.f7932a; if (bVar != null) { bVar.u(); } } @Override // android.app.Activity, android.content.ComponentCallbacks public void onConfigurationChanged(Configuration configuration) { super.onConfigurationChanged(configuration); int i10 = configuration.orientation; if (i10 == 2) { Log.d("VungleActivity", "landscape"); } else if (i10 == 1) { Log.d("VungleActivity", "portrait"); } m8.b bVar = this.f7932a; if (bVar != null) { bVar.b(); } } @Override // android.app.Activity protected void onCreate(Bundle bundle) { com.vungle.warren.d dVar; super.onCreate(bundle); requestWindowFeature(1); getWindow().setFlags(16777216, 16777216); this.f7934c = n(getIntent()); b0 f10 = b0.f(this); if (!((l0) f10.h(l0.class)).isInitialized() || f7931j == null || (dVar = this.f7934c) == null || TextUtils.isEmpty(dVar.f())) { finish(); return; } long currentTimeMillis = System.currentTimeMillis(); VungleLogger.i(true, "VungleActivity", "ttDownloadContext", String.format("Creating ad, request = %1$s, at: %2$d", this.f7934c, Long.valueOf(currentTimeMillis))); try { com.vungle.warren.ui.view.f fVar = new com.vungle.warren.ui.view.f(this, getWindow()); this.f7935d = (y) f10.h(y.class); o8.b bVar = bundle == null ? null : (o8.b) bundle.getParcelable("presenter_state"); this.f7936e = bVar; this.f7935d.c(this, this.f7934c, fVar, bVar, new C0116a(), new b(), bundle, this.f7940i); setContentView(fVar, fVar.getLayoutParams()); k(); VungleLogger.i(true, "VungleActivity", "ttDownloadContext", String.format("Ad created, request = %1$s, elapsed time: %2$dms", this.f7934c, Long.valueOf(System.currentTimeMillis() - currentTimeMillis))); } catch (InstantiationException unused) { m(10, this.f7934c); finish(); } } @Override // android.app.Activity protected void onDestroy() { k0.a.b(getApplicationContext()).e(this.f7933b); m8.b bVar = this.f7932a; if (bVar != null) { bVar.p((isChangingConfigurations() ? 1 : 0) | 2); } else { y yVar = this.f7935d; if (yVar != null) { yVar.destroy(); this.f7935d = null; m(25, this.f7934c); } } super.onDestroy(); } @Override // android.app.Activity protected void onNewIntent(Intent intent) { super.onNewIntent(intent); com.vungle.warren.d n10 = n(getIntent()); com.vungle.warren.d n11 = n(intent); String f10 = n10 != null ? n10.f() : null; String f11 = n11 != null ? n11.f() : null; if (f10 == null || f11 == null || f10.equals(f11)) { return; } Log.d("VungleActivity", "Tried to play another placement " + f11 + " while playing " + f10); m(15, n11); StringBuilder sb = new StringBuilder(); sb.append(a.class.getSimpleName()); sb.append("#onNewIntent"); VungleLogger.j(sb.toString(), String.format("Tried to play another placement %1$s while playing %2$s", f11, f10)); } @Override // android.app.Activity protected void onPause() { super.onPause(); this.f7939h = false; q(); } @Override // android.app.Activity protected void onRestoreInstanceState(Bundle bundle) { m8.b bVar; super.onRestoreInstanceState(bundle); Log.d("VungleActivity", "onRestoreInstanceState(" + bundle + ")"); if (bundle == null || (bVar = this.f7932a) == null) { return; } bVar.e((o8.b) bundle.getParcelable("presenter_state")); } @Override // android.app.Activity protected void onResume() { super.onResume(); this.f7939h = true; p(); } @Override // android.app.Activity protected void onSaveInstanceState(Bundle bundle) { Log.d("VungleActivity", "onSaveInstanceState"); o8.a aVar = new o8.a(); m8.b bVar = this.f7932a; if (bVar != null) { bVar.h(aVar); bundle.putParcelable("presenter_state", aVar); } y yVar = this.f7935d; if (yVar != null) { yVar.b(bundle); } super.onSaveInstanceState(bundle); } @Override // android.app.Activity, android.view.Window.Callback public void onWindowFocusChanged(boolean z10) { super.onWindowFocusChanged(z10); if (z10) { p(); } else { q(); } } @Override // android.app.Activity public void setRequestedOrientation(int i10) { if (j()) { super.setRequestedOrientation(i10); } } }