Swiggy v4.51.1版本的 MD5 值为:5af7ec91512a0a8c1510e3f8bac20b8b

以下内容为反编译后的 Godel.java 源代码,内容仅作参考


package in.juspay.hypersdk.safe;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.ViewGroup;
import android.view.ViewManager;
import android.view.ViewParent;
import android.webkit.CookieManager;
import android.webkit.URLUtil;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import com.google.android.gms.analytics.ecommerce.Promotion;
import com.google.android.gms.search.SearchAuth;
import com.newrelic.agent.android.instrumentation.Instrumented;
import com.newrelic.agent.android.instrumentation.URLConnectionInstrumentation;
import com.payu.threedsbase.constants.APIConstants;
import in.juspay.hyper.constants.Labels;
import in.juspay.hyper.constants.LogCategory;
import in.juspay.hyper.constants.LogLevel;
import in.juspay.hyper.constants.LogSubCategory;
import in.juspay.hyper.core.ExecutorManager;
import in.juspay.hyper.core.JuspayLogger;
import in.juspay.hypersdk.R;
import in.juspay.hypersdk.core.AcsInterface;
import in.juspay.hypersdk.core.DuiInterface;
import in.juspay.hypersdk.core.GodelJsInterface;
import in.juspay.hypersdk.core.JuspayServices;
import in.juspay.hypersdk.core.JuspayWebViewConfigurationCallback;
import in.juspay.hypersdk.core.PaymentConstants;
import in.juspay.hypersdk.core.PaymentUtils;
import in.juspay.hypersdk.core.SdkTracker;
import in.juspay.hypersdk.data.KeyValueStore;
import in.juspay.hypersdk.data.PaymentSessionInfo;
import in.juspay.hypersdk.services.FileProviderService;
import in.juspay.hypersdk.utils.Utils;
import in.juspay.hypersdk.utils.network.NetUtils;
import in.swiggy.android.tejas.TejasConstants;
import in.swiggy.android.tejas.network.HttpRequest;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.Reader;
import java.io.SequenceInputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@Instrumented
public class Godel {
    private static final String GODEL = "Godel";
    private static final String LOG_TAG = PaymentUtils.class.getSimpleName();
    private static final long ON_EXCEPTION_GODEL_OFF_STICKINESS = 86400000;
    @NonNull
    private final AcsInterface acsInterface;
    @NonNull
    private final JSONObject bundleParameters;
    @NonNull
    private JSONObject config;
    @NonNull
    private final Context context;
    @NonNull
    private final DuiInterface duiInterface;
    @NonNull
    private final JuspayServices juspayServices;
    @NonNull
    private final JuspayWebChromeClient juspayWebChromeClient;
    @NonNull
    private final JuspayWebView juspayWebView;
    @NonNull
    private final JuspayWebViewClient juspayWebViewClient;
    private final JuspayWebViewConfigurationCallback juspayWebViewConfigurationCallback;
    @NonNull
    private final PaymentSessionInfo paymentSessionInfo;
    private final JSONObject processPayload;
    @NonNull
    private final SdkTracker sdkTracker;
    @NonNull
    private final List<String> allowedDeeplinkPackages = new ArrayList();
    public boolean isRupaySupportedAdded = false;

    public Godel(@NonNull JuspayServices juspayServices) {
        Context context = juspayServices.getContext();
        this.context = context;
        this.juspayServices = juspayServices;
        Activity activity = juspayServices.getActivity();
        JuspayWebView juspayWebView = new JuspayWebView(activity != null ? activity : context);
        this.juspayWebView = juspayWebView;
        this.juspayWebViewClient = new JuspayWebViewClient(this, juspayWebView);
        this.juspayWebChromeClient = new JuspayWebChromeClient(this);
        this.acsInterface = new AcsInterface(juspayServices);
        this.juspayWebViewConfigurationCallback = juspayServices.getWebViewConfigurationCallback();
        this.sdkTracker = juspayServices.getSdkTracker();
        this.duiInterface = juspayServices.getJBridge();
        this.paymentSessionInfo = juspayServices.getPaymentSessionInfo();
        this.bundleParameters = juspayServices.getSessionInfo().getBundleParams();
        this.processPayload = juspayServices.getLastProcessPayload();
        this.config = new JSONObject();
    }

