导航菜单

页面标题

页面副标题

RummyCircle v11000.89 - Godel.java 源代码

正在查看: RummyCircle v11000.89 应用的 Godel.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package in.juspay.hypersdk.safe;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.ViewGroup;
import android.view.ViewManager;
import android.view.ViewParent;
import android.webkit.CookieManager;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.camera.camera2.internal.i;
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.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.core.i0;
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 java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Godel {
    private static final String GODEL = "Godel";
    private static final long ON_EXCEPTION_GODEL_OFF_STICKINESS = 86400000;

    @NonNull
    private final AcsInterface acsInterface;

    @NonNull
    private final List<String> allowedDeeplinkPackages = new ArrayList();

    @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;

    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 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 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.juspayServices.getSdkTracker().trackAndLogException(GODEL, LogCategory.ACTION, LogSubCategory.Action.SYSTEM, Labels.System.GODEL_WEBVIEW_WHITELIST, "Failed to read whitelisted config", e);
            }
        }
        return false;
    }

    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", 86400000L);
        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 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) {
        FrameLayout frameLayout;
        initializeJuspayWebView(this.context);
        if (activity != null) {
            frameLayout = (FrameLayout) activity.findViewById(Integer.parseInt(str));
        } else {
            this.sdkTracker.trackAction(LogSubCategory.Action.SYSTEM, "error", Labels.System.ADD_WEBVIEW, "missing", "activity");
            frameLayout = null;
        }
        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 i(this, 12));
    }

    @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 boolean isDuiLoaded() {
        return true;
    }

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

    public void onBrowserReady(Activity activity, String str, String str2, String str3) {
        ExecutorManager.runOnMainThread(new i0(this, 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"})
    public 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 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 void loadPage(String str, String str2) {
        try {
            this.bundleParameters.put(PaymentConstants.URL, str);
            this.bundleParameters.put(PaymentConstants.POST_DATA, 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);
            }
        });
    }
}