导航菜单

页面标题

页面副标题

Crafto v9.3.3 - BaseUtils.java 源代码

正在查看: Crafto v9.3.3 应用的 BaseUtils.java JAVA 源代码文件

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


package com.razorpay;

import C1.e;
import C1.r;
import J1.a;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.webkit.CookieManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
import androidx.core.content.FileProvider;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import com.google.firebase.perf.network.FirebasePerfUrlConnection;
import com.paytmpayments.customuisdk.transaction.PayUtility;
import com.phonepe.intent.sdk.bridges.BridgeHandler;
import com.razorpay.AdvertisingIdUtil;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import og.C1071d;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import proguard.annotation.Keep;
import proguard.annotation.KeepClassMembers;

@Keep
@KeepClassMembers
class BaseUtils {
    static final boolean $assertionsDisabled = false;
    private static String PERMISSION_DISABLED = "permission disabled";
    private static BaseUtils baseUtils;
    static String ipAddress;
    private String orderId;
    private String paymentId;
    private static boolean sWebViewDebuggingEnabled = L__R$.a.booleanValue();
    private static boolean isCompatibleWithGooglePay = true;
    private static boolean isGpayCardsUpiRegistered = false;

    public static String buildSerial() {
        return Build.SERIAL;
    }

    public static void checkForLatestVersion(Context context, int i) {
        if (g__v_.a().isSDKUpdateAlertEnabled() && isMerchantAppDebuggable(context) && i < g__v_.a().getLatestSDKVersionCode()) {
            Toast.makeText(context, g__v_.a().getUpdateSDKMsg(), 1).show();
        }
    }