    private WebResourceResponse addAcsToJSFile(@NonNull WebResourceRequest webResourceRequest, @NonNull String str, @NonNull String str2, @NonNull JSONObject jSONObject, @NonNull JSONObject jSONObject2) {
        InputStream dataFromGetRequest;
        HttpsURLConnection httpsURLConnection;
        String str3;
        if (!str.equals("POST")) {
            if (str.equals("GET")) {
                HttpsURLConnection httpsURLConnection2 = (HttpsURLConnection) URLConnectionInstrumentation.openConnection(new URL(webResourceRequest.getUrl().toString()).openConnection());
                dataFromGetRequest = getDataFromGetRequest(httpsURLConnection2, webResourceRequest);
                httpsURLConnection = httpsURLConnection2;
            }
            return null;
        }
        httpsURLConnection = getPostRequestConnection(jSONObject2, jSONObject, webResourceRequest);
        dataFromGetRequest = getDataAcsFromPostRequest(httpsURLConnection, str2);
        if (httpsURLConnection == null) {
            return null;
        }
        String contentType = httpsURLConnection.getContentType();
        String substring = (contentType == null || contentType.indexOf(59) <= -1) ? contentType : contentType.substring(0, contentType.indexOf(59));
        if (contentType != null && contentType.indexOf(59) > -1) {
            Matcher matcher = Pattern.compile("charset=([\\w-_]+)").matcher(contentType);
            if (matcher.find()) {
                str3 = matcher.group(1);
                HashMap hashMap = new HashMap();
                for (String str4 : httpsURLConnection.getHeaderFields().keySet()) {
                    hashMap.put(str4, httpsURLConnection.getHeaderField(str4));
                }
                int responseCode = httpsURLConnection.getResponseCode();
                String responseMessage = httpsURLConnection.getResponseMessage();
                if (dataFromGetRequest != null) {
                    return new WebResourceResponse(substring, str3, responseCode, responseMessage, hashMap, dataFromGetRequest);
                }
                return null;
            }
        }
        str3 = null;
        HashMap hashMap2 = new HashMap();
        while (r10.hasNext()) {
        }
        int responseCode2 = httpsURLConnection.getResponseCode();
        String responseMessage2 = httpsURLConnection.getResponseMessage();
        if (dataFromGetRequest != null) {
        }
        return null;
    }

    @NonNull
    private String getAcsScript() {
        FileProviderService fileProviderService = this.juspayServices.getFileProviderService();
        return ("window.juspayContext = {}; juspayContext['web_lab_rules'] = " + getWebLabRules()) + ", " + fileProviderService.readFromFile(this.juspayServices.getContext(), PaymentConstants.ACS);
    }

    private String getConnectionData(Reader reader, int i) {
        try {
            StringBuilder sb = new StringBuilder();
            char[] cArr = new char[i];
            while (true) {
                int read = reader.read(cArr);
                if (read == -1) {
                    return sb.toString();
                }
                sb.append(cArr, 0, read);
            }
        } catch (Exception unused) {
            return null;
        }
    }

    private InputStream getDataAcsFromPostRequest(HttpsURLConnection httpsURLConnection, @NonNull String str) {
        try {
            if (".html".matches(str)) {
                return handleHtmlFile(httpsURLConnection);
            }
            if (!APIConstants.JS_EXTENSION.matches(str) && !".jsp".matches(str)) {
                return null;
            }
            return handleJsFile(httpsURLConnection);
        } catch (Exception unused) {
            return null;
        }
    }

    private InputStream getDataFromGetRequest(@NonNull HttpsURLConnection httpsURLConnection, @NonNull WebResourceRequest webResourceRequest) {
        try {
            for (String str : webResourceRequest.getRequestHeaders().keySet()) {
                httpsURLConnection.setRequestProperty(str, webResourceRequest.getRequestHeaders().get(str));
            }
            httpsURLConnection.setDoOutput(false);
            return new SequenceInputStream(new ByteArrayInputStream(String.format("window.addEventListener('load', function() { if(!window.GK) { %s } });", getAcsScript()).getBytes(StandardCharsets.UTF_8)), httpsURLConnection.getInputStream());
        } catch (Exception unused) {
            return null;
        }
    }

