package io.flutter.plugins.urllauncher;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.q;
import androidx.browser.customtabs.r;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes.dex */
public final class f implements d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f28330a;

    @Nullable
    private Activity activity;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final com.google.gson.internal.a f28331b;

    public f(Context context) {
        com.google.gson.internal.a aVar = new com.google.gson.internal.a(context, 4);
        this.f28330a = context;
        this.f28331b = aVar;
    }

    public static Bundle b(Map map) {
        Bundle bundle = new Bundle();
        for (String str : map.keySet()) {
            bundle.putString(str, (String) map.get(str));
        }
        return bundle;
    }

    public final Boolean a(String str) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setData(Uri.parse(str));
        ComponentName componentNameResolveActivity = intent.resolveActivity(((Context) this.f28331b.f24293b).getPackageManager());
        return (componentNameResolveActivity == null ? null : componentNameResolveActivity.toShortString()) == null ? Boolean.FALSE : Boolean.valueOf(!"{com.android.fallback/com.android.fallback.Fallback}".equals(r3));
    }

    public final Boolean c(String str, Map map) {
        if (this.activity == null) {
            throw new Messages$FlutterError("NO_ACTIVITY", "Launching a URL requires a foreground activity.", null);
        }
        try {
            this.activity.startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse(str)).putExtra("com.android.browser.headers", b(map)));
            return Boolean.TRUE;
        } catch (ActivityNotFoundException unused) {
            return Boolean.FALSE;
        }
    }

    public final Boolean d(String str, Boolean bool, e eVar, a aVar) {
        if (this.activity == null) {
            throw new Messages$FlutterError("NO_ACTIVITY", "Launching a URL requires a foreground activity.", null);
        }
        Bundle bundleB = b(eVar.f28329c);
        if (bool.booleanValue()) {
            Iterator it = eVar.f28329c.keySet().iterator();
            while (true) {
                if (it.hasNext()) {
                    String lowerCase = ((String) it.next()).toLowerCase(Locale.US);
                    lowerCase.getClass();
                    switch (lowerCase) {
                    }
                } else {
                    Uri uri = Uri.parse(str);
                    Activity activity = this.activity;
                    q qVar = new q();
                    qVar.f880a.putExtra("android.support.customtabs.extra.TITLE_VISIBILITY", aVar.f28323a.booleanValue() ? 1 : 0);
                    r rVarB = qVar.b();
                    rVarB.f884a.putExtra("com.android.browser.headers", bundleB);
                    try {
                        rVarB.a(activity, uri);
                        return Boolean.TRUE;
                    } catch (ActivityNotFoundException unused) {
                    }
                }
            }
        }
        Activity activity2 = this.activity;
        boolean zBooleanValue = eVar.f28327a.booleanValue();
        boolean zBooleanValue2 = eVar.f28328b.booleanValue();
        int i10 = WebViewActivity.f28318e;
        try {
            this.activity.startActivity(new Intent(activity2, (Class<?>) WebViewActivity.class).putExtra(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str).putExtra("enableJavaScript", zBooleanValue).putExtra("enableDomStorage", zBooleanValue2).putExtra("com.android.browser.headers", bundleB));
            return Boolean.TRUE;
        } catch (ActivityNotFoundException unused2) {
            return Boolean.FALSE;
        }
    }

    public void setActivity(@Nullable Activity activity) {
        this.activity = activity;
    }
}
