package com.applovin.impl; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.ContextWrapper; import android.content.DialogInterface; import android.net.Uri; import android.text.SpannableString; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.view.View; import android.widget.TextView; import com.applovin.impl.h4; import com.applovin.impl.i4; import com.applovin.impl.j4; import com.applovin.impl.l4; import com.applovin.impl.privacy.cmp.CmpServiceImpl; import com.applovin.impl.sdk.utils.CollectionUtils; import com.applovin.impl.sdk.utils.StringUtils; import com.applovin.sdk.AppLovinCmpError; import com.applovin.sdk.AppLovinSdkConfiguration; import com.applovin.sdk.AppLovinSdkUtils; import com.applovin.sdk.AppLovinWebViewActivity; import com.applovin.sdk.R; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; /* loaded from: classes.dex */ public class n4 { private final com.applovin.impl.sdk.j a; private final int b; private List c; private String d; private j4 e; private h4.c f; private h4.b g; private j4 h; private Dialog i; private final p j = new a(); public boolean b() { return this.c != null; } public class a extends p { public a() { } @Override // com.applovin.impl.p, android.app.Application.ActivityLifecycleCallbacks public void onActivityResumed(Activity activity) { super.onActivityResumed(activity); if ((activity instanceof AppLovinWebViewActivity) || n4.this.h == null) { return; } if (n4.this.i != null) { n4 n4Var = n4.this; if (!r.a(n4Var.a(n4Var.i))) { n4.this.i.dismiss(); } n4.this.i = null; } j4 j4Var = n4.this.h; n4.this.h = null; n4 n4Var2 = n4.this; n4Var2.a(n4Var2.e, j4Var, activity); } } public n4(com.applovin.impl.sdk.j jVar) { this.a = jVar; this.b = ((Integer) jVar.a(sj.C6)).intValue(); } public void c() { h4.b bVar; this.c = null; this.e = null; this.a.e().b(this.j); h4.c cVar = this.f; if (cVar != null && (bVar = this.g) != null) { cVar.a(bVar); } this.f = null; this.g = null; } public class b implements DialogInterface.OnClickListener { final /* synthetic */ l4 a; final /* synthetic */ j4 b; final /* synthetic */ Activity c; public b(l4 l4Var, j4 j4Var, Activity activity) { this.a = l4Var; this.b = j4Var; this.c = activity; } @Override // android.content.DialogInterface.OnClickListener public void onClick(DialogInterface dialogInterface, int i) { n4.this.h = null; n4.this.i = null; j4 a = n4.this.a(this.a.a()); if (a == null) { n4.this.b("Destination state for TOS/PP alert is null"); return; } n4.this.a(this.b, a, this.c); if (a.c() != j4.b.ALERT) { dialogInterface.dismiss(); } } } public class c extends ClickableSpan { final /* synthetic */ Uri a; final /* synthetic */ Activity b; public c(Uri uri, Activity activity) { this.a = uri; this.b = activity; } @Override // android.text.style.ClickableSpan public void onClick(View view) { yp.a(this.a, this.b, n4.this.a); } } public class d extends ClickableSpan { final /* synthetic */ Uri a; final /* synthetic */ Activity b; public d(Uri uri, Activity activity) { this.a = uri; this.b = activity; } @Override // android.text.style.ClickableSpan public void onClick(View view) { yp.a(this.a, this.b, n4.this.a); } } public class e implements CmpServiceImpl.d { final /* synthetic */ j4 a; final /* synthetic */ Activity b; public e(j4 j4Var, Activity activity) { this.a = j4Var; this.b = activity; } @Override // com.applovin.impl.privacy.cmp.CmpServiceImpl.d public void a(AppLovinCmpError appLovinCmpError) { n4.this.a(this.a, this.b, Boolean.valueOf(appLovinCmpError == null)); } } public class f implements CmpServiceImpl.e { final /* synthetic */ j4 a; final /* synthetic */ Activity b; public f(j4 j4Var, Activity activity) { this.a = j4Var; this.b = activity; } @Override // com.applovin.impl.privacy.cmp.CmpServiceImpl.e public void a(AppLovinCmpError appLovinCmpError) { if (appLovinCmpError == null && n4.this.g != null) { n4.this.g.a(true); } n4.this.b(this.a, this.b); } } private void c(final j4 j4Var, final Activity activity) { AppLovinSdkUtils.runOnUiThread(new Runnable() { // from class: com.applovin.impl.n4$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { n4.this.a(j4Var, activity); } }); } public class g implements Runnable { final /* synthetic */ j4 a; public g(j4 j4Var) { this.a = j4Var; } @Override // java.lang.Runnable public void run() { n4 n4Var = n4.this; n4Var.a(n4Var.e, this.a, n4.this.a.n0()); } } /* JADX INFO: Access modifiers changed from: private */ public void b(String str) { q6.a(str, new Object[0]); this.a.E().a(la.I, str, (Map) CollectionUtils.hashMap("details", "Last started states: " + this.d + "\nLast successful state: " + this.e)); h4.b bVar = this.g; if (bVar != null) { bVar.a(new f4(f4.f, str)); } c(); } private j4 a() { List list = this.c; if (list == null) { return null; } for (j4 j4Var : list) { if (j4Var.d()) { return j4Var; } } return null; } /* JADX INFO: Access modifiers changed from: private */ public void b(j4 j4Var, Activity activity) { a(j4Var, activity, (Boolean) null); } /* JADX INFO: Access modifiers changed from: private */ public Activity a(Dialog dialog) { Context context = dialog.getContext(); if (context instanceof Activity) { return (Activity) context; } if (!(context instanceof ContextWrapper)) { return null; } Context baseContext = ((ContextWrapper) context).getBaseContext(); if (baseContext instanceof Activity) { return (Activity) baseContext; } return null; } /* JADX INFO: Access modifiers changed from: private */ public j4 a(String str) { List list = this.c; if (list == null) { return null; } for (j4 j4Var : list) { if (str.equalsIgnoreCase(j4Var.b())) { return j4Var; } } return null; } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(AlertDialog alertDialog, Activity activity, DialogInterface dialogInterface) { TextView textView = (TextView) alertDialog.findViewById(alertDialog.getContext().getResources().getIdentifier("android:id/alertTitle", null, null)); textView.setLinkTextColor(textView.getCurrentTextColor()); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setMaxLines(this.b); textView.setMinHeight(AppLovinSdkUtils.dpToPx(activity, 48)); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(j4 j4Var, final Activity activity) { SpannableString spannableString; if (j4Var == null) { b("Consent flow state is null"); return; } this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AppLovinSdk", "Transitioning to state: " + j4Var); } if (j4Var.c() == j4.b.ALERT) { if (r.a(activity)) { a(j4Var); return; } k4 k4Var = (k4) j4Var; this.h = k4Var; AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setCancelable(false); for (l4 l4Var : k4Var.e()) { b bVar = new b(l4Var, j4Var, activity); if (l4Var.c() == l4.a.POSITIVE) { builder.setPositiveButton(l4Var.d(), bVar); } else if (l4Var.c() == l4.a.NEGATIVE) { builder.setNegativeButton(l4Var.d(), bVar); } else { builder.setNeutralButton(l4Var.d(), bVar); } } String g2 = k4Var.g(); if (StringUtils.isValidString(g2)) { spannableString = new SpannableString(g2); String a2 = com.applovin.impl.sdk.j.a(R.string.applovin_terms_of_service_text); String a3 = com.applovin.impl.sdk.j.a(R.string.applovin_privacy_policy_text); if (StringUtils.containsAtLeastOneSubstring(g2, Arrays.asList(a2, a3))) { Uri i = this.a.u().i(); if (i != null) { StringUtils.addLinks(spannableString, Pattern.compile(a2), new c(i, activity), true); } StringUtils.addLinks(spannableString, Pattern.compile(a3), new d(this.a.u().h(), activity), true); } } else { spannableString = null; } final AlertDialog create = builder.setTitle(spannableString).setMessage(k4Var.f()).create(); create.setOnShowListener(new DialogInterface.OnShowListener() { // from class: com.applovin.impl.n4$$ExternalSyntheticLambda0 @Override // android.content.DialogInterface.OnShowListener public final void onShow(DialogInterface dialogInterface) { n4.this.a(create, activity, dialogInterface); } }); this.i = create; create.show(); return; } if (j4Var.c() == j4.b.EVENT) { m4 m4Var = (m4) j4Var; String f2 = m4Var.f(); Map e2 = m4Var.e(); if (e2 == null) { e2 = new HashMap<>(1); } e2.put("flow_type", this.a.u().e().b()); this.a.A().trackEvent(f2, e2); b(m4Var, activity); return; } if (j4Var.c() == j4.b.HAS_USER_CONSENT) { a(true); b(j4Var, activity); return; } if (j4Var.c() == j4.b.CMP_LOAD) { if (r.a(activity)) { a(j4Var); return; } else { this.a.o().loadCmp(activity, new e(j4Var, activity)); return; } } if (j4Var.c() == j4.b.CMP_SHOW) { if (r.a(activity)) { a(j4Var); return; } else { this.a.A().trackEvent("cf_start"); this.a.o().showCmp(activity, new f(j4Var, activity)); return; } } if (j4Var.c() == j4.b.DECISION) { j4.a a4 = j4Var.a(); if (a4 != j4.a.IS_AL_GDPR) { b("Invalid consent flow decision type: " + a4); return; } AppLovinSdkConfiguration.ConsentFlowUserGeography f3 = this.a.u().f(); AppLovinSdkConfiguration.ConsentFlowUserGeography consentFlowUserGeography = AppLovinSdkConfiguration.ConsentFlowUserGeography.GDPR; a(j4Var, activity, Boolean.valueOf(this.a.r().getConsentFlowUserGeography() == consentFlowUserGeography || (f3 == consentFlowUserGeography && yp.c(this.a)))); return; } if (j4Var.c() == j4.b.TERMS_FLOW) { List a5 = g4.a(this.a); if (a5 != null && a5.size() > 0) { this.a.A().trackEvent("cf_start"); this.c = a5; a(j4Var, a(), activity); return; } c(); return; } if (j4Var.c() == j4.b.REINIT) { c(); return; } b("Invalid consent flow destination state: " + j4Var); } public void a(boolean z) { if (this.a.u().e() == i4.a.TERMS) { return; } a4.b(z, com.applovin.impl.sdk.j.l()); } public void a(List list, Activity activity, h4.c cVar) { if (this.c != null) { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AppLovinSdk", "Unable to start states: " + list); } this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AppLovinSdk", "Consent flow already in progress for states: " + this.c); } cVar.a(new h4.b(new f4(f4.e, "Consent flow is already in progress."))); return; } this.c = list; this.d = String.valueOf(list); this.f = cVar; this.g = new h4.b(); com.applovin.impl.sdk.j.a(activity).a(this.j); a((j4) null, a(), activity); } /* JADX INFO: Access modifiers changed from: private */ public void a(j4 j4Var, Activity activity, Boolean bool) { a(j4Var, a(j4Var.a(bool)), activity); } /* JADX INFO: Access modifiers changed from: private */ public void a(j4 j4Var, j4 j4Var2, Activity activity) { this.e = j4Var; c(j4Var2, activity); } private void a(j4 j4Var) { AppLovinSdkUtils.runOnUiThreadDelayed(new g(j4Var), TimeUnit.SECONDS.toMillis(1L)); } }