    private List<Pattern> getExcludeUrlsPatternList() {
        JSONException jSONException;
        SdkTracker sdkTracker;
        String str;
        String str2;
        String str3;
        String str4;
        String str5;
        LinkedList linkedList = null;
        try {
            LinkedList linkedList2 = new LinkedList();
            try {
                JSONArray jSONArray = this.config.getJSONArray("exclude_url_patterns");
                if (isNotNull(jSONArray)) {
                    for (int i = 0; i < jSONArray.length(); i++) {
                        linkedList2.add(Pattern.compile(jSONArray.get(i).toString()));
                    }
                    return linkedList2;
                }
                return linkedList2;
            } catch (JSONException e) {
                jSONException = e;
                linkedList = linkedList2;
                sdkTracker = this.sdkTracker;
                str = LOG_TAG;
                str2 = LogCategory.ACTION;
                str3 = LogSubCategory.Action.SYSTEM;
                str4 = Labels.System.UTIL;
                str5 = "Json Exception while fetching excludeUrlPatterns from config";
                sdkTracker.trackAndLogException(str, str2, str3, str4, str5, jSONException);
                return linkedList;
            } catch (Exception e2) {
                jSONException = e2;
                linkedList = linkedList2;
                sdkTracker = this.sdkTracker;
                str = LOG_TAG;
                str2 = LogCategory.ACTION;
                str3 = LogSubCategory.Action.SYSTEM;
                str4 = Labels.System.UTIL;
                str5 = "Exception while compiling patterns in excludeUrlPatterns from config";
                sdkTracker.trackAndLogException(str, str2, str3, str4, str5, jSONException);
                return linkedList;
            }
        } catch (JSONException e3) {
            jSONException = e3;
        } catch (Exception e4) {
            jSONException = e4;
        }
    }

