package com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.b;
import androidx.browser.customtabs.r;
import androidx.browser.trusted.g;
import androidx.browser.trusted.h;
import androidx.browser.trusted.i;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class TrustedWebActivity extends ChromeCustomTabsActivity {
    protected static final String LOG_TAG = "TrustedWebActivity";
    public i builder;

    private void prepareCustomTabs() {
        b bVar = new b();
        String str = this.customSettings.toolbarBackgroundColor;
        if (str != null && !str.isEmpty()) {
            bVar.e(Color.parseColor(this.customSettings.toolbarBackgroundColor));
        }
        String str2 = this.customSettings.navigationBarColor;
        if (str2 != null && !str2.isEmpty()) {
            bVar.b(Color.parseColor(this.customSettings.navigationBarColor));
        }
        String str3 = this.customSettings.navigationBarDividerColor;
        if (str3 != null && !str3.isEmpty()) {
            bVar.c(Color.parseColor(this.customSettings.navigationBarDividerColor));
        }
        String str4 = this.customSettings.secondaryToolbarColor;
        if (str4 != null && !str4.isEmpty()) {
            bVar.d(Color.parseColor(this.customSettings.secondaryToolbarColor));
        }
        i iVar = this.builder;
        iVar.f906b.c(bVar.a());
        List<String> list = this.customSettings.additionalTrustedOrigins;
        if (list != null && !list.isEmpty()) {
            this.builder.b(this.customSettings.additionalTrustedOrigins);
        }
        ChromeCustomTabsSettings chromeCustomTabsSettings = this.customSettings;
        g gVar = chromeCustomTabsSettings.displayMode;
        if (gVar != null) {
            this.builder.f907c = gVar;
        }
        this.builder.f908d = chromeCustomTabsSettings.screenOrientation.intValue();
    }

    private void prepareCustomTabsIntent(h hVar) {
        Intent intent = hVar.f903a;
        String str = this.customSettings.packageName;
        if (str != null) {
            intent.setPackage(str);
        } else {
            intent.setPackage(CustomTabsHelper.getPackageNameToUse(this));
        }
        if (this.customSettings.keepAliveEnabled.booleanValue()) {
            CustomTabsHelper.addKeepAliveExtra(this, intent);
        }
        if (this.customSettings.alwaysUseBrowserUI.booleanValue()) {
            r.setAlwaysUseBrowserUI(intent);
        }
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeCustomTabsActivity
    public void launchUrl(@NonNull String str, @Nullable Map<String, String> map, @Nullable String str2, @Nullable List<String> list) {
        if (this.customTabsSession == null) {
            return;
        }
        Uri uri = Uri.parse(str);
        mayLaunchUrl(str, list);
        this.builder = new i(uri);
        prepareCustomTabs();
        h hVarA = this.builder.a(this.customTabsSession);
        prepareCustomTabsIntent(hVarA);
        CustomTabActivityHelper.openTrustedWebActivity(this, hVarA, uri, map, str2 != null ? Uri.parse(str2) : null, 100);
    }
}
