package L1;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.SystemClock;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.C0355c1;
import com.google.android.gms.internal.measurement.C0380h1;
import com.google.android.gms.internal.measurement.C0385i1;
import com.google.android.gms.internal.measurement.C0390j1;
import com.google.android.gms.internal.measurement.C0395k1;
import com.google.android.gms.internal.measurement.P3;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import p0.AbstractC0928a;
import w1.C1091a;

/* JADX INFO: renamed from: L1.n, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0119n extends Q1 {
    public static final String[] p = {"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[] q = {"associated_row_id", "ALTER TABLE upload_queue ADD COLUMN associated_row_id INTEGER;", "last_upload_timestamp", "ALTER TABLE upload_queue ADD COLUMN last_upload_timestamp INTEGER;"};

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final String[] f1908r = {"origin", "ALTER TABLE user_attributes ADD COLUMN origin TEXT;"};

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public static final String[] f1909s = {"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;", "config_last_modified_time", "ALTER TABLE apps ADD COLUMN config_last_modified_time TEXT;", "e_tag", "ALTER TABLE apps ADD COLUMN e_tag TEXT;", "session_stitching_token", "ALTER TABLE apps ADD COLUMN session_stitching_token TEXT;", "sgtm_upload_enabled", "ALTER TABLE apps ADD COLUMN sgtm_upload_enabled INTEGER;", "target_os_version", "ALTER TABLE apps ADD COLUMN target_os_version INTEGER;", "session_stitching_token_hash", "ALTER TABLE apps ADD COLUMN session_stitching_token_hash INTEGER;", "ad_services_version", "ALTER TABLE apps ADD COLUMN ad_services_version INTEGER;", "unmatched_first_open_without_ad_id", "ALTER TABLE apps ADD COLUMN unmatched_first_open_without_ad_id INTEGER;", "npa_metadata_value", "ALTER TABLE apps ADD COLUMN npa_metadata_value INTEGER;", "attribution_eligibility_status", "ALTER TABLE apps ADD COLUMN attribution_eligibility_status INTEGER;", "sgtm_preview_key", "ALTER TABLE apps ADD COLUMN sgtm_preview_key TEXT;", "dma_consent_state", "ALTER TABLE apps ADD COLUMN dma_consent_state INTEGER;", "daily_realtime_dcu_count", "ALTER TABLE apps ADD COLUMN daily_realtime_dcu_count INTEGER;", "bundle_delivery_index", "ALTER TABLE apps ADD COLUMN bundle_delivery_index INTEGER;", "serialized_npa_metadata", "ALTER TABLE apps ADD COLUMN serialized_npa_metadata TEXT;", "unmatched_pfo", "ALTER TABLE apps ADD COLUMN unmatched_pfo INTEGER;", "unmatched_uwa", "ALTER TABLE apps ADD COLUMN unmatched_uwa INTEGER;", "ad_campaign_info", "ALTER TABLE apps ADD COLUMN ad_campaign_info BLOB;", "daily_registered_triggers_count", "ALTER TABLE apps ADD COLUMN daily_registered_triggers_count INTEGER;", "client_upload_eligibility", "ALTER TABLE apps ADD COLUMN client_upload_eligibility INTEGER;", "gmp_version_for_remote_config", "ALTER TABLE apps ADD COLUMN gmp_version_for_remote_config INTEGER;"};

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public static final String[] f1910t = {"realtime", "ALTER TABLE raw_events ADD COLUMN realtime INTEGER;"};

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public static final String[] f1911u = {"has_realtime", "ALTER TABLE queue ADD COLUMN has_realtime INTEGER;", "retry_count", "ALTER TABLE queue ADD COLUMN retry_count INTEGER;"};

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public static final String[] f1912v = {"session_scoped", "ALTER TABLE event_filters ADD COLUMN session_scoped BOOLEAN;"};

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public static final String[] f1913w = {"session_scoped", "ALTER TABLE property_filters ADD COLUMN session_scoped BOOLEAN;"};

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public static final String[] f1914x = {"previous_install_count", "ALTER TABLE app2 ADD COLUMN previous_install_count INTEGER;"};

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static final String[] f1915y = {"consent_source", "ALTER TABLE consent_settings ADD COLUMN consent_source INTEGER;", "dma_consent_settings", "ALTER TABLE consent_settings ADD COLUMN dma_consent_settings TEXT;", "storage_consent_at_bundling", "ALTER TABLE consent_settings ADD COLUMN storage_consent_at_bundling TEXT;"};

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public static final String[] f1916z = {"idempotent", "CREATE INDEX IF NOT EXISTS trigger_uris_index ON trigger_uris (app_id);"};

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final C0116m f1917n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final T f1918o;

    public C0119n(W1 w12) {
        super(w12);
        this.f1918o = new T(((C0146w0) this.f29k).f2040u);
        ((C0146w0) this.f29k).getClass();
        this.f1917n = new C0116m(this, ((C0146w0) this.f29k).f2032k);
    }

    public static final String N(ArrayList arrayList) {
        return arrayList.isEmpty() ? "" : AbstractC0928a.l(" AND (upload_type IN (", TextUtils.join(", ", arrayList), "))");
    }

    public static final void T(ContentValues contentValues, Object obj) {
        s1.z.d("value");
        s1.z.g(obj);
        if (obj instanceof String) {
            contentValues.put("value", (String) obj);
        } else if (obj instanceof Long) {
            contentValues.put("value", (Long) obj);
        } else {
            if (!(obj instanceof Double)) {
                throw new IllegalArgumentException("Invalid value type");
            }
            contentValues.put("value", (Double) obj);
        }
    }

    public final long A(String str) {
        s1.z.d(str);
        return V("select count(1) from events where app_id=? and name not like '!_%' escape '!'", new String[]{str}, 0L);
    }

    public final void B(String str, Long l5, long j5, C0355c1 c0355c1) {
        k();
        l();
        s1.z.g(c0355c1);
        s1.z.d(str);
        byte[] bArrA = c0355c1.a();
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        X x5 = c0146w0.p;
        X x6 = c0146w0.p;
        C0146w0.l(x5);
        x5.f1631x.d(c0146w0.f2039t.a(str), Integer.valueOf(bArrA.length), "Saving complex main event, appId, data size");
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("event_id", l5);
        contentValues.put("children_to_process", Long.valueOf(j5));
        contentValues.put("main_event", bArrA);
        try {
            if (Z().insertWithOnConflict("main_event_params", null, contentValues, 5) == -1) {
                C0146w0.l(x6);
                x6.p.c("Failed to insert complex main event (got -1). appId", X.s(str));
            }
        } catch (SQLiteException e2) {
            C0146w0.l(x6);
            x6.p.d(X.s(str), e2, "Error storing complex main event. appId");
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:122:0x0116 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00f4  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void C(java.lang.String r25, java.lang.Long r26, java.lang.String r27, android.os.Bundle r28) {
        /*
            Method dump skipped, instruction units count: 709
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.C(java.lang.String, java.lang.Long, java.lang.String, android.os.Bundle):void");
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:24:0x005e  */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0061 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:28:0x0064  */
    /* JADX WARN: Type inference failed for: r2v0 */
    /* JADX WARN: Type inference failed for: r2v1, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r2v2 */
    /* JADX WARN: Type inference failed for: r3v1, types: [android.database.sqlite.SQLiteDatabase] */
    /* JADX WARN: Type inference failed for: r5v1, types: [java.lang.String[]] */
    /* JADX WARN: Type inference failed for: r5v4 */
    /* JADX WARN: Type inference failed for: r5v5 */
    /* JADX WARN: Type inference failed for: r5v6 */
    /* JADX WARN: Type inference failed for: r5v8, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r5v9, types: [android.database.Cursor] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final L1.L0 D(java.lang.String r5) {
        /*
            r4 = this;
            java.lang.Object r0 = r4.f29k
            L1.w0 r0 = (L1.C0146w0) r0
            s1.z.g(r5)
            r4.k()
            r4.l()
            java.lang.String[] r5 = new java.lang.String[]{r5}
            java.lang.String r1 = "select consent_state, consent_source from consent_settings where app_id=? limit 1;"
            r2 = 0
            android.database.sqlite.SQLiteDatabase r3 = r4.Z()     // Catch: java.lang.Throwable -> L47 android.database.sqlite.SQLiteException -> L4a
            android.database.Cursor r5 = r3.rawQuery(r1, r5)     // Catch: java.lang.Throwable -> L47 android.database.sqlite.SQLiteException -> L4a
            boolean r1 = r5.moveToFirst()     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
            if (r1 != 0) goto L36
            L1.X r1 = r0.p     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
            L1.C0146w0.l(r1)     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
            L1.V r1 = r1.f1631x     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
            java.lang.String r3 = "No data found"
            r1.b(r3)     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
        L2e:
            r5.close()
            goto L5c
        L32:
            r0 = move-exception
            goto L45
        L34:
            r1 = move-exception
            goto L4d
        L36:
            r1 = 0
            java.lang.String r1 = r5.getString(r1)     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
            r3 = 1
            int r3 = r5.getInt(r3)     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
            L1.L0 r2 = L1.L0.c(r3, r1)     // Catch: java.lang.Throwable -> L32 android.database.sqlite.SQLiteException -> L34
            goto L2e
        L45:
            r2 = r5
            goto L62
        L47:
            r5 = move-exception
            r0 = r5
            goto L62
        L4a:
            r5 = move-exception
            r1 = r5
            r5 = r2
        L4d:
            L1.X r0 = r0.p     // Catch: java.lang.Throwable -> L32
            L1.C0146w0.l(r0)     // Catch: java.lang.Throwable -> L32
            L1.V r0 = r0.p     // Catch: java.lang.Throwable -> L32
            java.lang.String r3 = "Error querying database."
            r0.c(r3, r1)     // Catch: java.lang.Throwable -> L32
            if (r5 == 0) goto L5c
            goto L2e
        L5c:
            if (r2 != 0) goto L61
            L1.L0 r5 = L1.L0.f1485c
            return r5
        L61:
            return r2
        L62:
            if (r2 == 0) goto L67
            r2.close()
        L67:
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.D(java.lang.String):L1.L0");
    }

    public final void E(String str, K1 k12) {
        k();
        l();
        s1.z.d(str);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        c0146w0.f2040u.getClass();
        long jCurrentTimeMillis = System.currentTimeMillis();
        E e2 = F.f1442v0;
        long jLongValue = jCurrentTimeMillis - ((Long) e2.a(null)).longValue();
        long j5 = k12.f1483l;
        X x5 = c0146w0.p;
        if (j5 < jLongValue || j5 > ((Long) e2.a(null)).longValue() + jCurrentTimeMillis) {
            C0146w0.l(x5);
            x5.f1626s.e("Storing trigger URI outside of the max retention time span. appId, now, timestamp", X.s(str), Long.valueOf(jCurrentTimeMillis), Long.valueOf(j5));
        }
        C0146w0.l(x5);
        x5.f1631x.b("Saving trigger URI");
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("trigger_uri", k12.f1482k);
        contentValues.put("source", Integer.valueOf(k12.f1484m));
        contentValues.put("timestamp_millis", Long.valueOf(j5));
        try {
            if (Z().insert("trigger_uris", null, contentValues) == -1) {
                C0146w0.l(x5);
                x5.p.c("Failed to insert trigger URI (got -1). appId", X.s(str));
            }
        } catch (SQLiteException e6) {
            C0146w0.l(x5);
            x5.p.d(X.s(str), e6, "Error storing trigger URI. appId");
        }
    }

    public final void F(String str, L0 l0) {
        s1.z.g(str);
        s1.z.g(l0);
        k();
        l();
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("consent_state", l0.g());
        contentValues.put("consent_source", Integer.valueOf(l0.f1487b));
        H(contentValues);
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0035  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final java.lang.String G(java.lang.String r4, java.lang.String[] r5) {
        /*
            r3 = this;
            android.database.sqlite.SQLiteDatabase r0 = r3.Z()
            r1 = 0
            android.database.Cursor r1 = r0.rawQuery(r4, r5)     // Catch: java.lang.Throwable -> L18 android.database.sqlite.SQLiteException -> L1a
            boolean r5 = r1.moveToFirst()     // Catch: java.lang.Throwable -> L18 android.database.sqlite.SQLiteException -> L1a
            if (r5 == 0) goto L1c
            r5 = 0
            java.lang.String r4 = r1.getString(r5)     // Catch: java.lang.Throwable -> L18 android.database.sqlite.SQLiteException -> L1a
            r1.close()
            return r4
        L18:
            r4 = move-exception
            goto L33
        L1a:
            r5 = move-exception
            goto L22
        L1c:
            r1.close()
            java.lang.String r4 = ""
            return r4
        L22:
            java.lang.Object r0 = r3.f29k     // Catch: java.lang.Throwable -> L18
            L1.w0 r0 = (L1.C0146w0) r0     // Catch: java.lang.Throwable -> L18
            L1.X r0 = r0.p     // Catch: java.lang.Throwable -> L18
            L1.C0146w0.l(r0)     // Catch: java.lang.Throwable -> L18
            L1.V r0 = r0.p     // Catch: java.lang.Throwable -> L18
            java.lang.String r2 = "Database error"
            r0.d(r4, r5, r2)     // Catch: java.lang.Throwable -> L18
            throw r5     // Catch: java.lang.Throwable -> L18
        L33:
            if (r1 == 0) goto L38
            r1.close()
        L38:
            throw r4
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.G(java.lang.String, java.lang.String[]):java.lang.String");
    }

    public final void H(ContentValues contentValues) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        try {
            SQLiteDatabase sQLiteDatabaseZ = Z();
            if (contentValues.getAsString("app_id") == null) {
                X x5 = c0146w0.p;
                C0146w0.l(x5);
                x5.f1625r.c("Value of the primary key is not set.", X.s("app_id"));
                return;
            }
            new StringBuilder(10).append("app_id = ?");
            if (sQLiteDatabaseZ.update("consent_settings", contentValues, r6.toString(), new String[]{r5}) == 0 && sQLiteDatabaseZ.insertWithOnConflict("consent_settings", null, contentValues, 5) == -1) {
                X x6 = c0146w0.p;
                C0146w0.l(x6);
                x6.p.d(X.s("consent_settings"), X.s("app_id"), "Failed to insert/update table (got -1). key");
            }
        } catch (SQLiteException e2) {
            X x7 = c0146w0.p;
            C0146w0.l(x7);
            x7.p.e("Error storing into table. key", X.s("consent_settings"), X.s("app_id"), e2);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:54:0x012d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final L1.C0133s I(java.lang.String r31, java.lang.String r32, java.lang.String r33) {
        /*
            Method dump skipped, instruction units count: 305
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.I(java.lang.String, java.lang.String, java.lang.String):L1.s");
    }

    public final void J(String str, C0133s c0133s) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        s1.z.g(c0133s);
        k();
        l();
        ContentValues contentValues = new ContentValues();
        String str2 = c0133s.f1977a;
        contentValues.put("app_id", str2);
        contentValues.put("name", c0133s.f1978b);
        contentValues.put("lifetime_count", Long.valueOf(c0133s.f1979c));
        contentValues.put("current_bundle_count", Long.valueOf(c0133s.f1980d));
        contentValues.put("last_fire_timestamp", Long.valueOf(c0133s.f1982f));
        contentValues.put("last_bundled_timestamp", Long.valueOf(c0133s.f1983g));
        contentValues.put("last_bundled_day", c0133s.f1984h);
        contentValues.put("last_sampled_complex_event_id", c0133s.i);
        contentValues.put("last_sampling_rate", c0133s.f1985j);
        contentValues.put("current_session_count", Long.valueOf(c0133s.f1981e));
        Boolean bool = c0133s.f1986k;
        contentValues.put("last_exempt_from_sampling", (bool == null || !bool.booleanValue()) ? null : 1L);
        try {
            if (Z().insertWithOnConflict(str, null, contentValues, 5) == -1) {
                X x5 = c0146w0.p;
                C0146w0.l(x5);
                x5.p.c("Failed to insert/update event aggregates (got -1). appId", X.s(str2));
            }
        } catch (SQLiteException e2) {
            X x6 = c0146w0.p;
            C0146w0.l(x6);
            x6.p.d(X.s(str2), e2, "Error storing event aggregates. appId");
        }
    }

    public final void K(String str, String str2) {
        s1.z.d(str2);
        k();
        l();
        try {
            Z().delete(str, "app_id=?", new String[]{str2});
        } catch (SQLiteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.p.d(X.s(str2), e2, "Error deleting snapshot. appId");
        }
    }

    public final Y1 L(String str, long j5, byte[] bArr, String str2, String str3, int i, int i5, long j6, long j7, long j8) {
        Y1 y12;
        C0146w0 c0146w0;
        EnumC0109j1 enumC0109j1;
        boolean zIsEmpty = TextUtils.isEmpty(str2);
        C0146w0 c0146w02 = (C0146w0) this.f29k;
        if (zIsEmpty) {
            X x5 = c0146w02.p;
            C0146w0.l(x5);
            x5.f1630w.b("Upload uri is null or empty. Destination is unknown. Dropping batch. ");
            return null;
        }
        try {
            C0380h1 c0380h1 = (C0380h1) C0084b0.X(C0385i1.w(), bArr);
            EnumC0109j1[] enumC0109j1ArrValues = EnumC0109j1.values();
            int length = enumC0109j1ArrValues.length;
            int i6 = 0;
            while (true) {
                if (i6 >= length) {
                    enumC0109j1 = EnumC0109j1.UNKNOWN;
                    break;
                }
                enumC0109j1 = enumC0109j1ArrValues[i6];
                if (enumC0109j1.f1880k == i) {
                    break;
                }
                i6++;
            }
            EnumC0109j1 enumC0109j12 = enumC0109j1;
            if (enumC0109j12 != EnumC0109j1.GOOGLE_SIGNAL && enumC0109j12 != EnumC0109j1.GOOGLE_SIGNAL_PENDING && i5 > 0) {
                ArrayList arrayList = new ArrayList();
                Iterator it = Collections.unmodifiableList(((C0385i1) c0380h1.f5142l).p()).iterator();
                while (it.hasNext()) {
                    C0390j1 c0390j1 = (C0390j1) ((C0395k1) it.next()).i();
                    c0390j1.b();
                    ((C0395k1) c0390j1.f5142l).T0(i5);
                    arrayList.add((C0395k1) c0390j1.e());
                }
                c0380h1.b();
                ((C0385i1) c0380h1.f5142l).B();
                c0380h1.b();
                ((C0385i1) c0380h1.f5142l).A(arrayList);
            }
            HashMap map = new HashMap();
            if (str3 != null) {
                String[] strArrSplit = str3.split("\r\n");
                int length2 = strArrSplit.length;
                int i7 = 0;
                while (true) {
                    if (i7 >= length2) {
                        break;
                    }
                    String str4 = strArrSplit[i7];
                    if (str4.isEmpty()) {
                        break;
                    }
                    String[] strArrSplit2 = str4.split("=", 2);
                    if (strArrSplit2.length != 2) {
                        X x6 = c0146w02.p;
                        C0146w0.l(x6);
                        x6.p.c("Invalid upload header: ", str4);
                        break;
                    }
                    map.put(strArrSplit2[0], strArrSplit2[1]);
                    i7++;
                }
            }
            y12 = null;
            c0146w0 = c0146w02;
            try {
                return new Y1(j5, (C0385i1) c0380h1.e(), str2, map, enumC0109j12, j6, j7, j8, i5);
            } catch (IOException e2) {
                e = e2;
                X x7 = c0146w0.p;
                C0146w0.l(x7);
                x7.p.d(str, e, "Failed to queued MeasurementBatch from upload_queue. appId");
                return y12;
            }
        } catch (IOException e6) {
            e = e6;
            y12 = null;
            c0146w0 = c0146w02;
        }
    }

    public final String M() {
        ((C0146w0) this.f29k).f2040u.getClass();
        long jCurrentTimeMillis = System.currentTimeMillis();
        Locale locale = Locale.US;
        Long l5 = (Long) F.f1379S.a(null);
        l5.getClass();
        String str = "(upload_type = 1 AND ABS(creation_timestamp - " + jCurrentTimeMillis + ") > " + l5 + ")";
        String str2 = "(upload_type != 1 AND ABS(creation_timestamp - " + jCurrentTimeMillis + ") > " + ((Long) F.f1377R.a(null)).longValue() + ")";
        StringBuilder sb = new StringBuilder(str.length() + 5 + str2.length() + 1);
        sb.append("(");
        sb.append(str);
        sb.append(" OR ");
        sb.append(str2);
        sb.append(")");
        return sb.toString();
    }

    public final void O(String str, L0 l0) {
        s1.z.g(str);
        k();
        l();
        F(str, D(str));
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("storage_consent_at_bundling", l0.g());
        H(contentValues);
    }

    public final L0 P(String str) {
        s1.z.g(str);
        k();
        l();
        return L0.c(100, G("select storage_consent_at_bundling from consent_settings where app_id=? limit 1;", new String[]{str}));
    }

    public final C0133s Q(String str, C0355c1 c0355c1, String str2) {
        C0133s c0133sI = I("events", str, c0355c1.s());
        if (c0133sI != null) {
            long j5 = c0133sI.f1981e + 1;
            long j6 = c0133sI.f1980d + 1;
            return new C0133s(c0133sI.f1977a, c0133sI.f1978b, c0133sI.f1979c + 1, j6, j5, c0133sI.f1982f, c0133sI.f1983g, c0133sI.f1984h, c0133sI.i, c0133sI.f1985j, c0133sI.f1986k);
        }
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        X x5 = c0146w0.p;
        C0146w0.l(x5);
        x5.f1626s.d(X.s(str), c0146w0.f2039t.a(str2), "Event aggregate wasn't created during raw event logging. appId, event");
        return new C0133s(str, c0355c1.s(), 1L, 1L, 1L, c0355c1.u(), 0L, null, null, null, null);
    }

    public final boolean R() {
        return ((C0146w0) this.f29k).f2032k.getDatabasePath("google_app_measurement.db").exists();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:47:0x00f8 A[Catch: all -> 0x007a, SQLiteException -> 0x007c, TryCatch #7 {all -> 0x007a, blocks: (B:15:0x0066, B:18:0x006e, B:19:0x0072, B:45:0x00d0, B:47:0x00f8, B:48:0x010a, B:49:0x010e, B:50:0x011e, B:52:0x0124, B:53:0x0134, B:56:0x0147, B:68:0x016e, B:71:0x0176, B:77:0x0195, B:61:0x015d, B:75:0x0187, B:76:0x0190, B:99:0x021f, B:40:0x00c0, B:43:0x00c8), top: B:122:0x0026 }] */
    /* JADX WARN: Removed duplicated region for block: B:48:0x010a A[Catch: all -> 0x007a, SQLiteException -> 0x007c, TRY_LEAVE, TryCatch #7 {all -> 0x007a, blocks: (B:15:0x0066, B:18:0x006e, B:19:0x0072, B:45:0x00d0, B:47:0x00f8, B:48:0x010a, B:49:0x010e, B:50:0x011e, B:52:0x0124, B:53:0x0134, B:56:0x0147, B:68:0x016e, B:71:0x0176, B:77:0x0195, B:61:0x015d, B:75:0x0187, B:76:0x0190, B:99:0x021f, B:40:0x00c0, B:43:0x00c8), top: B:122:0x0026 }] */
    /* JADX WARN: Type inference failed for: r5v1 */
    /* JADX WARN: Type inference failed for: r5v11 */
    /* JADX WARN: Type inference failed for: r5v12 */
    /* JADX WARN: Type inference failed for: r5v13 */
    /* JADX WARN: Type inference failed for: r5v2, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r5v6 */
    /* JADX WARN: Type inference failed for: r5v7, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r7v1, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r7v19 */
    /* JADX WARN: Type inference failed for: r7v5 */
    /* JADX WARN: Type inference failed for: r9v0 */
    /* JADX WARN: Type inference failed for: r9v1 */
    /* JADX WARN: Type inference failed for: r9v2, types: [boolean] */
    /* JADX WARN: Type inference failed for: r9v20 */
    /* JADX WARN: Type inference failed for: r9v21 */
    /* JADX WARN: Type inference failed for: r9v22 */
    /* JADX WARN: Type inference failed for: r9v23 */
    /* JADX WARN: Type inference failed for: r9v3 */
    /* JADX WARN: Type inference failed for: r9v5 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void S(java.lang.String r21, long r22, long r24, L1.C0102h0 r26) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 592
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.S(java.lang.String, long, long, L1.h0):void");
    }

    public final long U(String str, String[] strArr) {
        Cursor cursor = null;
        try {
            try {
                Cursor cursorRawQuery = Z().rawQuery(str, strArr);
                if (!cursorRawQuery.moveToFirst()) {
                    throw new SQLiteException("Database returned empty set");
                }
                long j5 = cursorRawQuery.getLong(0);
                cursorRawQuery.close();
                return j5;
            } catch (SQLiteException e2) {
                X x5 = ((C0146w0) this.f29k).p;
                C0146w0.l(x5);
                x5.p.d(str, e2, "Database error");
                throw e2;
            }
        } catch (Throwable th) {
            if (0 != 0) {
                cursor.close();
            }
            throw th;
        }
    }

    public final long V(String str, String[] strArr, long j5) {
        Cursor cursorRawQuery = null;
        try {
            try {
                cursorRawQuery = Z().rawQuery(str, strArr);
                if (cursorRawQuery.moveToFirst()) {
                    j5 = cursorRawQuery.getLong(0);
                }
                cursorRawQuery.close();
                return j5;
            } catch (SQLiteException e2) {
                X x5 = ((C0146w0) this.f29k).p;
                C0146w0.l(x5);
                x5.p.d(str, e2, "Database error");
                throw e2;
            }
        } catch (Throwable th) {
            if (cursorRawQuery != null) {
                cursorRawQuery.close();
            }
            throw th;
        }
    }

    public final void W() {
        l();
        Z().beginTransaction();
    }

    public final void X() {
        l();
        Z().setTransactionSuccessful();
    }

    public final void Y() {
        l();
        Z().endTransaction();
    }

    public final SQLiteDatabase Z() {
        k();
        try {
            return this.f1917n.getWritableDatabase();
        } catch (SQLiteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error opening database", e2);
            throw e2;
        }
    }

    public final void a0(String str) {
        C0133s c0133sI;
        K("events_snapshot", str);
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = Z().query("events", (String[]) Collections.singletonList("name").toArray(new String[0]), "app_id=?", new String[]{str}, null, null, null);
                if (cursorQuery.moveToFirst()) {
                    do {
                        String string = cursorQuery.getString(0);
                        if (string != null && (c0133sI = I("events", str, string)) != null) {
                            J("events_snapshot", c0133sI);
                        }
                    } while (cursorQuery.moveToNext());
                }
            } catch (SQLiteException e2) {
                X x5 = ((C0146w0) this.f29k).p;
                C0146w0.l(x5);
                x5.p.d(X.s(str), e2, "Error creating snapshot. appId");
            }
            if (cursorQuery != null) {
                cursorQuery.close();
            }
        } finally {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x00cb  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00d7  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0054  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x005b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void b0(java.lang.String r20) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 226
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.b0(java.lang.String):void");
    }

    public final void c0(String str, String str2) {
        s1.z.d(str);
        s1.z.d(str2);
        k();
        l();
        try {
            Z().delete("user_attributes", "app_id=? and name=?", new String[]{str, str2});
        } catch (SQLiteException e2) {
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.p.e("Error deleting user property. appId", X.s(str), c0146w0.f2039t.c(str2), e2);
        }
    }

    public final boolean d0(a2 a2Var) {
        k();
        l();
        String str = a2Var.f1668a;
        String str2 = a2Var.f1670c;
        a2 a2VarE0 = e0(str, str2);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        String str3 = a2Var.f1669b;
        if (a2VarE0 == null) {
            if (c2.i0(str2)) {
                if (U("select count(1) from user_attributes where app_id=? and name not like '!_%' escape '!'", new String[]{str}) >= Math.max(Math.min(c0146w0.f2035n.s(str, F.f1384V), 100), 25)) {
                    return false;
                }
            } else if (!"_npa".equals(str2)) {
                long jU = U("select count(1) from user_attributes where app_id=? and origin=? AND name like '!_%' escape '!'", new String[]{str, str3});
                c0146w0.getClass();
                if (jU >= 25) {
                    return false;
                }
            }
        }
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("origin", str3);
        contentValues.put("name", str2);
        contentValues.put("set_timestamp", Long.valueOf(a2Var.f1671d));
        T(contentValues, a2Var.f1672e);
        try {
            if (Z().insertWithOnConflict("user_attributes", null, contentValues, 5) != -1) {
                return true;
            }
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.p.c("Failed to insert/update user property (got -1). appId", X.s(str));
            return true;
        } catch (SQLiteException e2) {
            X x6 = c0146w0.p;
            C0146w0.l(x6);
            x6.p.d(X.s(str), e2, "Error storing user property. appId");
            return true;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x009d  */
    /* JADX WARN: Removed duplicated region for block: B:43:? A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final L1.a2 e0(java.lang.String r12, java.lang.String r13) {
        /*
            r11 = this;
            java.lang.Object r0 = r11.f29k
            r1 = r0
            L1.w0 r1 = (L1.C0146w0) r1
            s1.z.d(r12)
            s1.z.d(r13)
            r11.k()
            r11.l()
            r2 = 0
            android.database.sqlite.SQLiteDatabase r3 = r11.Z()     // Catch: java.lang.Throwable -> L77 android.database.sqlite.SQLiteException -> L7a
            java.lang.String r4 = "user_attributes"
            java.lang.String r0 = "set_timestamp"
            java.lang.String r5 = "value"
            java.lang.String r6 = "origin"
            java.lang.String[] r5 = new java.lang.String[]{r0, r5, r6}     // Catch: java.lang.Throwable -> L77 android.database.sqlite.SQLiteException -> L7a
            java.lang.String r6 = "app_id=? and name=?"
            java.lang.String[] r7 = new java.lang.String[]{r12, r13}     // Catch: java.lang.Throwable -> L77 android.database.sqlite.SQLiteException -> L7a
            r10 = 0
            r8 = 0
            r9 = 0
            android.database.Cursor r3 = r3.query(r4, r5, r6, r7, r8, r9, r10)     // Catch: java.lang.Throwable -> L77 android.database.sqlite.SQLiteException -> L7a
            boolean r0 = r3.moveToFirst()     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L71
            if (r0 != 0) goto L37
            goto L95
        L37:
            r0 = 0
            long r8 = r3.getLong(r0)     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L71
            r0 = 1
            java.lang.Object r10 = r11.x(r3, r0)     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L71
            if (r10 != 0) goto L44
            goto L95
        L44:
            r0 = 2
            java.lang.String r6 = r3.getString(r0)     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L71
            L1.a2 r4 = new L1.a2     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L71
            r5 = r12
            r7 = r13
            r4.<init>(r5, r6, r7, r8, r10)     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L6a
            boolean r12 = r3.moveToNext()     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L6a
            if (r12 == 0) goto L6d
            L1.X r12 = r1.p     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L6a
            L1.C0146w0.l(r12)     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L6a
            L1.V r12 = r12.p     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L6a
            java.lang.String r13 = "Got multiple records for user property, expected one. appId"
            L1.W r0 = L1.X.s(r5)     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L6a
            r12.c(r13, r0)     // Catch: java.lang.Throwable -> L67 android.database.sqlite.SQLiteException -> L6a
            goto L6d
        L67:
            r0 = move-exception
            r12 = r0
            goto L75
        L6a:
            r0 = move-exception
        L6b:
            r12 = r0
            goto L7f
        L6d:
            r3.close()
            return r4
        L71:
            r0 = move-exception
            r5 = r12
            r7 = r13
            goto L6b
        L75:
            r2 = r3
            goto L9b
        L77:
            r0 = move-exception
            r12 = r0
            goto L9b
        L7a:
            r0 = move-exception
            r5 = r12
            r7 = r13
            r12 = r0
            r3 = r2
        L7f:
            L1.X r13 = r1.p     // Catch: java.lang.Throwable -> L67
            L1.C0146w0.l(r13)     // Catch: java.lang.Throwable -> L67
            L1.V r13 = r13.p     // Catch: java.lang.Throwable -> L67
            java.lang.String r0 = "Error querying user property. appId"
            L1.W r4 = L1.X.s(r5)     // Catch: java.lang.Throwable -> L67
            L1.Q r1 = r1.f2039t     // Catch: java.lang.Throwable -> L67
            java.lang.String r1 = r1.c(r7)     // Catch: java.lang.Throwable -> L67
            r13.e(r0, r4, r1, r12)     // Catch: java.lang.Throwable -> L67
        L95:
            if (r3 == 0) goto L9a
            r3.close()
        L9a:
            return r2
        L9b:
            if (r2 == 0) goto La0
            r2.close()
        La0:
            throw r12
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.e0(java.lang.String, java.lang.String):L1.a2");
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v1, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r0v4, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r0v6, types: [java.util.List] */
    public final List f0(String str) {
        String str2;
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        s1.z.d(str);
        k();
        l();
        ?? arrayList = new ArrayList();
        Cursor cursorQuery = null;
        try {
            try {
                c0146w0.getClass();
                cursorQuery = Z().query("user_attributes", new String[]{"name", "origin", "set_timestamp", "value"}, "app_id=?", new String[]{str}, null, null, "rowid", "1000");
                try {
                    if (cursorQuery.moveToFirst()) {
                        while (true) {
                            String string = cursorQuery.getString(0);
                            String string2 = cursorQuery.getString(1);
                            if (string2 == null) {
                                string2 = "";
                            }
                            String str3 = string2;
                            long j5 = cursorQuery.getLong(2);
                            Object objX = x(cursorQuery, 3);
                            if (objX == null) {
                                X x5 = c0146w0.p;
                                C0146w0.l(x5);
                                x5.p.c("Read invalid user property value, ignoring it. appId", X.s(str));
                                str2 = str;
                            } else {
                                str2 = str;
                                try {
                                    arrayList.add(new a2(str2, str3, string, j5, objX));
                                } catch (SQLiteException e2) {
                                    e = e2;
                                    X x6 = c0146w0.p;
                                    C0146w0.l(x6);
                                    x6.p.d(X.s(str2), e, "Error querying user properties. appId");
                                    arrayList = Collections.EMPTY_LIST;
                                }
                            }
                            if (!cursorQuery.moveToNext()) {
                                break;
                            }
                            str = str2;
                        }
                    }
                } catch (SQLiteException e6) {
                    e = e6;
                    str2 = str;
                }
            } finally {
            }
        } catch (SQLiteException e7) {
            e = e7;
            str2 = str;
        }
        if (cursorQuery != null) {
            cursorQuery.close();
        }
        return arrayList;
    }

    /* JADX WARN: Code restructure failed: missing block: B:22:0x00b1, code lost:
    
        L1.C0146w0.l(r8);
        r8.p.c("Read more than the max allowed user properties, ignoring excess", 1000);
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:50:0x012d  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x0134  */
    /* JADX WARN: Type inference failed for: r3v0, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r3v1, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r3v3, types: [java.util.List] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final java.util.List g0(java.lang.String r23, java.lang.String r24, java.lang.String r25) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 312
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.g0(java.lang.String, java.lang.String, java.lang.String):java.util.List");
    }

    public final boolean h0(C0092e c0092e) {
        k();
        l();
        String str = c0092e.f1757k;
        s1.z.g(str);
        a2 a2VarE0 = e0(str, c0092e.f1759m.f1654l);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (a2VarE0 == null) {
            long jU = U("SELECT COUNT(1) FROM conditional_properties WHERE app_id=?", new String[]{str});
            c0146w0.getClass();
            if (jU >= 1000) {
                return false;
            }
        }
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("origin", c0092e.f1758l);
        contentValues.put("name", c0092e.f1759m.f1654l);
        Object objA = c0092e.f1759m.a();
        s1.z.g(objA);
        T(contentValues, objA);
        contentValues.put("active", Boolean.valueOf(c0092e.f1761o));
        contentValues.put("trigger_event_name", c0092e.p);
        contentValues.put("trigger_timeout", Long.valueOf(c0092e.f1762r));
        c2 c2Var = c0146w0.f2038s;
        X x5 = c0146w0.p;
        C0146w0.j(c2Var);
        contentValues.put("timed_out_event", c2.O(c0092e.q));
        contentValues.put("creation_timestamp", Long.valueOf(c0092e.f1760n));
        C0146w0.j(c0146w0.f2038s);
        contentValues.put("triggered_event", c2.O(c0092e.f1763s));
        contentValues.put("triggered_timestamp", Long.valueOf(c0092e.f1759m.f1655m));
        contentValues.put("time_to_live", Long.valueOf(c0092e.f1764t));
        contentValues.put("expired_event", c2.O(c0092e.f1765u));
        try {
            if (Z().insertWithOnConflict("conditional_properties", null, contentValues, 5) != -1) {
                return true;
            }
            C0146w0.l(x5);
            x5.p.c("Failed to insert/update conditional user property (got -1)", X.s(str));
            return true;
        } catch (SQLiteException e2) {
            C0146w0.l(x5);
            x5.p.d(X.s(str), e2, "Error storing conditional user property");
            return true;
        }
    }

    /* JADX WARN: Not initialized variable reg: 10, insn: 0x00f6: MOVE (r9 I:??[OBJECT, ARRAY]) = (r10 I:??[OBJECT, ARRAY]) (LINE:247), block:B:29:0x00f6 */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0116  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x011c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final L1.C0092e i0(java.lang.String r27, java.lang.String r28) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 288
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.i0(java.lang.String, java.lang.String):L1.e");
    }

    public final void j0(String str, String str2) {
        s1.z.d(str);
        s1.z.d(str2);
        k();
        l();
        try {
            Z().delete("conditional_properties", "app_id=? and name=?", new String[]{str, str2});
        } catch (SQLiteException e2) {
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.p.e("Error deleting conditional property", X.s(str), c0146w0.f2039t.c(str2), e2);
        }
    }

    public final List k0(String str, String str2, String str3) {
        s1.z.d(str);
        k();
        l();
        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 l0(sb.toString(), (String[]) arrayList.toArray(new String[arrayList.size()]));
    }

    /* JADX WARN: Code restructure failed: missing block: B:7:0x0056, code lost:
    
        r3 = r2.p;
        L1.C0146w0.l(r3);
        r3.p.c("Read more than the max allowed conditional properties, ignoring extra", 1000);
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v1, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r0v3, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r0v5, types: [java.util.List] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final java.util.List l0(java.lang.String r29, java.lang.String[] r30) {
        /*
            Method dump skipped, instruction units count: 278
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.l0(java.lang.String, java.lang.String[]):java.util.List");
    }

    /* JADX WARN: Removed duplicated region for block: B:126:0x03ed  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final L1.C0087c0 m0(java.lang.String r53) {
        /*
            Method dump skipped, instruction units count: 1009
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.m0(java.lang.String):L1.c0");
    }

    public final void n0(C0087c0 c0087c0, boolean z5) {
        k();
        l();
        String strD = c0087c0.D();
        s1.z.g(strD);
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", strD);
        K0 k02 = K0.ANALYTICS_STORAGE;
        W1 w12 = this.f1500l;
        if (z5) {
            contentValues.put("app_instance_id", (String) null);
        } else if (w12.c(strD).i(k02)) {
            contentValues.put("app_instance_id", c0087c0.E());
        }
        contentValues.put("gmp_app_id", c0087c0.G());
        boolean zI = w12.c(strD).i(K0.AD_STORAGE);
        C0146w0 c0146w0 = c0087c0.f1702a;
        if (zI) {
            C0137t0 c0137t0 = c0146w0.q;
            C0146w0.l(c0137t0);
            c0137t0.k();
            contentValues.put("resettable_device_id_hash", c0087c0.f1706e);
        }
        C0137t0 c0137t02 = c0146w0.q;
        C0146w0.l(c0137t02);
        c0137t02.k();
        contentValues.put("last_bundle_index", Long.valueOf(c0087c0.f1708g));
        C0137t0 c0137t03 = c0146w0.q;
        C0146w0.l(c0137t03);
        c0137t03.k();
        contentValues.put("last_bundle_start_timestamp", Long.valueOf(c0087c0.f1709h));
        C0137t0 c0137t04 = c0146w0.q;
        C0146w0.l(c0137t04);
        c0137t04.k();
        contentValues.put("last_bundle_end_timestamp", Long.valueOf(c0087c0.i));
        contentValues.put("app_version", c0087c0.N());
        C0137t0 c0137t05 = c0146w0.q;
        C0146w0.l(c0137t05);
        c0137t05.k();
        contentValues.put("app_store", c0087c0.f1712l);
        C0137t0 c0137t06 = c0146w0.q;
        C0146w0.l(c0137t06);
        c0137t06.k();
        contentValues.put("gmp_version", Long.valueOf(c0087c0.f1713m));
        C0137t0 c0137t07 = c0146w0.q;
        C0146w0.l(c0137t07);
        c0137t07.k();
        contentValues.put("dev_cert_hash", Long.valueOf(c0087c0.f1714n));
        C0137t0 c0137t08 = c0146w0.q;
        C0146w0.l(c0137t08);
        c0137t08.k();
        contentValues.put("measurement_enabled", Boolean.valueOf(c0087c0.f1715o));
        C0137t0 c0137t09 = c0146w0.q;
        C0146w0.l(c0137t09);
        c0137t09.k();
        contentValues.put("day", Long.valueOf(c0087c0.J));
        C0137t0 c0137t010 = c0146w0.q;
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("daily_public_events_count", Long.valueOf(c0087c0.K));
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("daily_events_count", Long.valueOf(c0087c0.f1694L));
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("daily_conversions_count", Long.valueOf(c0087c0.f1695M));
        C0137t0 c0137t011 = c0146w0.q;
        C0146w0.l(c0137t011);
        c0137t011.k();
        contentValues.put("config_fetched_time", Long.valueOf(c0087c0.f1700R));
        C0137t0 c0137t012 = c0146w0.q;
        C0146w0.l(c0137t012);
        c0137t012.k();
        contentValues.put("failed_config_fetch_time", Long.valueOf(c0087c0.f1701S));
        contentValues.put("app_version_int", Long.valueOf(c0087c0.P()));
        contentValues.put("firebase_instance_id", c0087c0.J());
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("daily_error_events_count", Long.valueOf(c0087c0.f1696N));
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("daily_realtime_events_count", Long.valueOf(c0087c0.f1697O));
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("health_monitor_sample", c0087c0.f1698P);
        contentValues.put("android_id", (Long) 0L);
        C0137t0 c0137t013 = c0146w0.q;
        C0146w0.l(c0137t013);
        c0137t013.k();
        contentValues.put("adid_reporting_enabled", Boolean.valueOf(c0087c0.p));
        contentValues.put("dynamite_version", Long.valueOf(c0087c0.b()));
        if (w12.c(strD).i(k02)) {
            C0137t0 c0137t014 = c0146w0.q;
            C0146w0.l(c0137t014);
            c0137t014.k();
            contentValues.put("session_stitching_token", c0087c0.f1718t);
        }
        contentValues.put("sgtm_upload_enabled", Boolean.valueOf(c0087c0.y()));
        C0137t0 c0137t015 = c0146w0.q;
        C0146w0.l(c0137t015);
        c0137t015.k();
        contentValues.put("target_os_version", Long.valueOf(c0087c0.f1720v));
        C0137t0 c0137t016 = c0146w0.q;
        C0146w0.l(c0137t016);
        c0137t016.k();
        contentValues.put("session_stitching_token_hash", Long.valueOf(c0087c0.f1721w));
        P3.a();
        C0146w0 c0146w02 = (C0146w0) this.f29k;
        if (c0146w02.f2035n.u(strD, F.f1375P0)) {
            C0137t0 c0137t017 = c0146w0.q;
            C0146w0.l(c0137t017);
            c0137t017.k();
            contentValues.put("ad_services_version", Integer.valueOf(c0087c0.f1722x));
            C0137t0 c0137t018 = c0146w0.q;
            C0146w0.l(c0137t018);
            c0137t018.k();
            contentValues.put("attribution_eligibility_status", Long.valueOf(c0087c0.f1687B));
        }
        C0137t0 c0137t019 = c0146w0.q;
        C0146w0.l(c0137t019);
        c0137t019.k();
        contentValues.put("unmatched_first_open_without_ad_id", Boolean.valueOf(c0087c0.f1723y));
        contentValues.put("npa_metadata_value", c0087c0.w());
        C0137t0 c0137t020 = c0146w0.q;
        C0146w0.l(c0137t020);
        c0137t020.k();
        contentValues.put("bundle_delivery_index", Long.valueOf(c0087c0.f1691F));
        contentValues.put("sgtm_preview_key", c0087c0.C());
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("dma_consent_state", Integer.valueOf(c0087c0.f1689D));
        C0146w0.l(c0137t010);
        c0137t010.k();
        contentValues.put("daily_realtime_dcu_count", Integer.valueOf(c0087c0.f1690E));
        contentValues.put("serialized_npa_metadata", c0087c0.s());
        contentValues.put("client_upload_eligibility", Integer.valueOf(c0087c0.t()));
        C0137t0 c0137t021 = c0146w0.q;
        C0146w0.l(c0137t021);
        c0137t021.k();
        ArrayList arrayList = c0087c0.f1717s;
        X x5 = c0146w02.p;
        if (arrayList != null) {
            if (arrayList.isEmpty()) {
                C0146w0.l(x5);
                x5.f1626s.c("Safelisted events should not be an empty list. appId", strD);
            } else {
                contentValues.put("safelisted_events", TextUtils.join(",", arrayList));
            }
        }
        if (c0146w02.f2035n.u(null, F.f1366K0) && !contentValues.containsKey("safelisted_events")) {
            contentValues.put("safelisted_events", (String) null);
        }
        C0137t0 c0137t022 = c0146w0.q;
        C0146w0.l(c0137t022);
        c0137t022.k();
        contentValues.put("unmatched_pfo", c0087c0.f1724z);
        C0137t0 c0137t023 = c0146w0.q;
        C0146w0.l(c0137t023);
        c0137t023.k();
        contentValues.put("unmatched_uwa", c0087c0.f1686A);
        C0137t0 c0137t024 = c0146w0.q;
        C0146w0.l(c0137t024);
        c0137t024.k();
        contentValues.put("ad_campaign_info", c0087c0.f1693H);
        try {
            SQLiteDatabase sQLiteDatabaseZ = Z();
            if (sQLiteDatabaseZ.update("apps", contentValues, "app_id = ?", new String[]{strD}) == 0 && sQLiteDatabaseZ.insertWithOnConflict("apps", null, contentValues, 5) == -1) {
                C0146w0.l(x5);
                x5.p.c("Failed to insert/update app (got -1). appId", X.s(strD));
            }
        } catch (SQLiteException e2) {
            C0146w0.l(x5);
            x5.p.d(X.s(strD), e2, "Error storing app. appId");
        }
    }

    public final long o(String str, C0385i1 c0385i1, String str2, Map map, EnumC0109j1 enumC0109j1, Long l5) {
        int iDelete;
        k();
        l();
        s1.z.g(c0385i1);
        s1.z.d(str);
        k();
        l();
        boolean zR = R();
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (zR) {
            W1 w12 = this.f1500l;
            long jA = w12.f1614s.p.a();
            c0146w0.f2040u.getClass();
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            if (Math.abs(jElapsedRealtime - jA) > ((Long) F.f1369M.a(null)).longValue()) {
                w12.f1614s.p.b(jElapsedRealtime);
                k();
                l();
                boolean zR2 = R();
                X x5 = c0146w0.p;
                if (zR2 && (iDelete = Z().delete("upload_queue", M(), new String[0])) > 0) {
                    C0146w0.l(x5);
                    x5.f1631x.c("Deleted stale MeasurementBatch rows from upload_queue. rowsDeleted", Integer.valueOf(iDelete));
                }
                s1.z.d(str);
                k();
                l();
                try {
                    int iS = c0146w0.f2035n.s(str, F.f1348A);
                    if (iS > 0) {
                        Z().delete("upload_queue", "rowid in (SELECT rowid FROM upload_queue WHERE app_id=? ORDER BY rowid DESC LIMIT -1 OFFSET ?)", new String[]{str, String.valueOf(iS)});
                    }
                } catch (SQLiteException e2) {
                    C0146w0.l(x5);
                    x5.p.d(X.s(str), e2, "Error deleting over the limit queued batches. appId");
                }
            }
        }
        ArrayList arrayList = new ArrayList();
        for (Map.Entry entry : map.entrySet()) {
            String str3 = (String) entry.getKey();
            String str4 = (String) entry.getValue();
            StringBuilder sb = new StringBuilder(String.valueOf(str3).length() + 1 + String.valueOf(str4).length());
            sb.append(str3);
            sb.append("=");
            sb.append(str4);
            arrayList.add(sb.toString());
        }
        byte[] bArrA = c0385i1.a();
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("measurement_batch", bArrA);
        contentValues.put("upload_uri", str2);
        StringBuilder sb2 = new StringBuilder();
        Iterator it = arrayList.iterator();
        if (it.hasNext()) {
            while (true) {
                sb2.append((CharSequence) it.next());
                if (!it.hasNext()) {
                    break;
                }
                sb2.append((CharSequence) "\r\n");
            }
        }
        contentValues.put("upload_headers", sb2.toString());
        contentValues.put("upload_type", Integer.valueOf(enumC0109j1.f1880k));
        C1091a c1091a = c0146w0.f2040u;
        X x6 = c0146w0.p;
        c1091a.getClass();
        contentValues.put("creation_timestamp", Long.valueOf(System.currentTimeMillis()));
        contentValues.put("retry_count", (Integer) 0);
        if (l5 != null) {
            contentValues.put("associated_row_id", l5);
        }
        try {
            long jInsert = Z().insert("upload_queue", null, contentValues);
            if (jInsert != -1) {
                return jInsert;
            }
            C0146w0.l(x6);
            x6.p.c("Failed to insert MeasurementBatch (got -1) to upload_queue. appId", str);
            return -1L;
        } catch (SQLiteException e6) {
            C0146w0.l(x6);
            x6.p.d(str, e6, "Error storing MeasurementBatch to upload_queue. appId");
            return -1L;
        }
    }

    public final C0107j o0(long j5, String str, boolean z5, boolean z6, boolean z7, boolean z8) {
        return p0(j5, str, 1L, false, false, z5, false, z6, z7, z8);
    }

    /* JADX WARN: Removed duplicated region for block: B:27:0x00de  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final java.util.List p(java.lang.String r19, L1.O1 r20, int r21) {
        /*
            Method dump skipped, instruction units count: 226
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.p(java.lang.String, L1.O1, int):java.util.List");
    }

    public final C0107j p0(long j5, String str, long j6, boolean z5, boolean z6, boolean z7, boolean z8, boolean z9, boolean z10, boolean z11) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        s1.z.d(str);
        k();
        l();
        String[] strArr = {str};
        C0107j c0107j = new C0107j();
        Cursor cursorQuery = null;
        try {
            try {
                SQLiteDatabase sQLiteDatabaseZ = Z();
                cursorQuery = sQLiteDatabaseZ.query("apps", new String[]{"day", "daily_events_count", "daily_public_events_count", "daily_conversions_count", "daily_error_events_count", "daily_realtime_events_count", "daily_realtime_dcu_count", "daily_registered_triggers_count"}, "app_id=?", new String[]{str}, null, null, null);
                if (cursorQuery.moveToFirst()) {
                    if (cursorQuery.getLong(0) == j5) {
                        c0107j.f1849b = cursorQuery.getLong(1);
                        c0107j.f1848a = cursorQuery.getLong(2);
                        c0107j.f1850c = cursorQuery.getLong(3);
                        c0107j.f1851d = cursorQuery.getLong(4);
                        c0107j.f1852e = cursorQuery.getLong(5);
                        c0107j.f1853f = cursorQuery.getLong(6);
                        c0107j.f1854g = cursorQuery.getLong(7);
                    }
                    if (z5) {
                        c0107j.f1849b += j6;
                    }
                    if (z6) {
                        c0107j.f1848a += j6;
                    }
                    if (z7) {
                        c0107j.f1850c += j6;
                    }
                    if (z8) {
                        c0107j.f1851d += j6;
                    }
                    if (z9) {
                        c0107j.f1852e += j6;
                    }
                    if (z10) {
                        c0107j.f1853f += j6;
                    }
                    if (z11) {
                        c0107j.f1854g += j6;
                    }
                    ContentValues contentValues = new ContentValues();
                    contentValues.put("day", Long.valueOf(j5));
                    contentValues.put("daily_public_events_count", Long.valueOf(c0107j.f1848a));
                    contentValues.put("daily_events_count", Long.valueOf(c0107j.f1849b));
                    contentValues.put("daily_conversions_count", Long.valueOf(c0107j.f1850c));
                    contentValues.put("daily_error_events_count", Long.valueOf(c0107j.f1851d));
                    contentValues.put("daily_realtime_events_count", Long.valueOf(c0107j.f1852e));
                    contentValues.put("daily_realtime_dcu_count", Long.valueOf(c0107j.f1853f));
                    contentValues.put("daily_registered_triggers_count", Long.valueOf(c0107j.f1854g));
                    sQLiteDatabaseZ.update("apps", contentValues, "app_id=?", strArr);
                } else {
                    X x5 = c0146w0.p;
                    C0146w0.l(x5);
                    x5.f1626s.c("Not updating daily counts, app is not known. appId", X.s(str));
                }
            } catch (SQLiteException e2) {
                X x6 = c0146w0.p;
                C0146w0.l(x6);
                x6.p.d(X.s(str), e2, "Error updating daily counts. appId");
            }
            if (cursorQuery != null) {
                cursorQuery.close();
            }
            return c0107j;
        } catch (Throwable th) {
            if (0 != 0) {
                cursorQuery.close();
            }
            throw th;
        }
    }

    public final boolean q(String str) {
        EnumC0109j1[] enumC0109j1Arr = {EnumC0109j1.GOOGLE_SIGNAL};
        ArrayList arrayList = new ArrayList(1);
        arrayList.add(Integer.valueOf(enumC0109j1Arr[0].f1880k));
        String strN = N(arrayList);
        String strM = M();
        StringBuilder sb = new StringBuilder(strN.length() + 61 + strM.length());
        sb.append("SELECT COUNT(1) > 0 FROM upload_queue WHERE app_id=?");
        sb.append(strN);
        sb.append(" AND NOT ");
        sb.append(strM);
        return U(sb.toString(), new String[]{str}) != 0;
    }

    /* JADX WARN: Not initialized variable reg: 3, insn: 0x006b: MOVE (r2 I:??[OBJECT, ARRAY]) = (r3 I:??[OBJECT, ARRAY]) (LINE:108), block:B:19:0x006b */
    /* JADX WARN: Removed duplicated region for block: B:29:0x008a  */
    /* JADX WARN: Removed duplicated region for block: B:35:? A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final B2.a q0(java.lang.String r12) throws java.lang.Throwable {
        /*
            r11 = this;
            java.lang.Object r0 = r11.f29k
            r1 = r0
            L1.w0 r1 = (L1.C0146w0) r1
            s1.z.d(r12)
            r11.k()
            r11.l()
            r2 = 0
            android.database.sqlite.SQLiteDatabase r3 = r11.Z()     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L70
            java.lang.String r4 = "apps"
            java.lang.String r0 = "remote_config"
            java.lang.String r5 = "config_last_modified_time"
            java.lang.String r6 = "e_tag"
            java.lang.String[] r5 = new java.lang.String[]{r0, r5, r6}     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L70
            java.lang.String r6 = "app_id=?"
            java.lang.String[] r7 = new java.lang.String[]{r12}     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L70
            r10 = 0
            r8 = 0
            r9 = 0
            android.database.Cursor r3 = r3.query(r4, r5, r6, r7, r8, r9, r10)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L70
            boolean r0 = r3.moveToFirst()     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            if (r0 != 0) goto L33
            goto L82
        L33:
            r0 = 0
            byte[] r0 = r3.getBlob(r0)     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            r4 = 1
            java.lang.String r4 = r3.getString(r4)     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            r5 = 2
            java.lang.String r5 = r3.getString(r5)     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            boolean r6 = r3.moveToNext()     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            if (r6 == 0) goto L5e
            L1.X r6 = r1.p     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            L1.C0146w0.l(r6)     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            L1.V r6 = r6.p     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            java.lang.String r7 = "Got multiple records for app config, expected one. appId"
            L1.W r8 = L1.X.s(r12)     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            r6.c(r7, r8)     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            goto L5e
        L59:
            r0 = move-exception
            r12 = r0
            goto L6b
        L5c:
            r0 = move-exception
            goto L72
        L5e:
            if (r0 != 0) goto L61
            goto L82
        L61:
            B2.a r6 = new B2.a     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            r7 = 5
            r6.<init>(r0, r4, r5, r7)     // Catch: java.lang.Throwable -> L59 android.database.sqlite.SQLiteException -> L5c
            r3.close()
            return r6
        L6b:
            r2 = r3
            goto L88
        L6d:
            r0 = move-exception
            r12 = r0
            goto L88
        L70:
            r0 = move-exception
            r3 = r2
        L72:
            L1.X r1 = r1.p     // Catch: java.lang.Throwable -> L59
            L1.C0146w0.l(r1)     // Catch: java.lang.Throwable -> L59
            L1.V r1 = r1.p     // Catch: java.lang.Throwable -> L59
            java.lang.String r4 = "Error querying remote config. appId"
            L1.W r12 = L1.X.s(r12)     // Catch: java.lang.Throwable -> L59
            r1.d(r12, r0, r4)     // Catch: java.lang.Throwable -> L59
        L82:
            if (r3 == 0) goto L87
            r3.close()
        L87:
            return r2
        L88:
            if (r2 == 0) goto L8d
            r2.close()
        L8d:
            throw r12
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.q0(java.lang.String):B2.a");
    }

    public final void r(Long l5) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        k();
        l();
        try {
            if (Z().delete("upload_queue", "rowid=?", new String[]{l5.toString()}) != 1) {
                X x5 = c0146w0.p;
                C0146w0.l(x5);
                x5.f1626s.b("Deleted fewer rows from upload_queue than expected");
            }
        } catch (SQLiteException e2) {
            X x6 = c0146w0.p;
            C0146w0.l(x6);
            x6.p.c("Failed to delete a MeasurementBatch in a upload_queue table", e2);
            throw e2;
        }
    }

    public final void r0(C0395k1 c0395k1, boolean z5) {
        k();
        l();
        s1.z.d(c0395k1.p());
        if (!c0395k1.b2()) {
            throw new IllegalStateException();
        }
        u();
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        c0146w0.f2040u.getClass();
        long jCurrentTimeMillis = System.currentTimeMillis();
        long jC2 = c0395k1.c2();
        E e2 = F.f1377R;
        long jLongValue = jCurrentTimeMillis - ((Long) e2.a(null)).longValue();
        X x5 = c0146w0.p;
        if (jC2 < jLongValue || c0395k1.c2() > ((Long) e2.a(null)).longValue() + jCurrentTimeMillis) {
            C0146w0.l(x5);
            x5.f1626s.e("Storing bundle outside of the max uploading time span. appId, now, timestamp", X.s(c0395k1.p()), Long.valueOf(jCurrentTimeMillis), Long.valueOf(c0395k1.c2()));
        }
        byte[] bArrA = c0395k1.a();
        try {
            C0084b0 c0084b0 = this.f1500l.q;
            W1.T(c0084b0);
            byte[] bArrW = c0084b0.W(bArrA);
            C0146w0.l(x5);
            x5.f1631x.c("Saving bundle, size", Integer.valueOf(bArrW.length));
            ContentValues contentValues = new ContentValues();
            contentValues.put("app_id", c0395k1.p());
            contentValues.put("bundle_end_timestamp", Long.valueOf(c0395k1.c2()));
            contentValues.put("data", bArrW);
            contentValues.put("has_realtime", Integer.valueOf(z5 ? 1 : 0));
            if (c0395k1.p0()) {
                contentValues.put("retry_count", Integer.valueOf(c0395k1.q0()));
            }
            try {
                if (Z().insert("queue", null, contentValues) == -1) {
                    C0146w0.l(x5);
                    x5.p.c("Failed to insert bundle (got -1). appId", X.s(c0395k1.p()));
                }
            } catch (SQLiteException e6) {
                C0146w0.l(x5);
                x5.p.d(X.s(c0395k1.p()), e6, "Error storing bundle. appId");
            }
        } catch (IOException e7) {
            C0146w0.l(x5);
            x5.p.d(X.s(c0395k1.p()), e7, "Data loss. Failed to serialize bundle. appId");
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:23:0x003f  */
    /* JADX WARN: Type inference failed for: r1v0 */
    /* JADX WARN: Type inference failed for: r1v1, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r1v3 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final java.lang.String s() throws java.lang.Throwable {
        /*
            r6 = this;
            android.database.sqlite.SQLiteDatabase r0 = r6.Z()
            r1 = 0
            java.lang.String r2 = "select app_id from queue order by has_realtime desc, rowid asc limit 1;"
            android.database.Cursor r0 = r0.rawQuery(r2, r1)     // Catch: java.lang.Throwable -> L22 android.database.sqlite.SQLiteException -> L24
            boolean r2 = r0.moveToFirst()     // Catch: java.lang.Throwable -> L1a android.database.sqlite.SQLiteException -> L1c
            if (r2 == 0) goto L37
            r2 = 0
            java.lang.String r1 = r0.getString(r2)     // Catch: java.lang.Throwable -> L1a android.database.sqlite.SQLiteException -> L1c
            r0.close()
            return r1
        L1a:
            r1 = move-exception
            goto L1e
        L1c:
            r2 = move-exception
            goto L27
        L1e:
            r5 = r1
            r1 = r0
            r0 = r5
            goto L3d
        L22:
            r0 = move-exception
            goto L3d
        L24:
            r0 = move-exception
            r2 = r0
            r0 = r1
        L27:
            java.lang.Object r3 = r6.f29k     // Catch: java.lang.Throwable -> L1a
            L1.w0 r3 = (L1.C0146w0) r3     // Catch: java.lang.Throwable -> L1a
            L1.X r3 = r3.p     // Catch: java.lang.Throwable -> L1a
            L1.C0146w0.l(r3)     // Catch: java.lang.Throwable -> L1a
            L1.V r3 = r3.p     // Catch: java.lang.Throwable -> L1a
            java.lang.String r4 = "Database error getting next bundle app id"
            r3.c(r4, r2)     // Catch: java.lang.Throwable -> L1a
        L37:
            if (r0 == 0) goto L3c
            r0.close()
        L3c:
            return r1
        L3d:
            if (r1 == 0) goto L42
            r1.close()
        L42:
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.s():java.lang.String");
    }

    public final void t(long j5) {
        k();
        l();
        try {
            if (Z().delete("queue", "rowid=?", new String[]{String.valueOf(j5)}) == 1) {
            } else {
                throw new SQLiteException("Deleted fewer rows from queue than expected");
            }
        } catch (SQLiteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.p.c("Failed to delete a bundle in a queue table", e2);
            throw e2;
        }
    }

    public final void u() {
        k();
        l();
        if (R()) {
            W1 w12 = this.f1500l;
            long jA = w12.f1614s.f1295o.a();
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            c0146w0.f2040u.getClass();
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            if (Math.abs(jElapsedRealtime - jA) > ((Long) F.f1369M.a(null)).longValue()) {
                w12.f1614s.f1295o.b(jElapsedRealtime);
                k();
                l();
                if (R()) {
                    SQLiteDatabase sQLiteDatabaseZ = Z();
                    c0146w0.f2040u.getClass();
                    int iDelete = sQLiteDatabaseZ.delete("queue", "abs(bundle_end_timestamp - ?) > cast(? as integer)", new String[]{String.valueOf(System.currentTimeMillis()), String.valueOf(((Long) F.f1377R.a(null)).longValue())});
                    if (iDelete > 0) {
                        X x5 = c0146w0.p;
                        C0146w0.l(x5);
                        x5.f1631x.c("Deleted stale rows. rowsDeleted", Integer.valueOf(iDelete));
                    }
                }
            }
        }
    }

    public final void v(ArrayList arrayList) {
        k();
        l();
        s1.z.g(arrayList);
        if (arrayList.size() == 0) {
            throw new IllegalArgumentException("Given Integer is zero");
        }
        if (R()) {
            String strJoin = TextUtils.join(",", arrayList);
            StringBuilder sb = new StringBuilder(String.valueOf(strJoin).length() + 2);
            sb.append("(");
            sb.append(strJoin);
            sb.append(")");
            String string = sb.toString();
            StringBuilder sb2 = new StringBuilder(string.length() + 80);
            sb2.append("SELECT COUNT(1) FROM queue WHERE rowid IN ");
            sb2.append(string);
            sb2.append(" AND retry_count =  2147483647 LIMIT 1");
            long jU = U(sb2.toString(), null);
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            if (jU > 0) {
                X x5 = c0146w0.p;
                C0146w0.l(x5);
                x5.f1626s.b("The number of upload retries exceeds the limit. Will remain unchanged.");
            }
            try {
                SQLiteDatabase sQLiteDatabaseZ = Z();
                StringBuilder sb3 = new StringBuilder(string.length() + 127);
                sb3.append("UPDATE queue SET retry_count = IFNULL(retry_count, 0) + 1 WHERE rowid IN ");
                sb3.append(string);
                sb3.append(" AND (retry_count IS NULL OR retry_count < 2147483647)");
                sQLiteDatabaseZ.execSQL(sb3.toString());
            } catch (SQLiteException e2) {
                X x6 = c0146w0.p;
                C0146w0.l(x6);
                x6.p.c("Error incrementing retry count. error", e2);
            }
        }
    }

    public final void w(Long l5) {
        k();
        l();
        if (R()) {
            StringBuilder sb = new StringBuilder(l5.toString().length() + 86);
            sb.append("SELECT COUNT(1) FROM upload_queue WHERE rowid = ");
            sb.append(l5);
            sb.append(" AND retry_count =  2147483647 LIMIT 1");
            long jU = U(sb.toString(), null);
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            if (jU > 0) {
                X x5 = c0146w0.p;
                C0146w0.l(x5);
                x5.f1626s.b("The number of upload retries exceeds the limit. Will remain unchanged.");
            }
            try {
                SQLiteDatabase sQLiteDatabaseZ = Z();
                c0146w0.f2040u.getClass();
                long jCurrentTimeMillis = System.currentTimeMillis();
                StringBuilder sb2 = new StringBuilder(String.valueOf(jCurrentTimeMillis).length() + 60);
                sb2.append(" SET retry_count = retry_count + 1, last_upload_timestamp = ");
                sb2.append(jCurrentTimeMillis);
                String string = sb2.toString();
                StringBuilder sb3 = new StringBuilder(string.length() + 34 + l5.toString().length() + 29);
                sb3.append("UPDATE upload_queue");
                sb3.append(string);
                sb3.append(" WHERE rowid = ");
                sb3.append(l5);
                sb3.append(" AND retry_count < 2147483647");
                sQLiteDatabaseZ.execSQL(sb3.toString());
            } catch (SQLiteException e2) {
                X x6 = c0146w0.p;
                C0146w0.l(x6);
                x6.p.c("Error incrementing retry count. error", e2);
            }
        }
    }

    public final Object x(Cursor cursor, int i) {
        int type = cursor.getType(i);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (type == 0) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.p.b("Loaded invalid null value from database");
            return null;
        }
        if (type == 1) {
            return Long.valueOf(cursor.getLong(i));
        }
        if (type == 2) {
            return Double.valueOf(cursor.getDouble(i));
        }
        if (type == 3) {
            return cursor.getString(i);
        }
        if (type == 4) {
            X x6 = c0146w0.p;
            C0146w0.l(x6);
            x6.p.b("Loaded invalid blob type value, ignoring it");
            return null;
        }
        X x7 = c0146w0.p;
        C0146w0.l(x7);
        x7.p.c("Loaded invalid unknown value type, ignoring it", Integer.valueOf(type));
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0093 A[Catch: all -> 0x006d, SQLiteException -> 0x00a4, TryCatch #0 {SQLiteException -> 0x00a4, blocks: (B:15:0x0072, B:17:0x0093, B:20:0x00a6), top: B:30:0x0072 }] */
    /* JADX WARN: Removed duplicated region for block: B:20:0x00a6 A[Catch: all -> 0x006d, SQLiteException -> 0x00a4, TRY_LEAVE, TryCatch #0 {SQLiteException -> 0x00a4, blocks: (B:15:0x0072, B:17:0x0093, B:20:0x00a6), top: B:30:0x0072 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final long y(java.lang.String r14) {
        /*
            r13 = this;
            java.lang.Object r0 = r13.f29k
            L1.w0 r0 = (L1.C0146w0) r0
            java.lang.String r1 = "select first_open_count from app2 where app_id=?"
            s1.z.d(r14)
            java.lang.String r2 = "first_open_count"
            s1.z.d(r2)
            r13.k()
            r13.l()
            android.database.sqlite.SQLiteDatabase r3 = r13.Z()
            r3.beginTransaction()
            r4 = 0
            java.lang.StringBuilder r6 = new java.lang.StringBuilder     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r7 = 48
            r6.<init>(r7)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r6.append(r1)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            java.lang.String r1 = r6.toString()     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            java.lang.String[] r6 = new java.lang.String[]{r14}     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r7 = -1
            long r9 = r13.V(r1, r6, r7)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            int r1 = (r9 > r7 ? 1 : (r9 == r7 ? 0 : -1))
            java.lang.String r6 = "app2"
            java.lang.String r11 = "app_id"
            if (r1 != 0) goto L72
            android.content.ContentValues r1 = new android.content.ContentValues     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r1.<init>()     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r1.put(r11, r14)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r9 = 0
            java.lang.Integer r9 = java.lang.Integer.valueOf(r9)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r1.put(r2, r9)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            java.lang.String r10 = "previous_install_count"
            r1.put(r10, r9)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r9 = 0
            r10 = 5
            long r9 = r3.insertWithOnConflict(r6, r9, r1, r10)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            int r1 = (r9 > r7 ? 1 : (r9 == r7 ? 0 : -1))
            if (r1 != 0) goto L71
            L1.X r1 = r0.p     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            L1.C0146w0.l(r1)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            L1.V r1 = r1.p     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            java.lang.String r6 = "Failed to insert column (got -1). appId"
            L1.W r9 = L1.X.s(r14)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            r1.d(r9, r2, r6)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> L6f
            goto Lbd
        L6d:
            r14 = move-exception
            goto Lc1
        L6f:
            r1 = move-exception
            goto Lac
        L71:
            r9 = r4
        L72:
            android.content.ContentValues r1 = new android.content.ContentValues     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            r1.<init>()     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            r1.put(r11, r14)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            r11 = 1
            long r11 = r11 + r9
            java.lang.Long r11 = java.lang.Long.valueOf(r11)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            r1.put(r2, r11)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            java.lang.String r11 = "app_id = ?"
            java.lang.String[] r12 = new java.lang.String[]{r14}     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            int r1 = r3.update(r6, r1, r11, r12)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            long r11 = (long) r1     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            int r1 = (r11 > r4 ? 1 : (r11 == r4 ? 0 : -1))
            if (r1 != 0) goto La6
            L1.X r1 = r0.p     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            L1.C0146w0.l(r1)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            L1.V r1 = r1.p     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            java.lang.String r4 = "Failed to update column (got 0). appId"
            L1.W r5 = L1.X.s(r14)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            r1.d(r5, r2, r4)     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            goto Lbd
        La4:
            r1 = move-exception
            goto Lab
        La6:
            r3.setTransactionSuccessful()     // Catch: java.lang.Throwable -> L6d android.database.sqlite.SQLiteException -> La4
            r7 = r9
            goto Lbd
        Lab:
            r4 = r9
        Lac:
            L1.X r0 = r0.p     // Catch: java.lang.Throwable -> L6d
            L1.C0146w0.l(r0)     // Catch: java.lang.Throwable -> L6d
            L1.V r0 = r0.p     // Catch: java.lang.Throwable -> L6d
            java.lang.String r6 = "Error inserting column. appId"
            L1.W r14 = L1.X.s(r14)     // Catch: java.lang.Throwable -> L6d
            r0.e(r6, r14, r2, r1)     // Catch: java.lang.Throwable -> L6d
            r7 = r4
        Lbd:
            r3.endTransaction()
            return r7
        Lc1:
            r3.endTransaction()
            throw r14
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.C0119n.y(java.lang.String):long");
    }

    public final boolean z(String str, String str2) {
        return U("select count(1) from raw_events where app_id = ? and name = ?", new String[]{str, str2}) > 0;
    }

    @Override // L1.Q1
    public final void n() {
    }
}
