导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - RzpAssist.java 源代码

正在查看: Clash Legends v0.0.1 应用的 RzpAssist.java JAVA 源代码文件

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


package com.razorpay;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Toast;
import com.onesignal.inAppMessages.internal.display.impl.WebViewManager;
import com.payu.custombrowser.util.b;
import com.razorpay.AnalyticsProperty;
import in.juspay.godel.core.Constants;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

public final class RzpAssist implements SmsAgentInterface {
    private Activity activity;
    private OtpElfData elfData;
    String lastSms;
    private String merchantKey;
    private long pageStartTime;
    private String paymentId;
    private String sdkType;
    private int sdkVersionCode;
    private SmsAgent smsAgent;
    private WebView webview;
    private boolean hasOtpPermission = false;
    private String lastURL = "";
    private String currentLoadingUrl = "";
    private boolean isMagic = false;
    private boolean isRazorpayOtpReceived = false;
    private JSONObject otpElfPreferences = new JSONObject();
    private JSONObject paymentData = new JSONObject();
    private boolean isRzpAssistEnabled = false;
    private boolean otpRead = false;
    private boolean jsInsertedInCurrentPage = false;

    public RzpAssist(String merchantKey, Activity activity, WebView webview, String sdkType, int sdkVersionCode, String sdkVersion) {
        this.sdkType = "standalone";
        if (!CoreConfig.getInstance().isOTPElfEnabled().booleanValue()) {
            return;
        }
        if (merchantKey == null || merchantKey.isEmpty()) {
            throw new RuntimeException("merchantKey cannot be null or empty");
        }
        this.sdkType = sdkType;
        this.sdkVersionCode = sdkVersionCode;
        Logger.d("OTPElf Constructor");
        if (sdkType.equals("standalone")) {
            AnalyticsUtil.setup(activity, merchantKey, sdkType, sdkVersionCode, sdkVersion);
        }
        this.webview = webview;
        this.merchantKey = merchantKey;
        this.activity = activity;
        OtpElfData otpElfData = new OtpElfData(activity);
        this.elfData = otpElfData;
        otpElfData.checkForUpdates();
        setup();
        AnalyticsUtil.addProperty("OTPElf Version", new AnalyticsProperty(BaseUtils.getLocalVersion(activity, OtpElfData.versionKey), AnalyticsProperty.Scope.ORDER));
    }

    private void setup() {
        SmsAgent smsAgentInstance = SmsAgent.getSmsAgentInstance();
        this.smsAgent = smsAgentInstance;
        smsAgentInstance.registerForCallbacks(this);
        this.smsAgent.takeActionsIfPermissionsAreGranted(this.activity);
        this.webview.addJavascriptInterface(this, "OTPElfBridge");
        this.webview.getSettings().setUseWideViewPort(true);
    }

    void enableMagic() {
        this.isMagic = true;
    }

    void setPaymentData(JSONObject jsonObject) {
        this.paymentData = jsonObject;
    }

    public void setOtpElfPreferences(JSONObject preferences) {
        this.otpElfPreferences = preferences;
    }

    public void onPageFinished(WebView webview, String url) {
        long timeInterval = System.nanoTime() - this.pageStartTime;
        AnalyticsUtil.trackPageLoadEnd(url, timeInterval);
        this.lastURL = url;
        this.currentLoadingUrl = "";
        if (CoreConfig.getInstance().isOTPElfEnabled().booleanValue() && !this.jsInsertedInCurrentPage) {
            handleJsInsertion();
            this.jsInsertedInCurrentPage = true;
        }
    }

    private void handleJsInsertion() {
        try {
            JSONObject settings = CoreConfig.getInstance().getOTPElfSettings();
            settings.put("merchant_key", this.merchantKey);
            settings.put("otp_permission", this.hasOtpPermission);
            JSONObject sdk = new JSONObject();
            sdk.put(WebViewManager.EVENT_TYPE_KEY, this.sdkType);
            sdk.put("version_code", this.sdkVersionCode);
            settings.put("sdk", sdk);
            JSONObject plugin = new JSONObject();
            if (!this.isMagic) {
                Logger.d("not magic");
                plugin.put(WebViewManager.EVENT_TYPE_KEY, "rzpassist");
                plugin.put("version_code", ResourceUtils.getRzpAssistVersionCode());
            } else {
                Logger.d("This is Magic");
                plugin.put(WebViewManager.EVENT_TYPE_KEY, "magic");
                plugin.put("version_code", ResourceUtils.getMagicVersionCode());
            }
            settings.put("plugin", plugin);
            settings.put("payment_data", this.paymentData);
            settings.put("preferences", this.otpElfPreferences);
            injectJs("window.__rzp_options = " + settings.toString());
        } catch (Exception e) {
            Logger.e("Unable to load otpelf settings", e);
        }
        injectJs(this.elfData.getOtpElfJs());
        String str = this.lastSms;
        if (str != null) {
            injectJs(String.format("OTPElf.elfBridge.setSms(%s)", str));
            this.lastSms = null;
        }
    }

    public void onProgressChanged(int progress) {
        CoreConfig.getInstance().isOTPElfEnabled().booleanValue();
    }

    public void onPageStarted(WebView view, String url) {
        Logger.d("RzpAssist onPageStarted: " + url);
        AnalyticsUtil.trackPageLoadStart(url);
        this.pageStartTime = System.nanoTime();
        this.currentLoadingUrl = url;
        this.jsInsertedInCurrentPage = false;
    }