    public static boolean checkGpayCardsUpiRegistered(Activity activity, String str) {
        if (str == null) {
            return isGpayCardsUpiRegistered;
        }
        try {
            String string = new JSONObject(str).getString(BridgeHandler.CODE);
            if (string.hashCode() == -1534821982 && string.equals("google_pay")) {
                return isGpayCardsUpiRegistered;
            }
            return false;
        } catch (JSONException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean checkUpiRegisteredApp(Context context, String str) {
        str.getClass();
        if (str.equals("com.google.android.apps.nbu.paisa.user")) {
            return isCompatibleWithGooglePay;
        }
        return true;
    }

    public static String constructBasicAuth(String str) {
        return Base64.encodeToString((str + ":").getBytes("UTF-8"), 2);
    }

    public static PublicKey constructPublicKey(String str) {
        try {
            return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str.getBytes(), 0)));
        } catch (Exception unused) {
            return null;
        }
    }

    public static String decryptFile(String str) {
        try {
            CryptLib cryptLib = new CryptLib();
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            messageDigest.update("rzpisunitedred".getBytes("UTF-8"));
            byte[] digest = messageDigest.digest();
            StringBuffer stringBuffer = new StringBuffer();
            for (byte b : digest) {
                stringBuffer.append(String.format("%02x", Byte.valueOf(b)));
            }
            return cryptLib.b(str, 32 > stringBuffer.toString().length() ? stringBuffer.toString() : stringBuffer.toString().substring(0, 32), "glorygloryunited");
        } catch (Exception e) {
            AnalyticsUtil.reportError(e.getMessage(), "S2", e.getLocalizedMessage());
            e.getMessage();
            return null;
        }
    }

    public static int dpToPixels(Context context, int i) {
        return (int) TypedValue.applyDimension(1, i, context.getResources().getDisplayMetrics());
    }

    private static void enableJavaScriptInWebView(WebView webView) {
        webView.getSettings().setJavaScriptEnabled(true);
    }

    public static void fetchIP(final RzpJSONCallback rzpJSONCallback) {
        new Thread(new Runnable() {
            @Override
            public final void run() {
                HttpsURLConnection httpsURLConnection;
                JSONObject responseJson;
                HttpsURLConnection httpsURLConnection2 = null;
                try {
                    try {
                        try {
                            httpsURLConnection = (HttpsURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(new URL("https://approvals-api.getsimpl.com/my-ip").openConnection()));
                        } catch (Throwable th2) {
                            th = th2;
                        }
                        try {
                            httpsURLConnection.setRequestMethod("GET");
                            httpsURLConnection.setReadTimeout(150);
                            httpsURLConnection.setConnectTimeout(250);
                            if (httpsURLConnection.getResponseCode() == 200) {
                                responseJson = BaseUtils.getResponseJson(httpsURLConnection);
                                RzpJSONCallback.this.onResponse(responseJson);
                            } else {
                                RzpJSONCallback.this.onResponse(new JSONObject().put("error", "error"));
                            }
                            httpsURLConnection.disconnect();
                        } catch (SocketTimeoutException unused) {
                            httpsURLConnection2 = httpsURLConnection;
                            RzpJSONCallback.this.onResponse(new JSONObject().put("error", "timeout"));
                            if (httpsURLConnection2 == null) {
                                return;
                            }
                            httpsURLConnection2.disconnect();
                        } catch (Exception e) {
                            e = e;
                            httpsURLConnection2 = httpsURLConnection;
                            AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
                            if (httpsURLConnection2 == null) {
                                return;
                            }
                            httpsURLConnection2.disconnect();
                        } catch (Throwable th3) {
                            th = th3;
                            httpsURLConnection2 = httpsURLConnection;
                            if (httpsURLConnection2 != null) {
                                httpsURLConnection2.disconnect();
                            }
                            throw th;
                        }
                    } catch (SocketTimeoutException unused2) {
                    } catch (Exception e2) {
                        e = e2;
                    }
                } catch (Exception e3) {
                    AnalyticsUtil.reportError(e3.getMessage(), "S2", e3.getMessage());
                }
            }
        }).start();
    }

    public static HashMap<String, String> getAllPluginsFromManifest(Context context) {
        ApplicationInfo applicationInfo;
        try {
            applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), UserMetadata.MAX_ROLLOUT_ASSIGNMENTS);
        } catch (PackageManager.NameNotFoundException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getMessage());
            return null;
        }
        if (applicationInfo.metaData == null) {
            return null;
        }
        HashMap<String, String> hashMap = new HashMap<>();
        for (String str : applicationInfo.metaData.keySet()) {
            if (str.contains("com.razorpay.plugin.") && applicationInfo.metaData.getString(str).equalsIgnoreCase("com.razorpay.RzpGpayMerged")) {
                try {
                    if (Class.forName("com.google.android.apps.nbu.paisa.inapp.client.api.PaymentsClient").newInstance() != null) {
                        hashMap.put(str, applicationInfo.metaData.getString(str));
                    }
                } catch (ClassNotFoundException e2) {
                    AnalyticsUtil.reportError(e2.getMessage(), "S2", "GooglePay SDK is not included");
                } catch (IllegalAccessException e3) {
                    e = e3;
                    e.printStackTrace();
                } catch (InstantiationException e4) {
                    e = e4;
                    e.printStackTrace();
                }
            } else if (str.contains("com.razorpay.plugin.") && applicationInfo.metaData.getString(str).equalsIgnoreCase("com.razorpay.RzpGooglePay")) {
                try {
                    if (Class.forName("com.google.android.apps.nbu.paisa.inapp.client.api.PaymentsClient").newInstance() != null) {
                        hashMap.put(str, applicationInfo.metaData.getString(str));
                    }
                } catch (ClassNotFoundException e5) {
                    AnalyticsUtil.reportError(e5.getMessage(), "S2", "GooglePay SDK is not included");
                } catch (IllegalAccessException e6) {
                    e = e6;
                    e.printStackTrace();
                } catch (InstantiationException e7) {
                    e = e7;
                    e.printStackTrace();
                }
            } else if (str.contains("com.razorpay.plugin.") && applicationInfo.metaData.getString(str) != null) {
                hashMap.put(str, applicationInfo.metaData.getString(str));
            }
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getMessage());
            return null;
        }
        return hashMap;
    }

    public static String getAndroidId(Context context) {
        return Settings.Secure.getString(context.getContentResolver(), "android_id");
    }

    public static String getAppBuildType(Context context) {
        return (context.getApplicationInfo().flags & 2) != 0 ? "development" : "production";
    }

    public static String getAppNameOfPackageName(String str, Context context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo(str, UserMetadata.MAX_ROLLOUT_ASSIGNMENTS);
            int i = applicationInfo.labelRes;
            return i == 0 ? applicationInfo.nonLocalizedLabel.toString() : packageManager.getResourcesForApplication(applicationInfo).getString(i);
        } catch (Exception e) {
            AnalyticsUtil.reportError(e.getMessage(), "error:exception", e.getLocalizedMessage());
            e.printStackTrace();
            throw e;
        }
    }

    public static String getAppNameOfResolveInfo(ResolveInfo resolveInfo, Context context) {
        return getAppNameOfPackageName(resolveInfo.activityInfo.packageName, context);
    }

    public static String getBase64FromOtherAppsResource(Context context, String str) {
        PackageManager packageManager = context.getPackageManager();
        try {
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo(str, UserMetadata.MAX_ROLLOUT_ASSIGNMENTS);
            return getBase64FromResource(packageManager.getResourcesForApplication(applicationInfo), applicationInfo.icon);
        } catch (PackageManager.NameNotFoundException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
            e.printStackTrace();
            return null;
        }
    }

    public static String getBase64FromResource(Resources resources, int i) {
        Drawable drawable;
        Bitmap decodeResource = BitmapFactory.decodeResource(resources, i);
        if (decodeResource == null && (drawable = resources.getDrawable(i)) != null) {
            if (drawable instanceof BitmapDrawable) {
                decodeResource = ((BitmapDrawable) drawable).getBitmap();
            } else {
                decodeResource = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(decodeResource);
                drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                drawable.draw(canvas);
            }
        }
        if (decodeResource == null) {
            return null;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        decodeResource.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        return "data:image/png;base64," + Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2);
    }

    public static String getCarrierOperatorName(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        return telephonyManager != null ? telephonyManager.getNetworkOperatorName() : PERMISSION_DISABLED;
    }

    public static String getCellularNetworkProviderName(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(context, "phone");
        return telephonyManager != null ? telephonyManager.getNetworkOperatorName() : "unknown";
    }

    public static String getCellularNetworkType(Context context) {
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
            if (a.checkSelfPermission(context, "android.permission.READ_PHONE_STATE") != 0) {
                switch (telephonyManager.getNetworkType()) {
                }
                return "NA";
            }
        } catch (Exception e) {
            AnalyticsUtil.reportError(e.getMessage(), "S2", e.getLocalizedMessage());
        }
        return "NA";
    }

    public static NetworkType getDataNetworkType(Context context) {
        ConnectivityManager connectivityManager;
        if (hasPermission(context, "android.permission.ACCESS_NETWORK_STATE") && (connectivityManager = (ConnectivityManager) getSystemService(context, "connectivity")) != null) {
            NetworkInfo networkInfo = connectivityManager.getNetworkInfo(1);
            if (networkInfo != null && networkInfo.isConnected()) {
                return NetworkType.WIFI;
            }
            NetworkInfo networkInfo2 = connectivityManager.getNetworkInfo(7);
            if (networkInfo2 != null && networkInfo2.isConnected()) {
                return NetworkType.BLUETOOTH;
            }
            NetworkInfo networkInfo3 = connectivityManager.getNetworkInfo(0);
            if (networkInfo3 != null && networkInfo3.isConnected()) {
                return NetworkType.CELLULAR;
            }
        }
        return NetworkType.UNKNOWN;
    }

    public static Map<String, String> getDeviceAttributes(Context context) {
        HashMap hashMap = new HashMap();
        if (context.checkCallingOrSelfPermission("android.permission.READ_PHONE_STATE") == 0) {
            context.getSystemService("phone");
            hashMap.put(PayUtility.DEVICE_ID, BaseConfig.getAdvertisingId(context));
            hashMap.put("sim_serial_number", PERMISSION_DISABLED);
            hashMap.put("build_unique_id", UUID.randomUUID().toString());
        } else {
            hashMap.put(PayUtility.DEVICE_ID, PERMISSION_DISABLED);
            hashMap.put("sim_serial_number", PERMISSION_DISABLED);
        }
        hashMap.put("device_manufacturer", Build.MANUFACTURER);
        hashMap.put("device_model", Build.MODEL);
        return hashMap;
    }

    public static void getDeviceParamValues(final Context context, final RzpJSONCallback rzpJSONCallback) {
        final JSONObject jSONObject = new JSONObject();
        try {
            fetchIP(new c__C_());
            AdvertisingIdUtil.getId(context, new AdvertisingIdUtil.AdvertisingIdCallback() {
                @Override
                public final void onResult(String str) {
                    try {
                        jSONObject.put("advertising_id", str);
                        jSONObject.put("is_roming", BaseUtils.isNetworkRoaming(context));
                        jSONObject.put("carrier_network", BaseUtils.getCarrierOperatorName(context));
                        jSONObject.put("carrier_id", "null");
                        Map<String, String> deviceAttributes = BaseUtils.getDeviceAttributes(context);
                        jSONObject.put("device_Id", deviceAttributes.get("device_Id"));
                        jSONObject.put("device_manufacturer", deviceAttributes.get("device_manufacturer"));
                        jSONObject.put("device_model", deviceAttributes.get("device_model"));
                        jSONObject.put("serial_number", BaseUtils.buildSerial());
                        jSONObject.put("ip_address", BaseUtils.ipAddress);
                        jSONObject.put("wifi_ssid", BaseUtils.getWifiSSID(context));
                        jSONObject.put("android_id", BaseUtils.getAndroidId(context));
                        jSONObject.put("safety_net basic_integrity", "true");
                        jSONObject.put("safety_net_cts_profile_match", "null");
                        rzpJSONCallback.onResponse(jSONObject);
                    } catch (JSONException e) {
                        AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
                    }
                }
            });
        } catch (Exception e) {
            AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
        }
    }

    public static int getDisplayHeight(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.heightPixels;
    }

    public static String getDisplayResolution(Context context) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        Locale locale = Locale.ENGLISH;
        return displayMetrics.widthPixels + "x" + displayMetrics.heightPixels + "x" + displayMetrics.densityDpi;
    }

    public static int getDisplayWidth(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.widthPixels;
    }

    public static String getFileFromInternal(Activity activity, String str, String str2) {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(activity.openFileInput(getVersionedAssetName(getLocalVersion(activity, str2).toString(), str)), "UTF-8"));
        StringBuilder sb = new StringBuilder();
        while (true) {
            String readLine = bufferedReader.readLine();
            if (readLine == null) {
                bufferedReader.close();
                return decryptFile(sb.toString());
            }
            sb.append(readLine);
        }
    }

    public static String getGenericPaymentErrorResponse(String str) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(BridgeHandler.CODE, "BAD_REQUEST_ERROR");
            jSONObject.put("description", str);
            jSONObject.put("source", "customer");
            jSONObject.put("step", "payment_authentication");
            jSONObject.put("reason", "payment_timeout");
            return new JSONObject().put("error", jSONObject).toString();
        } catch (JSONException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
            return null;
        }
    }

    public static BaseUtils getInstance() {
        BaseUtils baseUtils2 = baseUtils;
        if (baseUtils2 != null) {
            return baseUtils2;
        }
        BaseUtils baseUtils3 = new BaseUtils();
        baseUtils = baseUtils3;
        return baseUtils3;
    }

    public static JSONObject getJSONFromIntentData(Intent intent) {
        Bundle extras;
        JSONObject jSONObject = new JSONObject();
        if (intent != null && (extras = intent.getExtras()) != null) {
            for (String str : extras.keySet()) {
                try {
                    jSONObject.put(str, extras.get(str));
                } catch (JSONException e) {
                    AnalyticsUtil.reportError(e.getMessage(), "error:exception", e.getLocalizedMessage());
                }
            }
        }
        return jSONObject;
    }

    public static Object getJsonValue(String str, JSONObject jSONObject, Object obj) {
        Object jsonValue = getJsonValue(str.split("\\."), jSONObject, 0);
        return jsonValue != null ? jsonValue : obj;
    }

    public static String getKeyId(Context context) {
        try {
            Bundle bundle = context.getPackageManager().getApplicationInfo(context.getPackageName(), UserMetadata.MAX_ROLLOUT_ASSIGNMENTS).metaData;
            if (bundle == null) {
                return null;
            }
            return bundle.getString("com.razorpay.ApiKey");
        } catch (PackageManager.NameNotFoundException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getMessage());
            return null;
        }
    }

    public static List<ResolveInfo> getListOfAppsWhichHandleDeepLink(Context context, String str) {
        Intent intent = new Intent();
        intent.setData(Uri.parse(str));
        return context.getPackageManager().queryIntentActivities(intent, 131072);
    }

    public static String getLocalVersion(Activity activity, String str) {
        String a = E$_q$.a(activity, str);
        return a == null ? getVersionFromJsonString("{\n  \"hash\" : \"MD5\",\n  \"magic_hash\": \"MD5\"\n}\n", str) : a;
    }

    public static String getLocale() {
        return Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry();
    }

    public static HashMap<String, String> getMapFromJSONObject(JSONObject jSONObject) {
        HashMap<String, String> hashMap = new HashMap<>();
        try {
            Iterator<String> keys = jSONObject.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                hashMap.put(next, jSONObject.getString(next));
            }
        } catch (Exception e) {
            AnalyticsUtil.reportError(e.getMessage(), "error:exception", e.getMessage());
            e.printStackTrace();
        }
        return hashMap;
    }

    public static int getNetworkType(Context context) {
        NetworkType dataNetworkType = getDataNetworkType(context);
        if (dataNetworkType == NetworkType.WIFI) {
            return 0;
        }
        if (dataNetworkType == NetworkType.BLUETOOTH) {
            return 1;
        }
        if (dataNetworkType != NetworkType.CELLULAR) {
            return -1;
        }
        String cellularNetworkType = getCellularNetworkType(context);
        if (cellularNetworkType.equalsIgnoreCase("2G")) {
            return 2;
        }
        if (cellularNetworkType.equalsIgnoreCase("3G")) {
            return 3;
        }
        return cellularNetworkType.equalsIgnoreCase("4G") ? 4 : -1;
    }

    public static String getPaymentCancelledResponse(String str) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(BridgeHandler.CODE, "BAD_REQUEST_ERROR");
            jSONObject.put("description", "Payment processing cancelled by user");
            jSONObject.put("source", "customer");
            jSONObject.put("step", "payment_authentication");
            jSONObject.put("reason", "payment_cancelled");
            if (str != null) {
                if (str.startsWith("pay")) {
                    JSONObject jSONObject2 = new JSONObject();
                    jSONObject2.put("payment_id", str);
                    jSONObject.put("metadata", jSONObject2);
                } else {
                    jSONObject.put("metadata", new JSONObject(str));
                }
            }
            return new JSONObject().put("error", jSONObject).toString();
        } catch (JSONException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
            return null;
        }
    }

    public static String getRandomString() {
        return new BigInteger(130, new SecureRandom()).toString(32);
    }

    public static JSONObject getResponseJson(HttpsURLConnection httpsURLConnection) {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream()));
        StringBuilder sb = new StringBuilder();
        while (true) {
            String readLine = bufferedReader.readLine();
            if (readLine == null) {
                bufferedReader.close();
                return new JSONObject(sb.toString());
            }
            sb.append(readLine);
        }
    }

    public static HashSet<String> getSetOfPackageNamesSupportingUpi(Context context) {
        List<ResolveInfo> listOfAppsWhichHandleDeepLink = getListOfAppsWhichHandleDeepLink(context, "upi://pay");
        HashSet<String> hashSet = new HashSet<>();
        if (listOfAppsWhichHandleDeepLink != null && listOfAppsWhichHandleDeepLink.size() > 0) {
            Iterator<ResolveInfo> it = listOfAppsWhichHandleDeepLink.iterator();
            while (it.hasNext()) {
                try {
                    hashSet.add(it.next().activityInfo.packageName);
                } catch (Exception e) {
                    AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
                }
            }
        }
        if (hashSet.size() > 0 && !checkUpiRegisteredApp(context, "com.google.android.apps.nbu.paisa.user")) {
            hashSet.remove("com.google.android.apps.nbu.paisa.user");
        }
        if (hashSet.size() > 0 && !checkUpiRegisteredApp(context, "com.truecaller")) {
            hashSet.remove("com.truecaller");
        }
        return hashSet;
    }

    public static void getSignalStrength(Context context) {
        ((TelephonyManager) context.getSystemService("phone")).listen(new PhoneStateListener() {
            @Override
            public final void onSignalStrengthsChanged(SignalStrength signalStrength) {
                super.onSignalStrengthsChanged(signalStrength);
                if (!signalStrength.isGsm()) {
                    signalStrength.getCdmaDbm();
                } else if (signalStrength.getGsmSignalStrength() != 99) {
                    signalStrength.getGsmSignalStrength();
                } else {
                    signalStrength.getGsmSignalStrength();
                }
            }
        }, 256);
    }

    public static <T> T getSystemService(Context context, String str) {
        return (T) context.getApplicationContext().getSystemService(str);
    }

    public static String getVersionFromJsonString(String str, String str2) {
        try {
            JSONObject jSONObject = new JSONObject(str);
            if (str2.equalsIgnoreCase("otpelf_version")) {
                return jSONObject.getString("hash");
            }
            if (str2.equalsIgnoreCase("magic_version")) {
                return jSONObject.getString("magic_hash");
            }
            return null;
        } catch (Exception unused) {
            return null;
        }
    }

    public static String getVersionedAssetName(String str, String str2) {
        return C1071d.b(str.replaceAll("\\.", "-"), "-", str2);
    }

    public static CharSequence getWebViewUserAgent(Context context) {
        return AnalyticsUtil.returnUndefinedIfNull(new WebView(context).getSettings().getUserAgentString());
    }

    public static String getWifiSSID(Context context) {
        return context.checkCallingOrSelfPermission("android.permission.ACCESS_WIFI_STATE") == 0 ? ((WifiManager) context.getApplicationContext().getSystemService("wifi")).getConnectionInfo().getSSID() : PERMISSION_DISABLED;
    }

    public static Certificate getX509Certificate(SslCertificate sslCertificate) {
        byte[] byteArray = SslCertificate.saveState(sslCertificate).getByteArray("x509-certificate");
        if (byteArray == null) {
            return null;
        }
        try {
            return CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(byteArray));
        } catch (CertificateException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
            return null;
        }
    }

    public static boolean hasFeature(Context context, String str) {
        return context.getPackageManager().hasSystemFeature(str);
    }

    public static boolean hasPermission(Context context, String str) {
        try {
            return context.checkCallingOrSelfPermission(str) == 0;
        } catch (Exception e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getMessage());
            return false;
        }
    }

    public static String installedApps(Context context) {
        StringBuilder sb = new StringBuilder();
        try {
            for (ApplicationInfo applicationInfo : context.getPackageManager().getInstalledApplications(0)) {
                if ((applicationInfo.flags & 1) == 0) {
                    if (sb.length() != 0) {
                        sb.append(",");
                    }
                    sb.append(applicationInfo.packageName);
                }
            }
            return sb.toString();
        } catch (Throwable unused) {
            return "Apps not available";
        }
    }

    public static boolean isDeviceHaveCorrectTlsVersion() {
        String[] protocols;
        try {
            protocols = SSLContext.getDefault().getDefaultSSLParameters().getProtocols();
        } catch (NoSuchAlgorithmException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getMessage());
        }
        if (protocols == null) {
            return false;
        }
        for (String str : protocols) {
            if (str.startsWith("TLS") && !str.equalsIgnoreCase("TLSv1")) {
                return true;
            }
        }
        return false;
    }

    public static boolean isMerchantAppDebuggable(Context context) {
        return (context.getApplicationInfo().flags & 2) != 0;
    }

    private boolean isMocked(Context context, Location location) {
        return location.isFromMockProvider();
    }

    public static boolean isNetworkRoaming(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (telephonyManager != null) {
            return telephonyManager.isNetworkRoaming();
        }
        return false;
    }

    private static Boolean isUserRegisteredOnTruePay(Context context) {
        try {
            boolean z = true;
            if (context.getPackageManager().getComponentEnabledSetting(new ComponentName("com.truecaller", "com.truecaller.truepay.UserRegistered")) != 1) {
                z = false;
            }
            return Boolean.valueOf(z);
        } catch (Exception e) {
            e.printStackTrace();
            AnalyticsUtil.reportError(e.getMessage(), "S1", e.getMessage());
            return Boolean.FALSE;
        }
    }

    public static ArrayList<String> jsonStringArrayToArrayList(JSONArray jSONArray) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < jSONArray.length(); i++) {
            arrayList.add(jSONArray.getString(i));
        }
        return arrayList;
    }

    public static String makeErrorPayload(String str, String str2) {
        try {
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put(BridgeHandler.CODE, str);
            jSONObject2.put("description", str2);
            jSONObject.put("error", jSONObject2);
            return jSONObject.toString();
        } catch (JSONException e) {
            AnalyticsUtil.reportError(e.getMessage(), "error:exception", e.getMessage());
            e.printStackTrace();
            return "{\"error\":{\"code\": \"BAD_REQUEST_ERROR\", \"description\": \"An unknown error occurred.\"}}";
        }
    }

    public static String makeUrlEncodedPayload(JSONObject jSONObject) {
        StringBuilder sb = new StringBuilder();
        Iterator<String> keys = jSONObject.keys();
        while (keys.hasNext()) {
            String next = keys.next();
            sb.append(next + "=" + Uri.encode(jSONObject.getString(next)) + "&");
        }
        return sb.deleteCharAt(sb.length() - 1).toString();
    }

    public static String nanoTimeToSecondsString(long j, int i) {
        double round = round(j / 1.0E9d, i);
        StringBuilder sb = new StringBuilder();
        sb.append(round);
        return sb.toString();
    }

    public static void pdfDownloadHelper(Activity activity, String str, String str2) {
        try {
            FileOutputStream openFileOutput = activity.openFileOutput(str, 0);
            openFileOutput.write(Base64.decode(str2, 0));
            openFileOutput.close();
        } catch (Exception unused) {
        }
        try {
            Uri d = FileProvider.d(activity, activity.getApplicationContext().getPackageName(), new File(activity.getFilesDir().toString() + "/" + str + ".pdf"));
            Intent intent = new Intent("android.intent.action.CREATE_DOCUMENT");
            intent.addCategory("android.intent.category.OPENABLE");
            intent.putExtra("android.intent.extra.TITLE", str);
            intent.setDataAndType(d, "application/pdf");
            if (Build.VERSION.SDK_INT >= 26) {
                intent.putExtra("android.provider.extra.INITIAL_URI", Uri.parse("/Documents"));
            }
            activity.startActivityForResult(intent, 77);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static double round(double d, int i) {
        if (i >= 0) {
            return new BigDecimal(d).setScale(i, RoundingMode.HALF_UP).doubleValue();
        }
        throw new IllegalArgumentException();
    }

    private static void setBaseWebViewSettings() {
        WebView.setWebContentsDebuggingEnabled(sWebViewDebuggingEnabled);
    }

    public static void setCompatibleWithGooglePay(boolean z) {
        isCompatibleWithGooglePay = z;
    }

    public static void setIsGpayCardsUpiRegistered(boolean z) {
        isGpayCardsUpiRegistered = z;
    }

    public static void setWebViewSettings(final Context context, WebView webView, boolean z) {
        setBaseWebViewSettings();
        enableJavaScriptInWebView(webView);
        CookieManager.getInstance().setAcceptCookie(true);
        webView.setTag("");
        WebSettings settings = webView.getSettings();
        settings.setDomStorageEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setTextZoom(100);
        String path = context.getApplicationContext().getDir("database", 0).getPath();
        if (Build.VERSION.SDK_INT < 24) {
            settings.setGeolocationDatabasePath(path);
        }
        CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
        if (z) {
            settings.setCacheMode(2);
        }
        settings.setSaveFormData(false);
        webView.addJavascriptInterface(new Object(context) {
            private SharedPreferences a;
            private SharedPreferences.Editor b;

            {
                this.a = context.getSharedPreferences("rzp_preferences_storage_bridge", 0);
                this.b = context.getSharedPreferences("rzp_preferences_storage_bridge", 0).edit();
            }

            @JavascriptInterface
            public final boolean getBoolean(String str) {
                try {
                    return this.a.getBoolean(str, false);
                } catch (Exception unused) {
                    return false;
                }
            }

            @JavascriptInterface
            public final float getFloat(String str) {
                try {
                    return this.a.getFloat(str, 0.0f);
                } catch (Exception unused) {
                    return 0.0f;
                }
            }

            @JavascriptInterface
            public final int getInt(String str) {
                try {
                    return this.a.getInt(str, 0);
                } catch (Exception unused) {
                    return 0;
                }
            }

            @JavascriptInterface
            public final String getString(String str) {
                try {
                    return this.a.getString(str, null);
                } catch (Exception unused) {
                    return null;
                }
            }

            @JavascriptInterface
            public final void setBoolean(String str, boolean z2) {
                try {
                    this.b.putBoolean(str, z2);
                    this.b.commit();
                } catch (Exception e) {
                    d__1_.a("Error saving boolean", e);
                }
            }

            @JavascriptInterface
            public final void setFloat(String str, float f) {
                try {
                    this.b.putFloat(str, f);
                    this.b.commit();
                } catch (Exception e) {
                    d__1_.a("Error saving float", e);
                }
            }

            @JavascriptInterface
            public final void setInt(String str, int i) {
                try {
                    this.b.putInt(str, i);
                    this.b.commit();
                } catch (Exception e) {
                    d__1_.a("Error saving integer", e);
                }
            }

            @JavascriptInterface
            public final void setString(String str, String str2) {
                try {
                    this.b.putString(str, str2);
                    this.b.commit();
                } catch (Exception e) {
                    d__1_.a("Error saving string", e);
                }
            }
        }, "StorageBridge");
    }

    public static void setup() {
        AnalyticsUtil.reset();
    }

    public static void startActivityForResult(String str, String str2, Activity activity) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setData(Uri.parse(str));
            if (str2 != null && str2.length() > 0) {
                intent.setPackage(str2);
            }
            if (str.startsWith("credpay")) {
                activity.startActivityForResult(intent, 20);
            } else {
                activity.startActivityForResult(intent, 99);
            }
        } catch (ActivityNotFoundException e) {
            AnalyticsUtil.reportError("BaseUtils", "S2", e.getMessage());
        }
    }

    public static boolean storeFileInInternal(Activity activity, String str, String str2) {
        try {
            FileOutputStream openFileOutput = activity.openFileOutput(str, 0);
            openFileOutput.write(str2.getBytes());
            openFileOutput.close();
            return true;
        } catch (Exception e) {
            AnalyticsUtil.reportError(e.getMessage(), "S1", e.a("Error in saving file: ", str));
            r.b("Error in saving file: ", str, "com.razorpay.checkout");
            return false;
        }
    }

    public static void updateLocalVersion(Activity activity, String str, String str2) {
        E$_q$.b(activity, str, str2);
    }

    public String getMetadata() {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("payment_id", this.paymentId);
            jSONObject.put("order_id", this.orderId);
            return jSONObject.toString();
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }

    public String getSystemFontSize(Context context) {
        return String.valueOf(context.getResources().getConfiguration().fontScale);
    }

    public void setOrderId(String str) {
        this.orderId = str;
    }

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

    private static Object getJsonValue(String[] strArr, Object obj, int i) {
        while (i != strArr.length) {
            String str = strArr[i];
            if (obj instanceof JSONObject) {
                obj = ((JSONObject) obj).opt(str);
            } else {
                if (!(obj instanceof JSONArray)) {
                    return null;
                }
                JSONArray jSONArray = (JSONArray) obj;
                if (!TextUtils.isDigitsOnly(str)) {
                    return null;
                }
                obj = jSONArray.opt(Integer.parseInt(str));
            }
            i++;
        }
        return obj;
    }

    public static String getGenericPaymentErrorResponse(String str, String str2) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(BridgeHandler.CODE, "BAD_REQUEST_ERROR");
            jSONObject.put("description", str);
            jSONObject.put("source", "customer");
            jSONObject.put("step", "payment_authentication");
            jSONObject.put("reason", "payment_error");
            if (str2 != null) {
                jSONObject.put("metadata", new JSONObject(str2));
            }
            return new JSONObject().put("error", jSONObject).toString();
        } catch (JSONException e) {
            AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
            return null;
        }
    }
}