    private HttpsURLConnection getPostRequestConnection(@NonNull JSONObject jSONObject, @NonNull JSONObject jSONObject2, @NonNull WebResourceRequest webResourceRequest) {
        try {
            String sessionAttribute = this.juspayServices.getJBridge().getSessionAttribute("iframe_form_data", "wait_for_me");
            JSONObject jSONObject3 = this.config.getJSONObject("waiting_time_postparams");
            int optInt = jSONObject3.optInt("interval", 50);
            for (int optInt2 = jSONObject3.optInt("total_time", 1000); sessionAttribute.equals("wait_for_me") && optInt2 > 0; optInt2 -= optInt) {
                TimeUnit.MILLISECONDS.sleep(optInt);
                sessionAttribute = this.juspayServices.getJBridge().getSessionAttribute("iframe_form_data", "wait_for_me");
            }
            if (sessionAttribute.equals("wait_for_me")) {
                return null;
            }
            this.juspayServices.getJBridge().setSessionAttribute("iframe_form_data", "wait_for_me");
            HashMap<String, String> map = toMap(sessionAttribute);
            NetUtils netUtils = new NetUtils(jSONObject.optInt("connection_timeout", SearchAuth.StatusCodes.AUTH_DISABLED), jSONObject.optInt("read_timeout", SearchAuth.StatusCodes.AUTH_DISABLED));
            HashMap hashMap = new HashMap();
            Iterator<String> keys = jSONObject2.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                hashMap.put(next, jSONObject2.getString(next));
            }
            return netUtils.postUrl(new URL(webResourceRequest.getUrl().toString()), hashMap, map, new JSONObject());
        } catch (Exception unused) {
            return null;
        }
    }

    private List<String> getRupaySpecificDomains() {
        JSONException jSONException;
        SdkTracker sdkTracker;
        String str;
        String str2;
        String str3;
        String str4;
        String str5;
        ArrayList arrayList = null;
        try {
            JSONArray jSONArray = this.config.getJSONArray("rupay_specific_domains");
            JuspayServices juspayServices = this.juspayServices;
            String str6 = LOG_TAG;
            juspayServices.sdkDebug(str6, "printing urlArray" + jSONArray);
            if (isNotNull(jSONArray)) {
                int length = jSONArray.length();
                ArrayList arrayList2 = new ArrayList(length);
                for (int i = 0; i < length; i++) {
                    try {
                        arrayList2.add(jSONArray.get(i).toString());
                    } catch (JSONException e) {
                        jSONException = e;
                        arrayList = arrayList2;
                        sdkTracker = this.sdkTracker;
                        str = LOG_TAG;
                        str2 = LogCategory.ACTION;
                        str3 = LogSubCategory.Action.SYSTEM;
                        str4 = Labels.System.UTIL;
                        str5 = "Json Exception while fetching Rupay Urls from config";
                        sdkTracker.trackAndLogException(str, str2, str3, str4, str5, jSONException);
                        return arrayList;
                    } catch (Exception e2) {
                        jSONException = e2;
                        arrayList = arrayList2;
                        sdkTracker = this.sdkTracker;
                        str = LOG_TAG;
                        str2 = LogCategory.ACTION;
                        str3 = LogSubCategory.Action.SYSTEM;
                        str4 = Labels.System.UTIL;
                        str5 = "Exception while getting rupay urls from config";
                        sdkTracker.trackAndLogException(str, str2, str3, str4, str5, jSONException);
                        return arrayList;
                    }
                }
                return arrayList2;
            }
            return null;
        } catch (JSONException e3) {
            jSONException = e3;
        } catch (Exception e4) {
            jSONException = e4;
        }
    }

    private java.io.InputStream handleHtmlFile(javax.net.ssl.HttpsURLConnection r8) {
        throw new UnsupportedOperationException("Method not decompiled: in.juspay.hypersdk.safe.Godel.handleHtmlFile(javax.net.ssl.HttpsURLConnection):java.io.InputStream");
    }

    private InputStream handleJsFile(HttpsURLConnection httpsURLConnection) {
        if (httpsURLConnection == null) {
            return null;
        }
        try {
            return new SequenceInputStream(new ByteArrayInputStream(String.format("window.addEventListener('load', function() { if(!window.GK) { %s } });", getAcsScript()).getBytes(StandardCharsets.UTF_8)), httpsURLConnection.getInputStream());
        } catch (Exception unused) {
            return null;
        }
    }

    private void initializeJuspayWebView(@NonNull Context context) {
        this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "info", Labels.System.INITIALISE_JUSPAY_WEBVIEW, "started", context);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
        this.juspayWebView.setId(R.id.juspay_browser_view);
        this.juspayWebView.setLayoutParams(layoutParams);
        this.juspayWebView.setHorizontalScrollBarEnabled(false);
        this.juspayWebView.setVerticalScrollBarEnabled(false);
        this.juspayWebView.addJavascriptInterface(this.acsInterface, "ACSGatekeeper");
        FileProviderService fileProviderService = this.juspayServices.getFileProviderService();
        this.paymentSessionInfo.setPaymentDetails(this.bundleParameters);
        fileProviderService.addToFileCacheWhiteList("acs.jsa");
        prepareWebView();
    }

    private boolean isAcsToBeAddedToResource(@NonNull URL url) {
        List<String> rupaySpecificDomains = getRupaySpecificDomains();
        if (rupaySpecificDomains == null) {
            return false;
        }
        for (String str : rupaySpecificDomains) {
            if (url.toString().toLowerCase().contains(str) && url.getPath().toLowerCase().endsWith(APIConstants.JS_EXTENSION) && !url.getPath().toLowerCase().endsWith(".jsp")) {
                return true;
            }
        }
        return false;
    }

    private boolean isClientWhitelistedForWebViewAccess(String str) {
        JSONArray optJSONArray = Utils.optJSONArray(Utils.optJSONObject(Utils.optJSONObject(this.juspayServices.getSdkConfigService().getSdkConfig(), "godelConfig"), "webViewAccess"), "whitelistedClientIds");
        for (int i = 0; i < optJSONArray.length(); i++) {
            try {
                if (str.contains(optJSONArray.getString(i))) {
                    return true;
                }
            } catch (JSONException e) {
                this.sdkTracker.trackAndLogException(GODEL, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.GODEL_WEBVIEW_WHITELIST, "Failed to read whitelisted config", e);
            }
        }
        return false;
    }

    private static boolean isNotNull(JSONArray jSONArray) {
        return (jSONArray == null || jSONArray == JSONObject.NULL) ? false : true;
    }

    public void lambda$onBrowserReady$0(Activity activity, String str, String str2, String str3) {
        addWebView(activity, str);
        loadPage(str2, str3);
    }

    public void lambda$onBrowserReady$1(Activity activity, String str, String str2, String str3, String str4, String str5, String str6) {
        addWebView(activity, str);
        this.juspayWebView.loadDataWithBaseURL(str2, str3, str4, str5, str6);
    }

    private boolean shouldDisableGodel(Context context) {
        long j;
        if (context == null || !KeyValueStore.contains(this.juspayServices, "GODEL_EXCEPTION_OFF")) {
            return false;
        }
        long optLong = getConfig().optLong("ON_EXCEPTION_GODEL_OFF_STICKINESS", ON_EXCEPTION_GODEL_OFF_STICKINESS);
        try {
            j = System.currentTimeMillis() - Long.parseLong(KeyValueStore.read(this.juspayServices, "GODEL_EXCEPTION_OFF", String.valueOf(System.currentTimeMillis())));
        } catch (NumberFormatException e) {
            long currentTimeMillis = System.currentTimeMillis();
            this.sdkTracker.trackAndLogException(GODEL, LogCategory.ACTION, LogSubCategory.Action.USER, Labels.User.SHOULD_DISABLE_GODEL, "Failed while parsing number", e);
            j = currentTimeMillis;
        }
        this.sdkTracker.trackAction(LogSubCategory.Action.USER, "info", Labels.User.SHOULD_DISABLE_GODEL, "exception_info", KeyValueStore.read(this.juspayServices, "EXCEPTION_INFO", null));
        if (j <= optLong) {
            return true;
        }
        KeyValueStore.remove(this.juspayServices, "GODEL_EXCEPTION_OFF");
        KeyValueStore.remove(this.juspayServices, "EXCEPTION_OFF");
        return false;
    }

    private WebResourceResponse shouldExcludeResource(@NonNull String str) {
        String str2;
        Pattern compile = Pattern.compile(".*\\.(gif|jpg|jpeg|png)([;?].*)?$");
        Bitmap createBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        createBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        List<Pattern> excludeUrlsPatternList = getExcludeUrlsPatternList();
        if (excludeUrlsPatternList == null) {
            excludeUrlsPatternList = new ArrayList<>();
        }
        for (Pattern pattern : excludeUrlsPatternList) {
            if (pattern.matcher(str).matches()) {
                if (compile.matcher(str).matches()) {
                    str2 = "text/html";
                } else {
                    byteArray = "[blocked]".getBytes();
                    str2 = HttpRequest.SHARE_TYPE;
                }
                return new WebResourceResponse(str2, "utf-8", new ByteArrayInputStream(byteArray));
            }
        }
        return null;
    }

    private HashMap<String, String> toMap(@NonNull String str) {
        HashMap<String, String> hashMap = new HashMap<>();
        try {
            JSONObject jSONObject = new JSONObject(str);
            Iterator<String> keys = jSONObject.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                hashMap.put(next, jSONObject.getString(next));
            }
            return hashMap;
        } catch (JSONException unused) {
            JuspayLogger.d(LOG_TAG, "Not a json string. Passing as such");
            return null;
        }
    }

    private void turnOffGodelIfNeeded() {
        if (shouldDisableGodel(this.context)) {
            this.paymentSessionInfo.setGodelDisabled(PaymentConstants.GodelOffReasons.ON_GODEL_EXCEPTION);
        }
        if (!PaymentUtils.hasTelephonyService(this.juspayServices)) {
            this.juspayServices.sdkDebug(GODEL, "No telephony service found.. disabling JB");
            this.paymentSessionInfo.setGodelDisabled(PaymentConstants.GodelOffReasons.TELEPHONY_NOT_FOUND);
        }
        PaymentUtils.switchOffGodelIfLowOnMemory(this, this.juspayServices, this.paymentSessionInfo);
    }

    public void addWebView(Activity activity, String str) {
        initializeJuspayWebView(this.context);
        FrameLayout frameLayout = this.juspayServices.getContainer() != null ? (FrameLayout) this.juspayServices.getContainer().findViewById(Integer.parseInt(str)) : null;
        if (frameLayout != null || activity == null) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "error", Labels.System.ADD_WEBVIEW, "missing", "activity");
        } else {
            frameLayout = (FrameLayout) activity.findViewById(Integer.parseInt(str));
        }
        if (frameLayout == null) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "error", Labels.System.ADD_WEBVIEW, "missing", Promotion.ACTION_VIEW);
        } else if (this.juspayWebView.getParent() == frameLayout) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, LogLevel.WARNING, Labels.System.ADD_WEBVIEW, "parent", "parent view is same as before");
        } else {
            turnOffGodelIfNeeded();
            ViewParent parent = this.juspayWebView.getParent();
            if (parent != null) {
                this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, LogLevel.WARNING, Labels.System.ADD_WEBVIEW, "parent", "already present");
                if (!(parent instanceof ViewGroup)) {
                    this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "error", Labels.System.ADD_WEBVIEW, "parent", "not a ViewGroup");
                    return;
                }
                ((ViewGroup) parent).removeView(this.juspayWebView);
            }
            frameLayout.addView(this.juspayWebView, 0);
        }
    }

    public void exit() {
        ExecutorManager.runOnMainThread(new Runnable() {
            @Override
            public final void run() {
                Godel.this.resetWebView();
            }
        });
    }

    @NonNull
    public AcsInterface getAcsInterface() {
        return this.acsInterface;
    }

    @NonNull
    public List<String> getAllowedDeeplinkPackages() {
        return this.allowedDeeplinkPackages;
    }

    @NonNull
    public JSONObject getConfig() {
        return this.config;
    }

    @NonNull
    public Context getContext() {
        return this.context;
    }

    @NonNull
    public DuiInterface getDuiInterface() {
        return this.duiInterface;
    }

    @NonNull
    public JuspayServices getJuspayServices() {
        return this.juspayServices;
    }

    @NonNull
    public JuspayWebView getJuspayWebView() {
        return this.juspayWebView;
    }

    @NonNull
    public PaymentSessionInfo getPaymentSessionInfo() {
        return this.paymentSessionInfo;
    }

    public JSONObject getWebLabRules() {
        try {
            return this.config.getJSONObject("weblab");
        } catch (Exception e) {
            this.sdkTracker.trackAndLogException(LOG_TAG, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.UTIL, "Unable to find weblab key in config", e);
            return null;
        }
    }

    public boolean isDuiLoaded() {
        return true;
    }

    public void loadPage() {
        String str;
        String str2;
        if (this.bundleParameters.has("url")) {
            str = "file:///android_assets/juspay/acs_blank.html";
            str2 = null;
        } else {
            str = this.bundleParameters.optString("url");
            str2 = this.bundleParameters.optString("postData");
        }
        loadPage(str, str2);
    }

    public void onBrowserReady(final Activity activity, final String str, final String str2, final String str3) {
        ExecutorManager.runOnMainThread(new Runnable() {
            @Override
            public final void run() {
                Godel.this.lambda$onBrowserReady$0(activity, str3, str, str2);
            }
        });
    }

    public void onDuiReady() {
        this.paymentSessionInfo.setGodelManager(this);
        this.juspayServices.getJBridge().attach(PaymentConstants.NETWORK_STATUS, "{}", "");
        setupAllowedDeeplinkPackages();
        this.sdkTracker.trackLifecycle(LogSubCategory.LifeCycle.HYPER_SDK, "info", Labels.HyperSdk.ON_DUI_READY, "class", "HyperFragment");
    }

    public void onDuiReleased() {
        this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "error", Labels.System.ON_DUI_RELEASED, "exit_sdk", JSONObject.NULL);
        exit();
        this.paymentSessionInfo.setGodelManager(null);
    }

    @SuppressLint({"SetJavaScriptEnabled"})
    protected void prepareWebView() {
        this.juspayWebView.getSettings().setJavaScriptEnabled(true);
        this.juspayWebView.getSettings().setDomStorageEnabled(true);
        JSONObject jSONObject = null;
        try {
            jSONObject = this.bundleParameters.getJSONObject(PaymentConstants.PAYLOAD);
            if (jSONObject.optBoolean("godel_receive_merchant_messages")) {
                this.juspayWebView.addJavascriptInterface(new GodelJsInterface(this.juspayServices), "GodelInterface");
            }
        } catch (JSONException e) {
            this.sdkTracker.trackAndLogException(GODEL, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.INITIALISE_JUSPAY_WEBVIEW, "Initiate payload is missing", e);
        }
        this.juspayWebView.setDefaultWebViewClient(this.juspayWebViewClient);
        this.juspayWebView.setDefaultWebChromeClient(this.juspayWebChromeClient);
        this.juspayWebView.getSettings().setAllowFileAccess(true);
        this.juspayWebView.getSettings().setCacheMode(-1);
        this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "info", Labels.System.INITIALISE_JUSPAY_WEBVIEW, "enabling_third_party_cookies", Boolean.TRUE);
        CookieManager.getInstance().setAcceptThirdPartyCookies(this.juspayWebView, true);
        if (!this.juspayServices.getJBridge().execute(PaymentConstants.NETWORK_STATUS, "", "{}", "").equals(String.valueOf(true))) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "info", Labels.System.INITIALISE_JUSPAY_WEBVIEW, "no_network", "Setting web view to load from cache if there is no network");
            this.juspayWebView.getSettings().setCacheMode(1);
        }
        if (this.bundleParameters.has("clearCookies") && this.bundleParameters.optBoolean("clearCookies")) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "info", Labels.System.INITIALISE_JUSPAY_WEBVIEW, "clearing", "cookies");
            PaymentUtils.clearCookies(this.juspayServices);
        }
        if (jSONObject == null) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "error", Labels.System.INITIALISE_JUSPAY_WEBVIEW, "missing", "JuspayWebView");
            return;
        }
        String optString = jSONObject.optString(PaymentConstants.CLIENT_ID_CAMEL, "");
        if (this.juspayWebViewConfigurationCallback == null || !isClientWhitelistedForWebViewAccess(optString)) {
            return;
        }
        this.juspayWebViewConfigurationCallback.configureJuspayWebView(this.juspayWebView);
        this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "info", Labels.System.GODEL_WEBVIEW_WHITELIST, "configured", "JuspayWebView");
    }

    public void resetWebView() {
        JuspayWebView juspayWebView = this.juspayWebView;
        juspayWebView.setDefaultWebChromeClient(juspayWebView.getWebChromeClient());
        JuspayWebView juspayWebView2 = this.juspayWebView;
        juspayWebView2.setDefaultWebViewClient(juspayWebView2.getWebViewClient());
        this.juspayWebView.stopLoading();
        this.juspayWebView.removeJavascriptInterface("ACSGatekeeper");
        this.juspayWebView.clearHistory();
        this.juspayWebView.destroy();
        if (this.juspayWebView.getParent() != null) {
            ((ViewManager) this.juspayWebView.getParent()).removeView(this.juspayWebView);
        }
    }

    public void setConfig(@NonNull JSONObject jSONObject) {
        this.config = jSONObject;
    }

    public void setIsRupaySupportedAdded(boolean z) {
        this.isRupaySupportedAdded = z;
    }

    public void setupAllowedDeeplinkPackages() {
        JSONObject jSONObject = this.processPayload;
        JSONObject optJSONObject = jSONObject != null ? jSONObject.optJSONObject(PaymentConstants.PAYLOAD) : null;
        if (optJSONObject == null) {
            return;
        }
        JSONArray optJSONArray = optJSONObject.optJSONArray("allowedDeepLinkPackages");
        this.allowedDeeplinkPackages.clear();
        if (optJSONArray != null) {
            for (int i = 0; i < optJSONArray.length(); i++) {
                String optString = optJSONArray.optString(i);
                if (optString != null) {
                    this.allowedDeeplinkPackages.add(optString);
                }
            }
        }
    }

    public WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest webResourceRequest) {
        JSONArray optJSONArray;
        try {
            int i = 0;
            if (!this.juspayServices.getSessionInfo().get("inject_acs_into_iframes", TejasConstants.ENABLE_V4_PROFILE_API_DEFAULT).equals("true") || !webResourceRequest.getMethod().equals("GET")) {
                if (!webResourceRequest.getMethod().equals("POST") || (optJSONArray = this.config.optJSONArray("post_urls")) == null) {
                    return null;
                }
                while (i < optJSONArray.length()) {
                    JSONObject jSONObject = optJSONArray.getJSONObject(i);
                    if (Pattern.compile(jSONObject.getString("url")).matcher(webResourceRequest.getUrl().toString()).find()) {
                        return addAcsToJSFile(webResourceRequest, "POST", jSONObject.getString("file_type"), jSONObject.getJSONObject("headers"), jSONObject.getJSONObject("timeout"));
                    }
                    i++;
                }
                return null;
            }
            JSONArray optJSONArray2 = this.config.optJSONArray("bank_js_urls_v2");
            if (optJSONArray2 == null) {
                JSONArray optJSONArray3 = this.config.optJSONArray("bank_js_urls");
                if (optJSONArray3 != null) {
                    while (i < optJSONArray3.length()) {
                        if (Pattern.compile(optJSONArray3.getString(i)).matcher(webResourceRequest.getUrl().toString()).find()) {
                            return addAcsToJSFile(webResourceRequest, "GET", ".*\\.jsp?$", new JSONObject(), new JSONObject());
                        }
                        i++;
                    }
                }
            } else {
                for (int i2 = 0; i2 < optJSONArray2.length(); i2++) {
                    JSONArray jSONArray = optJSONArray2.getJSONArray(i2);
                    if (Pattern.compile(jSONArray.getString(0)).matcher(webResourceRequest.getUrl().toString()).find()) {
                        return addAcsToJSFile(webResourceRequest, "GET", jSONArray.getString(1), new JSONObject(), new JSONObject());
                    }
                }
            }
            return null;
        } catch (Exception e) {
            this.sdkTracker.trackAndLogException(LOG_TAG, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.UTIL, "Exception while adding ACS to js file", e);
            return null;
        }
    }

    public void loadPage(String str, String str2) {
        try {
            this.bundleParameters.put("url", str);
            this.bundleParameters.put("postData", str2);
        } catch (JSONException e) {
            this.sdkTracker.trackAndLogException(GODEL, LogCategory.LIFECYCLE, LogSubCategory.LifeCycle.HYPER_SDK, Labels.System.LOAD_PAGE, "Failed to write to JSON bundle parameters", e);
        }
        if (str2 != null) {
            this.juspayWebView.postUrl(str, str2.getBytes());
        } else {
            this.juspayWebView.loadUrl(str);
        }
    }

    public void onBrowserReady(final Activity activity, final String str, final String str2, final String str3, final String str4, final String str5, final String str6) {
        ExecutorManager.runOnMainThread(new Runnable() {
            @Override
            public final void run() {
                Godel.this.lambda$onBrowserReady$1(activity, str6, str, str2, str3, str4, str5);
            }
        });
    }

    public WebResourceResponse shouldInterceptRequest(@NonNull String str) {
        try {
            JuspayServices juspayServices = this.juspayServices;
            String str2 = LOG_TAG;
            juspayServices.sdkDebug(str2, String.format("Intercepted URL: %s", str));
            if (!URLUtil.isValidUrl(str) || !isAcsToBeAddedToResource(new URL(str)) || this.isRupaySupportedAdded) {
                WebResourceResponse shouldExcludeResource = shouldExcludeResource(str);
                if (shouldExcludeResource != null) {
                    this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "info", Labels.System.UTIL, "url_excluded", str);
                    return shouldExcludeResource;
                }
                return null;
            }
            URL url = new URL(str);
            this.juspayServices.sdkDebug(str2, String.format("Intercepted URL and modified: %s", str));
            setIsRupaySupportedAdded(true);
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(getAcsScript().getBytes(StandardCharsets.UTF_8));
            SequenceInputStream sequenceInputStream = new SequenceInputStream(byteArrayInputStream, url.openStream());
            try {
                WebResourceResponse webResourceResponse = new WebResourceResponse("text/javascript", "utf-8", sequenceInputStream);
                sequenceInputStream.close();
                byteArrayInputStream.close();
                return webResourceResponse;
            } catch (Throwable th) {
                try {
                    sequenceInputStream.close();
                } catch (Throwable th2) {
                    th.addSuppressed(th2);
                }
                throw th;
            }
        } catch (Exception e) {
            this.sdkTracker.trackAndLogException(LOG_TAG, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.UTIL, "Error while Caching Files", e);
            return null;
        }
    }
}