导航菜单

页面标题

页面副标题

bbinstant v6.24.0 - Godel.java 源代码

正在查看: bbinstant v6.24.0 应用的 Godel.java JAVA 源代码文件

本页面展示 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 com.snowplowanalytics.snowplow.tracker.constants.Parameters;
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 java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
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.Pattern;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

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;
    private final AcsInterface acsInterface;
    private final JSONObject bundleParameters;
    private JSONObject config;
    private final Context context;
    private final DuiInterface duiInterface;
    private final JuspayServices juspayServices;
    private final JuspayWebChromeClient juspayWebChromeClient;
    private final JuspayWebView juspayWebView;
    private final JuspayWebViewClient juspayWebViewClient;
    private final JuspayWebViewConfigurationCallback juspayWebViewConfigurationCallback;
    private final PaymentSessionInfo paymentSessionInfo;
    private final JSONObject processPayload;
    private final SdkTracker sdkTracker;
    private final List<String> allowedDeeplinkPackages = new ArrayList();
    public boolean isRupaySupportedAdded = false;

    public Godel(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 android.webkit.WebResourceResponse addAcsToJSFile(android.webkit.WebResourceRequest r9, java.lang.String r10, java.lang.String r11, org.json.JSONObject r12, org.json.JSONObject r13) {
        throw new UnsupportedOperationException("Method not decompiled: in.juspay.hypersdk.safe.Godel.addAcsToJSFile(android.webkit.WebResourceRequest, java.lang.String, java.lang.String, org.json.JSONObject, org.json.JSONObject):android.webkit.WebResourceResponse");
    }

    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 i2) {
        try {
            StringBuilder sb = new StringBuilder();
            char[] cArr = new char[i2];
            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, String str) {
        try {
            if (".html".matches(str)) {
                return handleHtmlFile(httpsURLConnection);
            }
            if (!".js".matches(str) && !".jsp".matches(str)) {
                return null;
            }
            return handleJsFile(httpsURLConnection);
        } catch (Exception unused) {
            return null;
        }
    }

    private InputStream getDataFromGetRequest(HttpsURLConnection httpsURLConnection, 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() {
        Exception exc;
        SdkTracker sdkTracker;
        String str;
        String str2;
        String str3;
        LinkedList linkedList = null;
        try {
            LinkedList linkedList2 = new LinkedList();
            try {
                JSONArray jSONArray = this.config.getJSONArray("exclude_url_patterns");
                if (!isNotNull(jSONArray)) {
                    return linkedList2;
                }
                for (int i2 = 0; i2 < jSONArray.length(); i2++) {
                    linkedList2.add(Pattern.compile(jSONArray.get(i2).toString()));
                }
                return linkedList2;
            } catch (JSONException e2) {
                exc = e2;
                linkedList = linkedList2;
                sdkTracker = this.sdkTracker;
                str = LOG_TAG;
                str2 = Labels.System.UTIL;
                str3 = "Json Exception while fetching excludeUrlPatterns from config";
                sdkTracker.trackAndLogException(str, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, str2, str3, exc);
                return linkedList;
            } catch (Exception e3) {
                exc = e3;
                linkedList = linkedList2;
                sdkTracker = this.sdkTracker;
                str = LOG_TAG;
                str2 = Labels.System.UTIL;
                str3 = "Exception while compiling patterns in excludeUrlPatterns from config";
                sdkTracker.trackAndLogException(str, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, str2, str3, exc);
                return linkedList;
            }
        } catch (JSONException e4) {
            exc = e4;
        } catch (Exception e5) {
            exc = e5;
        }
    }

    private HttpsURLConnection getPostRequestConnection(JSONObject jSONObject, JSONObject jSONObject2, 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", 10000), jSONObject.optInt("read_timeout", 10000));
            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() {
        Exception exc;
        SdkTracker sdkTracker;
        String str;
        String str2;
        String str3;
        ArrayList arrayList = null;
        try {
            JSONArray jSONArray = this.config.getJSONArray("rupay_specific_domains");
            this.juspayServices.sdkDebug(LOG_TAG, "printing urlArray" + jSONArray);
            if (!isNotNull(jSONArray)) {
                return null;
            }
            int length = jSONArray.length();
            ArrayList arrayList2 = new ArrayList(length);
            for (int i2 = 0; i2 < length; i2++) {
                try {
                    arrayList2.add(jSONArray.get(i2).toString());
                } catch (JSONException e2) {
                    exc = e2;
                    arrayList = arrayList2;
                    sdkTracker = this.sdkTracker;
                    str = LOG_TAG;
                    str2 = Labels.System.UTIL;
                    str3 = "Json Exception while fetching Rupay Urls from config";
                    sdkTracker.trackAndLogException(str, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, str2, str3, exc);
                    return arrayList;
                } catch (Exception e3) {
                    exc = e3;
                    arrayList = arrayList2;
                    sdkTracker = this.sdkTracker;
                    str = LOG_TAG;
                    str2 = Labels.System.UTIL;
                    str3 = "Exception while getting rupay urls from config";
                    sdkTracker.trackAndLogException(str, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, str2, str3, exc);
                    return arrayList;
                }
            }
            return arrayList2;
        } catch (JSONException e4) {
            exc = e4;
        } catch (Exception e5) {
            exc = e5;
        }
    }

    private InputStream handleHtmlFile(HttpsURLConnection httpsURLConnection) {
        String connectionData;
        BufferedReader bufferedReader;
        String str;
        if (httpsURLConnection == null) {
            return null;
        }
        try {
            ?? format = String.format("<script>{ %s } </script></body>", getAcsScript());
            String contentEncoding = httpsURLConnection.getContentEncoding();
            try {
                if (contentEncoding == null || !contentEncoding.equalsIgnoreCase("gzip")) {
                    if (contentEncoding != null && !contentEncoding.equals("")) {
                        str = 0;
                    }
                    BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream()), 8000);
                    try {
                        connectionData = getConnectionData(bufferedReader2, 8000);
                        bufferedReader = bufferedReader2;
                        bufferedReader.close();
                        str = connectionData;
                    } catch (Throwable th) {
                        bufferedReader2.close();
                        throw th;
                    }
                } else {
                    bufferedReader = new BufferedReader(new InputStreamReader(new GZIPInputStream(httpsURLConnection.getInputStream()), StandardCharsets.UTF_8), 8000);
                    try {
                        connectionData = getConnectionData(bufferedReader, 8000);
                        bufferedReader.close();
                        str = connectionData;
                    } catch (Throwable th2) {
                        bufferedReader.close();
                        throw th2;
                    }
                }
                if (str != 0) {
                    return new ByteArrayInputStream(str.replace("</body>", (CharSequence) format).getBytes(StandardCharsets.UTF_8));
                }
                return null;
            } catch (Throwable th3) {
                format.addSuppressed(th3);
                throw format;
            }
        } catch (Exception unused) {
            return null;
        }
    }

    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(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(URL url) {
        List<String> rupaySpecificDomains = getRupaySpecificDomains();
        if (rupaySpecificDomains == null) {
            return false;
        }
        Iterator<String> it = rupaySpecificDomains.iterator();
        while (it.hasNext()) {
            if (url.toString().toLowerCase().contains(it.next()) && url.getPath().toLowerCase().endsWith(".js") && !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 i2 = 0; i2 < optJSONArray.length(); i2++) {
            try {
                if (str.contains(optJSONArray.getString(i2))) {
                    return true;
                }
            } catch (JSONException e2) {
                this.sdkTracker.trackAndLogException(GODEL, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.GODEL_WEBVIEW_WHITELIST, "Failed to read whitelisted config", e2);
            }
        }
        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 e2) {
            long currentTimeMillis = System.currentTimeMillis();
            this.sdkTracker.trackAndLogException(GODEL, LogCategory.ACTION, LogSubCategory.Action.USER, Labels.User.SHOULD_DISABLE_GODEL, "Failed while parsing number", e2);
            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(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<>();
        }
        Iterator<Pattern> it = excludeUrlsPatternList.iterator();
        while (it.hasNext()) {
            if (it.next().matcher(str).matches()) {
                if (compile.matcher(str).matches()) {
                    str2 = "text/html";
                } else {
                    byteArray = "[blocked]".getBytes();
                    str2 = "text/plain";
                }
                return new WebResourceResponse(str2, "utf-8", new ByteArrayInputStream(byteArray));
            }
        }
        return null;
    }

    private HashMap<String, String> toMap(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", Parameters.SCREEN_ACTIVITY);
        } else {
            frameLayout = (FrameLayout) activity.findViewById(Integer.parseInt(str));
        }
        if (frameLayout == null) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "error", Labels.System.ADD_WEBVIEW, "missing", "view");
            return;
        }
        if (this.juspayWebView.getParent() == frameLayout) {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, LogLevel.WARNING, Labels.System.ADD_WEBVIEW, "parent", "parent view is same as before");
            return;
        }
        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();
            }
        });
    }

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

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

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

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

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

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

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

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

    public JSONObject getWebLabRules() {
        try {
            return this.config.getJSONObject("weblab");
        } catch (Exception e2) {
            this.sdkTracker.trackAndLogException(LOG_TAG, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.UTIL, "Unable to find weblab key in config", e2);
            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(PaymentConstants.POST_DATA);
        }
        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("payload");
            if (jSONObject.optBoolean("godel_receive_merchant_messages")) {
                this.juspayWebView.addJavascriptInterface(new GodelJsInterface(this.juspayServices), "GodelInterface");
            }
        } catch (JSONException e2) {
            this.sdkTracker.trackAndLogException(GODEL, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.INITIALISE_JUSPAY_WEBVIEW, "Initiate payload is missing", e2);
        }
        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");
    }

    protected 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(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("payload") : null;
        if (optJSONObject == null) {
            return;
        }
        JSONArray optJSONArray = optJSONObject.optJSONArray("allowedDeepLinkPackages");
        this.allowedDeeplinkPackages.clear();
        if (optJSONArray != null) {
            for (int i2 = 0; i2 < optJSONArray.length(); i2++) {
                String optString = optJSONArray.optString(i2);
                if (optString != null) {
                    this.allowedDeeplinkPackages.add(optString);
                }
            }
        }
    }

    public WebResourceResponse shouldInterceptRequest(WebResourceRequest webResourceRequest) {
        JSONArray optJSONArray;
        try {
            int i2 = 0;
            if (!this.juspayServices.getSessionInfo().get("inject_acs_into_iframes", "false").equals("true") || !webResourceRequest.getMethod().equals("GET")) {
                if (!webResourceRequest.getMethod().equals("POST") || (optJSONArray = this.config.optJSONArray("post_urls")) == null) {
                    return null;
                }
                while (i2 < optJSONArray.length()) {
                    JSONObject jSONObject = optJSONArray.getJSONObject(i2);
                    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"));
                    }
                    i2++;
                }
                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 (i2 < optJSONArray3.length()) {
                        if (Pattern.compile(optJSONArray3.getString(i2)).matcher(webResourceRequest.getUrl().toString()).find()) {
                            return addAcsToJSFile(webResourceRequest, "GET", ".*\\.jsp?$", new JSONObject(), new JSONObject());
                        }
                        i2++;
                    }
                }
            } else {
                for (int i3 = 0; i3 < optJSONArray2.length(); i3++) {
                    JSONArray jSONArray = optJSONArray2.getJSONArray(i3);
                    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 e2) {
            this.sdkTracker.trackAndLogException(LOG_TAG, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.UTIL, "Exception while adding ACS to js file", e2);
            return null;
        }
    }

    public void loadPage(String str, String str2) {
        try {
            this.bundleParameters.put("url", str);
            this.bundleParameters.put(PaymentConstants.POST_DATA, str2);
        } catch (JSONException e2) {
            this.sdkTracker.trackAndLogException(GODEL, LogCategory.LIFECYCLE, LogSubCategory.LifeCycle.HYPER_SDK, Labels.System.LOAD_PAGE, "Failed to write to JSON bundle parameters", e2);
        }
        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(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) {
                    return null;
                }
                this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "info", Labels.System.UTIL, "url_excluded", str);
                return shouldExcludeResource;
            }
            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));
            try {
                SequenceInputStream sequenceInputStream = new SequenceInputStream(byteArrayInputStream, url.openStream());
                try {
                    WebResourceResponse webResourceResponse = new WebResourceResponse("text/javascript", "utf-8", sequenceInputStream);
                    sequenceInputStream.close();
                    byteArrayInputStream.close();
                    return webResourceResponse;
                } finally {
                }
            } finally {
            }
        } catch (Exception e2) {
            this.sdkTracker.trackAndLogException(LOG_TAG, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.UTIL, "Error while Caching Files", e2);
            return null;
        }
    }
}