Initial commit
This commit is contained in:
167
sources/com/ubtrobot/analytics/mobile/AnalyticsKit.java
Normal file
167
sources/com/ubtrobot/analytics/mobile/AnalyticsKit.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package com.ubtrobot.analytics.mobile;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
import com.ubtrobot.analytics.AnalyticsServiceImpl;
|
||||
import com.ubtrobot.analytics.Event;
|
||||
import com.ubtrobot.analytics.device.DeviceInfoUtils;
|
||||
import com.ubtrobot.analytics.device.MobileDeviceInfo;
|
||||
import com.ubtrobot.analytics.event.AppActivenessEventSource;
|
||||
import com.ubtrobot.analytics.event.Ticker;
|
||||
import com.unity3d.ads.metadata.MediationMetaData;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class AnalyticsKit {
|
||||
private static volatile Context a;
|
||||
private static volatile String b;
|
||||
private static volatile AppActivenessEventSource c;
|
||||
private static volatile AnalyticsServiceImpl d;
|
||||
private static String e;
|
||||
|
||||
private AnalyticsKit() {
|
||||
}
|
||||
|
||||
public static void a(Context context, String str, String str2, String str3, Executor executor) {
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("Context is null.");
|
||||
}
|
||||
a("appId", str);
|
||||
a("appKey", str2);
|
||||
if (str3 == null || str3.isEmpty()) {
|
||||
str3 = DeviceInfoUtils.e(context);
|
||||
}
|
||||
String str4 = str3;
|
||||
if (d != null) {
|
||||
return;
|
||||
}
|
||||
synchronized (AnalyticsKit.class) {
|
||||
if (d != null) {
|
||||
return;
|
||||
}
|
||||
a = context.getApplicationContext();
|
||||
b = a(a);
|
||||
if (executor == null) {
|
||||
executor = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
Executor executor2 = executor;
|
||||
c = new AppActivenessEventSource(a, new Ticker(), executor2);
|
||||
c.a(b);
|
||||
d = new AnalyticsServiceImpl(a, str, str2, str4, c, executor2);
|
||||
((Application) a).registerActivityLifecycleCallbacks(c);
|
||||
}
|
||||
}
|
||||
|
||||
public static void b(boolean z) {
|
||||
a();
|
||||
d.b(z);
|
||||
}
|
||||
|
||||
public static void c(String str, String str2) {
|
||||
d.a(new MobileDeviceInfo(a).setUserId(str).setChannel(str2));
|
||||
}
|
||||
|
||||
public static void d(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
throw new IllegalArgumentException("Argument viewName is null or isEmpty.");
|
||||
}
|
||||
b("page_end", b(str, "view"));
|
||||
}
|
||||
|
||||
public static void e(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
throw new IllegalArgumentException("Argument viewName is null or isEmpty.");
|
||||
}
|
||||
b("page_start", b(str, "view"));
|
||||
}
|
||||
|
||||
public static void b(String str, long j, Map<String, String> map) {
|
||||
if (str == null || str.length() <= 0 || str.length() > 64) {
|
||||
throw new IllegalArgumentException("Argument need 0 < eventId.length <= 64.");
|
||||
}
|
||||
if (j >= 0) {
|
||||
a(str, j, map);
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("Argument duration < 0.");
|
||||
}
|
||||
|
||||
public static void c(String str) {
|
||||
a(str, 0L);
|
||||
}
|
||||
|
||||
public static void b(String str) {
|
||||
a("activityName", str);
|
||||
b("page_start", b(str, "activity"));
|
||||
}
|
||||
|
||||
private static void b(String str, Map<String, String> map) {
|
||||
a();
|
||||
Event.Builder builder = new Event.Builder(str, "predefined_event");
|
||||
builder.b(map);
|
||||
builder.a(e);
|
||||
builder.b(b);
|
||||
d.a(builder.a());
|
||||
}
|
||||
|
||||
private static String a(Context context) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException unused) {
|
||||
Log.w("Analytics", "Get app version fail.");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> b(String str, String str2) {
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put("type", str2);
|
||||
hashMap.put(MediationMetaData.KEY_NAME, str);
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
private static void a(String str, String str2) {
|
||||
if (str2 == null || str2.length() <= 0) {
|
||||
throw new IllegalArgumentException("Argument:" + str + " is null.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void a() {
|
||||
if (d == null) {
|
||||
throw new IllegalStateException("Please call com.ubtrobot.analytics.mobile.AnalyticsKit.initialize");
|
||||
}
|
||||
}
|
||||
|
||||
public static void a(boolean z) {
|
||||
a();
|
||||
d.a(z);
|
||||
}
|
||||
|
||||
public static void a(String str, long j) {
|
||||
b(str, j, null);
|
||||
}
|
||||
|
||||
public static void a(String str, Map<String, String> map) {
|
||||
b(str, 0L, map);
|
||||
}
|
||||
|
||||
private static void a(String str, long j, Map<String, String> map) {
|
||||
a();
|
||||
Event.Builder builder = new Event.Builder(str, "custom_event");
|
||||
builder.a(j);
|
||||
builder.a(map);
|
||||
builder.a(e);
|
||||
builder.b(b);
|
||||
d.a(builder.a());
|
||||
}
|
||||
|
||||
public static void a(String str) {
|
||||
a("activityName", str);
|
||||
b("page_end", b(str, "activity"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user