正在查看: Housing v14.7.8 应用的 Lumberjack.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Housing v14.7.8 应用的 Lumberjack.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.razorpay;
import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import androidx.camera.camera2.internal.t2;
import com.newrelic.agent.android.instrumentation.Instrumented;
import com.newrelic.agent.android.instrumentation.JSONObjectInstrumentation;
import com.quickblox.core.ConstsInternal;
import com.quickblox.users.Consts;
import com.razorpay.AnalyticsProperty;
import io.sentry.protocol.f;
import io.sentry.protocol.m;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TimeZone;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import v4.c;
@Instrumented
final class Lumberjack {
private static boolean NETWORK_BLUETOOTH = false;
private static String NETWORK_CARRIER = null;
private static boolean NETWORK_CELLULAR = false;
private static String NETWORK_CELLULAR_TYPE = null;
private static boolean NETWORK_WIFI = false;
private static final String SAVED_EVENTS_DATA = "SavedEventsData";
private static float SCREEN_DENSITY;
private static int SCREEN_HEIGHT;
private static int SCREEN_WIDTH;
private static JSONObject contextJsonData;
private static JSONObject lumberjackPayload;
private static Map<String, Object> orderProperties;
private static Map<String, Object> paymentProperties;
private static String sdkVersion;
private static String DEVICE_MANUFACTURER = Build.MANUFACTURER;
private static String DEVICE_MODEL = Build.MODEL;
private static String DEVICE_NAME = Build.DEVICE;
private static boolean isLumberjackInitialized = false;
private static String sdkType = "standalone";
private static ArrayList<JSONObject> preInitBatch = new ArrayList<>();
class AnonymousClass3 {
static final int[] $SwitchMap$com$razorpay$NetworkType;
static {
int[] iArr = new int[NetworkType.values().length];
$SwitchMap$com$razorpay$NetworkType = iArr;
try {
iArr[NetworkType.WIFI.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$razorpay$NetworkType[NetworkType.CELLULAR.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$com$razorpay$NetworkType[NetworkType.BLUETOOTH.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
}
}
public static void addAmountToProperties(JSONObject jSONObject) {
try {
addOrderProperty("amount", Long.valueOf(Long.parseLong(getStringFromJsonObject(jSONObject, "amount"))));
} catch (Exception unused) {
}
}
public static void addFilteredPropertiesFromPayload(JSONObject jSONObject) {
try {
addAmountToProperties(jSONObject);
addFrameworkToProperties(jSONObject);
AnalyticsProperty.Scope scope = AnalyticsProperty.Scope.ORDER;
addPropertyFromJSONObject(jSONObject, "contact", scope);
addPropertyFromJSONObject(jSONObject, "email", scope);
addPropertyFromJSONObject(jSONObject, "order_id", scope);
String stringFromJsonObject = getStringFromJsonObject(jSONObject, "method");
if (stringFromJsonObject == null) {
return;
}
if (jSONObject.has("token")) {
stringFromJsonObject = "saved card";
}
addPaymentProperty("method", stringFromJsonObject);
if (stringFromJsonObject.equals("card")) {
String stringFromJsonObject2 = getStringFromJsonObject(jSONObject, "card[number]");
if (AnalyticsUtil.isNullOrEmpty(stringFromJsonObject2) || stringFromJsonObject2.length() < 6) {
return;
}
addPaymentProperty("card_number", stringFromJsonObject2.substring(0, 6));
return;
}
if (stringFromJsonObject.equals("saved card")) {
boolean booleanFromJsonObject = getBooleanFromJsonObject(jSONObject, "razorpay_otp");
StringBuilder sb = new StringBuilder();
sb.append(!booleanFromJsonObject);
addOrderProperty("Checkout Login", sb.toString());
return;
}
if (stringFromJsonObject.equals("netbanking")) {
addPropertyFromJSONObject(jSONObject, "bank", AnalyticsProperty.Scope.PAYMENT);
} else if (stringFromJsonObject.equals("wallet")) {
addPropertyFromJSONObject(jSONObject, "wallet", AnalyticsProperty.Scope.PAYMENT);
} else if (stringFromJsonObject.equals("upi")) {
addPaymentProperty("flow", getStringFromJsonObject(jSONObject, "_[flow]"));
}
} catch (Exception e) {
e.getMessage();
AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
}
}
public static void addFrameworkToProperties(JSONObject jSONObject) {
try {
addOrderProperty("framework", jSONObject.has("framework") ? getStringFromJsonObject(jSONObject, "framework") : "native");
} catch (Exception unused) {
}
}
public static JSONObject addGlobalProperties(JSONObject jSONObject) {
try {
JSONObject jSONObject2 = jSONObject.has("properties") ? jSONObject.getJSONObject("properties") : null;
if (jSONObject2 == null) {
jSONObject2 = new JSONObject();
}
jSONObject2.put("merchant_app_name", AnalyticsUtil.MERCHANT_APP_NAME);
jSONObject2.put("merchant_app_version", AnalyticsUtil.MERCHANT_APP_VERSION);
jSONObject2.put("merchant_app_build", AnalyticsUtil.MERCHANT_APP_BUILD);
jSONObject2.put("platform", "mobile_sdk");
jSONObject2.put("platform_version", sdkVersion);
jSONObject2.put(m.TYPE, "android");
jSONObject2.put("os_version", Build.VERSION.RELEASE);
jSONObject2.put("library", AnalyticsUtil.libraryType);
for (Map.Entry<String, Object> entry : paymentProperties.entrySet()) {
try {
jSONObject2.put(entry.getKey(), entry.getValue());
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", "Error adding analytics property " + entry.getKey() + " to JSONObject");
}
}
for (Map.Entry<String, Object> entry2 : orderProperties.entrySet()) {
try {
jSONObject2.put(entry2.getKey(), entry2.getValue());
} catch (Exception e2) {
AnalyticsUtil.reportError(e2.getMessage(), "S0", "Error adding analytics property " + entry2.getKey() + " to JSONObject");
}
}
jSONObject.put("properties", jSONObject2);
} catch (Exception unused) {
}
return jSONObject;
}
public static void addOrderProperty(String str, Object obj) {
orderProperties.put(str, obj);
}
public static void addPaymentProperty(String str, Object obj) {
paymentProperties.put(str, obj);
}
private static void addPropertyFromJSONObject(JSONObject jSONObject, String str, AnalyticsProperty.Scope scope) {
try {
Object valueFromJsonObject = getValueFromJsonObject(jSONObject, str);
if (valueFromJsonObject != null) {
if (scope == AnalyticsProperty.Scope.PAYMENT) {
addPaymentProperty(str, valueFromJsonObject);
} else if (scope == AnalyticsProperty.Scope.ORDER) {
addOrderProperty(str, valueFromJsonObject);
}
}
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
}
}
private static void addQueuedDataToBatch() {
Iterator<JSONObject> it = preInitBatch.iterator();
while (it.hasNext()) {
addToBatch(it.next());
}
clearPreInitData();
}
private static void addToBatch(JSONObject jSONObject) {
if (!isLumberjackInitialized) {
preInitBatch.add(jSONObject);
return;
}
try {
JSONObject addGlobalProperties = addGlobalProperties(jSONObject);
synchronized (lumberjackPayload) {
lumberjackPayload.getJSONArray("events").put(addGlobalProperties);
}
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", e.getMessage());
}
}
private static void clearEventData() {
clearEvents();
clearPreInitData();
}
private static void clearEvents() {
try {
JSONObject jSONObject = lumberjackPayload;
if (jSONObject == null) {
return;
}
synchronized (jSONObject) {
lumberjackPayload.put("events", new JSONArray());
}
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", e.getMessage());
}
}
public static void clearOrderProperties() {
orderProperties = new HashMap();
}
public static void clearPaymentProperties() {
paymentProperties = new HashMap();
}
private static void clearPreInitData() {
preInitBatch = new ArrayList<>();
}
public static JSONObject createBaseTrackEvent(String str) {
try {
return new JSONObject("{event: '" + str + "',timestamp: '" + getTimestamp() + "'}");
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", "Error in creating base for trackEvent");
return null;
}
}
public static void destroy() {
clearOrderProperties();
clearPaymentProperties();
clearEventData();
isLumberjackInitialized = false;
}
public static JSONObject filterEvent(JSONObject jSONObject) {
if (jSONObject.has("properties")) {
JSONObject jSONObject2 = jSONObject.getJSONObject("properties");
if (jSONObject2.has("url")) {
jSONObject2.put("url", filterUrl(jSONObject2.getString("url")));
}
jSONObject.put("properties", jSONObject2);
}
return jSONObject;
}
public static JSONObject filterPayload(JSONObject jSONObject) {
try {
JSONArray jSONArray = jSONObject.getJSONArray("events");
for (int i = 0; i < jSONArray.length(); i++) {
jSONArray.put(i, filterEvent(jSONArray.getJSONObject(i)));
}
jSONObject.put("events", jSONArray);
} catch (JSONException unused) {
}
return jSONObject;
}
public static String filterUrl(String str) {
return str.startsWith("data:") ? "Data present in url" : str;
}
public static boolean getBooleanFromJsonObject(JSONObject jSONObject, String str) {
try {
return jSONObject.getBoolean(str);
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
return false;
}
}
private static JSONObject getContextDataJson(Context context) {
JSONObject jSONObject = new JSONObject();
jSONObject.put("mode", AnalyticsUtil.getKeyType());
jSONObject.put(f.TYPE, getDeviceDataJson(context));
jSONObject.put("sdk", getSdkDataJson());
jSONObject.put("network", getNetworkDataJson(context));
jSONObject.put("screen", getScreenDataJson());
jSONObject.put("locale", BaseUtils.getLocale());
jSONObject.put("timezone", getTimeZone());
jSONObject.put("framework", sdkType + "_android_" + AnalyticsUtil.getFramework());
jSONObject.put("user_agent", getUserAgent());
jSONObject.put("sdk_session_id", AnalyticsUtil.getLocalOrderId());
jSONObject.put("local_order_id", AnalyticsUtil.getLocalOrderId());
jSONObject.put("webview_user_agent", BaseUtils.getWebViewUserAgent(context));
return jSONObject;
}
public static JSONObject getContextPayload() {
return contextJsonData;
}
private static JSONObject getDeviceDataJson(Context context) {
JSONObject jSONObject = new JSONObject();
jSONObject.put("id", BaseConfig.getAdvertisingId(context));
jSONObject.put("manufacturer", DEVICE_MANUFACTURER);
jSONObject.put("model", DEVICE_MODEL);
jSONObject.put("name", DEVICE_NAME);
jSONObject.put("type", Consts.ADDRESS_BOOK_CONTACTS_PHONE);
jSONObject.put("version", ConstsInternal.HEADER_FRAMEWORK_VERSION_VALUE_PREFIX + Build.VERSION.RELEASE);
jSONObject.put(DEVICE_MANUFACTURER, Build.MANUFACTURER);
jSONObject.put(DEVICE_MODEL, Build.MODEL);
jSONObject.put("device_size", BaseUtils.getDisplayWidth(context) + "w X " + BaseUtils.getDisplayHeight(context) + "h");
jSONObject.put("device_resolution", BaseUtils.getDisplayResolution(context));
return jSONObject;
}
public static JSONObject getLumberjackPayload() {
return lumberjackPayload;
}
private static JSONObject getNetworkDataJson(Context context) {
JSONObject jSONObject = new JSONObject();
jSONObject.put("bluetooth", NETWORK_BLUETOOTH);
jSONObject.put("carrier", NETWORK_CARRIER);
jSONObject.put("cellular", NETWORK_CELLULAR);
jSONObject.put("cellular_network_type", NETWORK_CELLULAR_TYPE);
jSONObject.put("wifi", NETWORK_WIFI);
jSONObject.put("carrier_network", BaseUtils.getCarrierOperatorName(context));
jSONObject.put("network_type", BaseUtils.getNetworkType(context));
jSONObject.put("ip_address", BaseUtils.ipAddress);
jSONObject.put("is_roming", BaseUtils.isNetworkRoaming(context));
Map<String, String> deviceAttributes = BaseUtils.getDeviceAttributes(context);
jSONObject.put("device_Id", deviceAttributes.get("device_Id"));
String str = DEVICE_MANUFACTURER;
jSONObject.put(str, deviceAttributes.get(str));
String str2 = DEVICE_MODEL;
jSONObject.put(str2, deviceAttributes.get(str2));
return jSONObject;
}
public static Map<String, Object> getOrderProperties() {
return orderProperties;
}
public static Map<String, Object> getPaymentProperties() {
return paymentProperties;
}
public static ArrayList<JSONObject> getPreInitBatch() {
return preInitBatch;
}
private static JSONObject getScreenDataJson() {
JSONObject jSONObject = new JSONObject();
jSONObject.put("density", SCREEN_DENSITY);
jSONObject.put("width", SCREEN_WIDTH);
jSONObject.put("height", SCREEN_HEIGHT);
return jSONObject;
}
private static JSONObject getSdkDataJson() {
JSONObject jSONObject = new JSONObject();
jSONObject.put("version", sdkVersion);
jSONObject.put("platform", "android");
jSONObject.put("type", sdkType);
jSONObject.put("framework", AnalyticsUtil.getFramework());
jSONObject.put("name", sdkType + "_android_" + AnalyticsUtil.getFramework());
return jSONObject;
}
public static JSONObject getSessionCreatedJson() {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("key", CoreConfig.getInstance().getLumberjackKey());
JSONArray jSONArray = new JSONArray();
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("name", "checkout.mobile.sessionCreated.metrics");
JSONArray jSONArray2 = new JSONArray();
JSONObject jSONObject3 = new JSONObject();
jSONObject3.put("type", "session_created");
jSONObject3.put("platform", "android");
jSONObject3.put("framework", sdkType + "_android_" + AnalyticsUtil.getFramework());
jSONArray2.put(jSONObject3);
jSONObject2.put("labels", jSONArray2);
jSONArray.put(jSONObject2);
jSONObject.put("metrics", jSONArray);
return jSONObject;
} catch (JSONException e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
return jSONObject;
}
}
public static JSONObject getSessionErroredJson(String str) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("key", CoreConfig.getInstance().getLumberjackKey());
JSONArray jSONArray = new JSONArray();
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("name", "checkout.mobile.sessionErrored.metrics");
JSONArray jSONArray2 = new JSONArray();
JSONObject jSONObject3 = new JSONObject();
jSONObject3.put("type", "session_errored");
jSONObject3.put("platform", "android");
jSONObject3.put("framework", sdkType + "_android_" + AnalyticsUtil.getFramework());
jSONObject3.put("severity", str);
jSONArray2.put(jSONObject3);
jSONObject2.put("labels", jSONArray2);
jSONArray.put(jSONObject2);
jSONObject.put("metrics", jSONArray);
return jSONObject;
} catch (JSONException e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", e.getLocalizedMessage());
return jSONObject;
}
}
public static String getStringFromJsonObject(JSONObject jSONObject, String str) {
try {
return jSONObject.getString(str);
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
return null;
}
}
private static CharSequence getTimeZone() {
return AnalyticsUtil.returnUndefinedIfNull(TimeZone.getDefault().getID());
}
private static String getTimestamp() {
return String.valueOf(System.currentTimeMillis() / 1000);
}
private static CharSequence getUserAgent() {
return AnalyticsUtil.returnUndefinedIfNull(System.getProperty("http.agent"));
}
public static Object getValueFromJsonObject(JSONObject jSONObject, String str) {
try {
return jSONObject.get(str);
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S2", e.getMessage());
return null;
}
}
private static boolean hasPermission(Context context, String str) {
return context.checkCallingOrSelfPermission(str) == 0;
}
public static void init(Context context, String str, String str2) {
sdkType = str;
sdkVersion = str2;
setBaseImportJSON(context);
isLumberjackInitialized = true;
addQueuedDataToBatch();
String protectedValue = SharedPreferenceUtil.getProtectedValue(context, SAVED_EVENTS_DATA, str2);
if (protectedValue == null || protectedValue.length() == 0) {
return;
}
try {
makePostRequest(new JSONObject(protectedValue));
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S1", e.getMessage());
} finally {
SharedPreferenceUtil.setValue(context, SAVED_EVENTS_DATA, null);
}
}
public static void logVajraCritialError(String str) {
makeSessionApiPostRequest(getSessionErroredJson(str));
}
private static void makePostRequest(JSONObject jSONObject) {
if (CoreConfig.getInstance().isLumberJackEnabled().booleanValue()) {
HashMap hashMap = new HashMap();
hashMap.put("x-identifier", CoreConfig.getInstance().getLumberjackSdkIdentifier());
hashMap.put("Content-Type", "application/json");
Owl.post(GlobalUrlConfig.instance().getTrackUrl(), jSONObject == null ? jSONObject.toString() : JSONObjectInstrumentation.toString(jSONObject), hashMap, new Callback() {
@Override
public void run(ResponseObject responseObject) {
responseObject.getResponseResult();
}
});
}
}
private static void makeSessionApiPostRequest(JSONObject jSONObject) {
HashMap hashMap = new HashMap();
hashMap.put("accept", "application/json");
hashMap.put("content-type", "applications/json");
Owl.post("https://lumberjack-metrics.razorpay.com/v1/frontend-metrics", jSONObject == null ? jSONObject.toString() : JSONObjectInstrumentation.toString(jSONObject), hashMap, new Callback() {
@Override
public void run(ResponseObject responseObject) {
responseObject.getResponseResult();
}
});
}
public static void postData() {
synchronized (lumberjackPayload) {
JSONObject filterPayload = filterPayload(lumberjackPayload);
lumberjackPayload = filterPayload;
makePostRequest(filterPayload);
}
clearEvents();
}
public static void saveEventsToPreferences(Context context) {
synchronized (lumberjackPayload) {
try {
JSONObject filterPayload = filterPayload(lumberjackPayload);
SharedPreferenceUtil.setProtectedValue(context, SAVED_EVENTS_DATA, filterPayload == null ? filterPayload.toString() : JSONObjectInstrumentation.toString(filterPayload), sdkVersion);
} catch (Throwable th) {
throw th;
}
}
}
public static void setBaseImportJSON(Context context) {
try {
setNetworkDetails(context);
setDisplayDetails(context);
JSONObject jSONObject = new JSONObject();
jSONObject.put("key", CoreConfig.getInstance().getLumberjackKey());
jSONObject.put("events", new JSONArray());
JSONObject contextDataJson = getContextDataJson(context);
contextJsonData = contextDataJson;
jSONObject.put("context", contextDataJson);
lumberjackPayload = jSONObject;
makeSessionApiPostRequest(getSessionCreatedJson());
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", "Error in creating BaseImportJSON");
lumberjackPayload = new JSONObject();
}
}
private static void setDisplayDetails(Context context) {
Display defaultDisplay = ((WindowManager) BaseUtils.getSystemService(context, "window")).getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
defaultDisplay.getMetrics(displayMetrics);
SCREEN_DENSITY = displayMetrics.density;
SCREEN_HEIGHT = displayMetrics.heightPixels;
SCREEN_WIDTH = displayMetrics.widthPixels;
}
private static void setNetworkDetails(Context context) {
NETWORK_CELLULAR_TYPE = BaseUtils.getCellularNetworkType(context);
NETWORK_CARRIER = BaseUtils.getCellularNetworkProviderName(context);
int i = AnonymousClass3.$SwitchMap$com$razorpay$NetworkType[BaseUtils.getDataNetworkType(context).ordinal()];
if (i == 1) {
NETWORK_WIFI = true;
} else if (i == 2) {
NETWORK_CELLULAR = true;
} else {
if (i != 3) {
return;
}
NETWORK_BLUETOOTH = true;
}
}
public static void trackEvent(String str, Map<String, Object> map) {
JSONObject jSONObject = new JSONObject();
for (Map.Entry<String, Object> entry : map.entrySet()) {
try {
jSONObject.put(entry.getKey(), entry.getValue());
} catch (JSONException e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", a.r(new StringBuilder("Error adding analytics property "), entry.getKey(), " to JSONObject"));
}
}
trackEvent(str, jSONObject);
}
public static void trackPage(String str, String str2) {
trackEvent(t2.p("Viewed ", str, " Page"), c.d("url", str2));
}
public static void trackEvent(String str, JSONObject jSONObject) {
try {
JSONObject createBaseTrackEvent = createBaseTrackEvent(str);
if (createBaseTrackEvent == null) {
createBaseTrackEvent = new JSONObject();
}
if (jSONObject == null) {
jSONObject = new JSONObject();
}
jSONObject.put("local_order_id", AnalyticsUtil.getLocalOrderId());
jSONObject.put("sdk_session_id", AnalyticsUtil.getLocalOrderId());
jSONObject.put("local_payment_id", AnalyticsUtil.getLocalPaymentId());
createBaseTrackEvent.put("properties", jSONObject);
addToBatch(createBaseTrackEvent);
} catch (Exception e) {
AnalyticsUtil.reportError(e.getMessage(), "S0", "Error in adding properties to base json for event tracking");
}
}
public static void trackEvent(String str) {
trackEvent(str, new JSONObject());
}
}