package com.ss.android.ugc.aweme.ecommerce.jsb;

import X.04w;
import X.0CB;
import X.0CH;
import X.6Is;
import X.7gp;
import X.9EH;
import X.C0394K2f;
import X.C0865KKi;
import X.FIu;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.net.Uri;
import android.webkit.WebView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.fe.base.BaseCommonJavaMethod;
import org.json.JSONObject;

public final class OpenThirdPartyAppMethod extends BaseCommonJavaMethod implements 6Is {
    public static final C0394K2f LIZIZ = new C0394K2f((byte) 0);
    public final C0865KKi LIZ;

    static {
        Covode.recordClassIndex(70132);
    }

    public OpenThirdPartyAppMethod(byte b) {
        this();
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public /* synthetic */ OpenThirdPartyAppMethod() {
        this((C0865KKi) null);
    }

    public OpenThirdPartyAppMethod(C0865KKi kKi) {
        super(kKi);
        this.LIZ = kKi;
    }

    public final void handle(JSONObject jSONObject, FIu fIu) {
        WebView webView;
        Context context;
        String str;
        C0865KKi kKi = this.LIZ;
        if (kKi != null && (webView = kKi.LIZLLL) != null && (context = webView.getContext()) != null) {
            while (true) {
                String str2 = null;
                if (context == null) {
                    return;
                }
                if (context instanceof Activity) {
                    Activity activity = (Activity) context;
                    if (activity != null) {
                        if (jSONObject != null) {
                            str = jSONObject.optString("url");
                            str2 = jSONObject.optString("packageName");
                        } else {
                            str = null;
                        }
                        if (7gp.LIZ(9EH.LJJIFFI.LIZ(), str2)) {
                            try {
                                04w r1 = new 04w();
                                r1.LIZ().LIZ.setPackage(str2);
                                r1.LIZ().LIZ(activity, Uri.parse(str));
                                if (fIu != null) {
                                    fIu.LIZ(new JSONObject());
                                    return;
                                }
                                return;
                            } catch (Exception e) {
                                if (fIu != null) {
                                    fIu.LIZ(-1, e.toString());
                                    return;
                                }
                                return;
                            }
                        } else if (fIu != null) {
                            fIu.LIZ(-1, "app not installed");
                            return;
                        } else {
                            return;
                        }
                    } else {
                        return;
                    }
                } else if (context instanceof ContextWrapper) {
                    context = ((ContextWrapper) context).getBaseContext();
                } else {
                    return;
                }
            }
        }
    }
}
