discord-jadx/app/src/main/java/c/i/a/f/i/b/g.java

1842 lines
74 KiB
Java

package c.i.a.f.i.b;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.WorkerThread;
import androidx.collection.ArrayMap;
import c.d.b.a.a;
import c.i.a.f.e.o.d;
import c.i.a.f.h.l.a1;
import c.i.a.f.h.l.c1;
import c.i.a.f.h.l.da;
import c.i.a.f.h.l.e1;
import c.i.a.f.h.l.l0;
import c.i.a.f.h.l.l9;
import c.i.a.f.h.l.o0;
import c.i.a.f.h.l.o8;
import c.i.a.f.h.l.u4;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.google.android.gms.measurement.internal.zzaq;
import com.google.android.gms.measurement.internal.zzku;
import com.google.android.gms.measurement.internal.zzz;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/* compiled from: com.google.android.gms:play-services-measurement@@18.0.0 */
public final class g extends i9 {
public static final String[] d = {"last_bundled_timestamp", "ALTER TABLE events ADD COLUMN last_bundled_timestamp INTEGER;", "last_bundled_day", "ALTER TABLE events ADD COLUMN last_bundled_day INTEGER;", "last_sampled_complex_event_id", "ALTER TABLE events ADD COLUMN last_sampled_complex_event_id INTEGER;", "last_sampling_rate", "ALTER TABLE events ADD COLUMN last_sampling_rate INTEGER;", "last_exempt_from_sampling", "ALTER TABLE events ADD COLUMN last_exempt_from_sampling INTEGER;", "current_session_count", "ALTER TABLE events ADD COLUMN current_session_count INTEGER;"};
public static final String[] e = {"origin", "ALTER TABLE user_attributes ADD COLUMN origin TEXT;"};
public static final String[] f = {"app_version", "ALTER TABLE apps ADD COLUMN app_version TEXT;", "app_store", "ALTER TABLE apps ADD COLUMN app_store TEXT;", "gmp_version", "ALTER TABLE apps ADD COLUMN gmp_version INTEGER;", "dev_cert_hash", "ALTER TABLE apps ADD COLUMN dev_cert_hash INTEGER;", "measurement_enabled", "ALTER TABLE apps ADD COLUMN measurement_enabled INTEGER;", "last_bundle_start_timestamp", "ALTER TABLE apps ADD COLUMN last_bundle_start_timestamp INTEGER;", "day", "ALTER TABLE apps ADD COLUMN day INTEGER;", "daily_public_events_count", "ALTER TABLE apps ADD COLUMN daily_public_events_count INTEGER;", "daily_events_count", "ALTER TABLE apps ADD COLUMN daily_events_count INTEGER;", "daily_conversions_count", "ALTER TABLE apps ADD COLUMN daily_conversions_count INTEGER;", "remote_config", "ALTER TABLE apps ADD COLUMN remote_config BLOB;", "config_fetched_time", "ALTER TABLE apps ADD COLUMN config_fetched_time INTEGER;", "failed_config_fetch_time", "ALTER TABLE apps ADD COLUMN failed_config_fetch_time INTEGER;", "app_version_int", "ALTER TABLE apps ADD COLUMN app_version_int INTEGER;", "firebase_instance_id", "ALTER TABLE apps ADD COLUMN firebase_instance_id TEXT;", "daily_error_events_count", "ALTER TABLE apps ADD COLUMN daily_error_events_count INTEGER;", "daily_realtime_events_count", "ALTER TABLE apps ADD COLUMN daily_realtime_events_count INTEGER;", "health_monitor_sample", "ALTER TABLE apps ADD COLUMN health_monitor_sample TEXT;", "android_id", "ALTER TABLE apps ADD COLUMN android_id INTEGER;", "adid_reporting_enabled", "ALTER TABLE apps ADD COLUMN adid_reporting_enabled INTEGER;", "ssaid_reporting_enabled", "ALTER TABLE apps ADD COLUMN ssaid_reporting_enabled INTEGER;", "admob_app_id", "ALTER TABLE apps ADD COLUMN admob_app_id TEXT;", "linked_admob_app_id", "ALTER TABLE apps ADD COLUMN linked_admob_app_id TEXT;", "dynamite_version", "ALTER TABLE apps ADD COLUMN dynamite_version INTEGER;", "safelisted_events", "ALTER TABLE apps ADD COLUMN safelisted_events TEXT;", "ga_app_id", "ALTER TABLE apps ADD COLUMN ga_app_id TEXT;"};
public static final String[] g = {"realtime", "ALTER TABLE raw_events ADD COLUMN realtime INTEGER;"};
public static final String[] h = {"has_realtime", "ALTER TABLE queue ADD COLUMN has_realtime INTEGER;", "retry_count", "ALTER TABLE queue ADD COLUMN retry_count INTEGER;"};
public static final String[] i = {"session_scoped", "ALTER TABLE event_filters ADD COLUMN session_scoped BOOLEAN;"};
public static final String[] j = {"session_scoped", "ALTER TABLE property_filters ADD COLUMN session_scoped BOOLEAN;"};
public static final String[] k = {"previous_install_count", "ALTER TABLE app2 ADD COLUMN previous_install_count INTEGER;"};
public final h l = new h(this, this.a.b, "google_app_measurement.db");
public final e9 m = new e9(this.a.o);
public g(k9 k9Var) {
super(k9Var);
}
@WorkerThread
public static void G(ContentValues contentValues, String str, Object obj) {
AnimatableValueParser.w(str);
Objects.requireNonNull(obj, "null reference");
if (obj instanceof String) {
contentValues.put(str, (String) obj);
} else if (obj instanceof Long) {
contentValues.put(str, (Long) obj);
} else if (obj instanceof Double) {
contentValues.put(str, (Double) obj);
} else {
throw new IllegalArgumentException("Invalid value type");
}
}
@WorkerThread
public final Object A(Cursor cursor, int i2) {
int type = cursor.getType(i2);
if (type == 0) {
g().f.a("Loaded invalid null value from database");
return null;
} else if (type == 1) {
return Long.valueOf(cursor.getLong(i2));
} else {
if (type == 2) {
return Double.valueOf(cursor.getDouble(i2));
}
if (type == 3) {
return cursor.getString(i2);
}
if (type != 4) {
g().f.b("Loaded invalid unknown value type, ignoring it", Integer.valueOf(type));
return null;
}
g().f.a("Loaded invalid blob type value, ignoring it");
return null;
}
}
/* JADX WARNING: Removed duplicated region for block: B:18:0x004b */
/* JADX WARNING: Removed duplicated region for block: B:23:0x0053 */
public final String B(long j2) {
Throwable th;
SQLiteException e2;
Cursor cursor;
b();
n();
Cursor cursor2 = null;
try {
cursor = t().rawQuery("select app_id from apps where app_id in (select distinct app_id from raw_events) and config_fetched_time < ? order by failed_config_fetch_time limit 1;", new String[]{String.valueOf(j2)});
try {
if (!cursor.moveToFirst()) {
g().n.a("No expired configs for apps with pending events");
cursor.close();
return null;
}
String string = cursor.getString(0);
cursor.close();
return string;
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.b("Error selecting expired configs", e2);
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
}
} catch (SQLiteException e4) {
e2 = e4;
cursor = null;
g().f.b("Error selecting expired configs", e2);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th3) {
th = th3;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
/* JADX WARNING: Removed duplicated region for block: B:33:0x00ad */
/* JADX WARNING: Removed duplicated region for block: B:38:0x00b5 */
@WorkerThread
public final List<u9> C(String str) {
Throwable th;
Cursor cursor;
SQLiteException e2;
AnimatableValueParser.w(str);
b();
n();
ArrayList arrayList = new ArrayList();
Cursor cursor2 = null;
try {
cursor = t().query("user_attributes", new String[]{"name", "origin", "set_timestamp", "value"}, "app_id=?", new String[]{str}, null, null, "rowid", "1000");
try {
if (!cursor.moveToFirst()) {
cursor.close();
return arrayList;
}
do {
String string = cursor.getString(0);
String string2 = cursor.getString(1);
if (string2 == null) {
string2 = "";
}
long j2 = cursor.getLong(2);
Object A = A(cursor, 3);
if (A == null) {
g().f.b("Read invalid user property value, ignoring it. appId", q3.s(str));
} else {
arrayList.add(new u9(str, string2, string, j2, A));
}
} while (cursor.moveToNext());
cursor.close();
return arrayList;
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.c("Error querying user properties. appId", q3.s(str), e2);
if (l9.b() || !this.a.h.u(str, p.F0)) {
if (cursor != null) {
cursor.close();
}
return null;
}
List<u9> emptyList = Collections.emptyList();
if (cursor != null) {
cursor.close();
}
return emptyList;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
}
} catch (SQLiteException e4) {
e2 = e4;
cursor = null;
g().f.c("Error querying user properties. appId", q3.s(str), e2);
if (l9.b()) {
}
if (cursor != null) {
}
return null;
} catch (Throwable th3) {
th = th3;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
@WorkerThread
public final List<Pair<e1, Long>> D(String str, int i2, int i3) {
b();
n();
AnimatableValueParser.m(i2 > 0);
AnimatableValueParser.m(i3 > 0);
AnimatableValueParser.w(str);
Cursor cursor = null;
try {
Cursor query = t().query("queue", new String[]{"rowid", "data", "retry_count"}, "app_id=?", new String[]{str}, null, null, "rowid", String.valueOf(i2));
if (!query.moveToFirst()) {
List<Pair<e1, Long>> emptyList = Collections.emptyList();
query.close();
return emptyList;
}
ArrayList arrayList = new ArrayList();
int i4 = 0;
do {
long j2 = query.getLong(0);
try {
byte[] S = m().S(query.getBlob(1));
if (!arrayList.isEmpty() && S.length + i4 > i3) {
break;
}
try {
e1.a aVar = (e1.a) q9.x(e1.u0(), S);
if (!query.isNull(2)) {
int i5 = query.getInt(2);
if (aVar.k) {
aVar.n();
aVar.k = false;
}
e1.V0((e1) aVar.j, i5);
}
i4 += S.length;
arrayList.add(Pair.create((e1) ((u4) aVar.p()), Long.valueOf(j2)));
} catch (IOException e2) {
g().f.c("Failed to merge queued bundle. appId", q3.s(str), e2);
}
if (!query.moveToNext()) {
break;
}
} catch (IOException e3) {
g().f.c("Failed to unzip queued bundle. appId", q3.s(str), e3);
}
} while (i4 <= i3);
query.close();
return arrayList;
} catch (SQLiteException e4) {
g().f.c("Error querying bundles. appId", q3.s(str), e4);
List<Pair<e1, Long>> emptyList2 = Collections.emptyList();
if (0 != 0) {
cursor.close();
}
return emptyList2;
} catch (Throwable th) {
if (0 != 0) {
cursor.close();
}
throw th;
}
}
/* JADX WARNING: Code restructure failed: missing block: B:34:0x00e8, code lost:
r0 = th;
*/
/* JADX WARNING: Code restructure failed: missing block: B:35:0x00ea, code lost:
r0 = e;
*/
/* JADX WARNING: Code restructure failed: missing block: B:36:0x00eb, code lost:
r4 = r23;
*/
/* JADX WARNING: Code restructure failed: missing block: B:43:0x010f, code lost:
r0 = java.util.Collections.emptyList();
*/
/* JADX WARNING: Code restructure failed: missing block: B:44:0x0113, code lost:
if (r12 != null) goto L_0x0115;
*/
/* JADX WARNING: Code restructure failed: missing block: B:45:0x0115, code lost:
r12.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:46:0x0118, code lost:
return r0;
*/
/* JADX WARNING: Code restructure failed: missing block: B:48:0x011b, code lost:
r12.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:53:0x0123, code lost:
r10.close();
*/
/* JADX WARNING: Failed to process nested try/catch */
/* JADX WARNING: Removed duplicated region for block: B:34:0x00e8 A[ExcHandler: all (th java.lang.Throwable), Splitter:B:1:0x0013] */
/* JADX WARNING: Removed duplicated region for block: B:41:0x0103 A[Catch:{ all -> 0x011f }] */
/* JADX WARNING: Removed duplicated region for block: B:48:0x011b */
/* JADX WARNING: Removed duplicated region for block: B:53:0x0123 */
@WorkerThread
public final List<u9> E(String str, String str2, String str3) {
Cursor cursor;
String str4;
SQLiteException e2;
AnimatableValueParser.w(str);
b();
n();
ArrayList arrayList = new ArrayList();
Cursor cursor2 = null;
try {
ArrayList arrayList2 = new ArrayList(3);
arrayList2.add(str);
StringBuilder sb = new StringBuilder("app_id=?");
if (!TextUtils.isEmpty(str2)) {
str4 = str2;
arrayList2.add(str4);
sb.append(" and origin=?");
} else {
str4 = str2;
}
if (!TextUtils.isEmpty(str3)) {
arrayList2.add(String.valueOf(str3).concat("*"));
sb.append(" and name glob ?");
}
cursor = t().query("user_attributes", new String[]{"name", "set_timestamp", "value", "origin"}, sb.toString(), (String[]) arrayList2.toArray(new String[arrayList2.size()]), null, null, "rowid", "1001");
try {
if (!cursor.moveToFirst()) {
cursor.close();
return arrayList;
}
while (true) {
if (arrayList.size() >= 1000) {
g().f.b("Read more than the max allowed user properties, ignoring excess", 1000);
break;
}
String string = cursor.getString(0);
long j2 = cursor.getLong(1);
Object A = A(cursor, 2);
String string2 = cursor.getString(3);
if (A == null) {
try {
g().f.d("(2)Read invalid user property value, ignoring it", q3.s(str), string2, str3);
} catch (SQLiteException e3) {
e2 = e3;
str4 = string2;
try {
g().f.d("(2)Error querying user properties", q3.s(str), str4, e2);
if (l9.b()) {
}
if (cursor != null) {
}
return null;
} catch (Throwable th) {
Throwable th2 = th;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th2;
}
}
} else {
arrayList.add(new u9(str, string2, string, j2, A));
}
if (!cursor.moveToNext()) {
break;
}
}
cursor.close();
return arrayList;
} catch (SQLiteException e4) {
e2 = e4;
g().f.d("(2)Error querying user properties", q3.s(str), str4, e2);
if (l9.b()) {
}
if (cursor != null) {
}
return null;
}
} catch (SQLiteException e5) {
e2 = e5;
cursor = null;
g().f.d("(2)Error querying user properties", q3.s(str), str4, e2);
if (l9.b()) {
}
if (cursor != null) {
}
return null;
} catch (Throwable th3) {
}
}
public final List<zzz> F(String str, String[] strArr) {
b();
n();
ArrayList arrayList = new ArrayList();
Cursor cursor = null;
try {
cursor = t().query("conditional_properties", new String[]{"app_id", "origin", "name", "value", "active", "trigger_event_name", "trigger_timeout", "timed_out_event", "creation_timestamp", "triggered_event", "triggered_timestamp", "time_to_live", "expired_event"}, str, strArr, null, null, "rowid", "1001");
if (!cursor.moveToFirst()) {
cursor.close();
return arrayList;
}
while (true) {
if (arrayList.size() < 1000) {
boolean z2 = false;
String string = cursor.getString(0);
String string2 = cursor.getString(1);
String string3 = cursor.getString(2);
Object A = A(cursor, 3);
if (cursor.getInt(4) != 0) {
z2 = true;
}
String string4 = cursor.getString(5);
long j2 = cursor.getLong(6);
q9 m = m();
byte[] blob = cursor.getBlob(7);
Parcelable.Creator<zzaq> creator = zzaq.CREATOR;
long j3 = cursor.getLong(8);
arrayList.add(new zzz(string, string2, new zzku(string3, cursor.getLong(10), A, string2), j3, z2, string4, (zzaq) m.u(blob, creator), j2, (zzaq) m().u(cursor.getBlob(9), creator), cursor.getLong(11), (zzaq) m().u(cursor.getBlob(12), creator)));
if (!cursor.moveToNext()) {
break;
}
} else {
g().f.b("Read more than the max allowed conditional properties, ignoring extra", 1000);
break;
}
}
cursor.close();
return arrayList;
} catch (SQLiteException e2) {
g().f.b("Error querying conditional user property value", e2);
List<zzz> emptyList = Collections.emptyList();
if (cursor != null) {
cursor.close();
}
return emptyList;
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
@WorkerThread
public final void H(l lVar) {
Objects.requireNonNull(lVar, "null reference");
b();
n();
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", lVar.a);
contentValues.put("name", lVar.b);
contentValues.put("lifetime_count", Long.valueOf(lVar.f1169c));
contentValues.put("current_bundle_count", Long.valueOf(lVar.d));
contentValues.put("last_fire_timestamp", Long.valueOf(lVar.f));
contentValues.put("last_bundled_timestamp", Long.valueOf(lVar.g));
contentValues.put("last_bundled_day", lVar.h);
contentValues.put("last_sampled_complex_event_id", lVar.i);
contentValues.put("last_sampling_rate", lVar.j);
contentValues.put("current_session_count", Long.valueOf(lVar.e));
Boolean bool = lVar.k;
contentValues.put("last_exempt_from_sampling", (bool == null || !bool.booleanValue()) ? null : 1L);
try {
if (t().insertWithOnConflict("events", null, contentValues, 5) == -1) {
g().f.b("Failed to insert/update event aggregates (got -1). appId", q3.s(lVar.a));
}
} catch (SQLiteException e2) {
g().f.c("Error storing event aggregates. appId", q3.s(lVar.a), e2);
}
}
@WorkerThread
public final void I(a4 a4Var) {
b();
n();
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", a4Var.o());
contentValues.put("app_instance_id", a4Var.s());
contentValues.put("gmp_app_id", a4Var.v());
contentValues.put("resettable_device_id_hash", a4Var.E());
contentValues.put("last_bundle_index", Long.valueOf(a4Var.U()));
contentValues.put("last_bundle_start_timestamp", Long.valueOf(a4Var.K()));
contentValues.put("last_bundle_end_timestamp", Long.valueOf(a4Var.L()));
contentValues.put("app_version", a4Var.M());
contentValues.put("app_store", a4Var.O());
contentValues.put("gmp_version", Long.valueOf(a4Var.P()));
contentValues.put("dev_cert_hash", Long.valueOf(a4Var.Q()));
contentValues.put("measurement_enabled", Boolean.valueOf(a4Var.T()));
a4Var.a.f().b();
contentValues.put("day", Long.valueOf(a4Var.f1135x));
a4Var.a.f().b();
contentValues.put("daily_public_events_count", Long.valueOf(a4Var.f1136y));
a4Var.a.f().b();
contentValues.put("daily_events_count", Long.valueOf(a4Var.f1137z));
a4Var.a.f().b();
contentValues.put("daily_conversions_count", Long.valueOf(a4Var.A));
a4Var.a.f().b();
contentValues.put("config_fetched_time", Long.valueOf(a4Var.F));
a4Var.a.f().b();
contentValues.put("failed_config_fetch_time", Long.valueOf(a4Var.G));
contentValues.put("app_version_int", Long.valueOf(a4Var.N()));
contentValues.put("firebase_instance_id", a4Var.H());
a4Var.a.f().b();
contentValues.put("daily_error_events_count", Long.valueOf(a4Var.B));
a4Var.a.f().b();
contentValues.put("daily_realtime_events_count", Long.valueOf(a4Var.C));
a4Var.a.f().b();
contentValues.put("health_monitor_sample", a4Var.D);
contentValues.put("android_id", Long.valueOf(a4Var.g()));
contentValues.put("adid_reporting_enabled", Boolean.valueOf(a4Var.h()));
contentValues.put("ssaid_reporting_enabled", Boolean.valueOf(a4Var.i()));
contentValues.put("admob_app_id", a4Var.y());
contentValues.put("dynamite_version", Long.valueOf(a4Var.S()));
if (a4Var.k() != null) {
if (a4Var.k().size() == 0) {
g().i.b("Safelisted events should not be an empty list. appId", a4Var.o());
} else {
contentValues.put("safelisted_events", TextUtils.join(",", a4Var.k()));
}
}
if (da.b() && this.a.h.u(a4Var.o(), p.f1184j0)) {
contentValues.put("ga_app_id", a4Var.B());
}
try {
SQLiteDatabase t = t();
if (((long) t.update("apps", contentValues, "app_id = ?", new String[]{a4Var.o()})) == 0 && t.insertWithOnConflict("apps", null, contentValues, 5) == -1) {
g().f.b("Failed to insert/update app (got -1). appId", q3.s(a4Var.o()));
}
} catch (SQLiteException e2) {
g().f.c("Error storing app. appId", q3.s(a4Var.o()), e2);
}
}
@WorkerThread
public final void J(List<Long> list) {
b();
n();
Objects.requireNonNull(list, "null reference");
if (list.size() == 0) {
throw new IllegalArgumentException("Given Integer is zero");
} else if (R()) {
String join = TextUtils.join(",", list);
String g2 = a.g(a.m(join, 2), "(", join, ")");
if (S(a.g(a.m(g2, 80), "SELECT COUNT(1) FROM queue WHERE rowid IN ", g2, " AND retry_count = 2147483647 LIMIT 1"), null) > 0) {
g().i.a("The number of upload retries exceeds the limit. Will remain unchanged.");
}
try {
SQLiteDatabase t = t();
StringBuilder sb = new StringBuilder(String.valueOf(g2).length() + 127);
sb.append("UPDATE queue SET retry_count = IFNULL(retry_count, 0) + 1 WHERE rowid IN ");
sb.append(g2);
sb.append(" AND (retry_count IS NULL OR retry_count < 2147483647)");
t.execSQL(sb.toString());
} catch (SQLiteException e2) {
g().f.b("Error incrementing retry count. error", e2);
}
}
}
@WorkerThread
public final boolean K(e1 e1Var, boolean z2) {
b();
n();
AnimatableValueParser.w(e1Var.G1());
AnimatableValueParser.F(e1Var.n1());
i0();
Objects.requireNonNull((d) this.a.o);
long currentTimeMillis = System.currentTimeMillis();
if (e1Var.o1() < currentTimeMillis - c.B() || e1Var.o1() > c.B() + currentTimeMillis) {
g().i.d("Storing bundle outside of the max uploading time span. appId, now, timestamp", q3.s(e1Var.G1()), Long.valueOf(currentTimeMillis), Long.valueOf(e1Var.o1()));
}
try {
byte[] T = m().T(e1Var.d());
g().n.b("Saving bundle, size", Integer.valueOf(T.length));
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", e1Var.G1());
contentValues.put("bundle_end_timestamp", Long.valueOf(e1Var.o1()));
contentValues.put("data", T);
contentValues.put("has_realtime", Integer.valueOf(z2 ? 1 : 0));
if (e1Var.f0()) {
contentValues.put("retry_count", Integer.valueOf(e1Var.n0()));
}
try {
if (t().insert("queue", null, contentValues) != -1) {
return true;
}
g().f.b("Failed to insert bundle (got -1). appId", q3.s(e1Var.G1()));
return false;
} catch (SQLiteException e2) {
g().f.c("Error storing bundle. appId", q3.s(e1Var.G1()), e2);
return false;
}
} catch (IOException e3) {
g().f.c("Data loss. Failed to serialize bundle. appId", q3.s(e1Var.G1()), e3);
return false;
}
}
public final boolean L(m mVar, long j2, boolean z2) {
b();
n();
AnimatableValueParser.w(mVar.a);
byte[] d2 = m().v(mVar).d();
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", mVar.a);
contentValues.put("name", mVar.b);
contentValues.put("timestamp", Long.valueOf(mVar.d));
contentValues.put("metadata_fingerprint", Long.valueOf(j2));
contentValues.put("data", d2);
contentValues.put("realtime", Integer.valueOf(z2 ? 1 : 0));
try {
if (t().insert("raw_events", null, contentValues) != -1) {
return true;
}
g().f.b("Failed to insert raw event (got -1). appId", q3.s(mVar.a));
return false;
} catch (SQLiteException e2) {
g().f.c("Error storing raw event. appId", q3.s(mVar.a), e2);
return false;
}
}
@WorkerThread
public final boolean M(u9 u9Var) {
b();
n();
if (Y(u9Var.a, u9Var.f1201c) == null) {
if (t9.X(u9Var.f1201c)) {
long S = S("select count(1) from user_attributes where app_id=? and name not like '!_%' escape '!'", new String[]{u9Var.a});
c cVar = this.a.h;
String str = u9Var.a;
Objects.requireNonNull(cVar);
int i2 = 25;
if (o8.b() && cVar.u(null, p.w0)) {
i2 = Math.max(Math.min(cVar.q(str, p.G), 100), 25);
}
if (S >= ((long) i2)) {
return false;
}
} else if (!"_npa".equals(u9Var.f1201c) && S("select count(1) from user_attributes where app_id=? and origin=? AND name like '!_%' escape '!'", new String[]{u9Var.a, u9Var.b}) >= 25) {
return false;
}
}
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", u9Var.a);
contentValues.put("origin", u9Var.b);
contentValues.put("name", u9Var.f1201c);
contentValues.put("set_timestamp", Long.valueOf(u9Var.d));
G(contentValues, "value", u9Var.e);
try {
if (t().insertWithOnConflict("user_attributes", null, contentValues, 5) == -1) {
g().f.b("Failed to insert/update user property (got -1). appId", q3.s(u9Var.a));
}
} catch (SQLiteException e2) {
g().f.c("Error storing user property. appId", q3.s(u9Var.a), e2);
}
return true;
}
@WorkerThread
public final boolean N(zzz zzz) {
b();
n();
if (Y(zzz.i, zzz.k.j) == null && S("SELECT COUNT(1) FROM conditional_properties WHERE app_id=?", new String[]{zzz.i}) >= 1000) {
return false;
}
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", zzz.i);
contentValues.put("origin", zzz.j);
contentValues.put("name", zzz.k.j);
G(contentValues, "value", zzz.k.v0());
contentValues.put("active", Boolean.valueOf(zzz.m));
contentValues.put("trigger_event_name", zzz.n);
contentValues.put("trigger_timeout", Long.valueOf(zzz.p));
e();
contentValues.put("timed_out_event", t9.g0(zzz.o));
contentValues.put("creation_timestamp", Long.valueOf(zzz.l));
e();
contentValues.put("triggered_event", t9.g0(zzz.q));
contentValues.put("triggered_timestamp", Long.valueOf(zzz.k.k));
contentValues.put("time_to_live", Long.valueOf(zzz.r));
e();
contentValues.put("expired_event", t9.g0(zzz.f2296s));
try {
if (t().insertWithOnConflict("conditional_properties", null, contentValues, 5) == -1) {
g().f.b("Failed to insert/update conditional user property (got -1)", q3.s(zzz.i));
}
} catch (SQLiteException e2) {
g().f.c("Error storing conditional user property", q3.s(zzz.i), e2);
}
return true;
}
@WorkerThread
public final boolean O(String str, int i2, l0 l0Var) {
n();
b();
AnimatableValueParser.w(str);
Objects.requireNonNull(l0Var, "null reference");
Integer num = null;
if (TextUtils.isEmpty(l0Var.z())) {
s3 s3Var = g().i;
Object s2 = q3.s(str);
Integer valueOf = Integer.valueOf(i2);
if (l0Var.x()) {
num = Integer.valueOf(l0Var.y());
}
s3Var.d("Event filter had no event name. Audience definition ignored. appId, audienceId, filterId", s2, valueOf, String.valueOf(num));
return false;
}
byte[] d2 = l0Var.d();
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", str);
contentValues.put("audience_id", Integer.valueOf(i2));
contentValues.put("filter_id", l0Var.x() ? Integer.valueOf(l0Var.y()) : null);
contentValues.put("event_name", l0Var.z());
contentValues.put("session_scoped", l0Var.G() ? Boolean.valueOf(l0Var.H()) : null);
contentValues.put("data", d2);
try {
if (t().insertWithOnConflict("event_filters", null, contentValues, 5) != -1) {
return true;
}
g().f.b("Failed to insert event filter (got -1). appId", q3.s(str));
return true;
} catch (SQLiteException e2) {
g().f.c("Error storing event filter. appId", q3.s(str), e2);
return false;
}
}
@WorkerThread
public final boolean P(String str, int i2, o0 o0Var) {
n();
b();
AnimatableValueParser.w(str);
Objects.requireNonNull(o0Var, "null reference");
Integer num = null;
if (TextUtils.isEmpty(o0Var.x())) {
s3 s3Var = g().i;
Object s2 = q3.s(str);
Integer valueOf = Integer.valueOf(i2);
if (o0Var.v()) {
num = Integer.valueOf(o0Var.w());
}
s3Var.d("Property filter had no property name. Audience definition ignored. appId, audienceId, filterId", s2, valueOf, String.valueOf(num));
return false;
}
byte[] d2 = o0Var.d();
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", str);
contentValues.put("audience_id", Integer.valueOf(i2));
contentValues.put("filter_id", o0Var.v() ? Integer.valueOf(o0Var.w()) : null);
contentValues.put("property_name", o0Var.x());
contentValues.put("session_scoped", o0Var.B() ? Boolean.valueOf(o0Var.C()) : null);
contentValues.put("data", d2);
try {
if (t().insertWithOnConflict("property_filters", null, contentValues, 5) != -1) {
return true;
}
g().f.b("Failed to insert property filter (got -1). appId", q3.s(str));
return false;
} catch (SQLiteException e2) {
g().f.c("Error storing property filter. appId", q3.s(str), e2);
return false;
}
}
public final boolean Q(String str, Long l, long j2, a1 a1Var) {
b();
n();
Objects.requireNonNull(a1Var, "null reference");
AnimatableValueParser.w(str);
Objects.requireNonNull(l, "null reference");
byte[] d2 = a1Var.d();
g().n.c("Saving complex main event, appId, data size", d().u(str), Integer.valueOf(d2.length));
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", str);
contentValues.put("event_id", l);
contentValues.put("children_to_process", Long.valueOf(j2));
contentValues.put("main_event", d2);
try {
if (t().insertWithOnConflict("main_event_params", null, contentValues, 5) != -1) {
return true;
}
g().f.b("Failed to insert complex main event (got -1). appId", q3.s(str));
return false;
} catch (SQLiteException e2) {
g().f.c("Error storing complex main event. appId", q3.s(str), e2);
return false;
}
}
public final boolean R() {
return this.a.b.getDatabasePath("google_app_measurement.db").exists();
}
@WorkerThread
public final long S(String str, String[] strArr) {
Cursor cursor = null;
try {
Cursor rawQuery = t().rawQuery(str, strArr);
if (rawQuery.moveToFirst()) {
long j2 = rawQuery.getLong(0);
rawQuery.close();
return j2;
}
throw new SQLiteException("Database returned empty set");
} catch (SQLiteException e2) {
g().f.c("Database error", str, e2);
throw e2;
} catch (Throwable th) {
if (0 != 0) {
cursor.close();
}
throw th;
}
}
/* JADX WARNING: Removed duplicated region for block: B:83:0x029b */
/* JADX WARNING: Removed duplicated region for block: B:88:0x02a3 */
@WorkerThread
public final a4 T(String str) {
Throwable th;
Cursor cursor;
SQLiteException e2;
AnimatableValueParser.w(str);
b();
n();
Cursor cursor2 = null;
try {
boolean z2 = true;
cursor = t().query("apps", new String[]{"app_instance_id", "gmp_app_id", "resettable_device_id_hash", "last_bundle_index", "last_bundle_start_timestamp", "last_bundle_end_timestamp", "app_version", "app_store", "gmp_version", "dev_cert_hash", "measurement_enabled", "day", "daily_public_events_count", "daily_events_count", "daily_conversions_count", "config_fetched_time", "failed_config_fetch_time", "app_version_int", "firebase_instance_id", "daily_error_events_count", "daily_realtime_events_count", "health_monitor_sample", "android_id", "adid_reporting_enabled", "ssaid_reporting_enabled", "admob_app_id", "dynamite_version", "safelisted_events", "ga_app_id"}, "app_id=?", new String[]{str}, null, null, null);
try {
if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
a4 a4Var = new a4(this.b.k, str);
a4Var.c(cursor.getString(0));
a4Var.m(cursor.getString(1));
a4Var.x(cursor.getString(2));
a4Var.C(cursor.getLong(3));
a4Var.a(cursor.getLong(4));
a4Var.l(cursor.getLong(5));
a4Var.D(cursor.getString(6));
a4Var.G(cursor.getString(7));
a4Var.t(cursor.getLong(8));
a4Var.w(cursor.getLong(9));
a4Var.e(cursor.isNull(10) || cursor.getInt(10) != 0);
long j2 = cursor.getLong(11);
a4Var.a.f().b();
a4Var.E |= a4Var.f1135x != j2;
a4Var.f1135x = j2;
long j3 = cursor.getLong(12);
a4Var.a.f().b();
a4Var.E |= a4Var.f1136y != j3;
a4Var.f1136y = j3;
long j4 = cursor.getLong(13);
a4Var.a.f().b();
a4Var.E |= a4Var.f1137z != j4;
a4Var.f1137z = j4;
long j5 = cursor.getLong(14);
a4Var.a.f().b();
a4Var.E |= a4Var.A != j5;
a4Var.A = j5;
a4Var.F(cursor.getLong(15));
a4Var.I(cursor.getLong(16));
a4Var.p(cursor.isNull(17) ? -2147483648L : (long) cursor.getInt(17));
a4Var.A(cursor.getString(18));
long j6 = cursor.getLong(19);
a4Var.a.f().b();
a4Var.E |= a4Var.B != j6;
a4Var.B = j6;
long j7 = cursor.getLong(20);
a4Var.a.f().b();
a4Var.E |= a4Var.C != j7;
a4Var.C = j7;
a4Var.J(cursor.getString(21));
long j8 = 0;
if (!this.a.h.o(p.y0)) {
a4Var.R(cursor.isNull(22) ? 0 : cursor.getLong(22));
}
a4Var.n(cursor.isNull(23) || cursor.getInt(23) != 0);
if (!cursor.isNull(24) && cursor.getInt(24) == 0) {
z2 = false;
}
a4Var.r(z2);
a4Var.q(cursor.getString(25));
if (!cursor.isNull(26)) {
j8 = cursor.getLong(26);
}
a4Var.z(j8);
if (!cursor.isNull(27)) {
a4Var.d(Arrays.asList(cursor.getString(27).split(",", -1)));
}
if (da.b() && this.a.h.u(str, p.f1184j0)) {
a4Var.u(cursor.getString(28));
}
a4Var.a.f().b();
a4Var.E = false;
if (cursor.moveToNext()) {
g().f.b("Got multiple records for app, expected one. appId", q3.s(str));
}
cursor.close();
return a4Var;
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.c("Error querying app. appId", q3.s(str), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
}
} catch (SQLiteException e4) {
e2 = e4;
cursor = null;
g().f.c("Error querying app. appId", q3.s(str), e2);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th3) {
th = th3;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
@WorkerThread
public final List<zzz> U(String str, String str2, String str3) {
AnimatableValueParser.w(str);
b();
n();
ArrayList arrayList = new ArrayList(3);
arrayList.add(str);
StringBuilder sb = new StringBuilder("app_id=?");
if (!TextUtils.isEmpty(str2)) {
arrayList.add(str2);
sb.append(" and origin=?");
}
if (!TextUtils.isEmpty(str3)) {
arrayList.add(String.valueOf(str3).concat("*"));
sb.append(" and name glob ?");
}
return F(sb.toString(), (String[]) arrayList.toArray(new String[arrayList.size()]));
}
@WorkerThread
public final void V(String str, String str2) {
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
b();
n();
try {
t().delete("user_attributes", "app_id=? and name=?", new String[]{str, str2});
} catch (SQLiteException e2) {
g().f.d("Error deleting user property. appId", q3.s(str), d().y(str2), e2);
}
}
public final boolean W(String str, List<Integer> list) {
AnimatableValueParser.w(str);
n();
b();
SQLiteDatabase t = t();
try {
long S = S("select count(1) from audience_filter_values where app_id=?", new String[]{str});
int max = Math.max(0, Math.min(2000, this.a.h.q(str, p.F)));
if (S <= ((long) max)) {
return false;
}
ArrayList arrayList = new ArrayList();
for (int i2 = 0; i2 < list.size(); i2++) {
Integer num = list.get(i2);
if (num == null) {
return false;
}
arrayList.add(Integer.toString(num.intValue()));
}
String join = TextUtils.join(",", arrayList);
String g2 = a.g(a.m(join, 2), "(", join, ")");
return t.delete("audience_filter_values", a.g(a.m(g2, 140), "audience_id in (select audience_id from audience_filter_values where app_id=? and audience_id not in ", g2, " order by rowid desc limit -1 offset ?)"), new String[]{str, Integer.toString(max)}) > 0;
} catch (SQLiteException e2) {
g().f.c("Database error querying filters. appId", q3.s(str), e2);
return false;
}
}
public final long X(String str) {
AnimatableValueParser.w(str);
b();
n();
try {
return (long) t().delete("raw_events", "rowid in (select rowid from raw_events where app_id=? order by rowid desc limit -1 offset ?)", new String[]{str, String.valueOf(Math.max(0, Math.min(1000000, this.a.h.q(str, p.p))))});
} catch (SQLiteException e2) {
g().f.c("Error deleting over the limit events. appId", q3.s(str), e2);
return 0;
}
}
/* JADX WARNING: Removed duplicated region for block: B:27:0x0099 */
/* JADX WARNING: Removed duplicated region for block: B:32:0x00a1 */
@WorkerThread
public final u9 Y(String str, String str2) {
Throwable th;
Cursor cursor;
SQLiteException e2;
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
b();
n();
Cursor cursor2 = null;
try {
cursor = t().query("user_attributes", new String[]{"set_timestamp", "value", "origin"}, "app_id=? and name=?", new String[]{str, str2}, null, null, null);
try {
if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
try {
u9 u9Var = new u9(str, cursor.getString(2), str2, cursor.getLong(0), A(cursor, 1));
if (cursor.moveToNext()) {
g().f.b("Got multiple records for user property, expected one. appId", q3.s(str));
}
cursor.close();
return u9Var;
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.d("Error querying user property. appId", q3.s(str), d().y(str2), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
}
} catch (SQLiteException e4) {
e2 = e4;
g().f.d("Error querying user property. appId", q3.s(str), d().y(str2), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th3) {
th = th3;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
} catch (SQLiteException e5) {
e2 = e5;
cursor = null;
g().f.d("Error querying user property. appId", q3.s(str), d().y(str2), e2);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th4) {
th = th4;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
/* JADX WARNING: Removed duplicated region for block: B:31:0x0111 */
/* JADX WARNING: Removed duplicated region for block: B:36:0x0119 */
@WorkerThread
public final zzz Z(String str, String str2) {
Throwable th;
Cursor cursor;
SQLiteException e2;
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
b();
n();
Cursor cursor2 = null;
try {
cursor = t().query("conditional_properties", new String[]{"origin", "value", "active", "trigger_event_name", "trigger_timeout", "timed_out_event", "creation_timestamp", "triggered_event", "triggered_timestamp", "time_to_live", "expired_event"}, "app_id=? and name=?", new String[]{str, str2}, null, null, null);
try {
if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
String string = cursor.getString(0);
try {
Object A = A(cursor, 1);
boolean z2 = cursor.getInt(2) != 0;
String string2 = cursor.getString(3);
long j2 = cursor.getLong(4);
q9 m = m();
byte[] blob = cursor.getBlob(5);
Parcelable.Creator<zzaq> creator = zzaq.CREATOR;
zzz zzz = new zzz(str, string, new zzku(str2, cursor.getLong(8), A, string), cursor.getLong(6), z2, string2, (zzaq) m.u(blob, creator), j2, (zzaq) m().u(cursor.getBlob(7), creator), cursor.getLong(9), (zzaq) m().u(cursor.getBlob(10), creator));
if (cursor.moveToNext()) {
g().f.c("Got multiple records for conditional property, expected one", q3.s(str), d().y(str2));
}
cursor.close();
return zzz;
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.d("Error querying conditional property", q3.s(str), d().y(str2), e2);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
} catch (SQLiteException e4) {
e2 = e4;
g().f.d("Error querying conditional property", q3.s(str), d().y(str2), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th3) {
th = th3;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
} catch (SQLiteException e5) {
e2 = e5;
cursor = null;
g().f.d("Error querying conditional property", q3.s(str), d().y(str2), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th4) {
th = th4;
if (cursor2 != null) {
}
throw th;
}
}
@WorkerThread
public final int a0(String str, String str2) {
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
b();
n();
try {
return t().delete("conditional_properties", "app_id=? and name=?", new String[]{str, str2});
} catch (SQLiteException e2) {
g().f.d("Error deleting conditional property", q3.s(str), d().y(str2), e2);
return 0;
}
}
@WorkerThread
public final void b0() {
n();
t().beginTransaction();
}
/* JADX WARNING: Removed duplicated region for block: B:36:0x00c3 */
/* JADX WARNING: Removed duplicated region for block: B:41:0x00cb */
public final Map<Integer, List<l0>> c0(String str, String str2) {
Throwable th;
Cursor cursor;
SQLiteException e2;
n();
b();
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
ArrayMap arrayMap = new ArrayMap();
Cursor cursor2 = null;
try {
cursor = t().query("event_filters", new String[]{"audience_id", "data"}, "app_id=? AND event_name=?", new String[]{str, str2}, null, null, null);
try {
if (!cursor.moveToFirst()) {
Map<Integer, List<l0>> emptyMap = Collections.emptyMap();
cursor.close();
return emptyMap;
}
do {
try {
l0 l0Var = (l0) ((u4) ((l0.a) q9.x(l0.I(), cursor.getBlob(1))).p());
int i2 = cursor.getInt(0);
List list = arrayMap.get(Integer.valueOf(i2));
if (list == null) {
list = new ArrayList();
arrayMap.put(Integer.valueOf(i2), list);
}
list.add(l0Var);
} catch (IOException e3) {
g().f.c("Failed to merge filter. appId", q3.s(str), e3);
}
} while (cursor.moveToNext());
cursor.close();
return arrayMap;
} catch (SQLiteException e4) {
e2 = e4;
try {
g().f.c("Database error querying filters. appId", q3.s(str), e2);
if (l9.b()) {
}
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
}
} catch (SQLiteException e5) {
e2 = e5;
cursor = null;
g().f.c("Database error querying filters. appId", q3.s(str), e2);
if (l9.b() || !this.a.h.u(str, p.F0)) {
if (cursor != null) {
cursor.close();
}
return null;
}
Map<Integer, List<l0>> emptyMap2 = Collections.emptyMap();
if (cursor != null) {
cursor.close();
}
return emptyMap2;
} catch (Throwable th3) {
th = th3;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
/* JADX WARNING: Removed duplicated region for block: B:36:0x00c3 */
/* JADX WARNING: Removed duplicated region for block: B:41:0x00cb */
public final Map<Integer, List<o0>> d0(String str, String str2) {
Throwable th;
Cursor cursor;
SQLiteException e2;
n();
b();
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
ArrayMap arrayMap = new ArrayMap();
Cursor cursor2 = null;
try {
cursor = t().query("property_filters", new String[]{"audience_id", "data"}, "app_id=? AND property_name=?", new String[]{str, str2}, null, null, null);
try {
if (!cursor.moveToFirst()) {
Map<Integer, List<o0>> emptyMap = Collections.emptyMap();
cursor.close();
return emptyMap;
}
do {
try {
o0 o0Var = (o0) ((u4) ((o0.a) q9.x(o0.D(), cursor.getBlob(1))).p());
int i2 = cursor.getInt(0);
List list = arrayMap.get(Integer.valueOf(i2));
if (list == null) {
list = new ArrayList();
arrayMap.put(Integer.valueOf(i2), list);
}
list.add(o0Var);
} catch (IOException e3) {
g().f.c("Failed to merge filter", q3.s(str), e3);
}
} while (cursor.moveToNext());
cursor.close();
return arrayMap;
} catch (SQLiteException e4) {
e2 = e4;
try {
g().f.c("Database error querying filters. appId", q3.s(str), e2);
if (l9.b()) {
}
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
}
} catch (SQLiteException e5) {
e2 = e5;
cursor = null;
g().f.c("Database error querying filters. appId", q3.s(str), e2);
if (l9.b() || !this.a.h.u(str, p.F0)) {
if (cursor != null) {
cursor.close();
}
return null;
}
Map<Integer, List<o0>> emptyMap2 = Collections.emptyMap();
if (cursor != null) {
cursor.close();
}
return emptyMap2;
} catch (Throwable th3) {
th = th3;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
@WorkerThread
public final void e0() {
n();
t().endTransaction();
}
public final long f0(String str) {
AnimatableValueParser.w(str);
return w("select count(1) from events where app_id=? and name not like '!_%' escape '!'", new String[]{str}, 0);
}
@WorkerThread
public final long g0(String str, String str2) {
Throwable th;
SQLiteException e2;
long w;
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
b();
n();
SQLiteDatabase t = t();
t.beginTransaction();
long j2 = 0;
try {
StringBuilder sb = new StringBuilder(str2.length() + 32);
sb.append("select ");
sb.append(str2);
sb.append(" from app2 where app_id=?");
try {
w = w(sb.toString(), new String[]{str}, -1);
if (w == -1) {
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", str);
contentValues.put("first_open_count", (Integer) 0);
contentValues.put("previous_install_count", (Integer) 0);
if (t.insertWithOnConflict("app2", null, contentValues, 5) == -1) {
g().f.c("Failed to insert column (got -1). appId", q3.s(str), str2);
t.endTransaction();
return -1;
}
w = 0;
}
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.d("Error inserting column. appId", q3.s(str), str2, e2);
t.endTransaction();
return j2;
} catch (Throwable th2) {
th = th2;
t.endTransaction();
throw th;
}
}
try {
ContentValues contentValues2 = new ContentValues();
contentValues2.put("app_id", str);
contentValues2.put(str2, Long.valueOf(1 + w));
if (((long) t.update("app2", contentValues2, "app_id = ?", new String[]{str})) == 0) {
g().f.c("Failed to update column (got 0). appId", q3.s(str), str2);
t.endTransaction();
return -1;
}
t.setTransactionSuccessful();
t.endTransaction();
return w;
} catch (SQLiteException e4) {
e2 = e4;
j2 = w;
g().f.d("Error inserting column. appId", q3.s(str), str2, e2);
t.endTransaction();
return j2;
}
} catch (SQLiteException e5) {
e2 = e5;
g().f.d("Error inserting column. appId", q3.s(str), str2, e2);
t.endTransaction();
return j2;
} catch (Throwable th3) {
th = th3;
t.endTransaction();
throw th;
}
}
/* JADX WARNING: Removed duplicated region for block: B:39:0x00c5 */
/* JADX WARNING: Removed duplicated region for block: B:44:0x00cd */
public final Bundle h0(String str) {
Throwable th;
SQLiteException e2;
Cursor cursor;
b();
n();
Cursor cursor2 = null;
try {
cursor = t().rawQuery("select parameters from default_event_params where app_id=?", new String[]{str});
try {
if (!cursor.moveToFirst()) {
g().n.a("Default event parameters not found");
cursor.close();
return null;
}
try {
a1 a1Var = (a1) ((u4) ((a1.a) q9.x(a1.M(), cursor.getBlob(0))).p());
m();
List<c1> v = a1Var.v();
Bundle bundle = new Bundle();
for (c1 c1Var : v) {
String B = c1Var.B();
if (c1Var.M()) {
bundle.putDouble(B, c1Var.N());
} else if (c1Var.K()) {
bundle.putFloat(B, c1Var.L());
} else if (c1Var.F()) {
bundle.putString(B, c1Var.G());
} else if (c1Var.I()) {
bundle.putLong(B, c1Var.J());
}
}
cursor.close();
return bundle;
} catch (IOException e3) {
g().f.c("Failed to retrieve default event parameters. appId", q3.s(str), e3);
cursor.close();
return null;
}
} catch (SQLiteException e4) {
e2 = e4;
try {
g().f.b("Error selecting default event parameters", e2);
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
cursor2 = cursor;
if (cursor2 != null) {
}
throw th;
}
}
} catch (SQLiteException e5) {
e2 = e5;
cursor = null;
g().f.b("Error selecting default event parameters", e2);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th3) {
th = th3;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
}
@WorkerThread
public final void i0() {
b();
n();
if (R()) {
long a = l().i.a();
Objects.requireNonNull((d) this.a.o);
long elapsedRealtime = SystemClock.elapsedRealtime();
if (Math.abs(elapsedRealtime - a) > p.f1187y.a(null).longValue()) {
l().i.b(elapsedRealtime);
b();
n();
if (R()) {
SQLiteDatabase t = t();
Objects.requireNonNull((d) this.a.o);
int delete = t.delete("queue", "abs(bundle_end_timestamp - ?) > cast(? as integer)", new String[]{String.valueOf(System.currentTimeMillis()), String.valueOf(c.B())});
if (delete > 0) {
g().n.b("Deleted stale rows. rowsDeleted", Integer.valueOf(delete));
}
}
}
}
}
public final long j0() {
Cursor cursor = null;
try {
cursor = t().rawQuery("select rowid from raw_events order by rowid desc limit 1;", null);
if (!cursor.moveToFirst()) {
cursor.close();
return -1;
}
long j2 = cursor.getLong(0);
cursor.close();
return j2;
} catch (SQLiteException e2) {
g().f.b("Error querying raw events", e2);
if (cursor != null) {
cursor.close();
}
return -1;
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
@Override // c.i.a.f.i.b.i9
public final boolean p() {
return false;
}
@WorkerThread
public final void s() {
n();
t().setTransactionSuccessful();
}
@WorkerThread
public final SQLiteDatabase t() {
b();
try {
return this.l.getWritableDatabase();
} catch (SQLiteException e2) {
g().i.b("Error opening database", e2);
throw e2;
}
}
/* JADX WARNING: Removed duplicated region for block: B:19:0x0034 */
/* JADX WARNING: Removed duplicated region for block: B:23:0x003b */
@WorkerThread
public final String u() {
Throwable th;
Cursor cursor;
SQLiteException e2;
try {
cursor = t().rawQuery("select app_id from queue order by has_realtime desc, rowid asc limit 1;", null);
try {
if (cursor.moveToFirst()) {
String string = cursor.getString(0);
cursor.close();
return string;
}
cursor.close();
return null;
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.b("Database error getting next bundle app id", e2);
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
if (cursor != null) {
}
throw th;
}
}
} catch (SQLiteException e4) {
e2 = e4;
cursor = null;
g().f.b("Database error getting next bundle app id", e2);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th3) {
th = th3;
cursor = null;
if (cursor != null) {
cursor.close();
}
throw th;
}
}
public final long v(e1 e1Var) throws IOException {
b();
n();
AnimatableValueParser.w(e1Var.G1());
byte[] d2 = e1Var.d();
long t = m().t(d2);
ContentValues contentValues = new ContentValues();
contentValues.put("app_id", e1Var.G1());
contentValues.put("metadata_fingerprint", Long.valueOf(t));
contentValues.put("metadata", d2);
try {
t().insertWithOnConflict("raw_events_metadata", null, contentValues, 4);
return t;
} catch (SQLiteException e2) {
g().f.c("Error storing raw event metadata. appId", q3.s(e1Var.G1()), e2);
throw e2;
}
}
@WorkerThread
public final long w(String str, String[] strArr, long j2) {
Cursor cursor = null;
try {
Cursor rawQuery = t().rawQuery(str, strArr);
if (rawQuery.moveToFirst()) {
long j3 = rawQuery.getLong(0);
rawQuery.close();
return j3;
}
rawQuery.close();
return j2;
} catch (SQLiteException e2) {
g().f.c("Database error", str, e2);
throw e2;
} catch (Throwable th) {
if (0 != 0) {
cursor.close();
}
throw th;
}
}
@WorkerThread
public final f x(long j2, String str, long j3, boolean z2, boolean z3, boolean z4, boolean z5, boolean z6) {
AnimatableValueParser.w(str);
b();
n();
String[] strArr = {str};
f fVar = new f();
Cursor cursor = null;
try {
SQLiteDatabase t = t();
Cursor query = t.query("apps", new String[]{"day", "daily_events_count", "daily_public_events_count", "daily_conversions_count", "daily_error_events_count", "daily_realtime_events_count"}, "app_id=?", new String[]{str}, null, null, null);
if (!query.moveToFirst()) {
g().i.b("Not updating daily counts, app is not known. appId", q3.s(str));
query.close();
return fVar;
}
if (query.getLong(0) == j2) {
fVar.b = query.getLong(1);
fVar.a = query.getLong(2);
fVar.f1151c = query.getLong(3);
fVar.d = query.getLong(4);
fVar.e = query.getLong(5);
}
if (z2) {
fVar.b += j3;
}
if (z3) {
fVar.a += j3;
}
if (z4) {
fVar.f1151c += j3;
}
if (z5) {
fVar.d += j3;
}
if (z6) {
fVar.e += j3;
}
ContentValues contentValues = new ContentValues();
contentValues.put("day", Long.valueOf(j2));
contentValues.put("daily_public_events_count", Long.valueOf(fVar.a));
contentValues.put("daily_events_count", Long.valueOf(fVar.b));
contentValues.put("daily_conversions_count", Long.valueOf(fVar.f1151c));
contentValues.put("daily_error_events_count", Long.valueOf(fVar.d));
contentValues.put("daily_realtime_events_count", Long.valueOf(fVar.e));
t.update("apps", contentValues, "app_id=?", strArr);
query.close();
return fVar;
} catch (SQLiteException e2) {
g().f.c("Error updating daily counts. appId", q3.s(str), e2);
if (0 != 0) {
cursor.close();
}
return fVar;
} catch (Throwable th) {
if (0 != 0) {
cursor.close();
}
throw th;
}
}
@WorkerThread
public final f y(long j2, String str, boolean z2, boolean z3) {
return x(j2, str, 1, false, false, z2, false, z3);
}
/* JADX WARNING: Removed duplicated region for block: B:59:0x013e */
/* JADX WARNING: Removed duplicated region for block: B:64:0x0147 */
@WorkerThread
public final l z(String str, String str2) {
Throwable th;
Cursor cursor;
SQLiteException e2;
Cursor cursor2;
Boolean bool;
AnimatableValueParser.w(str);
AnimatableValueParser.w(str2);
b();
n();
Cursor cursor3 = null;
try {
boolean z2 = false;
cursor = t().query("events", (String[]) new ArrayList(Arrays.asList("lifetime_count", "current_bundle_count", "last_fire_timestamp", "last_bundled_timestamp", "last_bundled_day", "last_sampled_complex_event_id", "last_sampling_rate", "last_exempt_from_sampling", "current_session_count")).toArray(new String[0]), "app_id=? and name=?", new String[]{str, str2}, null, null, null);
try {
if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
long j2 = cursor.getLong(0);
long j3 = cursor.getLong(1);
long j4 = cursor.getLong(2);
long j5 = cursor.isNull(3) ? 0 : cursor.getLong(3);
Long valueOf = cursor.isNull(4) ? null : Long.valueOf(cursor.getLong(4));
Long valueOf2 = cursor.isNull(5) ? null : Long.valueOf(cursor.getLong(5));
Long valueOf3 = cursor.isNull(6) ? null : Long.valueOf(cursor.getLong(6));
if (!cursor.isNull(7)) {
try {
if (cursor.getLong(7) == 1) {
z2 = true;
}
bool = Boolean.valueOf(z2);
} catch (SQLiteException e3) {
e2 = e3;
try {
g().f.d("Error querying events. appId", q3.s(str), d().u(str2), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th2) {
th = th2;
cursor3 = cursor;
if (cursor3 != null) {
}
throw th;
}
}
} else {
bool = null;
}
cursor2 = cursor;
try {
l lVar = new l(str, str2, j2, j3, cursor.isNull(8) ? 0 : cursor.getLong(8), j4, j5, valueOf, valueOf2, valueOf3, bool);
if (cursor2.moveToNext()) {
g().f.b("Got multiple records for event aggregates, expected one. appId", q3.s(str));
}
cursor2.close();
return lVar;
} catch (SQLiteException e4) {
e2 = e4;
cursor = cursor2;
g().f.d("Error querying events. appId", q3.s(str), d().u(str2), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th3) {
th = th3;
cursor3 = cursor2;
if (cursor3 != null) {
}
throw th;
}
} catch (SQLiteException e5) {
e2 = e5;
g().f.d("Error querying events. appId", q3.s(str), d().u(str2), e2);
if (cursor != null) {
}
return null;
} catch (Throwable th4) {
th = th4;
cursor2 = cursor;
cursor3 = cursor2;
if (cursor3 != null) {
}
throw th;
}
} catch (SQLiteException e6) {
e2 = e6;
cursor = null;
g().f.d("Error querying events. appId", q3.s(str), d().u(str2), e2);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th5) {
th = th5;
if (cursor3 != null) {
cursor3.close();
}
throw th;
}
}
}