package csdk.glucentralservices.consent; import android.R; import android.app.Activity; import android.app.Application; import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.util.Base64; import android.view.WindowManager; import android.webkit.WebResourceError; import android.webkit.WebResourceRequest; import android.webkit.WebView; import android.webkit.WebViewClient; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.facebook.internal.NativeProtocol; import com.google.firebase.perf.network.FirebasePerfUrlConnection; import csdk.glucentralservices.util.Common; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URL; import java.util.Iterator; import java.util.concurrent.atomic.AtomicReference; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes4.dex */ public class ConsentUI implements Application.ActivityLifecycleCallbacks { private final Activity mActivity; private JSONObject mConfig; private Dialog mDialog; private AtomicReference mListener; private final WebView mWebView; @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) { } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityPaused(@NonNull Activity activity) { } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) { } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityStarted(@NonNull Activity activity) { } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityStopped(@NonNull Activity activity) { } public ConsentUI(Activity activity) { this.mActivity = activity; activity.getApplication().registerActivityLifecycleCallbacks(this); this.mDialog = new Dialog(activity, R.style.Theme.Translucent.NoTitleBar); this.mListener = new AtomicReference<>(NullConsentListener.INSTANCE); WebView webView = new WebView(activity); this.mWebView = webView; webView.setBackgroundColor(0); this.mDialog.setContentView(webView); this.mDialog.setCancelable(false); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { // from class: csdk.glucentralservices.consent.ConsentUI.1 boolean isInternalRedirect; @Override // android.webkit.WebViewClient public void onLoadResource(WebView webView2, String str) { handleUrl(str); } @Override // android.webkit.WebViewClient @RequiresApi(api = 24) public boolean shouldOverrideUrlLoading(WebView webView2, WebResourceRequest webResourceRequest) { String uri = webResourceRequest.getUrl().toString(); if (!isConsentFormUrl(uri)) { return false; } handleUrl(uri); return true; } @Override // android.webkit.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView2, String str) { if (!isConsentFormUrl(str)) { return false; } handleUrl(str); return true; } @Override // android.webkit.WebViewClient public void onPageFinished(WebView webView2, String str) { if (!this.isInternalRedirect) { ConsentUI.this.updateDialogContent(webView2); } super.onPageFinished(webView2, str); } @Override // android.webkit.WebViewClient @RequiresApi(api = 23) public void onReceivedError(WebView webView2, WebResourceRequest webResourceRequest, WebResourceError webResourceError) { onReceivedError(webView2, webResourceError.getErrorCode(), webResourceError.getDescription().toString(), webResourceRequest.getUrl().toString()); } @Override // android.webkit.WebViewClient public void onReceivedError(WebView webView2, int i, String str, String str2) { if (isConsentFormUrl(str2)) { return; } System.out.println("WebViewClient::onReceivedError: " + str2); if (str2.startsWith("http") || str2.startsWith("chrome-extension")) { return; } ConsentUI.this.onConsentStatusEventReceived(null, new Exception(str)); } private boolean isConsentFormUrl(String str) { return !TextUtils.isEmpty(str) && str.startsWith("consent://"); } /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */ /* JADX WARN: Code restructure failed: missing block: B:25:0x004a, code lost: if (r1.equals(androidx.core.app.NotificationCompat.CATEGORY_EVENT) == false) goto L7; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private void handleUrl(java.lang.String r7) { /* r6 = this; boolean r0 = r6.isConsentFormUrl(r7) if (r0 != 0) goto L7 return L7: r0 = 1 r6.isInternalRedirect = r0 android.net.Uri r7 = android.net.Uri.parse(r7) java.lang.String r1 = "action" java.lang.String r1 = r7.getQueryParameter(r1) java.lang.String r2 = "status" java.lang.String r2 = r7.getQueryParameter(r2) java.lang.String r3 = "url" java.lang.String r7 = r7.getQueryParameter(r3) r1.hashCode() int r3 = r1.hashCode() r4 = 0 r5 = -1 switch(r3) { case -1370505102: goto L4d; case 96891546: goto L44; case 150940456: goto L39; case 1671672458: goto L2e; default: goto L2c; } L2c: r0 = r5 goto L57 L2e: java.lang.String r0 = "dismiss" boolean r0 = r1.equals(r0) if (r0 != 0) goto L37 goto L2c L37: r0 = 3 goto L57 L39: java.lang.String r0 = "browser" boolean r0 = r1.equals(r0) if (r0 != 0) goto L42 goto L2c L42: r0 = 2 goto L57 L44: java.lang.String r3 = "event" boolean r1 = r1.equals(r3) if (r1 != 0) goto L57 goto L2c L4d: java.lang.String r0 = "load_complete" boolean r0 = r1.equals(r0) if (r0 != 0) goto L56 goto L2c L56: r0 = r4 L57: switch(r0) { case 0: goto L6f; case 1: goto L69; case 2: goto L63; case 3: goto L5b; default: goto L5a; } L5a: goto L74 L5b: r6.isInternalRedirect = r4 csdk.glucentralservices.consent.ConsentUI r7 = csdk.glucentralservices.consent.ConsentUI.this csdk.glucentralservices.consent.ConsentUI.access$300(r7, r2) goto L74 L63: csdk.glucentralservices.consent.ConsentUI r0 = csdk.glucentralservices.consent.ConsentUI.this csdk.glucentralservices.consent.ConsentUI.access$400(r0, r7) goto L74 L69: csdk.glucentralservices.consent.ConsentUI r7 = csdk.glucentralservices.consent.ConsentUI.this csdk.glucentralservices.consent.ConsentUI.access$500(r7, r2) goto L74 L6f: csdk.glucentralservices.consent.ConsentUI r7 = csdk.glucentralservices.consent.ConsentUI.this csdk.glucentralservices.consent.ConsentUI.access$200(r7, r2) L74: return */ throw new UnsupportedOperationException("Method not decompiled: csdk.glucentralservices.consent.ConsentUI.AnonymousClass1.handleUrl(java.lang.String):void"); } }); } public void showConsent(String str, IConsentListener iConsentListener) { AtomicReference atomicReference = this.mListener; if (iConsentListener == null) { iConsentListener = NullConsentListener.INSTANCE; } atomicReference.set(iConsentListener); initConfig(str); doShowConsent(); load(); } private static String getApplicationName(Context context) { return context.getApplicationInfo().loadLabel(context.getPackageManager()).toString(); } private static String getAppIconURIString(Context context) { Drawable applicationIcon = context.getPackageManager().getApplicationIcon(context.getApplicationInfo()); Bitmap createBitmap = Bitmap.createBitmap(applicationIcon.getIntrinsicWidth(), applicationIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(createBitmap); applicationIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); applicationIcon.draw(canvas); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); createBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); return "data:image/png;base64," + Base64.encodeToString(byteArrayOutputStream.toByteArray(), 0); } private static String createJavascriptCommandAndDismissOnError(String str, String str2) { JSONObject jSONObject = new JSONObject(); try { JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("info", str2); jSONObject.put("args", jSONObject2); return "javascript:try{" + String.format("%s(%s)", str, jSONObject.toString()) + "}catch(e){window.location.href=\"consent://consent/?action=dismiss&status=Error%3A+\" + encodeURIComponent(e);}"; } catch (JSONException e) { throw Common.propagate(e); } } private void initConfig(String str) { try { this.mConfig = new JSONObject(str); } catch (JSONException e) { throw Common.propagate(e); } } private void load() { InputStream openStream; String optString = this.mConfig.optString("consent_form_url", "file:///android_asset/consentform.html"); try { if (optString.startsWith("file:///android_asset")) { openStream = this.mActivity.getAssets().open("consentform.html"); } else { openStream = FirebasePerfUrlConnection.openStream(new URL(optString)); } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] bArr = new byte[1024]; while (true) { int read = openStream.read(bArr); if (read != -1) { byteArrayOutputStream.write(bArr, 0, read); } else { String byteArrayOutputStream2 = byteArrayOutputStream.toString("UTF-8"); byteArrayOutputStream.close(); this.mWebView.loadDataWithBaseURL("", byteArrayOutputStream2, "text/html", "UTF-8", null); return; } } } catch (Exception e) { onConsentStatusEventReceived(null, e); } } private void doShowConsent() { boolean optBoolean = this.mConfig.optBoolean("disableAgeGateHardwareAcceleration", false); this.mDialog.getWindow().setLayout(-1, -1); if (optBoolean) { System.out.println("doShowConsent LAYER_TYPE_SOFTWARE"); this.mDialog.getWindow().getDecorView().setLayerType(1, null); } else { System.out.println("doShowConsent FLAG_HARDWARE_ACCELERATED"); this.mDialog.getWindow().setFlags(16777216, 16777216); } int i = Build.VERSION.SDK_INT; this.mDialog.getWindow().setFlags(8, 8); this.mDialog.getWindow().getDecorView().setSystemUiVisibility(4870); if (i >= 28) { WindowManager.LayoutParams attributes = this.mDialog.getWindow().getAttributes(); attributes.layoutInDisplayCutoutMode = 1; this.mDialog.getWindow().setAttributes(attributes); } this.mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0)); this.mDialog.setOnShowListener(new DialogInterface.OnShowListener() { // from class: csdk.glucentralservices.consent.ConsentUI.2 @Override // android.content.DialogInterface.OnShowListener public void onShow(DialogInterface dialogInterface) { } }); this.mDialog.show(); if (!this.mDialog.isShowing()) { onConsentStatusEventReceived(null, new Exception("Consent form could not be displayed.")); } this.mDialog.getWindow().clearFlags(8); } /* JADX INFO: Access modifiers changed from: private */ public void onConsentStatusEventReceived(String str, Throwable th) { this.mListener.get().onConsentStatusReceived(str, th); this.mListener.set(NullConsentListener.INSTANCE); } /* JADX INFO: Access modifiers changed from: private */ public void updateDialogContent(WebView webView) { JSONObject jSONObject = new JSONObject(); try { JSONObject jSONObject2 = this.mConfig; if (jSONObject2 != null) { Iterator keys = jSONObject2.keys(); while (keys.hasNext()) { String next = keys.next(); jSONObject.put(next, jSONObject2.get(next)); } } String optString = jSONObject.optString(NativeProtocol.BRIDGE_ARG_APP_NAME_STRING); String optString2 = jSONObject.optString("app_icon"); if (TextUtils.isEmpty(optString)) { jSONObject.put(NativeProtocol.BRIDGE_ARG_APP_NAME_STRING, getApplicationName(this.mActivity)); } if (TextUtils.isEmpty(optString2)) { jSONObject.put("app_icon", getAppIconURIString(this.mActivity)); } jSONObject.put("plat", "android"); webView.loadUrl(createJavascriptCommandAndDismissOnError("setUpConsentDialog", jSONObject.toString())); } catch (JSONException e) { throw Common.propagate(e); } } /* JADX INFO: Access modifiers changed from: private */ public void handleLoadComplete(String str) { if (TextUtils.isEmpty(str)) { onConsentStatusEventReceived(null, new Exception("No information")); } else if (str.contains("Error")) { onConsentStatusEventReceived(null, new Exception(str)); } } /* JADX INFO: Access modifiers changed from: private */ public void handleOpenBrowser(String str) { if (TextUtils.isEmpty(str)) { onConsentStatusEventReceived(null, new Exception("No valid URL for browser navigation.")); return; } try { this.mActivity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str))); } catch (ActivityNotFoundException unused) { onConsentStatusEventReceived(null, new Exception("No Activity found to handle browser intent.")); } } /* JADX INFO: Access modifiers changed from: private */ public void handleDismiss(String str) { this.mDialog.dismiss(); if (TextUtils.isEmpty(str)) { onConsentStatusEventReceived(null, new Exception("No information provided.")); } else if (str.contains("Error")) { onConsentStatusEventReceived(null, new Exception(str)); } else { onConsentStatusEventReceived(str, null); } } /* JADX INFO: Access modifiers changed from: private */ public void handleEvent(String str) { this.mListener.get().onConsentEventReceived(str); } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityResumed(@NonNull Activity activity) { Dialog dialog; if (activity != this.mActivity || (dialog = this.mDialog) == null) { return; } dialog.getWindow().getDecorView().setSystemUiVisibility(4870); } @Override // android.app.Application.ActivityLifecycleCallbacks public void onActivityDestroyed(@NonNull Activity activity) { Dialog dialog; if (activity == this.mActivity && (dialog = this.mDialog) != null && dialog.isShowing()) { this.mDialog.dismiss(); this.mDialog = null; } } }