    public void paymentFlowEnd() {
        if (this.sdkType.equals("standalone")) {
            AnalyticsUtil.postData();
        }
        if (!CoreConfig.getInstance().isOTPElfEnabled().booleanValue()) {
            return;
        }
        this.smsAgent.removeSMSBroadcastReceiver(this.activity);
        this.smsAgent.deregisterForCallbacks(this);
    }

    @Override
    public void postSms(String sender, String message) {
        if (!this.isRzpAssistEnabled) {
            return;
        }
        try {
            JSONObject sms = new JSONObject();
            sms.put(b.SENDER, sender);
            sms.put("message", message);
            String jSONObject = sms.toString();
            this.lastSms = jSONObject;
            injectJs(String.format("OTPElf.elfBridge.setSms(%s)", jSONObject));
        } catch (Exception e) {
            Logger.e("Exception", e);
        }
    }

    @Override
    public void setSmsPermission(boolean hasSmsPermission) {
        setOTPEnabled(hasSmsPermission);
    }

    void setPaymentId(String paymentId) {
        this.paymentId = paymentId;
    }

    private void postStatsToAPI() {
        try {
            String auth = BaseUtils.constructBasicAuth(this.merchantKey);
            Map<String, String> headers = new HashMap<>();
            headers.put("Authorization", "Basic " + auth);
            headers.put("Content-Type", "application/json");
            if (this.paymentId == null) {
                return;
            }
            String endpoint = "https://api.razorpay.com/v1/payments/" + this.paymentId + "/metadata";
            Logger.d("Sending Stats Request");
            JSONObject payload = AutoOtpUtils.createStatsPayload(this.otpRead);
            Logger.d("PAYLOAD");
            Logger.d(payload.toString());
            Logger.d(endpoint);
            Owl.post(endpoint, payload.toString(), headers, new Callback() {
                @Override
                public void run(ResponseObject response) {
                    Logger.d("API Metadata: " + response.getResponseResult());
                }
            });
        } catch (Exception e) {
            AnalyticsUtil.reportError(e, "critical", e.getMessage());
        }
    }

    private void injectJs(String js) {
        this.webview.loadUrl(String.format("javascript: %s", js));
    }

    void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        this.smsAgent.handleRequestPermissionsResult(this.activity, requestCode, permissions, grantResults);
    }

    String getLastLoadedUrl() {
        return this.lastURL;
    }

    String getCurrentLoadingUrl() {
        return this.currentLoadingUrl;
    }

    public final void reset() {
        postStatsToAPI();
        this.lastURL = "";
        this.currentLoadingUrl = "";
        this.otpRead = false;
    }

    boolean isRazorpayOtpReceived() {
        return this.isRazorpayOtpReceived;
    }

    void setOTPEnabled(boolean enabled) {
        this.hasOtpPermission = enabled;
        AnalyticsUtil.addProperty("otp_autoreading_access", new AnalyticsProperty(enabled, AnalyticsProperty.Scope.ORDER));
    }

    void setRzpAssistEnabled(boolean enabled) {
        this.isRzpAssistEnabled = enabled;
    }

    @JavascriptInterface
    public final void setUseWideViewPort(final boolean shouldUse) {
        this.activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                RzpAssist.this.webview.getSettings().setUseWideViewPort(shouldUse);
            }
        });
    }

    @JavascriptInterface
    public final void openKeyboard() {
        this.activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) RzpAssist.this.activity.getSystemService("input_method");
                imm.showSoftInput(RzpAssist.this.webview, 0);
            }
        });
    }

    @JavascriptInterface
    public final void toast(final String message) {
        this.activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(RzpAssist.this.activity, message, 1).show();
            }
        });
    }

    @JavascriptInterface
    public void trackEvent(String eventName, String properties) {
        try {
            AnalyticsEvent jsEvent = AnalyticsEvent.JS_EVENT;
            jsEvent.setEventName(eventName);
            JSONObject propertiesJson = new JSONObject(properties);
            AnalyticsUtil.trackEvent(jsEvent, propertiesJson);
        } catch (Exception e) {
            Logger.e("Error in tracking JS Event", e);
        }
    }

    @JavascriptInterface
    public final void trackEvent(String eventName) {
        AnalyticsEvent jsEvent = AnalyticsEvent.JS_EVENT;
        jsEvent.setEventName(eventName);
        AnalyticsUtil.trackEvent(jsEvent);
    }

    @JavascriptInterface
    public void onOtpParsed(final String otpJson) {
        this.activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    JSONObject jsonObject = new JSONObject(otpJson);
                    String pin = jsonObject.getString(Constants.OTP);
                    String sender = jsonObject.getString(b.SENDER);
                    String bank = jsonObject.getString("bank");
                    OTP otp = new OTP(pin, sender, bank);
                    Map<String, Object> properties = new HashMap<>();
                    properties.put(b.SENDER, otp.getSender());
                    if (otp.getSender().contains("RZRPAY")) {
                        RzpAssist.this.isRazorpayOtpReceived = true;
                        properties.put("razorpay_otp", true);
                    } else {
                        properties.put("razorpay_otp", false);
                        RzpAssist.this.otpRead = true;
                        AnalyticsUtil.addProperty("payment_otp_received", new AnalyticsProperty(true, AnalyticsProperty.Scope.PAYMENT));
                    }
                    AnalyticsUtil.trackEvent(AnalyticsEvent.OTP_RECEIVED, properties);
                } catch (Exception e) {
                    Logger.e("Error in parsing json", e);
                }
            }
        });
    }

    @JavascriptInterface
    public void copyToClipboard(String value) {
        ClipboardManager clipboard = (ClipboardManager) this.activity.getSystemService("clipboard");
        ClipData clip = ClipData.newPlainText("rzp_clip_data", value);
        clipboard.setPrimaryClip(clip);
    }
}