Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
package com.ubtrobot.analytics;
import android.os.SystemClock;
/* loaded from: classes2.dex */
public class ActivenessRecord {
private String a;
private String b;
private String c;
private long e = System.currentTimeMillis();
private long f = SystemClock.elapsedRealtime();
private long d = this.e - this.f;
public ActivenessRecord(String str) {
this.a = str;
}
public ActivenessRecord a(String str) {
this.b = str;
return this;
}
public ActivenessRecord b(String str) {
this.c = str;
return this;
}
public ActivenessRecord c(long j) {
this.e = j;
return this;
}
public long d() {
return this.e;
}
public String e() {
String str = this.b;
return str != null ? str : "";
}
public String f() {
return this.c;
}
public String toString() {
return "ActivenessRecord{eventId='" + this.a + "', userId='" + this.b + "', version='" + this.c + "', startedAt=" + this.d + ", ticktockAt=" + this.e + ", duration=" + this.f + '}';
}
public ActivenessRecord a(long j) {
this.f = j;
return this;
}
public ActivenessRecord b(long j) {
this.d = j;
return this;
}
public long c() {
return this.d;
}
public long a() {
return this.f;
}
public String b() {
return this.a;
}
}

View File

@@ -0,0 +1,74 @@
package com.ubtrobot.analytics;
import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import com.unity3d.ads.metadata.MediationMetaData;
/* loaded from: classes2.dex */
public class ActivenessScheme {
public static void a(AnalyticsDBHelper analyticsDBHelper) {
Log.i("Analytics", "Create table: activeness");
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("CREATE TABLE IF NOT EXISTS ");
stringBuffer.append("activeness");
stringBuffer.append("(");
stringBuffer.append(JockstickDataConverter.ID);
stringBuffer.append(" INTEGER PRIMARY KEY AUTOINCREMENT,");
stringBuffer.append("event_id");
stringBuffer.append(" VARCHAR NOT NULL,");
stringBuffer.append("user_id");
stringBuffer.append(" VARCHAR DEFAULT '',");
stringBuffer.append(MediationMetaData.KEY_VERSION);
stringBuffer.append(" VARCHAR DEFAULT '',");
stringBuffer.append("started_at");
stringBuffer.append(" INTEGER DEFAULT 0,");
stringBuffer.append("ticktock_at");
stringBuffer.append(" INTEGER DEFAULT 0,");
stringBuffer.append("duration");
stringBuffer.append(" INTEGER DEFAULT 0");
stringBuffer.append(")");
analyticsDBHelper.a(stringBuffer.toString());
}
public static void b(AnalyticsDBHelper analyticsDBHelper) {
Log.i("Analytics", "Running upgradeToVersion4 ...");
if (analyticsDBHelper.a("activeness", "user_id")) {
return;
}
String format = String.format("ALTER TABLE %s ADD COLUMN %s VARCHAR DEFAULT ''", "activeness", "user_id");
String format2 = String.format("ALTER TABLE %s ADD COLUMN %s VARCHAR DEFAULT ''", "activeness", MediationMetaData.KEY_VERSION);
analyticsDBHelper.b(format);
analyticsDBHelper.b(format2);
}
public static class Converters {
static ContentValues a(ActivenessRecord activenessRecord) {
ContentValues contentValues = new ContentValues();
contentValues.put("event_id", activenessRecord.b());
contentValues.put("user_id", activenessRecord.e());
contentValues.put(MediationMetaData.KEY_VERSION, activenessRecord.f());
contentValues.put("started_at", Long.valueOf(activenessRecord.c()));
contentValues.put("ticktock_at", Long.valueOf(activenessRecord.d()));
contentValues.put("duration", Long.valueOf(activenessRecord.a()));
return contentValues;
}
static ActivenessRecord a(Cursor cursor) {
String string = cursor.getString(cursor.getColumnIndex("event_id"));
String string2 = cursor.getString(cursor.getColumnIndex("user_id"));
String string3 = cursor.getString(cursor.getColumnIndex(MediationMetaData.KEY_VERSION));
long j = cursor.getLong(cursor.getColumnIndex("started_at"));
long j2 = cursor.getLong(cursor.getColumnIndex("ticktock_at"));
long j3 = cursor.getLong(cursor.getColumnIndex("duration"));
ActivenessRecord activenessRecord = new ActivenessRecord(string);
activenessRecord.a(string2);
activenessRecord.b(string3);
activenessRecord.b(j);
activenessRecord.c(j2);
activenessRecord.a(j3);
return activenessRecord;
}
}
}

View File

@@ -0,0 +1,91 @@
package com.ubtrobot.analytics;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import com.ubtrobot.analytics.ActivenessScheme;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
/* loaded from: classes2.dex */
public class ActivenessStorage {
private AnalyticsDBHelper a;
public ActivenessStorage(Context context) {
this.a = AnalyticsDBHelper.a(context);
}
public void a() throws IOException {
synchronized (this) {
String format = String.format("DELETE FROM %s WHERE %s IN(SELECT %s FROM(SELECT %s FROM %s GROUP BY %s HAVING count(%s) > 1))AND %s NOT IN(SELECT %s FROM(SELECT max(%s), %s FROM %s GROUP BY %s HAVING count(%s) > 1))", "activeness", "started_at", "started_at", "started_at", "activeness", "started_at", "started_at", "duration", "duration", "duration", "duration", "activeness", "started_at", "started_at");
Log.i("Analytics", "SQL deleteRepetition: " + format);
this.a.b(format);
}
}
public void b(ActivenessRecord activenessRecord) throws IOException {
synchronized (this) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("event_id");
stringBuffer.append(" = ? AND ");
stringBuffer.append("user_id");
stringBuffer.append(" = ? AND ");
stringBuffer.append(JockstickDataConverter.ID);
stringBuffer.append(" IN (SELECT ");
stringBuffer.append(JockstickDataConverter.ID);
stringBuffer.append(" FROM ");
stringBuffer.append("activeness");
stringBuffer.append(" ORDER BY ");
stringBuffer.append("ticktock_at");
stringBuffer.append(" DESC");
stringBuffer.append(" LIMIT 1");
stringBuffer.append(")");
this.a.a("activeness", ActivenessScheme.Converters.a(activenessRecord), stringBuffer.toString(), new String[]{activenessRecord.b(), activenessRecord.e()});
}
}
public int a(String str, int i) throws IOException {
int a;
synchronized (this) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("event_id");
stringBuffer.append(" = ? AND ");
stringBuffer.append(JockstickDataConverter.ID);
stringBuffer.append(" IN (SELECT ");
stringBuffer.append(JockstickDataConverter.ID);
stringBuffer.append(" FROM ");
stringBuffer.append("activeness");
stringBuffer.append(" ORDER BY ");
stringBuffer.append("ticktock_at");
stringBuffer.append(" ASC");
stringBuffer.append(" LIMIT ");
stringBuffer.append(i);
stringBuffer.append(")");
a = this.a.a("activeness", stringBuffer.toString(), new String[]{str});
}
return a;
}
public void a(ActivenessRecord activenessRecord) throws IOException {
synchronized (this) {
this.a.a("activeness", ActivenessScheme.Converters.a(activenessRecord));
}
}
public List<ActivenessRecord> a(String str) throws IOException {
synchronized (this) {
Cursor d = this.a.d(String.format("SELECT * FROM %s WHERE %s = '%s'", "activeness", "event_id", str));
LinkedList linkedList = new LinkedList();
if (d == null) {
return linkedList;
}
while (d.moveToNext()) {
linkedList.add(ActivenessScheme.Converters.a(d));
}
d.close();
return linkedList;
}
}
}

View File

@@ -0,0 +1,5 @@
package com.ubtrobot.analytics;
/* loaded from: classes2.dex */
public interface Analytics {
}

View File

