package com.ironsource.sdk.controller; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.RelativeLayout; import androidx.core.view.InputDeviceCompat; import com.ironsource.ce; import com.ironsource.cu; import com.ironsource.el; import com.ironsource.i9; import com.ironsource.kn; import com.ironsource.mediationsdk.logger.IronLog; import com.ironsource.n5; import com.ironsource.nb; import com.ironsource.pf; import com.ironsource.qi; import com.ironsource.sdk.controller.v; import com.ironsource.sdk.utils.Logger; import com.ironsource.sdk.utils.SDKUtils; import com.ironsource.sf; import com.ironsource.t2; import com.ironsource.v8; import com.ironsource.vp; import com.ironsource.xf; import com.ironsource.yu; /* loaded from: classes4.dex */ public class ControllerActivity extends Activity implements kn, cu { private static final String n = "ControllerActivity"; private static final int o = 1; private static String p = "removeWebViewContainerView | mContainer is null"; private static String q = "removeWebViewContainerView | view is null"; private String a; private v b; private RelativeLayout c; private FrameLayout d; private ce e; private String g; private t2 k; private boolean l; private boolean m; public int currentRequestedRotation = -1; private boolean f = false; private Handler h = new Handler(); private final Runnable i = new a(); final RelativeLayout.LayoutParams j = new RelativeLayout.LayoutParams(-1, -1); public class a implements Runnable { public a() { } @Override // java.lang.Runnable public void run() { ControllerActivity.this.getWindow().getDecorView().setSystemUiVisibility(SDKUtils.getActivityUIFlags(ControllerActivity.this.f)); } } public class b implements View.OnSystemUiVisibilityChangeListener { public b() { } @Override // android.view.View.OnSystemUiVisibilityChangeListener public void onSystemUiVisibilityChange(int i) { if ((i & InputDeviceCompat.SOURCE_TOUCHSCREEN) == 0) { ControllerActivity.this.h.removeCallbacks(ControllerActivity.this.i); ControllerActivity.this.h.postDelayed(ControllerActivity.this.i, 500L); } } } public class c implements Runnable { public c() { } @Override // java.lang.Runnable public void run() { ControllerActivity.this.getWindow().addFlags(128); } } public class d implements Runnable { public d() { } @Override // java.lang.Runnable public void run() { ControllerActivity.this.getWindow().clearFlags(128); } } private View a(ViewGroup viewGroup) { return d() ? viewGroup.findViewById(1) : pf.a().a(this.a).getPresentingView(); } private FrameLayout a(String str) { return !b(str) ? this.b.s() : yu.a(getApplicationContext(), pf.a().a(str).getPresentingView()); } private void a() { runOnUiThread(new d()); } @SuppressLint({"SourceLockedOrientationActivity"}) private void a(String str, int i) { int i2; if (str != null) { if ("landscape".equalsIgnoreCase(str)) { g(); return; } if ("portrait".equalsIgnoreCase(str)) { h(); return; } if ("device".equalsIgnoreCase(str)) { if (!this.e.B(this)) { return; } else { i2 = 1; } } else if (getRequestedOrientation() != -1) { return; } else { i2 = 4; } setRequestedOrientation(i2); } } private void b() { String str = n; Logger.i(str, "clearWebviewController"); v vVar = this.b; if (vVar == null) { Logger.i(str, "clearWebviewController, null"); return; } vVar.a(v.u.Gone); this.b.C(); this.b.D(); this.b.g(this.g, "onDestroy"); } private boolean b(String str) { return (TextUtils.isEmpty(str) || str.equals(Integer.toString(1))) ? false : true; } private void c() { Intent intent = getIntent(); a(intent.getStringExtra(v8.h.A), intent.getIntExtra(v8.h.B, 0)); } private boolean d() { return this.a == null; } private void e() { runOnUiThread(new c()); } private void f() { ViewGroup viewGroup; try { if (this.c == null) { throw new Exception(p); } ViewGroup viewGroup2 = (ViewGroup) this.d.getParent(); View a2 = a(viewGroup2); if (a2 == null) { throw new Exception(q); } if (isFinishing() && (viewGroup = (ViewGroup) a2.getParent()) != null) { viewGroup.removeView(a2); } viewGroup2.removeView(this.d); } catch (Exception e) { i9.d().a(e); xf.a(vp.s, new sf().a(nb.A, e.getMessage()).a()); Logger.i(n, "removeWebViewContainerView fail " + e.getMessage()); } } private void g() { String str; String str2; int I = this.e.I(this); String str3 = n; Logger.i(str3, "setInitiateLandscapeOrientation"); if (I != 0) { if (I == 2) { str2 = "ROTATION_180"; } else if (I == 3) { str2 = "ROTATION_270 Right Landscape"; } else { if (I != 1) { Logger.i(str3, "No Rotation"); return; } str = "ROTATION_90 Left Landscape"; } Logger.i(str3, str2); setRequestedOrientation(8); return; } str = "ROTATION_0"; Logger.i(str3, str); setRequestedOrientation(0); } @SuppressLint({"SourceLockedOrientationActivity"}) private void h() { String str; int I = this.e.I(this); String str2 = n; Logger.i(str2, "setInitiatePortraitOrientation"); if (I == 0) { str = "ROTATION_0"; } else if (I == 2) { Logger.i(str2, "ROTATION_180"); setRequestedOrientation(9); return; } else if (I == 1) { str = "ROTATION_270 Right Landscape"; } else { if (I != 3) { Logger.i(str2, "No Rotation"); return; } str = "ROTATION_90 Left Landscape"; } Logger.i(str2, str); setRequestedOrientation(1); } @Override // com.ironsource.kn public boolean onBackButtonPressed() { onBackPressed(); return true; } @Override // android.app.Activity public void onBackPressed() { Logger.i(n, "onBackPressed"); if (n5.a().a(this)) { return; } super.onBackPressed(); } @Override // com.ironsource.kn public void onCloseRequested() { finish(); } @Override // android.app.Activity public void onCreate(Bundle bundle) { super.onCreate(bundle); this.e = el.N().f(); try { new com.ironsource.m(this).a(); new com.ironsource.l(this).a(); v vVar = (v) qi.a((Context) this).a().j(); this.b = vVar; vVar.s().setId(1); this.b.a((kn) this); this.b.a((cu) this); Intent intent = getIntent(); this.g = intent.getStringExtra(v8.h.m); this.f = intent.getBooleanExtra(v8.h.v, false); this.a = intent.getStringExtra("adViewId"); this.l = false; this.m = intent.getBooleanExtra(v8.h.z0, false); if (this.f) { getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new b()); runOnUiThread(this.i); } RelativeLayout relativeLayout = new RelativeLayout(this); this.c = relativeLayout; setContentView(relativeLayout, this.j); this.d = a(this.a); if (this.c.findViewById(1) == null && this.d.getParent() != null) { finish(); } c(); this.c.addView(this.d, this.j); } catch (Exception e) { i9.d().a(e); IronLog.INTERNAL.error(e.toString()); finish(); } } @Override // android.app.Activity public void onDestroy() { super.onDestroy(); String str = n; Logger.i(str, "onDestroy"); f(); if (this.l) { return; } Logger.i(str, "onDestroy | destroyedFromBackground"); b(); } @Override // android.app.Activity, android.view.KeyEvent.Callback public boolean onKeyDown(int i, KeyEvent keyEvent) { if (i == 4 && this.b.y()) { this.b.x(); return true; } if (this.f && (i == 25 || i == 24)) { this.h.removeCallbacks(this.i); this.h.postDelayed(this.i, 500L); } return super.onKeyDown(i, keyEvent); } @Override // com.ironsource.kn public void onOrientationChanged(String str, int i) { a(str, i); } @Override // android.app.Activity public void onPause() { super.onPause(); Logger.i(n, "onPause, isFinishing=" + isFinishing()); t.a(this); v vVar = this.b; if (vVar != null) { vVar.a((Context) this); if (!this.m) { this.b.B(); } this.b.a(false, v8.h.Z); this.b.g(this.g, v8.h.t0); } if (isFinishing()) { this.l = true; b(); } } @Override // android.app.Activity public void onResume() { super.onResume(); Logger.i(n, v8.h.u0); v vVar = this.b; if (vVar != null) { vVar.b(this); if (!this.m) { this.b.F(); } this.b.a(true, v8.h.Z); this.b.g(this.g, v8.h.u0); } t.b(this); } @Override // android.app.Activity public void onStart() { super.onStart(); Logger.i(n, "onStart"); v vVar = this.b; if (vVar != null) { vVar.g(this.g, "onStart"); } } @Override // android.app.Activity public void onStop() { super.onStop(); Logger.i(n, "onStop"); v vVar = this.b; if (vVar != null) { vVar.g(this.g, "onStop"); } } @Override // android.app.Activity public void onUserLeaveHint() { super.onUserLeaveHint(); Logger.i(n, "onUserLeaveHint"); v vVar = this.b; if (vVar != null) { vVar.g(this.g, "onUserLeaveHint"); } } @Override // com.ironsource.cu public void onVideoEnded() { toggleKeepScreen(false); } @Override // com.ironsource.cu public void onVideoPaused() { toggleKeepScreen(false); } @Override // com.ironsource.cu public void onVideoResumed() { toggleKeepScreen(true); } @Override // com.ironsource.cu public void onVideoStarted() { toggleKeepScreen(true); } @Override // com.ironsource.cu public void onVideoStopped() { toggleKeepScreen(false); } @Override // android.app.Activity, android.view.Window.Callback public void onWindowFocusChanged(boolean z) { super.onWindowFocusChanged(z); if (this.f && z) { runOnUiThread(this.i); } } @Override // android.app.Activity public void setRequestedOrientation(int i) { if (this.currentRequestedRotation != i) { Logger.i(n, "Rotation: Req = " + i + " Curr = " + this.currentRequestedRotation); this.currentRequestedRotation = i; super.setRequestedOrientation(i); } } public void toggleKeepScreen(boolean z) { if (z) { e(); } else { a(); } } }