package com.applovin.impl; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.net.Uri; import android.os.Bundle; import com.applovin.communicator.AppLovinCommunicator; import com.applovin.communicator.AppLovinCommunicatorMessage; import com.applovin.communicator.AppLovinCommunicatorPublisher; import com.applovin.communicator.AppLovinCommunicatorSubscriber; import com.applovin.impl.h4; import com.applovin.impl.i4; import com.applovin.impl.sdk.utils.JsonUtils; import com.applovin.impl.sdk.utils.StringUtils; import com.applovin.sdk.AppLovinSdkConfiguration; import com.applovin.sdk.AppLovinSdkUtils; import com.google.android.gms.ads.AdError; import com.tapjoy.TapjoyConstants; import java.util.List; import java.util.Map; import org.json.JSONObject; /* loaded from: classes.dex */ public class h4 implements AppLovinCommunicatorSubscriber, AppLovinCommunicatorPublisher { private final com.applovin.impl.sdk.j a; private final n4 b; private List c; public static /* synthetic */ class a { static final /* synthetic */ int[] a; static { int[] iArr = new int[i4.a.values().length]; a = iArr; try { iArr[i4.a.UNIFIED.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { a[i4.a.TERMS.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } } } public interface c { void a(b bVar); } @Override // com.applovin.communicator.AppLovinCommunicatorEntity public String getCommunicatorId() { return "consent_flow_manager"; } public boolean j() { com.applovin.impl.sdk.j jVar = com.applovin.impl.sdk.j.v0; if (!jVar.A0()) { return false; } h4 u = jVar.u(); List list = u.c; return u.b.b() || (list != null && list.size() > 0); } public static class b { private boolean a; private f4 b; public b() { } public f4 a() { return this.b; } public void a(f4 f4Var) { this.b = f4Var; } public void a(boolean z) { this.a = z; } public boolean b() { return this.a; } public String toString() { return "ConsentFlowManager.FlowCompletionStatus(cmpPromptShown=" + b() + ", error=" + a() + ")"; } public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof b)) { return false; } b bVar = (b) obj; if (!bVar.a((Object) this) || b() != bVar.b()) { return false; } f4 a = a(); f4 a2 = bVar.a(); return a != null ? a.equals(a2) : a2 == null; } public int hashCode() { int i = b() ? 79 : 97; f4 a = a(); return ((i + 59) * 59) + (a == null ? 43 : a.hashCode()); } public b(f4 f4Var) { this.b = f4Var; } public boolean a(Object obj) { return obj instanceof b; } } public h4(com.applovin.impl.sdk.j jVar) { this.a = jVar; this.b = new n4(jVar); } public i4 d() { return (i4) this.a.v(); } public boolean k() { Map extraParameters = this.a.g0().getExtraParameters(); if (extraParameters.containsKey("consent_flow_enabled")) { return Boolean.parseBoolean(extraParameters.get("consent_flow_enabled")); } return d().isEnabled(); } public i4.a e() { return d().a(); } public Uri h() { return d().getPrivacyPolicyUri(); } public Uri i() { return d().getTermsOfServiceUri(); } public AppLovinSdkConfiguration.ConsentFlowUserGeography f() { return d().getDebugUserGeography(); } public static i4 b(JSONObject jSONObject) { Boolean bool = JsonUtils.getBoolean(jSONObject, "consent_flow_enabled", Boolean.FALSE); String string = JsonUtils.getString(jSONObject, "consent_flow_debug_user_geography", ""); String string2 = JsonUtils.getString(jSONObject, "consent_flow_terms_of_service", null); Uri parse = StringUtils.isValidString(string2) ? Uri.parse(string2) : null; String string3 = JsonUtils.getString(jSONObject, "consent_flow_privacy_policy", null); return new i4(bool.booleanValue(), a(string), i4.a.UNIFIED, StringUtils.isValidString(string3) ? Uri.parse(string3) : null, parse); } public static i4 a(JSONObject jSONObject) { Boolean bool = JsonUtils.getBoolean(jSONObject, "terms_flow_enabled", Boolean.FALSE); String string = JsonUtils.getString(jSONObject, "terms_flow_terms_of_service", null); Uri parse = StringUtils.isValidString(string) ? Uri.parse(string) : null; String string2 = JsonUtils.getString(jSONObject, "terms_flow_privacy_policy", null); return new i4(bool.booleanValue(), AppLovinSdkConfiguration.ConsentFlowUserGeography.UNKNOWN, i4.a.TERMS, StringUtils.isValidString(string2) ? Uri.parse(string2) : null, parse); } @Override // com.applovin.communicator.AppLovinCommunicatorSubscriber public void onMessageReceived(AppLovinCommunicatorMessage appLovinCommunicatorMessage) { if (i() != null && appLovinCommunicatorMessage.getMessageData().getBoolean("include_tos")) { this.c = o4.b(this.a); } else { this.c = o4.a(this.a); } if (this.c.size() == 0) { yp.a("No Consent Flow Available", (String) null, this.a.n0()); } else { b(this.a.n0(), new c() { // from class: com.applovin.impl.h4$$ExternalSyntheticLambda0 @Override // com.applovin.impl.h4.c public final void a(h4.b bVar) { h4.this.a(bVar); } }); } } public static i4 a(Context context) { if (context == null) { com.applovin.impl.sdk.n.h("AppLovinSdk", "Failed to get default terms flow settings."); return new i4(false, AppLovinSdkConfiguration.ConsentFlowUserGeography.UNKNOWN, i4.a.TERMS, null, null); } String a2 = yp.a(context.getResources().getIdentifier("applovin_settings", "raw", context.getPackageName()), context, (com.applovin.impl.sdk.j) null); JSONObject jsonObjectFromJsonString = StringUtils.isValidString(a2) ? JsonUtils.jsonObjectFromJsonString(a2, new JSONObject()) : new JSONObject(); i4.a c2 = c(jsonObjectFromJsonString); int i = a.a[c2.ordinal()]; if (i == 1) { return b(JsonUtils.getJSONObject(jsonObjectFromJsonString, "consent_flow_settings", new JSONObject())); } if (i == 2) { return a(JsonUtils.getJSONObject(jsonObjectFromJsonString, "terms_flow_settings", new JSONObject())); } throw new IllegalStateException("Unknown consent flow type: " + c2); } public JSONObject c() { i4 d = d(); Uri privacyPolicyUri = d.getPrivacyPolicyUri(); Uri termsOfServiceUri = d.getTermsOfServiceUri(); JSONObject jSONObject = new JSONObject(); JsonUtils.putString(jSONObject, "enabled", String.valueOf(k())); JsonUtils.putString(jSONObject, "privacy_policy_url", privacyPolicyUri != null ? privacyPolicyUri.toString() : ""); JsonUtils.putString(jSONObject, "terms_of_service_url", termsOfServiceUri != null ? termsOfServiceUri.toString() : ""); return jSONObject; } public String g() { d(); Object h = h(); Object i = i(); StringBuilder sb = new StringBuilder(); sb.append("\nConsent Flow Enabled - "); sb.append(k()); sb.append("\nPrivacy Policy - "); if (h == null) { h = AdError.UNDEFINED_DOMAIN; } sb.append(h); sb.append("\nTerms of Service - "); if (i == null) { i = AdError.UNDEFINED_DOMAIN; } sb.append(i); return sb.toString(); } private Uri b() { return Uri.parse((String) this.a.a(this.a.B0() ? sj.B6 : sj.A6)); } private static i4.a c(JSONObject jSONObject) { return jSONObject.has("consent_flow_settings") ? i4.a.UNIFIED : i4.a.TERMS; } public void a() { if (k()) { if (d().a() == i4.a.UNIFIED) { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AppLovinSdk", "Generating Unified Consent Flow..."); } this.c = g4.c(this.a); } else { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AppLovinSdk", "Generating Terms Flow..."); } this.c = g4.a(this.a); } } if (yp.i(com.applovin.impl.sdk.j.l())) { AppLovinCommunicator.getInstance(com.applovin.impl.sdk.j.l()).subscribe(this, "start_sdk_consent_flow"); } } public void b(final Activity activity, final c cVar) { if (!k()) { cVar.a(new b(new f4(f4.d, "Failed to start consent flow. Please make sure that the consent flow is enabled."))); return; } List list = this.c; if (list != null && list.size() != 0) { a(activity, new Runnable() { // from class: com.applovin.impl.h4$$ExternalSyntheticLambda5 @Override // java.lang.Runnable public final void run() { h4.this.a(activity, cVar); } }); } else { this.a.b(uj.o, Boolean.FALSE); cVar.a(new b(new f4(f4.c, "User may not be eligible for flow."))); } } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ void b(Uri uri, DialogInterface dialogInterface, int i) { throw new IllegalStateException("You cannot use the AppLovin SDK's consent flow without defining a Privacy Policy URL Please refer to " + uri.toString()); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(Uri uri, DialogInterface dialogInterface, int i) { tp.a(uri, com.applovin.impl.sdk.j.l(), this.a); throw new IllegalStateException("You cannot use the AppLovin SDK's consent flow without defining a Privacy Policy URL Please refer to " + uri.toString()); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(Activity activity) { final Uri b2 = b(); new AlertDialog.Builder(activity).setTitle("Missing Privacy Policy URL").setMessage("You cannot use the AppLovin SDK's consent flow without defining a Privacy Policy URL").setNeutralButton("Go To Documentation", new DialogInterface.OnClickListener() { // from class: com.applovin.impl.h4$$ExternalSyntheticLambda3 @Override // android.content.DialogInterface.OnClickListener public final void onClick(DialogInterface dialogInterface, int i) { h4.this.a(b2, dialogInterface, i); } }).setNegativeButton("DISMISS", new DialogInterface.OnClickListener() { // from class: com.applovin.impl.h4$$ExternalSyntheticLambda4 @Override // android.content.DialogInterface.OnClickListener public final void onClick(DialogInterface dialogInterface, int i) { h4.b(b2, dialogInterface, i); } }).create().show(); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(c cVar, b bVar) { if (bVar.b != null) { if (bVar.b.a() != f4.e) { this.c = null; } } else { this.a.b(uj.o, Boolean.FALSE); this.c = null; } cVar.a(bVar); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(Activity activity, final c cVar) { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("ConsentFlowManager", "Starting consent flow with states: " + this.c); } if (!this.a.t0()) { this.a.b(uj.o, Boolean.TRUE); } this.b.a(this.c, activity, new c() { // from class: com.applovin.impl.h4$$ExternalSyntheticLambda2 @Override // com.applovin.impl.h4.c public final void a(h4.b bVar) { h4.this.a(cVar, bVar); } }); } private void a(final Activity activity, Runnable runnable) { if (d().getPrivacyPolicyUri() != null) { runnable.run(); } else { AppLovinSdkUtils.runOnUiThread(new Runnable() { // from class: com.applovin.impl.h4$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { h4.this.a(activity); } }); } } private static AppLovinSdkConfiguration.ConsentFlowUserGeography a(String str) { if (TapjoyConstants.PREF_SUBJECT_TO_GDPR.equalsIgnoreCase(str)) { return AppLovinSdkConfiguration.ConsentFlowUserGeography.GDPR; } if ("other".equalsIgnoreCase(str)) { return AppLovinSdkConfiguration.ConsentFlowUserGeography.OTHER; } return AppLovinSdkConfiguration.ConsentFlowUserGeography.UNKNOWN; } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(b bVar) { AppLovinCommunicator.getInstance(com.applovin.impl.sdk.j.l()).getMessagingService().publish(new AppLovinCommunicatorMessage(new Bundle(), "sdk_consent_flow_finished", this)); } }