- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
175 lines
6.6 KiB
Java
175 lines
6.6 KiB
Java
package com.singular.sdk;
|
|
|
|
import android.content.Context;
|
|
import com.singular.sdk.internal.SingularExceptionReporter;
|
|
import com.singular.sdk.internal.SingularInstance;
|
|
import com.singular.sdk.internal.SingularLog;
|
|
import com.singular.sdk.internal.Utils;
|
|
import java.io.IOException;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public abstract class Singular {
|
|
public static SingularInstance singular;
|
|
public static final SingularLog logger = SingularLog.getLogger(Singular.class.getSimpleName());
|
|
public static boolean isInstanceAlreadyInitialized = false;
|
|
public static Context saved_application_context = null;
|
|
|
|
public static boolean init(Context context, SingularConfig singularConfig) {
|
|
if (context == null || singularConfig == null) {
|
|
return false;
|
|
}
|
|
try {
|
|
isInstanceAlreadyInitialized = singular != null;
|
|
SingularInstance singularInstance = SingularInstance.getInstance(context, singularConfig);
|
|
singular = singularInstance;
|
|
if (isInstanceAlreadyInitialized) {
|
|
singularInstance.startSessionIfOpenedWithDeeplink();
|
|
}
|
|
saved_application_context = context.getApplicationContext();
|
|
} catch (IOException e) {
|
|
SingularLog singularLog = logger;
|
|
singularLog.debug("Failed to init() Singular SDK");
|
|
singularLog.error("init() IOException", e);
|
|
singular = null;
|
|
} catch (RuntimeException e2) {
|
|
reportException(e2);
|
|
logger.error("Exception", e2);
|
|
}
|
|
return isInitialized();
|
|
}
|
|
|
|
public static void reportException(Throwable th) {
|
|
try {
|
|
SingularExceptionReporter.getReporter(saved_application_context).reportException(th);
|
|
} catch (RuntimeException unused) {
|
|
}
|
|
}
|
|
|
|
public static boolean isInitialized() {
|
|
if (singular != null) {
|
|
return true;
|
|
}
|
|
logger.error("Singular not initialized. You must call Singular.init() ");
|
|
return false;
|
|
}
|
|
|
|
public static boolean event(String str) {
|
|
try {
|
|
if (!isInitialized()) {
|
|
return false;
|
|
}
|
|
if (Utils.isEmptyOrNull(str)) {
|
|
logger.error("Event name can not be null or empty");
|
|
return false;
|
|
}
|
|
return singular.logEvent(str);
|
|
} catch (RuntimeException e) {
|
|
reportException(e);
|
|
logger.error("Exception", e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static boolean event(String str, Object... objArr) {
|
|
try {
|
|
if (!isInitialized()) {
|
|
return false;
|
|
}
|
|
if (Utils.isEmptyOrNull(str)) {
|
|
logger.error("Event name can not be null or empty");
|
|
return false;
|
|
}
|
|
if (objArr.length % 2 != 0) {
|
|
logger.error("Extra arguments must be in even numbers.");
|
|
return false;
|
|
}
|
|
try {
|
|
JSONObject jSONObject = new JSONObject();
|
|
for (int i = 0; i < objArr.length; i += 2) {
|
|
jSONObject.put((String) objArr[i], objArr[i + 1]);
|
|
}
|
|
return eventJSON(str, jSONObject);
|
|
} catch (JSONException e) {
|
|
logger.error("error in serializing extra args", e);
|
|
return false;
|
|
}
|
|
} catch (RuntimeException e2) {
|
|
reportException(e2);
|
|
logger.error("Exception", e2);
|
|
}
|
|
}
|
|
|
|
public static boolean revenue(String str, double d, Object obj) {
|
|
return customRevenue("__iap__", str, d, obj);
|
|
}
|
|
|
|
public static boolean revenue(String str, double d) {
|
|
return customRevenue("__iap__", str, d);
|
|
}
|
|
|
|
public static boolean revenue(String str, double d, String str2, String str3, String str4, int i, double d2) {
|
|
return customRevenue("__iap__", str, d, str2, str3, str4, i, d2);
|
|
}
|
|
|
|
public static boolean customRevenue(String str, String str2, double d, Object obj) {
|
|
if (obj != null && obj.getClass().getName().equals("com.android.billingclient.api.Purchase")) {
|
|
try {
|
|
Class<?> cls = obj.getClass();
|
|
return event(str, "pcc", str2, "r", Double.valueOf(d), "pk", (String) cls.getDeclaredMethod("getSku", new Class[0]).invoke(obj, new Object[0]), "receipt", (String) cls.getDeclaredMethod("getOriginalJson", new Class[0]).invoke(obj, new Object[0]), "receipt_signature", (String) cls.getDeclaredMethod("getSignature", new Class[0]).invoke(obj, new Object[0]), "is_revenue_event", Boolean.TRUE);
|
|
} catch (Exception e) {
|
|
logger.error("customRevenue has encountered an unexpected exception. Please verify that the 'purchase' object is of type 'com.android.billingclient.api.Purchase'", e);
|
|
}
|
|
}
|
|
return customRevenue(str, str2, d);
|
|
}
|
|
|
|
public static boolean customRevenue(String str, String str2, double d) {
|
|
return event(str, "pcc", str2, "r", Double.valueOf(d), "is_revenue_event", Boolean.TRUE);
|
|
}
|
|
|
|
public static boolean customRevenue(String str, String str2, double d, String str3, String str4, String str5, int i, double d2) {
|
|
return event(str, "pcc", str2, "r", Double.valueOf(d), "pk", str3, "pn", str4, "pc", str5, "pq", Integer.valueOf(i), "pp", Double.valueOf(d2), "is_revenue_event", Boolean.TRUE);
|
|
}
|
|
|
|
public static boolean eventJSON(String str, JSONObject jSONObject) {
|
|
try {
|
|
if (!isInitialized()) {
|
|
return false;
|
|
}
|
|
if (Utils.isEmptyOrNull(str)) {
|
|
logger.error("Event name can not be null or empty");
|
|
return false;
|
|
}
|
|
return singular.logEvent(str, jSONObject != null ? jSONObject.toString() : null);
|
|
} catch (RuntimeException e) {
|
|
reportException(e);
|
|
logger.error("Exception", e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static void setCustomUserId(String str) {
|
|
try {
|
|
if (isInitialized()) {
|
|
singular.saveCustomUserId(str);
|
|
}
|
|
} catch (RuntimeException e) {
|
|
reportException(e);
|
|
logger.error("Exception", e);
|
|
}
|
|
}
|
|
|
|
public static void unsetCustomUserId() {
|
|
try {
|
|
if (isInitialized()) {
|
|
singular.saveCustomUserId("");
|
|
}
|
|
} catch (RuntimeException e) {
|
|
reportException(e);
|
|
logger.error("Exception", e);
|
|
}
|
|
}
|
|
}
|