package com.tencent.wxop.stat; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import com.liulishuo.filedownloader.model.FileDownloadModel; import com.tencent.wxop.stat.common.StatLogger; import com.unity3d.ads.metadata.MediationMetaData; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import org.json.JSONObject; /* loaded from: classes.dex */ public class au { private static StatLogger h = com.tencent.wxop.stat.common.l.b(); private static Context i = null; private static au j = null; private bc c; private bc d; private com.tencent.wxop.stat.common.e e; private String f; private String g; private ConcurrentHashMap l; volatile int a = 0; com.tencent.wxop.stat.common.a b = null; private int k = 0; private boolean m = false; private HashMap n = new HashMap<>(); private au(Context context) { this.c = null; this.d = null; this.e = null; this.f = ""; this.g = ""; this.l = null; try { this.e = new com.tencent.wxop.stat.common.e(); i = context.getApplicationContext(); this.l = new ConcurrentHashMap<>(); this.f = com.tencent.wxop.stat.common.l.p(context); this.g = "pri_" + com.tencent.wxop.stat.common.l.p(context); this.c = new bc(i, this.f); this.d = new bc(i, this.g); a(true); a(false); f(); b(i); d(); j(); } catch (Throwable th) { h.e(th); } } public static au a(Context context) { if (j == null) { synchronized (au.class) { if (j == null) { j = new au(context); } } } return j; } private String a(List list) { StringBuilder sb = new StringBuilder(list.size() * 3); sb.append("event_id in ("); int size = list.size(); Iterator it = list.iterator(); int i2 = 0; while (it.hasNext()) { sb.append(it.next().a); if (i2 != size - 1) { sb.append(","); } i2++; } sb.append(")"); return sb.toString(); } private synchronized void a(int i2, boolean z) { try { if (this.a > 0 && i2 > 0 && !StatServiceImpl.a()) { if (StatConfig.isDebugEnable()) { h.i("Load " + this.a + " unsent events"); } ArrayList arrayList = new ArrayList(i2); b(arrayList, i2, z); if (arrayList.size() > 0) { if (StatConfig.isDebugEnable()) { h.i("Peek " + arrayList.size() + " unsent events."); } a(arrayList, 2, z); i.b(i).b(arrayList, new ba(this, arrayList, z)); } } } catch (Throwable th) { h.e(th); } } /* JADX WARN: Removed duplicated region for block: B:21:0x009f */ /* JADX WARN: Removed duplicated region for block: B:29:0x00c7 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private void a(com.tencent.wxop.stat.event.e r9, com.tencent.wxop.stat.h r10, boolean r11) { /* r8 = this; r0 = 1 r1 = 0 android.database.sqlite.SQLiteDatabase r2 = r8.c(r11) // Catch: java.lang.Throwable -> L8b r2.beginTransaction() // Catch: java.lang.Throwable -> L89 java.lang.String r3 = "events" if (r11 != 0) goto L2d int r11 = r8.a // Catch: java.lang.Throwable -> L89 int r4 = com.tencent.wxop.stat.StatConfig.getMaxStoreEventCount() // Catch: java.lang.Throwable -> L89 if (r11 <= r4) goto L2d com.tencent.wxop.stat.common.StatLogger r11 = com.tencent.wxop.stat.au.h // Catch: java.lang.Throwable -> L89 java.lang.String r4 = "Too many events stored in db." r11.warn(r4) // Catch: java.lang.Throwable -> L89 int r11 = r8.a // Catch: java.lang.Throwable -> L89 com.tencent.wxop.stat.bc r4 = r8.c // Catch: java.lang.Throwable -> L89 android.database.sqlite.SQLiteDatabase r4 = r4.getWritableDatabase() // Catch: java.lang.Throwable -> L89 java.lang.String r5 = "event_id in (select event_id from events where timestamp in (select min(timestamp) from events) limit 1)" int r4 = r4.delete(r3, r5, r1) // Catch: java.lang.Throwable -> L89 int r11 = r11 - r4 r8.a = r11 // Catch: java.lang.Throwable -> L89 L2d: android.content.ContentValues r11 = new android.content.ContentValues // Catch: java.lang.Throwable -> L89 r11.() // Catch: java.lang.Throwable -> L89 java.lang.String r4 = r9.g() // Catch: java.lang.Throwable -> L89 boolean r5 = com.tencent.wxop.stat.StatConfig.isDebugEnable() // Catch: java.lang.Throwable -> L89 if (r5 == 0) goto L4f com.tencent.wxop.stat.common.StatLogger r5 = com.tencent.wxop.stat.au.h // Catch: java.lang.Throwable -> L89 java.lang.StringBuilder r6 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L89 java.lang.String r7 = "insert 1 event, content:" r6.(r7) // Catch: java.lang.Throwable -> L89 r6.append(r4) // Catch: java.lang.Throwable -> L89 java.lang.String r6 = r6.toString() // Catch: java.lang.Throwable -> L89 r5.i(r6) // Catch: java.lang.Throwable -> L89 L4f: java.lang.String r4 = com.tencent.wxop.stat.common.r.b(r4) // Catch: java.lang.Throwable -> L89 java.lang.String r5 = "content" r11.put(r5, r4) // Catch: java.lang.Throwable -> L89 java.lang.String r4 = "send_count" java.lang.String r5 = "0" r11.put(r4, r5) // Catch: java.lang.Throwable -> L89 java.lang.String r4 = "status" java.lang.String r5 = java.lang.Integer.toString(r0) // Catch: java.lang.Throwable -> L89 r11.put(r4, r5) // Catch: java.lang.Throwable -> L89 java.lang.String r4 = "timestamp" long r5 = r9.c() // Catch: java.lang.Throwable -> L89 java.lang.Long r5 = java.lang.Long.valueOf(r5) // Catch: java.lang.Throwable -> L89 r11.put(r4, r5) // Catch: java.lang.Throwable -> L89 long r3 = r2.insert(r3, r1, r11) // Catch: java.lang.Throwable -> L89 r2.setTransactionSuccessful() // Catch: java.lang.Throwable -> L89 if (r2 == 0) goto L99 r2.endTransaction() // Catch: java.lang.Throwable -> L82 goto L99 L82: r11 = move-exception com.tencent.wxop.stat.common.StatLogger r1 = com.tencent.wxop.stat.au.h r1.e(r11) goto L99 L89: r11 = move-exception goto L8d L8b: r11 = move-exception r2 = r1 L8d: r3 = -1 com.tencent.wxop.stat.common.StatLogger r1 = com.tencent.wxop.stat.au.h // Catch: java.lang.Throwable -> Ldf r1.e(r11) // Catch: java.lang.Throwable -> Ldf if (r2 == 0) goto L99 r2.endTransaction() // Catch: java.lang.Throwable -> L82 L99: r1 = 0 int r11 = (r3 > r1 ? 1 : (r3 == r1 ? 0 : -1)) if (r11 <= 0) goto Lc7 int r11 = r8.a int r11 = r11 + r0 r8.a = r11 boolean r11 = com.tencent.wxop.stat.StatConfig.isDebugEnable() if (r11 == 0) goto Lc1 com.tencent.wxop.stat.common.StatLogger r11 = com.tencent.wxop.stat.au.h java.lang.StringBuilder r0 = new java.lang.StringBuilder java.lang.String r1 = "directStoreEvent insert event to db, event:" r0.(r1) java.lang.String r9 = r9.g() r0.append(r9) java.lang.String r9 = r0.toString() r11.d(r9) Lc1: if (r10 == 0) goto Lde r10.a() return Lc7: com.tencent.wxop.stat.common.StatLogger r10 = com.tencent.wxop.stat.au.h java.lang.StringBuilder r11 = new java.lang.StringBuilder java.lang.String r0 = "Failed to store event:" r11.(r0) java.lang.String r9 = r9.g() r11.append(r9) java.lang.String r9 = r11.toString() r10.error(r9) Lde: return Ldf: r9 = move-exception if (r2 == 0) goto Lec r2.endTransaction() // Catch: java.lang.Throwable -> Le6 goto Lec Le6: r10 = move-exception com.tencent.wxop.stat.common.StatLogger r11 = com.tencent.wxop.stat.au.h r11.e(r10) Lec: throw r9 */ throw new UnsupportedOperationException("Method not decompiled: com.tencent.wxop.stat.au.a(com.tencent.wxop.stat.event.e, com.tencent.wxop.stat.h, boolean):void"); } /* JADX INFO: Access modifiers changed from: private */ public synchronized void a(List list, int i2, boolean z) { SQLiteDatabase sQLiteDatabase; String str; if (list.size() == 0) { return; } int b = b(z); String str2 = null; try { sQLiteDatabase = c(z); } catch (Throwable th) { th = th; sQLiteDatabase = null; } try { if (i2 == 2) { str = "update events set status=" + i2 + ", send_count=send_count+1 where " + a(list); } else { str = "update events set status=" + i2 + " where " + a(list); if (this.k % 3 == 0) { str2 = "delete from events where send_count>" + b; } this.k++; } if (StatConfig.isDebugEnable()) { h.i("update sql:" + str); } sQLiteDatabase.beginTransaction(); sQLiteDatabase.execSQL(str); if (str2 != null) { h.i("update for delete sql:" + str2); sQLiteDatabase.execSQL(str2); f(); } sQLiteDatabase.setTransactionSuccessful(); } catch (Throwable th2) { th = th2; try { h.e(th); if (sQLiteDatabase != null) { try { sQLiteDatabase.endTransaction(); } catch (Throwable th3) { h.e(th3); } } } finally { if (sQLiteDatabase != null) { try { sQLiteDatabase.endTransaction(); } catch (Throwable th4) { h.e(th4); } } } } } /* JADX INFO: Access modifiers changed from: private */ public synchronized void a(List list, boolean z) { SQLiteDatabase sQLiteDatabase; Throwable th; if (list.size() == 0) { return; } if (StatConfig.isDebugEnable()) { h.i("Delete " + list.size() + " events, important:" + z); } StringBuilder sb = new StringBuilder(list.size() * 3); sb.append("event_id in ("); int i2 = 0; int size = list.size(); Iterator it = list.iterator(); while (it.hasNext()) { sb.append(it.next().a); if (i2 != size - 1) { sb.append(","); } i2++; } sb.append(")"); try { sQLiteDatabase = c(z); } catch (Throwable th2) { sQLiteDatabase = null; th = th2; } try { sQLiteDatabase.beginTransaction(); int delete = sQLiteDatabase.delete("events", sb.toString(), null); if (StatConfig.isDebugEnable()) { h.i("delete " + size + " event " + sb.toString() + ", success delete:" + delete); } this.a -= delete; sQLiteDatabase.setTransactionSuccessful(); f(); } catch (Throwable th3) { th = th3; try { h.e(th); if (sQLiteDatabase != null) { try { sQLiteDatabase.endTransaction(); } catch (Throwable th4) { h.e(th4); } } } finally { if (sQLiteDatabase != null) { try { sQLiteDatabase.endTransaction(); } catch (Throwable th5) { h.e(th5); } } } } } private void a(boolean z) { SQLiteDatabase sQLiteDatabase; try { try { sQLiteDatabase = c(z); } catch (Throwable th) { th = th; sQLiteDatabase = null; } try { sQLiteDatabase.beginTransaction(); ContentValues contentValues = new ContentValues(); contentValues.put(FileDownloadModel.STATUS, (Integer) 1); int update = sQLiteDatabase.update("events", contentValues, "status=?", new String[]{Long.toString(2L)}); if (StatConfig.isDebugEnable()) { h.i("update " + update + " unsent events."); } sQLiteDatabase.setTransactionSuccessful(); if (sQLiteDatabase != null) { sQLiteDatabase.endTransaction(); } } catch (Throwable th2) { th = th2; try { h.e(th); if (sQLiteDatabase != null) { sQLiteDatabase.endTransaction(); } } catch (Throwable th3) { if (sQLiteDatabase != null) { try { sQLiteDatabase.endTransaction(); } catch (Throwable th4) { h.e(th4); } } throw th3; } } } catch (Throwable th5) { h.e(th5); } } private int b(boolean z) { return !z ? StatConfig.getMaxSendRetryCount() : StatConfig.getMaxImportantDataSendRetryCount(); } public static au b() { return j; } /* JADX INFO: Access modifiers changed from: private */ public void b(int i2, boolean z) { if (i2 == -1) { i2 = !z ? g() : h(); } if (i2 > 0) { int sendPeriodMinutes = StatConfig.getSendPeriodMinutes() * 60 * StatConfig.getNumEventsCommitPerSec(); if (i2 > sendPeriodMinutes && sendPeriodMinutes > 0) { i2 = sendPeriodMinutes; } int a = StatConfig.a(); int i3 = i2 / a; int i4 = i2 % a; if (StatConfig.isDebugEnable()) { h.i("sentStoreEventsByDb sendNumbers=" + i2 + ",important=" + z + ",maxSendNumPerFor1Period=" + sendPeriodMinutes + ",maxCount=" + i3 + ",restNumbers=" + i4); } for (int i5 = 0; i5 < i3; i5++) { a(a, z); } if (i4 > 0) { a(i4, z); } } } /* JADX INFO: Access modifiers changed from: private */ public synchronized void b(com.tencent.wxop.stat.event.e eVar, h hVar, boolean z, boolean z2) { if (StatConfig.getMaxStoreEventCount() > 0) { if (StatConfig.m > 0 && !z && !z2) { if (StatConfig.m > 0) { if (StatConfig.isDebugEnable()) { h.i("cacheEventsInMemory.size():" + this.l.size() + ",numEventsCachedInMemory:" + StatConfig.m + ",numStoredEvents:" + this.a); StatLogger statLogger = h; StringBuilder sb = new StringBuilder("cache event:"); sb.append(eVar.g()); statLogger.i(sb.toString()); } this.l.put(eVar, ""); if (this.l.size() >= StatConfig.m) { i(); } if (hVar != null) { if (this.l.size() > 0) { i(); } hVar.a(); } } } a(eVar, hVar, z); } } /* JADX INFO: Access modifiers changed from: private */ public synchronized void b(f fVar) { Cursor cursor; boolean z; long insert; try { String a = fVar.a(); String a2 = com.tencent.wxop.stat.common.l.a(a); ContentValues contentValues = new ContentValues(); contentValues.put("content", fVar.b.toString()); contentValues.put("md5sum", a2); fVar.c = a2; contentValues.put(MediationMetaData.KEY_VERSION, Integer.valueOf(fVar.d)); cursor = this.c.getReadableDatabase().query("config", null, null, null, null, null, null); while (true) { try { if (!cursor.moveToNext()) { z = false; break; } else if (cursor.getInt(0) == fVar.a) { z = true; break; } } catch (Throwable th) { th = th; try { h.e(th); if (cursor != null) { cursor.close(); } try { this.c.getWritableDatabase().endTransaction(); return; } catch (Exception unused) { return; } } finally { if (cursor != null) { cursor.close(); } try { this.c.getWritableDatabase().endTransaction(); } catch (Exception unused2) { } } } } this.c.getWritableDatabase().beginTransaction(); if (true == z) { insert = this.c.getWritableDatabase().update("config", contentValues, "type=?", new String[]{Integer.toString(fVar.a)}); } else { contentValues.put("type", Integer.valueOf(fVar.a)); insert = this.c.getWritableDatabase().insert("config", null, contentValues); } if (insert == -1) { h.e("Failed to store cfg:" + a); } else { h.d("Sucessed to store cfg:" + a); } this.c.getWritableDatabase().setTransactionSuccessful(); try { this.c.getWritableDatabase().endTransaction(); } catch (Exception unused3) { } } catch (Throwable th2) { th = th2; cursor = null; } } private void b(List list, int i2, boolean z) { Cursor cursor = null; try { cursor = d(z).query("events", null, "status=?", new String[]{Integer.toString(1)}, null, null, null, Integer.toString(i2)); while (cursor.moveToNext()) { long j2 = cursor.getLong(0); String string = cursor.getString(1); if (!StatConfig.g) { string = com.tencent.wxop.stat.common.r.a(string); } String str = string; int i3 = cursor.getInt(2); int i4 = cursor.getInt(3); bd bdVar = new bd(j2, str, i3, i4); if (StatConfig.isDebugEnable()) { h.i("peek event, id=" + j2 + ",send_count=" + i4 + ",timestamp=" + cursor.getLong(4)); } list.add(bdVar); } } catch (Throwable th) { try { h.e(th); if (cursor != null) { cursor.close(); } } finally { if (cursor != null) { cursor.close(); } } } } private SQLiteDatabase c(boolean z) { return (!z ? this.c : this.d).getWritableDatabase(); } private SQLiteDatabase d(boolean z) { return (!z ? this.c : this.d).getReadableDatabase(); } private void f() { this.a = g() + h(); } private int g() { return (int) DatabaseUtils.queryNumEntries(this.c.getReadableDatabase(), "events"); } private int h() { return (int) DatabaseUtils.queryNumEntries(this.d.getReadableDatabase(), "events"); } /* JADX INFO: Access modifiers changed from: private */ /* JADX WARN: Removed duplicated region for block: B:33:0x00f1 A[Catch: all -> 0x0131, TryCatch #1 {, blocks: (B:8:0x0008, B:10:0x0010, B:12:0x0012, B:14:0x001b, B:31:0x00e8, B:33:0x00f1, B:34:0x011e, B:40:0x00cc, B:41:0x00ce, B:51:0x00e5, B:55:0x0130, B:60:0x012b, B:45:0x00d6, B:48:0x00dd, B:57:0x0123, B:37:0x00c4), top: B:7:0x0008, inners: #0, #3, #5, #6 }] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public void i() { /* Method dump skipped, instructions count: 308 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: com.tencent.wxop.stat.au.i():void"); } private void j() { Cursor cursor = null; try { cursor = this.c.getReadableDatabase().query("keyvalues", null, null, null, null, null, null); while (cursor.moveToNext()) { this.n.put(cursor.getString(0), cursor.getString(1)); } } catch (Throwable th) { try { h.e(th); if (cursor != null) { cursor.close(); } } finally { if (cursor != null) { cursor.close(); } } } } public int a() { return this.a; } void a(int i2) { this.e.a(new bb(this, i2)); } void a(com.tencent.wxop.stat.event.e eVar, h hVar, boolean z, boolean z2) { com.tencent.wxop.stat.common.e eVar2 = this.e; if (eVar2 != null) { eVar2.a(new ay(this, eVar, hVar, z, z2)); } } void a(f fVar) { if (fVar == null) { return; } this.e.a(new az(this, fVar)); } void a(List list, int i2, boolean z, boolean z2) { com.tencent.wxop.stat.common.e eVar = this.e; if (eVar != null) { eVar.a(new av(this, list, i2, z, z2)); } } void a(List list, boolean z, boolean z2) { com.tencent.wxop.stat.common.e eVar = this.e; if (eVar != null) { eVar.a(new aw(this, list, z, z2)); } } /* JADX WARN: Removed duplicated region for block: B:36:0x00b3 A[Catch: all -> 0x01cb, TryCatch #4 {all -> 0x01cb, blocks: (B:15:0x0039, B:17:0x0043, B:19:0x0060, B:22:0x0075, B:24:0x007f, B:25:0x0081, B:27:0x0089, B:29:0x008c, B:31:0x0090, B:36:0x00b3, B:38:0x00b6, B:39:0x00ee, B:41:0x0120, B:43:0x0133, B:45:0x0143, B:47:0x014d, B:49:0x0153, B:50:0x0169, B:52:0x01ac, B:65:0x00cd, B:67:0x00d3, B:69:0x00d9, B:70:0x009b, B:72:0x00a1, B:76:0x00ab), top: B:14:0x0039 }] */ /* JADX WARN: Removed duplicated region for block: B:41:0x0120 A[Catch: all -> 0x01cb, TryCatch #4 {all -> 0x01cb, blocks: (B:15:0x0039, B:17:0x0043, B:19:0x0060, B:22:0x0075, B:24:0x007f, B:25:0x0081, B:27:0x0089, B:29:0x008c, B:31:0x0090, B:36:0x00b3, B:38:0x00b6, B:39:0x00ee, B:41:0x0120, B:43:0x0133, B:45:0x0143, B:47:0x014d, B:49:0x0153, B:50:0x0169, B:52:0x01ac, B:65:0x00cd, B:67:0x00d3, B:69:0x00d9, B:70:0x009b, B:72:0x00a1, B:76:0x00ab), top: B:14:0x0039 }] */ /* JADX WARN: Removed duplicated region for block: B:43:0x0133 A[Catch: all -> 0x01cb, TryCatch #4 {all -> 0x01cb, blocks: (B:15:0x0039, B:17:0x0043, B:19:0x0060, B:22:0x0075, B:24:0x007f, B:25:0x0081, B:27:0x0089, B:29:0x008c, B:31:0x0090, B:36:0x00b3, B:38:0x00b6, B:39:0x00ee, B:41:0x0120, B:43:0x0133, B:45:0x0143, B:47:0x014d, B:49:0x0153, B:50:0x0169, B:52:0x01ac, B:65:0x00cd, B:67:0x00d3, B:69:0x00d9, B:70:0x009b, B:72:0x00a1, B:76:0x00ab), top: B:14:0x0039 }] */ /* JADX WARN: Removed duplicated region for block: B:67:0x00d3 A[Catch: all -> 0x01cb, TryCatch #4 {all -> 0x01cb, blocks: (B:15:0x0039, B:17:0x0043, B:19:0x0060, B:22:0x0075, B:24:0x007f, B:25:0x0081, B:27:0x0089, B:29:0x008c, B:31:0x0090, B:36:0x00b3, B:38:0x00b6, B:39:0x00ee, B:41:0x0120, B:43:0x0133, B:45:0x0143, B:47:0x014d, B:49:0x0153, B:50:0x0169, B:52:0x01ac, B:65:0x00cd, B:67:0x00d3, B:69:0x00d9, B:70:0x009b, B:72:0x00a1, B:76:0x00ab), top: B:14:0x0039 }] */ /* JADX WARN: Removed duplicated region for block: B:87:0x01d7 A[EXC_TOP_SPLITTER, SYNTHETIC] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public synchronized com.tencent.wxop.stat.common.a b(android.content.Context r19) { /* Method dump skipped, instructions count: 519 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: com.tencent.wxop.stat.au.b(android.content.Context):com.tencent.wxop.stat.common.a"); } void c() { if (StatConfig.isEnableStatService()) { try { this.e.a(new ax(this)); } catch (Throwable th) { h.e(th); } } } void d() { Cursor cursor = null; try { cursor = this.c.getReadableDatabase().query("config", null, null, null, null, null, null); while (cursor.moveToNext()) { int i2 = cursor.getInt(0); String string = cursor.getString(1); String string2 = cursor.getString(2); int i3 = cursor.getInt(3); f fVar = new f(i2); fVar.a = i2; fVar.b = new JSONObject(string); fVar.c = string2; fVar.d = i3; StatConfig.a(i, fVar); } } catch (Throwable th) { try { h.e(th); if (cursor != null) { cursor.close(); } } finally { if (cursor != null) { cursor.close(); } } } } }