正在查看: Chaupal v3.2 应用的 BaseUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Chaupal v3.2 应用的 BaseUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.razorpay;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
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.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import com.google.firebase.perf.network.FirebasePerfUrlConnection;
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 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 final String PERMISSION_DISABLED = "permission disabled";
static String apiKey;
private static BaseUtils baseUtils;
static String ipAddress;
private String orderId;
private String paymentId;
private static final boolean sWebViewDebuggingEnabled = Z$_A_.a.booleanValue();
private static boolean isCompatibleWithGooglePay = true;
private static boolean isGpayCardsUpiRegistered = false;
BaseUtils() {
}
static String buildSerial() {
return Build.SERIAL;
}
static void checkForLatestVersion(Context context, int i) {
if (e_$r$.a().isSDKUpdateAlertEnabled() && isMerchantAppDebuggable(context) && i < e_$r$.a().getLatestSDKVersionCode()) {
Toast.makeText(context, e_$r$.a().getUpdateSDKMsg(), 1).show();
}
}
public static boolean checkGpayCardsUpiRegistered(android.app.Activity r3, java.lang.String r4) {
throw new UnsupportedOperationException("Method not decompiled: com.razorpay.BaseUtils.checkGpayCardsUpiRegistered(android.app.Activity, java.lang.String):boolean");
}
static boolean checkUpiRegisteredApp(Context context, String str) {
str.hashCode();
if (str.equals("com.google.android.apps.nbu.paisa.user")) {
return isCompatibleWithGooglePay;
}
return true;
}
static String constructBasicAuth(String str) {
return Base64.encodeToString((str + ":").getBytes("UTF-8"), 2);
}
static PublicKey constructPublicKey(String str) {
try {
return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str.getBytes(), 0)));
} catch (Exception unused) {
return null;
}
}
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;
}
}
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);
}
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 th) {
th = th;
}
} catch (SocketTimeoutException unused) {
} catch (Exception e) {
e = e;
}
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 unused2) {
httpsURLConnection2 = httpsURLConnection;
RzpJSONCallback.this.onResponse(new JSONObject().put("error", "timeout"));
if (httpsURLConnection2 == null) {
return;
}
httpsURLConnection2.disconnect();
} catch (Exception e2) {
e = e2;
httpsURLConnection2 = httpsURLConnection;
AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
if (httpsURLConnection2 == null) {
return;
}
httpsURLConnection2.disconnect();
} catch (Throwable th2) {
th = th2;
httpsURLConnection2 = httpsURLConnection;
if (httpsURLConnection2 != null) {
httpsURLConnection2.disconnect();
}
throw th;
}
} catch (Exception e3) {
AnalyticsUtil.reportError(e3.getMessage(), "S2", e3.getMessage());
}
}
}).start();
}
static HashMap<String, String> getAllPluginsFromManifest(Context context) {
ApplicationInfo applicationInfo;
try {
applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128);
} 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 e10) {
e = e10;
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;
}
static String getAndroidId(Context context) {
return Settings.Secure.getString(context.getContentResolver(), "android_id");
}
static String getAppBuildType(Context context) {
return (context.getApplicationInfo().flags & 2) != 0 ? "development" : "production";
}
static String getAppNameOfPackageName(String str, Context context) {
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(str, 128);
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;
}
}
static String getAppNameOfResolveInfo(ResolveInfo resolveInfo, Context context) {
return getAppNameOfPackageName(resolveInfo.activityInfo.packageName, context);
}
public static ArrayList<String> getAppsWithPackageNames(Context context, ArrayList<String> arrayList) {
ArrayList<String> arrayList2 = new ArrayList<>();
if (arrayList != null && !arrayList.isEmpty()) {
Iterator<String> it = arrayList.iterator();
while (it.hasNext()) {
String next = it.next();
if (next != null && !next.isEmpty() && isAppInstalled(context, next)) {
arrayList2.add(next);
}
}
}
return arrayList2;
}
static String getBase64FromDrawable(Resources resources, Drawable drawable) {
Bitmap decodeResource = BitmapFactory.decodeResource(resources, R.drawable.rzp_logo);
if (drawable != 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) {
if (decodeResource != null && !decodeResource.isRecycled()) {
decodeResource.recycle();
}
return null;
}
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
decodeResource.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
String str = "data:image/png;base64," + Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2);
if (!decodeResource.isRecycled()) {
decodeResource.recycle();
}
return str;
} catch (Exception unused) {
if (!decodeResource.isRecycled()) {
decodeResource.recycle();
}
return null;
} catch (Throwable th) {
if (!decodeResource.isRecycled()) {
decodeResource.recycle();
}
throw th;
}
}
static String getBase64FromOtherAppsResource(Context context, String str) {
PackageManager packageManager = context.getPackageManager();
try {
return getBase64FromDrawable(packageManager.getResourcesForApplication(Build.VERSION.SDK_INT >= 33 ? packageManager.getApplicationInfo(str, PackageManager.ApplicationInfoFlags.of(0L)) : packageManager.getApplicationInfo(str, 128)), packageManager.getApplicationIcon(str));
} catch (PackageManager.NameNotFoundException e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
return null;
}
}
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;
}
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
decodeResource.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
return "data:image/png;base64," + Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2);
} catch (Exception unused) {
return null;
}
}
static String getCarrierOperatorName(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
return telephonyManager != null ? telephonyManager.getNetworkOperatorName() : PERMISSION_DISABLED;
}
static String getCellularNetworkProviderName(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(context, "phone");
return telephonyManager != null ? telephonyManager.getNetworkOperatorName() : "unknown";
}
static String getCellularNetworkType(Context context) {
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
if (androidx.core.content.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";
}
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;
}
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("device_id", BaseConfig.getAdvertisingId(context));
hashMap.put("sim_serial_number", PERMISSION_DISABLED);
hashMap.put("build_unique_id", UUID.randomUUID().toString());
} else {
hashMap.put("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;
}
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());
}
}
static int getDisplayHeight(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels;
}
static String getDisplayResolution(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return String.format(Locale.ENGLISH, "%dx%dx%d", Integer.valueOf(displayMetrics.widthPixels), Integer.valueOf(displayMetrics.heightPixels), Integer.valueOf(displayMetrics.densityDpi));
}
static int getDisplayWidth(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.widthPixels;
}
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 sb2 = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
bufferedReader.close();
return decryptFile(sb2.toString());
}
sb2.append(readLine);
}
}
static String getGenericPaymentErrorResponse(String str) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", "BAD_REQUEST_ERROR");
jSONObject.put("description", str);
jSONObject.put("source", "customer");
jSONObject.put("step", "payment_authentication");
jSONObject.put("reason", "payload_error");
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;
}
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;
}
static Object getJsonValue(String str, JSONObject jSONObject, Object obj) {
Object jsonValue;
try {
jsonValue = getJsonValue(str.split("\\."), jSONObject, 0);
} catch (Exception unused) {
}
return jsonValue != null ? jsonValue : obj;
}
static String getKeyId(Context context) {
try {
String str = apiKey;
if (str != null) {
return str;
}
Bundle bundle = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128).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;
}
}
static List<ResolveInfo> getListOfAppsWhichHandleDeepLink(Context context, String str) {
Intent intent = new Intent();
intent.setData(Uri.parse(str));
return context.getPackageManager().queryIntentActivities(intent, 131072);
}
static String getLocalVersion(Activity activity, String str) {
String a = A.a(activity, str);
return a == null ? getVersionFromJsonString("{\n \"hash\" : \"c4171614448e750850bd4daca2c7e8d1\",\n \"magic_hash\": \"e1ff492228196aa72f4892db1e05624e\"\n}\n", str) : a;
}
static String getLocale() {
return Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry();
}
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());
}
return hashMap;
}
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;
}
static String getPaymentCancelledResponse(String str) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", "BAD_REQUEST_ERROR");
jSONObject.put("description", "You may have cancelled the payment or there was a delay in response from the UPI app");
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;
}
}
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 sb2 = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
bufferedReader.close();
return new JSONObject(sb2.toString());
}
sb2.append(readLine);
}
}
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;
}
static HashSet<String> getSetOfPackageNamesSupportingUpiAutopay(Context context) {
List<ResolveInfo> listOfAppsWhichHandleDeepLink = getListOfAppsWhichHandleDeepLink(context, "upi://mandate");
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());
}
}
}
return hashSet;
}
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);
}
static <T> T getSystemService(Context context, String str) {
return (T) context.getApplicationContext().getSystemService(str);
}
@NonNull
static String getType(String str) {
str.hashCode();
switch (str) {
case "gif":
return "image/gif";
case "jpg":
case "jpeg":
return "image/jpeg";
case "png":
return "image/png";
default:
return "application/octet-stream";
}
}
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;
}
}
static String getVersionedAssetName(String str, String str2) {
return str.replaceAll("\\.", "-") + "-" + str2;
}
static CharSequence getWebViewUserAgent(Context context) {
try {
return AnalyticsUtil.returnUndefinedIfNull(new WebView(context).getSettings().getUserAgentString());
} catch (Exception unused) {
return "undefined";
}
}
static String getWifiSSID(Context context) {
return context.checkCallingOrSelfPermission("android.permission.ACCESS_WIFI_STATE") == 0 ? ((WifiManager) context.getApplicationContext().getSystemService("wifi")).getConnectionInfo().getSSID() : PERMISSION_DISABLED;
}
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;
}
}
static boolean hasFeature(Context context, String str) {
return context.getPackageManager().hasSystemFeature(str);
}
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;
}
}
static String installedApps(Context context) {
StringBuilder sb2 = new StringBuilder();
try {
for (ApplicationInfo applicationInfo : context.getPackageManager().getInstalledApplications(0)) {
if ((applicationInfo.flags & 1) == 0) {
if (sb2.length() != 0) {
sb2.append(",");
}
sb2.append(applicationInfo.packageName);
}
}
return sb2.toString();
} catch (Throwable unused) {
return "Apps not available";
}
}
static boolean isAppInstalled(Context context, String str) {
PackageManager packageManager = context.getPackageManager();
return ((Build.VERSION.SDK_INT >= 33 ? packageManager.getPackageInfo(str, PackageManager.PackageInfoFlags.of(0L)) : packageManager.getPackageInfo(str, 0)).applicationInfo.flags & 8388608) != 0;
}
static boolean isAppInstalledAndEnabled(Context context, String str) {
try {
PackageManager packageManager = context.getPackageManager();
return (Build.VERSION.SDK_INT >= 33 ? packageManager.getApplicationInfo(str, PackageManager.ApplicationInfoFlags.of(0L)) : packageManager.getApplicationInfo(str, 0)).enabled;
} catch (PackageManager.NameNotFoundException unused) {
return false;
}
}
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;
}
static boolean isMerchantAppDebuggable(Context context) {
return (context.getApplicationInfo().flags & 2) != 0;
}
private boolean isMocked(Context context, Location location) {
return location.isFromMockProvider();
}
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;
}
}
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;
}
static String makeErrorPayload(String str, String str2) {
try {
JSONObject jSONObject = new JSONObject();
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("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.\"}}";
}
}
static String makeUrlEncodedPayload(JSONObject jSONObject) {
StringBuilder sb2 = new StringBuilder();
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
sb2.append(String.format("%s=%s&", next, Uri.encode(jSONObject.getString(next))));
}
return sb2.deleteCharAt(sb2.length() - 1).toString();
}
public static String nanoTimeToSecondsString(long j, int i) {
double round = round(j / 1.0E9d, i);
StringBuilder sb2 = new StringBuilder();
sb2.append(round);
return sb2.toString();
}
static void openFile(Activity activity, Uri uri) {
try {
Intent intent = new Intent("android.intent.action.VIEW");
intent.setData(uri);
intent.setFlags(1);
if (activity.getPackageManager().queryIntentActivities(intent, 0).isEmpty()) {
Toast.makeText(activity, "No app found to open PDF", 1).show();
} else {
activity.startActivity(intent);
}
} catch (ActivityNotFoundException e) {
e.getMessage();
}
}
static void openPdfFile(Activity activity, Uri uri) {
try {
Intent intent = new Intent("android.intent.action.VIEW");
intent.setDataAndType(uri, "application/pdf");
intent.setFlags(1);
if (activity.getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
activity.startActivity(intent);
} else {
Toast.makeText(activity, "No app found to open PDF", 1).show();
}
} catch (ActivityNotFoundException e) {
e.getMessage();
}
}
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 e) {
System.out.println(e.getMessage());
}
try {
Uri f = FileProvider.f(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(f, "application/pdf");
if (Build.VERSION.SDK_INT >= 26) {
intent.putExtra("android.provider.extra.INITIAL_URI", Uri.parse("/Documents"));
}
activity.startActivityForResult(intent, 77);
} catch (Exception e2) {
e2.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() {
if (Build.VERSION.SDK_INT >= 19) {
WebView.setWebContentsDebuggingEnabled(sWebViewDebuggingEnabled);
}
}
static void setCompatibleWithGooglePay(boolean z) {
isCompatibleWithGooglePay = z;
}
static void setIsGpayCardsUpiRegistered(boolean z) {
isGpayCardsUpiRegistered = z;
}
static void setWebViewSettings(Context context, WebView webView, boolean z) {
setBaseWebViewSettings();
enableJavaScriptInWebView(webView);
CookieManager.getInstance().setAcceptCookie(true);
webView.setTag("razorpay");
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setTextZoom(100);
String path = context.getApplicationContext().getDir("database", 0).getPath();
int i = Build.VERSION.SDK_INT;
if (i < 19) {
settings.setDatabasePath(path);
}
if (i < 24) {
settings.setGeolocationDatabasePath(path);
}
if (i >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
settings.setCacheMode(-1);
if (z) {
settings.setCacheMode(2);
}
settings.setSaveFormData(false);
webView.addJavascriptInterface(new StorageBridge(context), "StorageBridge");
settings.setAllowFileAccess(false);
settings.setAllowFileAccessFromFileURLs(false);
settings.setAllowUniversalAccessFromFileURLs(false);
settings.setAllowContentAccess(false);
}
static void setup() {
AnalyticsUtil.reset();
}
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.isEmpty()) {
intent.setPackage(str2);
}
if (str.startsWith("credpay")) {
activity.startActivityForResult(intent, 20);
return;
}
if (str.startsWith("truecallersdk://truesdk")) {
activity.startActivityForResult(intent, 101);
} else if (str.contains("tngdigital") && str2 != null && str2.equalsIgnoreCase("my.com.tngdigital.ewallet")) {
activity.startActivity(intent);
} else {
activity.startActivityForResult(intent, 99);
}
} catch (ActivityNotFoundException e) {
AnalyticsUtil.reportError("BaseUtils", "S2", e.getMessage());
}
}
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", "Error in saving file: " + str);
return false;
}
}
static void updateLocalVersion(Activity activity, String str, String str2) {
A.b(activity, str, str2);
}
public void clearMetadata() {
this.paymentId = null;
this.orderId = null;
}
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;
}
}
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;
}
static String getGenericPaymentErrorResponse(String str, String str2, String str3) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", "BAD_REQUEST_ERROR");
jSONObject.put("description", str2);
jSONObject.put("source", "customer");
jSONObject.put("step", "payment_authentication");
jSONObject.put("reason", new JSONObject().put("code", str).put("description", str2));
if (str3 != null) {
jSONObject.put("metadata", new JSONObject(str3));
}
return new JSONObject().put("error", jSONObject).toString();
} catch (JSONException e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
return null;
}
}
static String getGenericPaymentErrorResponse(String str, String str2) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("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;
}
}
}