@@ -0,0 +1,186 @@
package com.ubtrobot.analytics;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDiskIOException;
import android.database.sqlite.SQLiteFullException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes2.dex */
public class AnalyticsDBHelper extends SQLiteOpenHelper {
private static final byte[] a = new byte[0];
private static volatile AnalyticsDBHelper b;
private static volatile SQLiteDatabase c;
private AnalyticsDBHelper(Context context) {
super(context, "analytics", (SQLiteDatabase.CursorFactory) null, 4);
}
public static AnalyticsDBHelper a(Context context) {
if (b != null) {
return b;
}
synchronized (a) {
if (b != null) {
return b;
}
b = new AnalyticsDBHelper(context);
return b;
}
}
public void b(String str) {
try {
a().execSQL(str);
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "Exec sql fail, msg:" + e.getMessage());
}
}
public int c(String str) {
try {
Cursor rawQuery = a().rawQuery("SELECT COUNT(*) FROM " + str, null);
try {
rawQuery.moveToFirst();
return (int) rawQuery.getLong(0);
} finally {
rawQuery.close();
}
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "GetCount fail, msg:" + e.getMessage());
return 0;
}
}
public Cursor d(String str) {
try {
return a().rawQuery(str, null);
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "CheckColumnExists fail, msg:" + e.getMessage());
return null;
}
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onCreate(SQLiteDatabase sQLiteDatabase) {
c = sQLiteDatabase;
EventScheme.a(b);
ActivenessScheme.a(b);
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
c = sQLiteDatabase;
while (i <= i2) {
if (i == 2) {
b();
} else if (i == 3) {
c();
} else if (i == 4) {
d();
}
i++;
}
}
private void b() {
EventScheme.b(b);
}
private void d() {
EventScheme.d(b);
ActivenessScheme.b(b);
}
private void c() {
EventScheme.c(b);
ActivenessScheme.a(b);
}
public void a(String str) {
Log.i("Analytics", "Create table: " + str);
try {
a().execSQL(str);
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "Create table fail, msg:" + e.getMessage());
}
}
private SQLiteDatabase a() {
c = c != null ? c : b.getWritableDatabase();
return c;
}
public void a(List<String> list) {
try {
a().beginTransaction();
Iterator<String> it = list.iterator();
while (it.hasNext()) {
a().execSQL(it.next());
}
a().setTransactionSuccessful();
a().endTransaction();
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "Exec sql list fail, msg:" + e.getMessage());
}
}
public int a(String str, String str2, String[] strArr) {
try {
return a().delete(str, str2, strArr);
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "Delete fail, msg:" + e.getMessage());
return 0;
} catch (SQLiteFullException e2) {
Log.e("Analytics", "Delete fail, msg:" + e2.getMessage());
a().execSQL(String.format("DROP TABLE %s", str));
if (str.equals("event")) {
EventScheme.a(b);
} else if (str.equals("activeness")) {
ActivenessScheme.a(b);
}
return 0;
}
}
public void a(String str, ContentValues contentValues, String str2, String[] strArr) {
try {
SQLiteDatabase a2 = a();
a2.beginTransaction();
if (a2.update(str, contentValues, str2, strArr) <= 0) {
a2.insert(str, null, contentValues);
}
a2.setTransactionSuccessful();
a2.endTransaction();
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "UpdateIfExist fail, msg:" + e.getMessage());
}
}
public void a(String str, ContentValues contentValues) {
try {
a().insert(str, null, contentValues);
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "Insert fail, msg:" + e.getMessage());
}
}
public boolean a(String str, String str2) {
try {
Cursor rawQuery = a().rawQuery("select * from sqlite_master where name = ? and sql like ?", new String[]{str, "%" + str2 + "%"});
boolean moveToFirst = rawQuery.moveToFirst();
if (!rawQuery.isClosed()) {
rawQuery.close();
}
return moveToFirst;
} catch (SQLiteDiskIOException e) {
Log.e("Analytics", "CheckColumnExists fail, msg:" + e.getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,550 @@
package com.ubtrobot.analytics;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import com.ubt.jimu.base.entities.Course;
import com.ubt.jimu.base.mvp.SingleClickListener;
import com.ubtrobot.analytics.NetWorkChangeReceiver;
import com.ubtrobot.analytics.Retry;
import com.ubtrobot.analytics.device.DeviceInfo;
import com.ubtrobot.analytics.event.ActivenessEventSource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
public class AnalyticsServiceImpl implements Analytics {
private static final long q = TimeUnit.MINUTES.toMillis(5);
private volatile long d;
private DeviceInfo f;
private boolean g;
private Executor h;
private MemEventStorage i;
private EventStorage j;
private RealtimeReport k;
private HttpReport l;
private ActivenessEventSource n;
private Handler o;
private NetWorkChangeReceiver p;
private final byte[] a = new byte[0];
private final byte[] b = new byte[0];
private volatile long c = b() + 20;
private long e = q;
private boolean m = true;
private class RealtimeReport {
private volatile Set<String> a;
private Context b;
private MemEventStorage c;
private boolean d;
private boolean e;
private Retry f;
private Runnable g;
/* JADX INFO: Access modifiers changed from: private */
public boolean g() {
synchronized (AnalyticsServiceImpl.this.b) {
int a = this.c.a();
List<Event> a2 = this.c.a(a);
boolean b = AnalyticsServiceImpl.this.b(a2);
Log.i("Analytics", "Forthwith report event report result:" + b);
if (!b) {
this.d = true;
return false;
}
if (!this.d) {
this.c.b(a);
return true;
}
this.d = false;
try {
this.c.b(a);
AnalyticsServiceImpl.this.j.a(a2);
return true;
} catch (IOException unused) {
Log.w("Analytics", "Remove mDiskStorage is fail.");
this.d = true;
return false;
}
}
}
private RealtimeReport(Context context) {
this.b = context;
this.c = new MemEventStorage(new MemoryEventStorage());
this.a = new HashSet();
f();
this.g = new Runnable(AnalyticsServiceImpl.this) { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.RealtimeReport.1
@Override // java.lang.Runnable
public void run() {
if (RealtimeReport.this.g()) {
RealtimeReport.this.f.b();
}
}
};
this.f = new Retry(new Retry.RetryListener(AnalyticsServiceImpl.this) { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.RealtimeReport.2
@Override // com.ubtrobot.analytics.Retry.RetryListener
public void a() {
Log.i("Analytics", "Report retrying ...");
AnalyticsServiceImpl.this.h.execute(RealtimeReport.this.g);
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public boolean b(boolean z) {
synchronized (AnalyticsServiceImpl.this.b) {
try {
if (!z) {
try {
if (!a()) {
Log.i("Analytics", "Realtime event sp is updated.");
return false;
}
} catch (ReportException e) {
Log.w("Analytics", "Request realtime is fail.", e);
this.e = false;
return false;
}
}
RealtimeEvent a = AnalyticsServiceImpl.this.l.a(b());
if (a == null) {
this.e = false;
return false;
}
Log.i("Analytics", "Realtime: " + a.toString());
this.a.addAll(a.b());
a(a.a(), this.a);
this.e = true;
return true;
} catch (Throwable th) {
throw th;
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public void c() {
this.a.addAll(this.b.getSharedPreferences("realtime_event_id", 0).getStringSet("event_id_set", new HashSet()));
}
private long d() {
return this.b.getSharedPreferences("realtime_event_id", 0).getLong("next_update_time", 0L);
}
/* JADX INFO: Access modifiers changed from: private */
public void e() {
Log.i("Analytics", "Force refresh realtime eventId list.");
a(true);
}
private void f() {
Log.i("Analytics", "Refresh realtime eventId list.");
a(false);
}
private void a(final boolean z) {
AnalyticsServiceImpl.this.h.execute(new Runnable() { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.RealtimeReport.3
@Override // java.lang.Runnable
public void run() {
if (RealtimeReport.this.b(z)) {
Log.i("Analytics", "Read realtime event from sp.");
RealtimeReport.this.c();
}
}
});
}
private boolean a() {
if (!this.e) {
return true;
}
if (d() > System.currentTimeMillis()) {
Log.i("Analytics", "Update realtime sp time:" + d());
return false;
}
this.e = false;
return true;
}
private void a(String str, Set<String> set) {
SharedPreferences sharedPreferences = this.b.getSharedPreferences("realtime_event_id", 0);
long currentTimeMillis = System.currentTimeMillis() + 3600000;
if (str.equals(b())) {
Log.i("Analytics", "Update realtime sp: next_update_time.");
sharedPreferences.edit().putLong("next_update_time", currentTimeMillis).apply();
} else {
Log.i("Analytics", "Update realtime sp.");
sharedPreferences.edit().putString(Course.TYPE_BLOCKLY, str).putStringSet("event_id_set", set).putLong("next_update_time", currentTimeMillis).apply();
}
}
private String b() {
return this.b.getSharedPreferences("realtime_event_id", 0).getString(Course.TYPE_BLOCKLY, "");
}
/* JADX INFO: Access modifiers changed from: private */
public boolean a(String str) {
if (AnalyticsServiceImpl.this.k.a()) {
f();
}
return this.a.contains(str);
}
/* JADX INFO: Access modifiers changed from: private */
public void a(final Event event) {
AnalyticsServiceImpl.this.h.execute(new Runnable() { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.RealtimeReport.4
@Override // java.lang.Runnable
public void run() {
RealtimeReport.this.c.a(event);
if (RealtimeReport.this.g()) {
return;
}
AnalyticsServiceImpl.this.c((List<Event>) Collections.singletonList(event));
RealtimeReport.this.f.a();
}
});
}
}
private class TimerReportRunnable implements Runnable {
private long a = a();
public TimerReportRunnable() {
}
private long a() {
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(1), calendar.get(2), calendar.get(5), 23, 59, 59);
return calendar.getTimeInMillis();
}
private void b() {
if (System.currentTimeMillis() > this.a) {
AnalyticsServiceImpl.this.g();
c();
this.a = a();
}
}
private void c() {
AnalyticsServiceImpl.this.h.execute(new Runnable() { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.TimerReportRunnable.1
@Override // java.lang.Runnable
public void run() {
AnalyticsServiceImpl.this.f();
}
});
}
@Override // java.lang.Runnable
public void run() {
b();
AnalyticsServiceImpl.this.o.postDelayed(this, 15000L);
}
}
public AnalyticsServiceImpl(Context context, String str, String str2, String str3, ActivenessEventSource activenessEventSource, Executor executor) {
this.h = executor;
Strategy strategy = Strategy.DEFAULT;
this.i = new MemEventStorage(new MemoryEventStorage());
this.l = new HttpReport(context, str, str2, str3);
this.j = new DiskEventStorage(context);
this.k = new RealtimeReport(context);
this.n = activenessEventSource;
a(this.n);
this.o = new Handler(Looper.getMainLooper());
this.o.post(new TimerReportRunnable());
a(context);
c();
}
private static class MemEventStorage implements EventStorage {
private final EventStorage a;
MemEventStorage(EventStorage eventStorage) {
this.a = eventStorage;
}
@Override // com.ubtrobot.analytics.EventStorage
public void a(Event event) {
try {
this.a.a(event);
} catch (IOException e) {
throw new IllegalStateException("Impossible(writeEvent) IOException on MemoryStorage", e);
}
}
@Override // com.ubtrobot.analytics.EventStorage
public void b(List<Event> list) {
try {
this.a.b(list);
} catch (IOException e) {
throw new IllegalStateException("Impossible(writeEvents) IOException on MemoryStorage", e);
}
}
@Override // com.ubtrobot.analytics.EventStorage
public int a() {
try {
return this.a.a();
} catch (IOException e) {
throw new IllegalStateException("Impossible(getEventCount) IOException on MemoryStorage", e);
}
}
@Override // com.ubtrobot.analytics.EventStorage
public void b(int i) {
try {
this.a.b(i);
} catch (IOException e) {
throw new IllegalStateException("Impossible IOException on MemoryStorage", e);
}
}
@Override // com.ubtrobot.analytics.EventStorage
public List<Event> a(int i) {
try {
return this.a.a(i);
} catch (IOException e) {
throw new IllegalStateException("Impossible IOException on MemoryStorage", e);
}
}
@Override // com.ubtrobot.analytics.EventStorage
public void a(List<Event> list) throws IOException {
throw new IllegalStateException("MemEventStorage nonsupport removeEvents(List<Event>).");
}
}
private void c() {
this.h.execute(new Runnable() { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.1
@Override // java.lang.Runnable
public void run() {
Log.i("Analytics", "First report.");
AnalyticsServiceImpl.this.f();
}
});
}
private List<Event> d() {
ArrayList arrayList = new ArrayList();
try {
return this.j.a(50);
} catch (IOException unused) {
Log.w("Analytics", "Operate event disk storage failed.");
return arrayList;
}
}
private void e() {
try {
if (this.f == null) {
Log.w("Analytics", "Please AnalyticsServiceImpl.setDeviceInfo.");
} else {
this.l.a(this.f);
this.g = true;
}
} catch (ReportException unused) {
this.g = false;
}
}
/* JADX INFO: Access modifiers changed from: private */
public void f() {
synchronized (this.b) {
while (true) {
if (!a()) {
break;
}
List<Event> d = d();
if (!b(d)) {
Log.i("Analytics", "Report fail, count: " + d.size());
break;
}
Log.i("Analytics", "Report success, count: " + d.size());
a(d);
}
if (!this.g) {
e();
}
this.d = b() + this.e;
}
}
/* JADX INFO: Access modifiers changed from: private */
public void g() {
synchronized (this.a) {
while (this.i.a() > 0) {
List<Event> a = this.i.a(SingleClickListener.FAST_CLICK_DELAY_TIME);
if (a.isEmpty()) {
return;
}
if (c(a)) {
this.i.b(a.size());
}
}
this.c = b() + 20;
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean h() {
return b() - this.d > 0;
}
private boolean i() {
return this.i.a() >= 500 || b() - this.c >= 0;
}
private void a(Context context) {
this.p = new NetWorkChangeReceiver(new NetWorkChangeReceiver.INetWorkChange() { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.2
@Override // com.ubtrobot.analytics.NetWorkChangeReceiver.INetWorkChange
public void a() {
AnalyticsServiceImpl.this.k.e();
}
});
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
intentFilter.addAction("android.net.wifi.STATE_CHANGE");
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
context.registerReceiver(this.p, intentFilter);
}
public void b(boolean z) {
this.l.a(z);
}
private void b(Event event) {
this.i.a(event);
if (i() || h()) {
this.h.execute(new Runnable() { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.4
@Override // java.lang.Runnable
public void run() {
AnalyticsServiceImpl.this.g();
if (AnalyticsServiceImpl.this.h()) {
Log.i("Analytics", "Report start...");
AnalyticsServiceImpl.this.f();
}
}
});
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean c(List<Event> list) {
try {
this.j.b(list);
return true;
} catch (IOException unused) {
Log.w("Analytics", "Save events to disk failed.");
return false;
}
}
private long b() {
return SystemClock.elapsedRealtime();
}
private void a(final ActivenessEventSource activenessEventSource) {
this.h.execute(new Runnable() { // from class: com.ubtrobot.analytics.AnalyticsServiceImpl.3
@Override // java.lang.Runnable
public void run() {
try {
List<Event> a = activenessEventSource.a();
int size = a.size();
if (size <= 0) {
Log.i("Analytics", "ActivenessEvent is not exist.");
return;
}
Log.i("Analytics", "ActivenessEvent count:" + size);
boolean z = false;
int i = 0;
int i2 = 0;
while (true) {
if (i >= size) {
break;
}
i += 50;
if (i > size) {
i = size;
}
if (!AnalyticsServiceImpl.this.c(a.subList(i2, i))) {
z = true;
break;
}
i2 = i;
}
if (z) {
Log.i("Analytics", "ActivenessEvent record to event table fail.");
} else {
Log.i("Analytics", "ActivenessEvent record to event table success.");
activenessEventSource.a(size);
}
} catch (IOException unused) {
}
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public boolean b(List<Event> list) {
try {
this.l.a(list);
return true;
} catch (ReportException e) {
Log.e("Analytics", "Report Error:" + e.getMessage());
if (e.causedByInternalServerError()) {
Log.w("Analytics", "Report(reportEvents) events failed due to server error.");
}
return false;
}
}
public void a(boolean z) {
this.m = z;
}
public void a(Event event) {
if (this.m) {
if (this.k.a(event.getEventId())) {
Log.i("Analytics", "Event is forthwith report event.");
this.k.a(event);
} else {
Log.i("Analytics", "Event is not forthwith report event.");
b(event);
}
}
}
private boolean a() {
try {
return this.j.a() > 0;
} catch (IOException unused) {
Log.w("Analytics", "Report(getEventCount) events failed due to server error.");
return false;
}
}
private void a(List<Event> list) {
try {
this.j.b(list.size());
} catch (IOException unused) {
Log.w("Analytics", "Report(removeEvents) events failed due to server error.");
}
}
public void a(DeviceInfo deviceInfo) {
this.f = deviceInfo;
}
}

View File

@@ -0,0 +1,120 @@
package com.ubtrobot.analytics;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import com.ubtrobot.analytics.EventScheme;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/* loaded from: classes2.dex */
public class DiskEventStorage implements EventStorage {
private int a = -1;
private AnalyticsDBHelper b;
public DiskEventStorage(Context context) {
this.b = AnalyticsDBHelper.a(context);
}
@Override // com.ubtrobot.analytics.EventStorage
public void a(Event event) throws IOException {
synchronized (this) {
b(Collections.singletonList(event));
}
}
@Override // com.ubtrobot.analytics.EventStorage
public void b(List<Event> list) throws IOException {
synchronized (this) {
this.b.b(EventScheme.Converters.a(list));
this.a = -1;
}
}
@Override // com.ubtrobot.analytics.EventStorage
public int a() throws IOException {
int i;
synchronized (this) {
this.a = this.a > 0 ? this.a : this.b.c("event");
i = this.a;
}
return i;
}
@Override // com.ubtrobot.analytics.EventStorage
public void b(int i) throws IOException {
synchronized (this) {
this.b.a("event", String.format("%s IN (SELECT %s FROM %s LIMIT %s)", JockstickDataConverter.ID, JockstickDataConverter.ID, "event", Integer.valueOf(i)), null);
this.a = -1;
}
}
@Override // com.ubtrobot.analytics.EventStorage
public List<Event> a(int i) throws IOException {
synchronized (this) {
LinkedList linkedList = new LinkedList();
int i2 = i / 5;
int i3 = 0;
while (true) {
if (i3 > i) {
break;
}
i3 += i2;
Cursor d = this.b.d(String.format("SELECT * FROM %s ORDER BY %s ASC LIMIT %s, %s", "event", JockstickDataConverter.ID, Integer.valueOf(i3), Integer.valueOf(i3)));
if (d == null) {
return Collections.emptyList();
}
try {
if (d.getCount() == 0) {
break;
}
while (d.moveToNext()) {
linkedList.add(EventScheme.Converters.a(d));
}
d.close();
} finally {
d.close();
}
}
return linkedList;
}
}
@Override // com.ubtrobot.analytics.EventStorage
public void a(List<Event> list) throws IOException {
synchronized (this) {
LinkedList linkedList = new LinkedList();
for (Event event : list) {
StringBuilder sb = new StringBuilder();
sb.append("DELETE FROM ");
sb.append("event");
sb.append(" WHERE ");
sb.append(JockstickDataConverter.ID);
sb.append(" IN(SELECT ");
sb.append(JockstickDataConverter.ID);
sb.append(" FROM ");
sb.append("event");
sb.append(" WHERE ");
sb.append("event_id");
sb.append(" = '");
sb.append(event.getEventId());
sb.append("' AND ");
sb.append("category");
sb.append(" = '");
sb.append(event.getCategory());
sb.append("' AND ");
sb.append("recorded_at");
sb.append(" = '");
sb.append(event.getRecordedAt());
sb.append("'");
sb.append(")");
linkedList.add(sb.toString());
Log.i("Analytics", "Remove event sql: " + sb.toString());
}
this.b.a(linkedList);
}
}
}

View File

@@ -0,0 +1,183 @@
package com.ubtrobot.analytics;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes2.dex */
public class Event implements Parcelable {
public static final Parcelable.Creator<Event> CREATOR = new Parcelable.Creator<Event>() { // from class: com.ubtrobot.analytics.Event.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public Event createFromParcel(Parcel parcel) {
return new Event(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public Event[] newArray(int i) {
return new Event[i];
}
};
private String category;
private Map<String, String> customSegmentation;
private long duration;
private String eventId;
private long recordedAt;
private Map<String, String> segmentation;
private String userId;
private String version;
public static class Builder {
private String a;
private String b;
private String c;
private String d;
private long e;
private long f = System.currentTimeMillis() / 1000;
private Map<String, String> g;
private Map<String, String> h;
public Builder(String str, String str2) {
this.a = str;
this.c = str2;
}
public Builder a(String str) {
this.b = str;
return this;
}
public Builder b(String str) {
this.d = str;
return this;
}
public String toString() {
return "Event.Builder{eventId='" + this.a + "', userId='" + this.b + "', category='" + this.c + "', version='" + this.d + "', duration=" + this.e + ", recordedAt=" + this.f + ", segmentation=" + this.g + ", customSegmentation=" + this.h + '}';
}
public Builder a(long j) {
this.e = j;
return this;
}
public Builder b(long j) {
this.f = j / 1000;
return this;
}
public Builder a(Map<String, String> map) {
this.h = map;
return this;
}
public Builder b(Map<String, String> map) {
this.g = map;
return this;
}
public Event a() {
Event event = new Event(this.a, this.c);
event.userId = this.b;
event.version = this.d;
event.duration = this.e;
event.recordedAt = this.f;
Map map = this.g;
if (map == null) {
map = new HashMap();
}
event.segmentation = map;
Map map2 = this.h;
if (map2 == null) {
map2 = new HashMap();
}
event.customSegmentation = map2;
return event;
}
}
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public String getCategory() {
return this.category;
}
public Map<String, String> getCustomSegmentation() {
return this.customSegmentation;
}
public long getDuration() {
return this.duration;
}
public String getEventId() {
return this.eventId;
}
public long getRecordedAt() {
return this.recordedAt;
}
public Map<String, String> getSegmentation() {
return this.segmentation;
}
public String getUserId() {
return this.userId;
}
public String getVersion() {
return this.version;
}
public String toString() {
return "Event{eventId='" + this.eventId + "', userId='" + this.userId + "', category='" + this.category + "', version='" + this.version + "', duration=" + this.duration + ", recordedAt=" + this.recordedAt + ", segmentation=" + this.segmentation + ", customSegmentation=" + this.customSegmentation + '}';
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.eventId);
parcel.writeString(this.userId);
parcel.writeString(this.category);
parcel.writeString(this.version);
parcel.writeLong(this.duration);
parcel.writeLong(this.recordedAt);
parcel.writeByte((byte) (this.segmentation == null ? 0 : 1));
Map<String, String> map = this.segmentation;
if (map != null) {
parcel.writeMap(map);
}
parcel.writeByte((byte) (this.customSegmentation != null ? 1 : 0));
Map<String, String> map2 = this.customSegmentation;
if (map2 != null) {
parcel.writeMap(map2);
}
}
private Event(String str, String str2) {
this.eventId = str;
this.category = str2;
}
private Event(Parcel parcel) {
this.eventId = parcel.readString();
this.userId = parcel.readString();
this.category = parcel.readString();
this.version = parcel.readString();
this.duration = parcel.readLong();
this.recordedAt = parcel.readLong();
if (parcel.readByte() != 0) {
this.segmentation = new HashMap();
parcel.readMap(this.segmentation, String.class.getClassLoader());
}
if (parcel.readByte() != 0) {
this.customSegmentation = new HashMap();
parcel.readMap(this.customSegmentation, String.class.getClassLoader());
}
}
}

View File

@@ -0,0 +1,5 @@
package com.ubtrobot.analytics;
/* loaded from: classes2.dex */
public interface EventReporter {
}

View File

@@ -0,0 +1,167 @@
package com.ubtrobot.analytics;
import android.database.Cursor;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import com.ubtrobot.analytics.Event;
import com.unity3d.ads.metadata.MediationMetaData;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes2.dex */
public class EventScheme {
public static void a(AnalyticsDBHelper analyticsDBHelper) {
Log.i("dance", "Create table: event");
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("CREATE TABLE IF NOT EXISTS ");
stringBuffer.append("event");
stringBuffer.append("(");
stringBuffer.append(JockstickDataConverter.ID);
stringBuffer.append(" INTEGER PRIMARY KEY AUTOINCREMENT,");
stringBuffer.append("event_id");
stringBuffer.append(" VARCHAR NOT NULL,");
stringBuffer.append("user_id");
stringBuffer.append(" VARCHAR DEFAULT '',");
stringBuffer.append("duration");
stringBuffer.append(" INTEGER DEFAULT 0,");
stringBuffer.append("category");
stringBuffer.append(" VARCHAR(32) NOT NULL,");
stringBuffer.append(MediationMetaData.KEY_VERSION);
stringBuffer.append(" VARCHAR(32) DEFAULT '',");
stringBuffer.append("recorded_at");
stringBuffer.append(" INTEGER DEFAULT 0,");
stringBuffer.append("segmentation");
stringBuffer.append(" VARCHAR DEFAULT '',");
stringBuffer.append("custom_segmentation");
stringBuffer.append(" VARCHAR DEFAULT ''");
stringBuffer.append(")");
analyticsDBHelper.a(stringBuffer.toString());
}
public static void b(AnalyticsDBHelper analyticsDBHelper) {
Log.i("dance", "Running upgradeToVersion2 ...");
if (analyticsDBHelper.a("event", "duration")) {
return;
}
analyticsDBHelper.b(String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", "event", "duration"));
}
public static void c(AnalyticsDBHelper analyticsDBHelper) {
Log.i("dance", "Running upgradeToVersion3 ...");
if (analyticsDBHelper.a("event", "user_id")) {
return;
}
analyticsDBHelper.b(String.format("ALTER TABLE %s ADD COLUMN %s VARCHAR DEFAULT ''", "event", "user_id"));
}
public static void d(AnalyticsDBHelper analyticsDBHelper) {
Log.i("dance", "Running upgradeToVersion4 ...");
if (analyticsDBHelper.a("event", MediationMetaData.KEY_VERSION)) {
return;
}
analyticsDBHelper.b(String.format("ALTER TABLE %s ADD COLUMN %s VARCHAR DEFAULT ''", "event", MediationMetaData.KEY_VERSION));
}
public static class Converters {
private static final Gson a = new Gson();
static String a(List<Event> list) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("INSERT INTO ");
stringBuffer.append("event");
stringBuffer.append("(");
stringBuffer.append("event_id");
stringBuffer.append(", ");
stringBuffer.append("user_id");
stringBuffer.append(", ");
stringBuffer.append("category");
stringBuffer.append(", ");
stringBuffer.append(MediationMetaData.KEY_VERSION);
stringBuffer.append(", ");
stringBuffer.append("duration");
stringBuffer.append(", ");
stringBuffer.append("recorded_at");
stringBuffer.append(", ");
stringBuffer.append("segmentation");
stringBuffer.append(", ");
stringBuffer.append("custom_segmentation");
stringBuffer.append(") ");
stringBuffer.append("values");
StringBuffer stringBuffer2 = new StringBuffer();
for (Event event : list) {
String userId = event.getUserId();
String str = "";
if (userId == null) {
userId = "";
}
String version = event.getVersion();
if (version != null) {
str = version;
}
stringBuffer2.append("(");
stringBuffer2.append("'");
stringBuffer2.append(event.getEventId());
stringBuffer2.append("', ");
stringBuffer2.append("'");
stringBuffer2.append(userId);
stringBuffer2.append("', ");
stringBuffer2.append("'");
stringBuffer2.append(event.getCategory());
stringBuffer2.append("', ");
stringBuffer2.append("'");
stringBuffer2.append(str);
stringBuffer2.append("', ");
stringBuffer2.append("'");
stringBuffer2.append(event.getDuration());
stringBuffer2.append("', ");
stringBuffer2.append("'");
stringBuffer2.append(event.getRecordedAt());
stringBuffer2.append("', ");
stringBuffer2.append("'");
stringBuffer2.append(a.toJson(event.getSegmentation()));
stringBuffer2.append("', ");
stringBuffer2.append("'");
stringBuffer2.append(a.toJson(event.getCustomSegmentation()));
stringBuffer2.append("'");
stringBuffer2.append(")");
stringBuffer2.append(", ");
}
stringBuffer2.delete(stringBuffer2.length() - 2, stringBuffer2.length() - 1);
stringBuffer.append(stringBuffer2.toString());
return stringBuffer.toString();
}
static Event a(Cursor cursor) {
String string = cursor.getString(cursor.getColumnIndex("event_id"));
String string2 = cursor.getString(cursor.getColumnIndex("user_id"));
String string3 = cursor.getString(cursor.getColumnIndex("category"));
String string4 = cursor.getString(cursor.getColumnIndex(MediationMetaData.KEY_VERSION));
long j = cursor.getLong(cursor.getColumnIndex("duration"));
long j2 = cursor.getLong(cursor.getColumnIndex("recorded_at"));
String string5 = cursor.getString(cursor.getColumnIndex("segmentation"));
String string6 = cursor.getString(cursor.getColumnIndex("custom_segmentation"));
Event.Builder builder = new Event.Builder(string, string3);
builder.a(string2);
builder.b(string4);
builder.a(j);
builder.b(j2 * 1000);
builder.b(a(string5));
builder.a(a(string6));
return builder.a();
}
private static Map<String, String> a(String str) {
try {
return (Map) a.fromJson(str, new TypeToken<Map<String, String>>() { // from class: com.ubtrobot.analytics.EventScheme.Converters.1
}.getType());
} catch (JsonSyntaxException unused) {
Log.e("dance", "Converters to map failed:" + str);
return new HashMap();
}
}
}
}

View File

@@ -0,0 +1,19 @@
package com.ubtrobot.analytics;
import java.io.IOException;
import java.util.List;
/* loaded from: classes2.dex */
public interface EventStorage {
int a() throws IOException;
List<Event> a(int i) throws IOException;
void a(Event event) throws IOException;
void a(List<Event> list) throws IOException;
void b(int i) throws IOException;
void b(List<Event> list) throws IOException;
}

View File

@@ -0,0 +1,164 @@
package com.ubtrobot.analytics;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import com.google.gson.Gson;
import com.ubtrobot.analytics.ReportException;
import com.ubtrobot.analytics.device.DeviceInfo;
import com.ubtrobot.analytics.device.DeviceInfoReporter;
import com.ubtrobot.analytics.device.MobileDeviceInfo;
import com.ubtrobot.analytics.device.RobotDeviceInfo;
import com.ubtrobot.http.rest.URestException;
import com.ubtrobot.okhttp.interceptor.sign.AuthorizationInterceptor;
import com.ubtrobot.okhttp.interceptor.sign.HttpSignInterceptor;
import com.ubtrobot.retrofit.adapter.urest.URestCall;
import com.ubtrobot.retrofit.adapter.urest.URestCallAdapterFactory;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
/* loaded from: classes2.dex */
public class HttpReport implements EventReporter, DeviceInfoReporter {
private final Context a;
private final String b;
private final String c;
private final String d;
private ReportService e;
public interface ReportService {
@GET("configuration/realtime/eventIds")
URestCall<RealtimeEvent> getForthwithEventIdList(@Query("eventCode") String str);
@POST("collected/device")
URestCall<Void> reportDeviceInfo(@Body MobileDeviceInfo mobileDeviceInfo);
@POST("collected/device")
URestCall<Void> reportDeviceInfo(@Body RobotDeviceInfo robotDeviceInfo);
@POST("collected/events")
URestCall<Void> reportEvent(@Body List<Event> list);
}
public HttpReport(Context context, String str, String str2, String str3) {
this.a = context;
this.b = str;
this.c = str2;
if (str3 == null || str3.length() == 0) {
throw new IllegalArgumentException("deviceId is not null.");
}
this.d = str3;
b();
}
private void b() {
this.e = b("https://apis.ubtrobot.com/v1/collect-rest/");
}
private void a() {
this.e = b("https://test79.ubtrobot.com/v1/collect-rest/");
}
private ReportService b(String str) {
Log.i("Analytics", "Url:" + str);
return (ReportService) new Retrofit.Builder().client(new OkHttpClient.Builder().addInterceptor(new HttpSignInterceptor(this.b, this.c, new HttpSignInterceptor.DeviceInfoSource() { // from class: com.ubtrobot.analytics.HttpReport.2
@Override // com.ubtrobot.okhttp.interceptor.sign.HttpSignInterceptor.DeviceInfoSource
public String a(Request request) {
return HttpReport.this.d;
}
})).addInterceptor(new AuthorizationInterceptor(new AuthorizationInterceptor.AuthenticationInfoSource() { // from class: com.ubtrobot.analytics.HttpReport.1
@Override // com.ubtrobot.okhttp.interceptor.sign.AuthorizationInterceptor.AuthenticationInfoSource
public String a(Request request) {
return HttpReport.this.d;
}
@Override // com.ubtrobot.okhttp.interceptor.sign.AuthorizationInterceptor.AuthenticationInfoSource
public String b(Request request) {
return null;
}
})).build()).addConverterFactory(GsonConverterFactory.create(new Gson())).addCallAdapterFactory(URestCallAdapterFactory.create()).baseUrl(str).build().create(ReportService.class);
}
public void a(boolean z) {
if (z) {
Log.i("Analytics", "Change debug environment.");
a();
} else {
Log.i("Analytics", "Change release environment.");
b();
}
}
public RealtimeEvent a(String str) throws ReportException {
try {
return this.e.getForthwithEventIdList(str).a();
} catch (URestException e) {
Log.e("Analytics", "Get forthwith event id list fail.", e);
a(e);
throw null;
} catch (IllegalStateException e2) {
Log.e("Analytics", "Method getRealtimeEventIdList fail.", e2);
return null;
}
}
public void a(List<Event> list) throws ReportException {
try {
Log.i("Analytics", "Start report event:" + list.size());
this.e.reportEvent(list).a();
} catch (URestException e) {
a(e);
throw null;
}
}
private void a(URestException uRestException) throws ReportException {
int code = uRestException.getCode();
if (code == -3) {
throw ReportException.Factory.c(uRestException);
}
if (code == -2) {
if (a(this.a)) {
throw ReportException.Factory.b(uRestException);
}
throw ReportException.Factory.a(uRestException);
}
if (code == -1) {
throw new IllegalStateException("Should add permission(android.permission.INTERNET).", uRestException);
}
if (code != 1001) {
throw ReportException.Factory.a(uRestException);
}
throw ReportException.Factory.d(uRestException);
}
private boolean a(Context context) {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return false;
}
return activeNetworkInfo.isConnected();
}
public void a(DeviceInfo deviceInfo) throws ReportException {
try {
if (deviceInfo instanceof MobileDeviceInfo) {
this.e.reportDeviceInfo((MobileDeviceInfo) deviceInfo).a();
} else if (deviceInfo instanceof RobotDeviceInfo) {
this.e.reportDeviceInfo((RobotDeviceInfo) deviceInfo).a();
}
} catch (URestException e) {
a(e);
throw null;
} catch (IncompatibleClassChangeError e2) {
Log.e("Analytics", "Method reportDeviceInfo fail", e2);
}
}
}

View File

@@ -0,0 +1,73 @@
package com.ubtrobot.analytics;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/* loaded from: classes2.dex */
public class MemoryEventStorage implements EventStorage {
private final LinkedList<Event> a;
private final int b;
public MemoryEventStorage() {
this(17895697);
}
@Override // com.ubtrobot.analytics.EventStorage
public void a(Event event) throws IOException {
synchronized (this.a) {
this.a.add(event);
}
}
@Override // com.ubtrobot.analytics.EventStorage
public void b(List<Event> list) throws IOException {
synchronized (this.a) {
this.a.addAll(list);
if (this.a.size() <= this.b) {
return;
}
b(this.a.size() - this.b);
}
}
public MemoryEventStorage(int i) {
this.a = new LinkedList<>();
this.b = i;
}
@Override // com.ubtrobot.analytics.EventStorage
public int a() throws IOException {
int size;
synchronized (this.a) {
size = this.a.size();
}
return size;
}
@Override // com.ubtrobot.analytics.EventStorage
public List<Event> a(int i) throws IOException {
LinkedList linkedList;
synchronized (this.a) {
linkedList = new LinkedList(this.a.subList(0, Math.min(i, this.a.size())));
}
return linkedList;
}
@Override // com.ubtrobot.analytics.EventStorage
public void b(int i) throws IOException {
synchronized (this.a) {
Iterator<Event> it = this.a.iterator();
for (int i2 = 0; it.hasNext() && i2 < i; i2++) {
it.next();
it.remove();
}
}
}
@Override // com.ubtrobot.analytics.EventStorage
public void a(List<Event> list) throws IOException {
throw new IllegalStateException("MemoryEventStorage nonsupport removeEvents(List<Event>).");
}
}

View File

@@ -0,0 +1,56 @@
package com.ubtrobot.analytics;
import android.os.Parcel;
import android.os.Parcelable;
/* loaded from: classes2.dex */
public class ModuleVersion implements Parcelable {
public static final Parcelable.Creator<ModuleVersion> CREATOR = new Parcelable.Creator<ModuleVersion>() { // from class: com.ubtrobot.analytics.ModuleVersion.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public ModuleVersion createFromParcel(Parcel parcel) {
return new ModuleVersion(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public ModuleVersion[] newArray(int i) {
return new ModuleVersion[i];
}
};
private String name;
private String version;
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public String getName() {
return this.name;
}
public String getVersion() {
return this.version;
}
public String toString() {
return "ModuleVersion{name='" + this.name + "', version='" + this.version + "'}";
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.name);
parcel.writeString(this.version);
}
public ModuleVersion(String str, String str2) {
this.name = str;
this.version = str2;
}
private ModuleVersion(Parcel parcel) {
this.name = parcel.readString();
this.version = parcel.readString();
}
}

View File

@@ -0,0 +1,37 @@
package com.ubtrobot.analytics;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
/* loaded from: classes2.dex */
public class NetWorkChangeReceiver extends BroadcastReceiver {
private INetWorkChange a;
public interface INetWorkChange {
void a();
}
public NetWorkChangeReceiver(INetWorkChange iNetWorkChange) {
this.a = iNetWorkChange;
}
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
Log.i("Analytics", "Action: " + intent.getAction());
if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo == null) {
Log.w("Analytics", "NetworkInfo get fail.");
} else if (NetworkInfo.State.CONNECTED != activeNetworkInfo.getState() || !activeNetworkInfo.isConnected()) {
Log.w("Analytics", "NetWork is not connect.");
} else {
Log.i("Analytics", "NetWork is connected.");
this.a.a();
}
}
}
}

View File

@@ -0,0 +1,27 @@
package com.ubtrobot.analytics;
import java.util.Collections;
import java.util.List;
/* loaded from: classes2.dex */
public class RealtimeEvent {
private String a;
private List<String> b;
private RealtimeEvent() {
}
public String a() {
String str = this.a;
return str != null ? str : "";
}
public List<String> b() {
List<String> list = this.b;
return list != null ? list : Collections.emptyList();
}
public String toString() {
return "RealtimeEvent{eventCode='" + this.a + "', eventIdList=" + this.b + '}';
}
}

View File

@@ -0,0 +1,49 @@
package com.ubtrobot.analytics;
/* loaded from: classes2.dex */
public class ReportException extends Exception {
private static final int CODE_INTERNAL_SERVER_ERROR = 2;
private static final int CODE_NETWORK_DISCONNECTED = 1;
private static final int CODE_TIMEOUT = 3;
private static final int CODE_UNAUTHORIZED = 4;
private final int code;
public static class Factory {
public static ReportException a(Throwable th) {
return new ReportException(2, "Can not connect the server or unauthorized key.", th);
}
public static ReportException b(Throwable th) {
return new ReportException(1, "Network disconnected.", th);
}
public static ReportException c(Throwable th) {
return new ReportException(3, "Report timeout.", th);
}
public static ReportException d(Throwable th) {
return new ReportException(4, "unauthorized key.", th);
}
}
public boolean causedByInternalServerError() {
return this.code == 2;
}
public boolean causedByNetworkDisconnected() {
return this.code == 1;
}
public boolean causedByTimeOut() {
return this.code == 3;
}
public boolean causedByUnauthorized() {
return this.code == 4;
}
private ReportException(int i, String str, Throwable th) {
super(str, th);
this.code = i;
}
}

View File

@@ -0,0 +1,54 @@
package com.ubtrobot.analytics;
import android.os.Handler;
/* loaded from: classes2.dex */
public class Retry {
private int a;
private RetryRunnable b;
private Handler c;
private RetryListener d;
public interface RetryListener {
void a();
}
private class RetryRunnable implements Runnable {
private RetryRunnable() {
}
@Override // java.lang.Runnable
public void run() {
Retry.this.d.a();
Retry.this.c.postDelayed(this, (long) (Math.pow(2.0d, Retry.this.a) * 1000.0d));
Retry.c(Retry.this);
Retry retry = Retry.this;
retry.a = retry.a > 32 ? 0 : Retry.this.a;
}
}
public Retry(RetryListener retryListener) {
if (retryListener == null) {
throw new IllegalArgumentException("Argument retryListener is null.");
}
this.d = retryListener;
this.b = new RetryRunnable();
this.c = new Handler();
}
static /* synthetic */ int c(Retry retry) {
int i = retry.a;
retry.a = i + 1;
return i;
}
public void b() {
this.c.removeCallbacks(this.b);
}
public void a() {
this.a = 0;
this.c.removeCallbacks(this.b);
this.c.post(this.b);
}
}

View File

@@ -0,0 +1,65 @@
package com.ubtrobot.analytics;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
public class Strategy implements Parcelable {
private static final int MIN_REPORT_INTERVAL_MINUTE = 1;
private long reportIntervalSeconds;
public static final Strategy DEFAULT = new Builder().a();
private static final long DEFAULT_REPORT_INTERVAL_SECONDS = TimeUnit.MINUTES.toSeconds(5);
public static final Parcelable.Creator<Strategy> CREATOR = new Parcelable.Creator<Strategy>() { // from class: com.ubtrobot.analytics.Strategy.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public Strategy createFromParcel(Parcel parcel) {
return new Strategy(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public Strategy[] newArray(int i) {
return new Strategy[i];
}
};
public static class Builder {
private long a = Strategy.DEFAULT_REPORT_INTERVAL_SECONDS;
public Strategy a() {
Strategy strategy = new Strategy();
strategy.reportIntervalSeconds = this.a;
return strategy;
}
public String toString() {
return "Builder{reportIntervalSeconds=" + this.a + '}';
}
}
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public long getReportIntervalSeconds() {
return this.reportIntervalSeconds;
}
public String toString() {
return "Strategy{reportIntervalSeconds=" + this.reportIntervalSeconds + '}';
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeLong(this.reportIntervalSeconds);
}
private Strategy() {
}
private Strategy(Parcel parcel) {
this.reportIntervalSeconds = parcel.readLong();
}
}

View File

@@ -0,0 +1,5 @@
package com.ubtrobot.analytics.device;
/* loaded from: classes2.dex */
public interface DeviceInfo {
}

View File

@@ -0,0 +1,5 @@
package com.ubtrobot.analytics.device;
/* loaded from: classes2.dex */
public interface DeviceInfoReporter {
}

View File

@@ -0,0 +1,236 @@
package com.ubtrobot.analytics.device;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import com.ijm.dataencryption.de.DataDecryptTool;
import com.ubt.jimu.diy.model.CategoryModel;
import com.ubt.jimu.diy.view.fragment.BuildStepFragment;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.Enumeration;
import java.util.Locale;
import java.util.TimeZone;
import java.util.UUID;
/* loaded from: classes2.dex */
public class DeviceInfoUtils {
private static final byte[] a = new byte[0];
private static volatile String b;
public static String a() {
return Locale.getDefault().getLanguage();
}
public static String b() {
return Build.MODEL;
}
public static String c() {
return Build.VERSION.RELEASE;
}
public static String d(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException unused) {
Log.w("Analytics", "Get app version fail.");
return "";
}
}
public static String e() {
try {
return TimeZone.getDefault().getDisplayName(false, 0);
} catch (AssertionError unused) {
Log.w("Analytics", "Fail get time zone.");
String date = new Date(119, 5, 9).toString();
return date.substring(20, date.length() - 5);
}
}
@SuppressLint({"MissingPermission"})
private static String f(Context context) {
String imei;
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
if (telephonyManager != null) {
try {
imei = Build.VERSION.SDK_INT >= 26 ? telephonyManager.getImei() : telephonyManager.getDeviceId();
} catch (SecurityException unused) {
}
return (imei != null || "000000000000000".equals(imei)) ? "" : imei;
}
imei = null;
if (imei != null) {
}
}
private static String g(Context context) {
String macAddress;
if (Build.VERSION.SDK_INT >= 23) {
macAddress = g();
if (TextUtils.isEmpty(macAddress)) {
macAddress = f();
}
} else {
macAddress = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo().getMacAddress();
}
return (macAddress == null || "02:00:00:00:00:00".equals(macAddress)) ? "" : macAddress;
}
public static String h(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
return telephonyManager != null ? telephonyManager.getSimOperator() : "";
}
private static String i(Context context) {
if (b != null) {
return b;
}
synchronized (a) {
if (b != null) {
return b;
}
String j = j(context);
if (j.length() == 0) {
j = a(context);
}
b = j;
return b;
}
}
private static String j(Context context) {
return context.getApplicationContext().getSharedPreferences("deviceId", 0).getString(BuildStepFragment.UUID, "");
}
private static String a(Context context) {
String b2 = b(b(context));
a(context, b2);
return b2;
}
private static String b(String str) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(str.getBytes());
return new BigInteger(1, messageDigest.digest()).toString(16);
} catch (NoSuchAlgorithmException unused) {
throw new IllegalStateException("MessageDigest md5 fail.");
}
}
private static String c(Context context) {
String string = Settings.Secure.getString(context.getContentResolver(), "android_id");
return (string == null || "9774d56d682e549c".equals(string)) ? "" : string;
}
private static void a(Context context, String str) {
SharedPreferences.Editor edit = context.getApplicationContext().getSharedPreferences("deviceId", 0).edit();
edit.putString(BuildStepFragment.UUID, str);
edit.apply();
}
@SuppressLint({"MissingPermission"})
private static String d() {
try {
String serial = Build.VERSION.SDK_INT >= 26 ? Build.getSerial() : Build.SERIAL;
return CategoryModel.unknown.equals(serial.toLowerCase()) ? "" : serial;
} catch (SecurityException unused) {
Log.i("Analytics", "Get sn is not permission.");
return "";
}
}
private static String f() {
for (String str : new String[]{"/sys/class/net/wlan0/address", "/sys/class/net/eth0/address", "/sys/devices/virtual/net/wlan0/address"}) {
String a2 = a(str);
if (a2.length() > 0) {
return a2;
}
}
return "";
}
private static String b(Context context) {
String g = g(context);
String c = c(context);
String f = f(context);
String d = d();
StringBuffer stringBuffer = new StringBuffer();
if (g.length() != 0) {
stringBuffer.append(g);
}
if (c.length() != 0) {
stringBuffer.append(c);
}
if (f.length() != 0) {
stringBuffer.append(f);
}
if (d.length() != 0) {
stringBuffer.append(d);
}
if (stringBuffer.length() == 0) {
stringBuffer.append(UUID.randomUUID().toString().replace("-", ""));
}
return stringBuffer.toString();
}
public static String e(Context context) {
return i(context);
}
private static String g() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
if (!networkInterfaces.hasMoreElements()) {
return "";
}
NetworkInterface nextElement = networkInterfaces.nextElement();
String name = nextElement.getName();
if (!"wlan0".equals(name) && !"eth0".equals(name)) {
return "";
}
try {
byte[] hardwareAddress = nextElement.getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (byte b2 : hardwareAddress) {
sb.append(String.format("%02X:", Byte.valueOf(b2)));
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString().toLowerCase(Locale.getDefault());
} catch (SocketException unused) {
return "";
}
} catch (SocketException unused2) {
Log.w("Analytics", "Get Enumeration fail.");
return "";
}
}
private static String a(String str) {
String str2 = "";
try {
FileReader fileReader = new FileReader(str);
str2 = new BufferedReader(fileReader, DataDecryptTool.DECRYPT_SP_FILE).readLine();
fileReader.close();
} catch (FileNotFoundException | IOException unused) {
}
return str2;
}
}

View File

@@ -0,0 +1,114 @@
package com.ubtrobot.analytics.device;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
/* loaded from: classes2.dex */
public class MobileDeviceInfo implements DeviceInfo, Parcelable {
public static final Parcelable.Creator<MobileDeviceInfo> CREATOR = new Parcelable.Creator<MobileDeviceInfo>() { // from class: com.ubtrobot.analytics.device.MobileDeviceInfo.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public MobileDeviceInfo createFromParcel(Parcel parcel) {
return new MobileDeviceInfo(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public MobileDeviceInfo[] newArray(int i) {
return new MobileDeviceInfo[i];
}
};
private static final String TAG = "Analytics";
private String appVersion;
private String channel;
private String language;
private String model;
private String osVersion;
private String simOperator;
private String timezone;
private String userId;
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public String getAppVersion() {
return this.appVersion;
}
public String getChannel() {
return this.channel;
}
public String getLanguage() {
return this.language;
}
public String getModel() {
return this.model;
}
public String getOsVersion() {
return this.osVersion;
}
public String getSimOperator() {
return this.simOperator;
}
public String getTimezone() {
return this.timezone;
}
public String getUserId() {
return this.userId;
}
public MobileDeviceInfo setChannel(String str) {
this.channel = str;
return this;
}
public MobileDeviceInfo setUserId(String str) {
this.userId = str;
return this;
}
public String toString() {
return "MobileDeviceInfo{model='" + this.model + "', osVersion='" + this.osVersion + "', language='" + this.language + "', timezone='" + this.timezone + "', appVersion='" + this.appVersion + "', userId='" + this.userId + "', channel='" + this.channel + "', simOperator='" + this.simOperator + "'}";
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.model);
parcel.writeString(this.osVersion);
parcel.writeString(this.language);
parcel.writeString(this.timezone);
parcel.writeString(this.appVersion);
parcel.writeString(this.userId);
parcel.writeString(this.channel);
parcel.writeString(this.simOperator);
}
public MobileDeviceInfo(Context context) {
this.model = DeviceInfoUtils.b();
this.osVersion = DeviceInfoUtils.c();
this.language = DeviceInfoUtils.a();
this.timezone = DeviceInfoUtils.e();
this.appVersion = DeviceInfoUtils.d(context);
this.simOperator = DeviceInfoUtils.h(context);
}
private MobileDeviceInfo(Parcel parcel) {
this.model = parcel.readString();
this.osVersion = parcel.readString();
this.language = parcel.readString();
this.timezone = parcel.readString();
this.appVersion = parcel.readString();
this.userId = parcel.readString();
this.channel = parcel.readString();
this.simOperator = parcel.readString();
}
}

View File

@@ -0,0 +1,106 @@
package com.ubtrobot.analytics.device;
import android.os.Parcel;
import android.os.Parcelable;
import com.ubtrobot.analytics.ModuleVersion;
import java.util.List;
/* loaded from: classes2.dex */
public class RobotDeviceInfo implements DeviceInfo, Parcelable {
public static final Parcelable.Creator<RobotDeviceInfo> CREATOR = new Parcelable.Creator<RobotDeviceInfo>() { // from class: com.ubtrobot.analytics.device.RobotDeviceInfo.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public RobotDeviceInfo createFromParcel(Parcel parcel) {
return new RobotDeviceInfo(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public RobotDeviceInfo[] newArray(int i) {
return new RobotDeviceInfo[i];
}
};
private String channel;
private String language;
private String model;
private List<ModuleVersion> moduleVersions;
private String osVersion;
private String timezone;
private String userId;
public RobotDeviceInfo(List<ModuleVersion> list) {
this.model = DeviceInfoUtils.b();
this.osVersion = DeviceInfoUtils.c();
this.language = DeviceInfoUtils.a();
this.timezone = DeviceInfoUtils.e();
this.moduleVersions = list;
}
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public String getChannel() {
return this.channel;
}
public String getLanguage() {
return this.language;
}
public String getModel() {
return this.model;
}
public List<ModuleVersion> getModuleVersions() {
return this.moduleVersions;
}
public String getOsVersion() {
return this.osVersion;
}
public String getTimezone() {
return this.timezone;
}
public String getUserId() {
return this.userId;
}
public RobotDeviceInfo setChannel(String str) {
this.channel = str;
return this;
}
public RobotDeviceInfo setUserId(String str) {
this.userId = str;
return this;
}
public String toString() {
return "RobotDeviceInfo{model='" + this.model + "', osVersion='" + this.osVersion + "', language='" + this.language + "', timezone='" + this.timezone + "', moduleVersions=" + this.moduleVersions + ", userId='" + this.userId + "', channel='" + this.channel + "'}";
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.model);
parcel.writeString(this.osVersion);
parcel.writeString(this.language);
parcel.writeString(this.timezone);
parcel.writeTypedList(this.moduleVersions);
parcel.writeString(this.userId);
parcel.writeString(this.channel);
}
protected RobotDeviceInfo(Parcel parcel) {
this.model = parcel.readString();
this.osVersion = parcel.readString();
this.language = parcel.readString();
this.timezone = parcel.readString();
this.moduleVersions = parcel.createTypedArrayList(ModuleVersion.CREATOR);
this.userId = parcel.readString();
this.channel = parcel.readString();
}
}

View File

@@ -0,0 +1,12 @@
package com.ubtrobot.analytics.event;
import com.ubtrobot.analytics.Event;
import java.io.IOException;
import java.util.List;
/* loaded from: classes2.dex */
public interface ActivenessEventSource {
int a(int i) throws IOException;
List<Event> a() throws IOException;
}

View File

@@ -0,0 +1,214 @@
package com.ubtrobot.analytics.event;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import com.ubtrobot.analytics.ActivenessRecord;
import com.ubtrobot.analytics.ActivenessStorage;
import com.ubtrobot.analytics.Event;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
public class AppActivenessEventSource implements ActivenessEventSource, Application.ActivityLifecycleCallbacks {
private static final long i = TimeUnit.SECONDS.toMillis(60);
private Ticker b;
private Executor c;
private String d;
private String e;
private ActivenessStorage g;
private final long a = TimeUnit.SECONDS.toMillis(15);
private long f = System.currentTimeMillis();
private AppTicktockListener h = new AppTicktockListener();
private class AppTicktockListener implements TicktockListener {
private long a;
private long b;
private long c;
static /* synthetic */ AppTicktockListener a(AppTicktockListener appTicktockListener, long j) {
appTicktockListener.c(j);
return appTicktockListener;
}
static /* synthetic */ AppTicktockListener b(AppTicktockListener appTicktockListener, long j) {
appTicktockListener.b(j);
return appTicktockListener;
}
private AppTicktockListener() {
this.a = System.currentTimeMillis();
}
/* JADX INFO: Access modifiers changed from: private */
public void d(long j) {
this.c += j;
AppActivenessEventSource.this.c.execute(new Runnable() { // from class: com.ubtrobot.analytics.event.AppActivenessEventSource.AppTicktockListener.2
@Override // java.lang.Runnable
public void run() {
try {
AppActivenessEventSource.this.g.b(AppTicktockListener.this.a(0L));
} catch (IOException unused) {
}
}
});
}
private AppTicktockListener b(long j) {
this.c = j;
return this;
}
private AppTicktockListener c(long j) {
this.a = j;
return this;
}
@Override // com.ubtrobot.analytics.event.TicktockListener
public void a() {
AppActivenessEventSource.this.c.execute(new Runnable() { // from class: com.ubtrobot.analytics.event.AppActivenessEventSource.AppTicktockListener.1
@Override // java.lang.Runnable
public void run() {
try {
AppActivenessEventSource.this.g.b(AppTicktockListener.this.a(AppActivenessEventSource.this.a));
} catch (IOException unused) {
}
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public ActivenessRecord a(long j) {
this.b = System.currentTimeMillis();
this.c += j;
ActivenessRecord activenessRecord = new ActivenessRecord("app_activeness");
activenessRecord.a(AppActivenessEventSource.this.d);
activenessRecord.b(AppActivenessEventSource.this.e);
activenessRecord.b(this.a);
activenessRecord.c(this.b);
activenessRecord.a(this.c);
return activenessRecord;
}
/* JADX INFO: Access modifiers changed from: private */
public long b() {
return this.b;
}
/* JADX INFO: Access modifiers changed from: private */
public void c() {
AppActivenessEventSource.this.c.execute(new Runnable() { // from class: com.ubtrobot.analytics.event.AppActivenessEventSource.AppTicktockListener.3
@Override // java.lang.Runnable
public void run() {
try {
AppActivenessEventSource.this.g.a(AppTicktockListener.this.a(0L));
} catch (IOException unused) {
}
}
});
}
}
public AppActivenessEventSource(Context context, Ticker ticker, Executor executor) {
this.b = ticker;
this.c = executor;
this.g = new ActivenessStorage(context);
b();
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityCreated(Activity activity, Bundle bundle) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityDestroyed(Activity activity) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityPaused(Activity activity) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityResumed(Activity activity) {
c();
this.f = System.currentTimeMillis();
if (Math.abs(this.f - this.h.b()) < i) {
return;
}
AppTicktockListener appTicktockListener = this.h;
AppTicktockListener.a(appTicktockListener, this.f);
AppTicktockListener.b(appTicktockListener, 0 - this.a);
appTicktockListener.c();
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityStarted(Activity activity) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityStopped(Activity activity) {
d();
this.h.d(System.currentTimeMillis() - this.f);
}
private void b() {
this.c.execute(new Runnable() { // from class: com.ubtrobot.analytics.event.AppActivenessEventSource.1
@Override // java.lang.Runnable
public void run() {
try {
AppActivenessEventSource.this.g.a();
} catch (IOException e) {
Log.e("Analytics", "Execute delete repetition sql fail.", e);
}
}
});
}
private void c() {
AppTicktockListener appTicktockListener = this.h;
AppTicktockListener.b(appTicktockListener, appTicktockListener.c - this.a);
this.b.a(this.h, 15, TimeUnit.SECONDS);
}
private void d() {
this.b.a();
}
public void a(String str) {
this.e = str;
}
@Override // com.ubtrobot.analytics.event.ActivenessEventSource
public List<Event> a() throws IOException {
LinkedList linkedList = new LinkedList();
for (ActivenessRecord activenessRecord : this.g.a("app_activeness")) {
if (Math.abs(System.currentTimeMillis() - activenessRecord.d()) >= i) {
HashMap hashMap = new HashMap();
hashMap.put("startTime", String.valueOf(activenessRecord.c()));
Event.Builder builder = new Event.Builder("app_activeness", "predefined_event");
builder.a(activenessRecord.e());
builder.b(activenessRecord.f());
builder.b(hashMap);
builder.b(activenessRecord.d());
builder.a(activenessRecord.a());
linkedList.add(builder.a());
}
}
return linkedList;
}
@Override // com.ubtrobot.analytics.event.ActivenessEventSource
public int a(int i2) throws IOException {
return this.g.a("app_activeness", i2);
}
}

View File

@@ -0,0 +1,42 @@
package com.ubtrobot.analytics.event;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
public class Ticker {
private Handler a = new Handler(Looper.getMainLooper());
private ListenerRunnable b;
private class ListenerRunnable implements Runnable {
private TicktockListener a;
private int b;
private TimeUnit c;
public ListenerRunnable(TicktockListener ticktockListener, int i, TimeUnit timeUnit) {
this.a = ticktockListener;
this.b = i;
this.c = timeUnit;
}
@Override // java.lang.Runnable
public void run() {
this.a.a();
Ticker.this.a.postDelayed(this, this.c.toMillis(this.b));
}
}
public void a(TicktockListener ticktockListener, int i, TimeUnit timeUnit) {
ListenerRunnable listenerRunnable = this.b;
if (listenerRunnable == null) {
listenerRunnable = new ListenerRunnable(ticktockListener, i, timeUnit);
}
this.b = listenerRunnable;
this.a.post(this.b);
}
public void a() {
this.a.removeCallbacks(this.b);
}
}

View File

@@ -0,0 +1,6 @@
package com.ubtrobot.analytics.event;
/* loaded from: classes2.dex */
public interface TicktockListener {
void a();
}

View 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"));
}
}