package d3;

import N1.C0207h;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteFullException;
import android.os.Bundle;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: renamed from: d3.t1, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0824t1 extends F {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final ServiceConnectionC0821s1 f12178s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public K f12179t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public volatile Boolean f12180u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final C0816q1 f12181v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public ScheduledExecutorService f12182w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final C0207h f12183x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final ArrayList f12184y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final C0816q1 f12185z;

    public C0824t1(C0817r0 c0817r0) {
        super(c0817r0);
        this.f12184y = new ArrayList();
        this.f12183x = new C0207h(c0817r0.D);
        this.f12178s = new ServiceConnectionC0821s1(this);
        this.f12181v = new C0816q1(this, c0817r0, 0);
        this.f12185z = new C0816q1(this, c0817r0, 1);
    }

    public static void X(C0824t1 c0824t1, ComponentName componentName) {
        c0824t1.E();
        if (c0824t1.f12179t != null) {
            c0824t1.f12179t = null;
            Z z8 = ((C0817r0) c0824t1.f5146q).f12150y;
            C0817r0.k(z8);
            z8.D.c(componentName, "Disconnected from device MeasurementService");
            c0824t1.E();
            c0824t1.I();
        }
    }

    @Override // d3.F
    public final boolean H() {
        return false;
    }

    public final void I() {
        E();
        F();
        if (O()) {
            return;
        }
        if (R()) {
            this.f12178s.a();
            return;
        }
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (c0817r0.f12148w.H()) {
            return;
        }
        List<ResolveInfo> listQueryIntentServices = c0817r0.f12142q.getPackageManager().queryIntentServices(new Intent().setClassName(c0817r0.f12142q, "com.google.android.gms.measurement.AppMeasurementService"), 65536);
        if (listQueryIntentServices == null || listQueryIntentServices.isEmpty()) {
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11875v.b("Unable to use remote or local measurement implementation. Please register the AppMeasurementService service in the app manifest");
            return;
        }
        Intent intent = new Intent("com.google.android.gms.measurement.START");
        intent.setComponent(new ComponentName(c0817r0.f12142q, "com.google.android.gms.measurement.AppMeasurementService"));
        ServiceConnectionC0821s1 serviceConnectionC0821s1 = this.f12178s;
        C0824t1 c0824t1 = serviceConnectionC0821s1.f12173s;
        c0824t1.E();
        Context context = ((C0817r0) c0824t1.f5146q).f12142q;
        S2.a aVarA = S2.a.a();
        synchronized (serviceConnectionC0821s1) {
            try {
                if (serviceConnectionC0821s1.f12171q) {
                    Z z9 = ((C0817r0) serviceConnectionC0821s1.f12173s.f5146q).f12150y;
                    C0817r0.k(z9);
                    z9.D.b("Connection attempt already in progress");
                    return;
                }
                C0824t1 c0824t12 = serviceConnectionC0821s1.f12173s;
                Z z10 = ((C0817r0) c0824t12.f5146q).f12150y;
                C0817r0.k(z10);
                z10.D.b("Using local app measurement service");
                serviceConnectionC0821s1.f12171q = true;
                aVarA.c(context, context.getClass().getName(), intent, c0824t12.f12178s, 129, null);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void J() {
        E();
        F();
        ServiceConnectionC0821s1 serviceConnectionC0821s1 = this.f12178s;
        if (serviceConnectionC0821s1.f12172r != null && (serviceConnectionC0821s1.f12172r.d() || serviceConnectionC0821s1.f12172r.b())) {
            serviceConnectionC0821s1.f12172r.j();
        }
        serviceConnectionC0821s1.f12172r = null;
        try {
            S2.a.a().b(((C0817r0) this.f5146q).f12142q, serviceConnectionC0821s1);
        } catch (IllegalArgumentException | IllegalStateException unused) {
        }
        this.f12179t = null;
    }

    public final void K(AtomicReference atomicReference) {
        E();
        F();
        V(new J.m((Object) this, (Object) atomicReference, (Object) S(false), 7));
    }

    /* JADX WARN: Removed duplicated region for block: B:254:0x041b A[Catch: all -> 0x03a0, TRY_ENTER, TryCatch #0 {all -> 0x03a0, blocks: (B:264:0x0447, B:254:0x041b, B:256:0x0421, B:257:0x0424, B:272:0x0465, B:215:0x038b, B:217:0x0395, B:224:0x03a8), top: B:370:0x0447 }] */
    /* JADX WARN: Removed duplicated region for block: B:259:0x0433  */
    /* JADX WARN: Removed duplicated region for block: B:267:0x044e  */
    /* JADX WARN: Removed duplicated region for block: B:269:0x0453 A[PHI: r8 r13 r23 r25 r27 r34 r35
      0x0453: PHI (r8v5 int) = (r8v3 int), (r8v3 int), (r8v6 int) binds: [B:260:0x0436, B:275:0x0477, B:268:0x0451] A[DONT_GENERATE, DONT_INLINE]
      0x0453: PHI (r13v15 android.database.sqlite.SQLiteDatabase) = 
      (r13v10 android.database.sqlite.SQLiteDatabase)
      (r13v11 android.database.sqlite.SQLiteDatabase)
      (r13v16 android.database.sqlite.SQLiteDatabase)
     binds: [B:260:0x0436, B:275:0x0477, B:268:0x0451] A[DONT_GENERATE, DONT_INLINE]
      0x0453: PHI (r23v9 java.lang.String) = (r23v6 java.lang.String), (r23v7 java.lang.String), (r23v10 java.lang.String) binds: [B:260:0x0436, B:275:0x0477, B:268:0x0451] A[DONT_GENERATE, DONT_INLINE]
      0x0453: PHI (r25v9 java.lang.String) = (r25v6 java.lang.String), (r25v7 java.lang.String), (r25v10 java.lang.String) binds: [B:260:0x0436, B:275:0x0477, B:268:0x0451] A[DONT_GENERATE, DONT_INLINE]
      0x0453: PHI (r27v11 d3.r0) = (r27v8 d3.r0), (r27v9 d3.r0), (r27v12 d3.r0) binds: [B:260:0x0436, B:275:0x0477, B:268:0x0451] A[DONT_GENERATE, DONT_INLINE]
      0x0453: PHI (r34v9 int) = (r34v6 int), (r34v7 int), (r34v10 int) binds: [B:260:0x0436, B:275:0x0477, B:268:0x0451] A[DONT_GENERATE, DONT_INLINE]
      0x0453: PHI (r35v9 java.lang.String) = (r35v6 java.lang.String), (r35v7 java.lang.String), (r35v10 java.lang.String) binds: [B:260:0x0436, B:275:0x0477, B:268:0x0451] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:274:0x0474  */
    /* JADX WARN: Removed duplicated region for block: B:279:0x0489  */
    /* JADX WARN: Removed duplicated region for block: B:281:0x048e  */
    /* JADX WARN: Removed duplicated region for block: B:286:0x04aa  */
    /* JADX WARN: Removed duplicated region for block: B:287:0x04b3  */
    /* JADX WARN: Removed duplicated region for block: B:294:0x04d9  */
    /* JADX WARN: Removed duplicated region for block: B:299:0x057b  */
    /* JADX WARN: Removed duplicated region for block: B:332:0x0614  */
    /* JADX WARN: Removed duplicated region for block: B:336:0x061c  */
    /* JADX WARN: Removed duplicated region for block: B:451:0x047a A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:452:0x047a A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:454:0x047a A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void L(K k8, Q2.a aVar, X1 x12) throws Throwable {
        int i;
        ArrayList arrayList;
        C0817r0 c0817r0;
        int i5;
        int i8;
        SQLiteDatabase sQLiteDatabase;
        int i9;
        String str;
        String str2;
        String str3;
        Cursor cursor;
        Cursor cursor2;
        Cursor cursorQuery;
        long j8;
        String str4;
        String[] strArr;
        Z z8;
        Cursor cursor3;
        C0817r0 c0817r02;
        long j9;
        String string;
        Parcel parcelObtain;
        C0825u c0825uCreateFromParcel;
        char c3;
        C0778e c0778eCreateFromParcel;
        T1 t1CreateFromParcel;
        int size;
        int size2;
        int i10;
        X1 x13;
        boolean z9;
        int i11;
        long jElapsedRealtime;
        long j10;
        long jCurrentTimeMillis;
        Q2.a aVar2 = aVar;
        E();
        F();
        W();
        C0817r0 c0817r03 = (C0817r0) this.f5146q;
        c0817r03.getClass();
        X1 x14 = x12;
        int i12 = 100;
        int i13 = 0;
        for (int i14 = 100; i13 < 1001 && i12 == i14; i14 = 100) {
            ArrayList arrayList2 = new ArrayList();
            S sO = c0817r03.o();
            String str5 = "entry";
            String str6 = "type";
            String str7 = "rowid";
            sO.E();
            if (sO.f11704t) {
                c0817r0 = c0817r03;
                i = i14;
                i5 = i13;
            } else {
                i = i14;
                arrayList = new ArrayList();
                C0817r0 c0817r04 = (C0817r0) sO.f5146q;
                if (c0817r04.f12142q.getDatabasePath("google_app_measurement_local.db").exists()) {
                    i5 = i13;
                    int i15 = 0;
                    int i16 = 5;
                    for (int i17 = 5; i15 < i17; i17 = 5) {
                        try {
                            SQLiteDatabase sQLiteDatabaseI = sO.I();
                            if (sQLiteDatabaseI == null) {
                                try {
                                    try {
                                        sO.f11704t = true;
                                        c0817r0 = c0817r03;
                                    } catch (Throwable th) {
                                        th = th;
                                        sQLiteDatabase = sQLiteDatabaseI;
                                        cursor = null;
                                        if (cursor != null) {
                                        }
                                        if (sQLiteDatabase != null) {
                                        }
                                        throw th;
                                    }
                                } catch (SQLiteDatabaseLockedException unused) {
                                    i9 = i15;
                                    c0817r0 = c0817r03;
                                    str = str5;
                                    str2 = str6;
                                    str3 = str7;
                                    sQLiteDatabase = sQLiteDatabaseI;
                                    cursor2 = null;
                                    try {
                                        SystemClock.sleep(i16);
                                        i16 += 20;
                                        if (cursor2 != null) {
                                        }
                                        if (sQLiteDatabase == null) {
                                        }
                                        i15 = i9 + 1;
                                        str6 = str2;
                                        str7 = str3;
                                        c0817r03 = c0817r0;
                                        str5 = str;
                                    } catch (Throwable th2) {
                                        th = th2;
                                        cursor = cursor2;
                                        if (cursor != null) {
                                            cursor.close();
                                        }
                                        if (sQLiteDatabase != null) {
                                            sQLiteDatabase.close();
                                        }
                                        throw th;
                                    }
                                } catch (SQLiteFullException e8) {
                                    e = e8;
                                    i9 = i15;
                                    c0817r0 = c0817r03;
                                    str = str5;
                                    str2 = str6;
                                    str3 = str7;
                                    sQLiteDatabase = sQLiteDatabaseI;
                                    cursor2 = null;
                                    Z z10 = c0817r04.f12150y;
                                    C0817r0.k(z10);
                                    z10.f11875v.c(e, "Error reading entries from local database");
                                    sO.f11704t = true;
                                    if (cursor2 != null) {
                                    }
                                    if (sQLiteDatabase == null) {
                                    }
                                    i15 = i9 + 1;
                                    str6 = str2;
                                    str7 = str3;
                                    c0817r03 = c0817r0;
                                    str5 = str;
                                } catch (SQLiteException e9) {
                                    e = e9;
                                    i9 = i15;
                                    c0817r0 = c0817r03;
                                    str = str5;
                                    str2 = str6;
                                    str3 = str7;
                                    sQLiteDatabase = sQLiteDatabaseI;
                                    cursor2 = null;
                                    if (sQLiteDatabase != null) {
                                    }
                                    Z z11 = c0817r04.f12150y;
                                    C0817r0.k(z11);
                                    z11.f11875v.c(e, "Error reading entries from local database");
                                    sO.f11704t = true;
                                    if (cursor2 != null) {
                                    }
                                    if (sQLiteDatabase == null) {
                                    }
                                    i15 = i9 + 1;
                                    str6 = str2;
                                    str7 = str3;
                                    c0817r03 = c0817r0;
                                    str5 = str;
                                }
                            } else {
                                sQLiteDatabaseI.beginTransaction();
                                try {
                                    cursorQuery = sQLiteDatabaseI.query("messages", new String[]{str7}, "type=?", new String[]{"3"}, null, null, "rowid desc", "1");
                                    try {
                                        long j11 = -1;
                                        if (cursorQuery.moveToFirst()) {
                                            i9 = i15;
                                            try {
                                                j8 = cursorQuery.getLong(0);
                                                try {
                                                    cursorQuery.close();
                                                } catch (SQLiteDatabaseLockedException unused2) {
                                                    c0817r0 = c0817r03;
                                                    str = str5;
                                                    str2 = str6;
                                                    str3 = str7;
                                                    sQLiteDatabase = sQLiteDatabaseI;
                                                    cursor2 = null;
                                                    SystemClock.sleep(i16);
                                                    i16 += 20;
                                                    if (cursor2 != null) {
                                                    }
                                                    if (sQLiteDatabase == null) {
                                                    }
                                                    i15 = i9 + 1;
                                                    str6 = str2;
                                                    str7 = str3;
                                                    c0817r03 = c0817r0;
                                                    str5 = str;
                                                } catch (SQLiteFullException e10) {
                                                    e = e10;
                                                    c0817r0 = c0817r03;
                                                    str = str5;
                                                    str2 = str6;
                                                    str3 = str7;
                                                    sQLiteDatabase = sQLiteDatabaseI;
                                                    cursor2 = null;
                                                    Z z102 = c0817r04.f12150y;
                                                    C0817r0.k(z102);
                                                    z102.f11875v.c(e, "Error reading entries from local database");
                                                    sO.f11704t = true;
                                                    if (cursor2 != null) {
                                                    }
                                                    if (sQLiteDatabase == null) {
                                                    }
                                                    i15 = i9 + 1;
                                                    str6 = str2;
                                                    str7 = str3;
                                                    c0817r03 = c0817r0;
                                                    str5 = str;
                                                } catch (SQLiteException e11) {
                                                    e = e11;
                                                    c0817r0 = c0817r03;
                                                    str = str5;
                                                    str2 = str6;
                                                    str3 = str7;
                                                    sQLiteDatabase = sQLiteDatabaseI;
                                                    cursor2 = null;
                                                    if (sQLiteDatabase != null) {
                                                    }
                                                    Z z112 = c0817r04.f12150y;
                                                    C0817r0.k(z112);
                                                    z112.f11875v.c(e, "Error reading entries from local database");
                                                    sO.f11704t = true;
                                                    if (cursor2 != null) {
                                                    }
                                                    if (sQLiteDatabase == null) {
                                                    }
                                                    i15 = i9 + 1;
                                                    str6 = str2;
                                                    str7 = str3;
                                                    c0817r03 = c0817r0;
                                                    str5 = str;
                                                }
                                            } catch (Throwable th3) {
                                                th = th3;
                                                c0817r0 = c0817r03;
                                                str = str5;
                                                str2 = str6;
                                                str3 = str7;
                                                sQLiteDatabase = sQLiteDatabaseI;
                                                if (cursorQuery != null) {
                                                    try {
                                                        cursorQuery.close();
                                                    } catch (SQLiteDatabaseLockedException unused3) {
                                                        cursor2 = null;
                                                        SystemClock.sleep(i16);
                                                        i16 += 20;
                                                        if (cursor2 != null) {
                                                        }
                                                        if (sQLiteDatabase == null) {
                                                        }
                                                        i15 = i9 + 1;
                                                        str6 = str2;
                                                        str7 = str3;
                                                        c0817r03 = c0817r0;
                                                        str5 = str;
                                                    } catch (SQLiteFullException e12) {
                                                        e = e12;
                                                        cursor2 = null;
                                                        Z z1022 = c0817r04.f12150y;
                                                        C0817r0.k(z1022);
                                                        z1022.f11875v.c(e, "Error reading entries from local database");
                                                        sO.f11704t = true;
                                                        if (cursor2 != null) {
                                                        }
                                                        if (sQLiteDatabase == null) {
                                                        }
                                                        i15 = i9 + 1;
                                                        str6 = str2;
                                                        str7 = str3;
                                                        c0817r03 = c0817r0;
                                                        str5 = str;
                                                    } catch (SQLiteException e13) {
                                                        e = e13;
                                                        cursor2 = null;
                                                        if (sQLiteDatabase != null) {
                                                        }
                                                        Z z1122 = c0817r04.f12150y;
                                                        C0817r0.k(z1122);
                                                        z1122.f11875v.c(e, "Error reading entries from local database");
                                                        sO.f11704t = true;
                                                        if (cursor2 != null) {
                                                        }
                                                        if (sQLiteDatabase == null) {
                                                        }
                                                        i15 = i9 + 1;
                                                        str6 = str2;
                                                        str7 = str3;
                                                        c0817r03 = c0817r0;
                                                        str5 = str;
                                                    } catch (Throwable th4) {
                                                        th = th4;
                                                        cursor = null;
                                                        if (cursor != null) {
                                                        }
                                                        if (sQLiteDatabase != null) {
                                                        }
                                                        throw th;
                                                    }
                                                }
                                                throw th;
                                            }
                                        } else {
                                            i9 = i15;
                                            cursorQuery.close();
                                            j8 = -1;
                                        }
                                        if (j8 != -1) {
                                            str4 = "rowid<?";
                                            strArr = new String[]{String.valueOf(j8)};
                                        } else {
                                            str4 = null;
                                            strArr = null;
                                        }
                                        String[] strArr2 = {str7, str6, str5};
                                        str = str5;
                                        try {
                                            int i18 = 4;
                                            if (c0817r04.f12148w.R(null, I.f11570m1)) {
                                                strArr2 = new String[]{str7, str6, str, "app_version", "app_version_int"};
                                            }
                                            Cursor cursorQuery2 = sQLiteDatabaseI.query("messages", strArr2, str4, strArr, null, null, "rowid asc", Integer.toString(i));
                                            while (true) {
                                                try {
                                                    try {
                                                        boolean zMoveToNext = cursorQuery2.moveToNext();
                                                        z8 = c0817r04.f12150y;
                                                        if (!zMoveToNext) {
                                                            break;
                                                        }
                                                        try {
                                                            j11 = cursorQuery2.getLong(0);
                                                            try {
                                                                int i19 = cursorQuery2.getInt(1);
                                                                str2 = str6;
                                                                try {
                                                                    try {
                                                                        byte[] blob = cursorQuery2.getBlob(2);
                                                                        try {
                                                                            str3 = str7;
                                                                            try {
                                                                                if (c0817r04.f12148w.R(null, I.f11570m1)) {
                                                                                    try {
                                                                                        string = cursorQuery2.getString(3);
                                                                                        cursor3 = cursorQuery2;
                                                                                        c0817r02 = c0817r03;
                                                                                        j9 = cursorQuery2.getLong(i18);
                                                                                    } catch (SQLiteDatabaseLockedException unused4) {
                                                                                        cursor2 = cursorQuery2;
                                                                                        c0817r0 = c0817r03;
                                                                                        sQLiteDatabase = sQLiteDatabaseI;
                                                                                        SystemClock.sleep(i16);
                                                                                        i16 += 20;
                                                                                        if (cursor2 != null) {
                                                                                        }
                                                                                        if (sQLiteDatabase == null) {
                                                                                        }
                                                                                        i15 = i9 + 1;
                                                                                        str6 = str2;
                                                                                        str7 = str3;
                                                                                        c0817r03 = c0817r0;
                                                                                        str5 = str;
                                                                                    } catch (SQLiteFullException e14) {
                                                                                        e = e14;
                                                                                        cursor2 = cursorQuery2;
                                                                                        c0817r0 = c0817r03;
                                                                                        sQLiteDatabase = sQLiteDatabaseI;
                                                                                        Z z10222 = c0817r04.f12150y;
                                                                                        C0817r0.k(z10222);
                                                                                        z10222.f11875v.c(e, "Error reading entries from local database");
                                                                                        sO.f11704t = true;
                                                                                        if (cursor2 != null) {
                                                                                        }
                                                                                        if (sQLiteDatabase == null) {
                                                                                        }
                                                                                        i15 = i9 + 1;
                                                                                        str6 = str2;
                                                                                        str7 = str3;
                                                                                        c0817r03 = c0817r0;
                                                                                        str5 = str;
                                                                                    } catch (SQLiteException e15) {
                                                                                        e = e15;
                                                                                        cursor2 = cursorQuery2;
                                                                                        c0817r0 = c0817r03;
                                                                                        sQLiteDatabase = sQLiteDatabaseI;
                                                                                        if (sQLiteDatabase != null) {
                                                                                        }
                                                                                        Z z11222 = c0817r04.f12150y;
                                                                                        C0817r0.k(z11222);
                                                                                        z11222.f11875v.c(e, "Error reading entries from local database");
                                                                                        sO.f11704t = true;
                                                                                        if (cursor2 != null) {
                                                                                        }
                                                                                        if (sQLiteDatabase == null) {
                                                                                        }
                                                                                        i15 = i9 + 1;
                                                                                        str6 = str2;
                                                                                        str7 = str3;
                                                                                        c0817r03 = c0817r0;
                                                                                        str5 = str;
                                                                                    }
                                                                                } else {
                                                                                    cursor3 = cursorQuery2;
                                                                                    c0817r02 = c0817r03;
                                                                                    j9 = 0;
                                                                                    string = null;
                                                                                }
                                                                                if (i19 == 0) {
                                                                                    cursor2 = cursor3;
                                                                                    try {
                                                                                        try {
                                                                                            parcelObtain = Parcel.obtain();
                                                                                            try {
                                                                                                c0817r0 = c0817r02;
                                                                                                try {
                                                                                                    try {
                                                                                                        parcelObtain.unmarshall(blob, 0, blob.length);
                                                                                                        parcelObtain.setDataPosition(0);
                                                                                                        C0828v c0828vCreateFromParcel = C0828v.CREATOR.createFromParcel(parcelObtain);
                                                                                                        try {
                                                                                                            if (c0828vCreateFromParcel != null) {
                                                                                                                arrayList.add(new Q(c0828vCreateFromParcel, string, j9));
                                                                                                            }
                                                                                                        } catch (SQLiteDatabaseLockedException unused5) {
                                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                                            SystemClock.sleep(i16);
                                                                                                            i16 += 20;
                                                                                                            if (cursor2 != null) {
                                                                                                            }
                                                                                                            if (sQLiteDatabase == null) {
                                                                                                            }
                                                                                                            i15 = i9 + 1;
                                                                                                            str6 = str2;
                                                                                                            str7 = str3;
                                                                                                            c0817r03 = c0817r0;
                                                                                                            str5 = str;
                                                                                                        } catch (SQLiteFullException e16) {
                                                                                                            e = e16;
                                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                                            Z z102222 = c0817r04.f12150y;
                                                                                                            C0817r0.k(z102222);
                                                                                                            z102222.f11875v.c(e, "Error reading entries from local database");
                                                                                                            sO.f11704t = true;
                                                                                                            if (cursor2 != null) {
                                                                                                                cursor2.close();
                                                                                                            }
                                                                                                            if (sQLiteDatabase == null) {
                                                                                                            }
                                                                                                            i15 = i9 + 1;
                                                                                                            str6 = str2;
                                                                                                            str7 = str3;
                                                                                                            c0817r03 = c0817r0;
                                                                                                            str5 = str;
                                                                                                        } catch (SQLiteException e17) {
                                                                                                            e = e17;
                                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                                            if (sQLiteDatabase != null && sQLiteDatabase.inTransaction()) {
                                                                                                                sQLiteDatabase.endTransaction();
                                                                                                            }
                                                                                                            Z z112222 = c0817r04.f12150y;
                                                                                                            C0817r0.k(z112222);
                                                                                                            z112222.f11875v.c(e, "Error reading entries from local database");
                                                                                                            sO.f11704t = true;
                                                                                                            if (cursor2 != null) {
                                                                                                                cursor2.close();
                                                                                                            }
                                                                                                            if (sQLiteDatabase == null) {
                                                                                                            }
                                                                                                            i15 = i9 + 1;
                                                                                                            str6 = str2;
                                                                                                            str7 = str3;
                                                                                                            c0817r03 = c0817r0;
                                                                                                            str5 = str;
                                                                                                        }
                                                                                                    } catch (Throwable th5) {
                                                                                                        th = th5;
                                                                                                        throw th;
                                                                                                    }
                                                                                                } catch (Q2.b unused6) {
                                                                                                    C0817r0.k(z8);
                                                                                                    z8.f11875v.b("Failed to load event from local database");
                                                                                                    parcelObtain.recycle();
                                                                                                }
                                                                                            } catch (Q2.b unused7) {
                                                                                                c0817r0 = c0817r02;
                                                                                            } catch (Throwable th6) {
                                                                                                th = th6;
                                                                                            }
                                                                                        } catch (Throwable th7) {
                                                                                            th = th7;
                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                            cursor = cursor2;
                                                                                            if (cursor != null) {
                                                                                            }
                                                                                            if (sQLiteDatabase != null) {
                                                                                            }
                                                                                            throw th;
                                                                                        }
                                                                                    } catch (SQLiteDatabaseLockedException unused8) {
                                                                                        c0817r0 = c0817r02;
                                                                                    } catch (SQLiteFullException e18) {
                                                                                        e = e18;
                                                                                        c0817r0 = c0817r02;
                                                                                    } catch (SQLiteException e19) {
                                                                                        e = e19;
                                                                                        c0817r0 = c0817r02;
                                                                                    }
                                                                                } else {
                                                                                    cursor2 = cursor3;
                                                                                    c0817r0 = c0817r02;
                                                                                    if (i19 == 1) {
                                                                                        parcelObtain = Parcel.obtain();
                                                                                        try {
                                                                                            try {
                                                                                                parcelObtain.unmarshall(blob, 0, blob.length);
                                                                                                parcelObtain.setDataPosition(0);
                                                                                                t1CreateFromParcel = T1.CREATOR.createFromParcel(parcelObtain);
                                                                                            } finally {
                                                                                            }
                                                                                        } catch (Q2.b unused9) {
                                                                                            C0817r0.k(z8);
                                                                                            z8.f11875v.b("Failed to load user property from local database");
                                                                                            parcelObtain.recycle();
                                                                                            t1CreateFromParcel = null;
                                                                                        }
                                                                                        if (t1CreateFromParcel != null) {
                                                                                            arrayList.add(new Q(t1CreateFromParcel, string, j9));
                                                                                        }
                                                                                    } else if (i19 == 2) {
                                                                                        parcelObtain = Parcel.obtain();
                                                                                        try {
                                                                                            try {
                                                                                                parcelObtain.unmarshall(blob, 0, blob.length);
                                                                                                parcelObtain.setDataPosition(0);
                                                                                                c0778eCreateFromParcel = C0778e.CREATOR.createFromParcel(parcelObtain);
                                                                                            } finally {
                                                                                            }
                                                                                        } catch (Q2.b unused10) {
                                                                                            C0817r0.k(z8);
                                                                                            z8.f11875v.b("Failed to load conditional user property from local database");
                                                                                            parcelObtain.recycle();
                                                                                            c0778eCreateFromParcel = null;
                                                                                        }
                                                                                        if (c0778eCreateFromParcel != null) {
                                                                                            arrayList.add(new Q(c0778eCreateFromParcel, string, j9));
                                                                                        }
                                                                                    } else if (i19 == 4) {
                                                                                        try {
                                                                                            parcelObtain = Parcel.obtain();
                                                                                            try {
                                                                                                try {
                                                                                                    try {
                                                                                                        parcelObtain.unmarshall(blob, 0, blob.length);
                                                                                                        parcelObtain.setDataPosition(0);
                                                                                                        c0825uCreateFromParcel = C0825u.CREATOR.createFromParcel(parcelObtain);
                                                                                                    } catch (Throwable th8) {
                                                                                                        th = th8;
                                                                                                        throw th;
                                                                                                    }
                                                                                                } catch (Q2.b unused11) {
                                                                                                    C0817r0.k(z8);
                                                                                                    z8.f11875v.b("Failed to load default event parameters from local database");
                                                                                                    parcelObtain.recycle();
                                                                                                    c0825uCreateFromParcel = null;
                                                                                                }
                                                                                            } catch (Q2.b unused12) {
                                                                                            } catch (Throwable th9) {
                                                                                                th = th9;
                                                                                            }
                                                                                        } catch (SQLiteDatabaseLockedException unused13) {
                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                            SystemClock.sleep(i16);
                                                                                            i16 += 20;
                                                                                            if (cursor2 != null) {
                                                                                            }
                                                                                            if (sQLiteDatabase == null) {
                                                                                            }
                                                                                            i15 = i9 + 1;
                                                                                            str6 = str2;
                                                                                            str7 = str3;
                                                                                            c0817r03 = c0817r0;
                                                                                            str5 = str;
                                                                                        } catch (SQLiteFullException e20) {
                                                                                            e = e20;
                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                            Z z1022222 = c0817r04.f12150y;
                                                                                            C0817r0.k(z1022222);
                                                                                            z1022222.f11875v.c(e, "Error reading entries from local database");
                                                                                            sO.f11704t = true;
                                                                                            if (cursor2 != null) {
                                                                                            }
                                                                                            if (sQLiteDatabase == null) {
                                                                                            }
                                                                                            i15 = i9 + 1;
                                                                                            str6 = str2;
                                                                                            str7 = str3;
                                                                                            c0817r03 = c0817r0;
                                                                                            str5 = str;
                                                                                        } catch (SQLiteException e21) {
                                                                                            e = e21;
                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                            if (sQLiteDatabase != null) {
                                                                                            }
                                                                                            Z z1122222 = c0817r04.f12150y;
                                                                                            C0817r0.k(z1122222);
                                                                                            z1122222.f11875v.c(e, "Error reading entries from local database");
                                                                                            sO.f11704t = true;
                                                                                            if (cursor2 != null) {
                                                                                            }
                                                                                            if (sQLiteDatabase == null) {
                                                                                            }
                                                                                            i15 = i9 + 1;
                                                                                            str6 = str2;
                                                                                            str7 = str3;
                                                                                            c0817r03 = c0817r0;
                                                                                            str5 = str;
                                                                                        }
                                                                                        try {
                                                                                            if (c0825uCreateFromParcel != null) {
                                                                                                arrayList.add(new Q(c0825uCreateFromParcel, string, j9));
                                                                                            }
                                                                                            c3 = 3;
                                                                                            str6 = str2;
                                                                                            str7 = str3;
                                                                                            cursorQuery2 = cursor2;
                                                                                            c0817r03 = c0817r0;
                                                                                            i18 = 4;
                                                                                        } catch (SQLiteDatabaseLockedException unused14) {
                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                            SystemClock.sleep(i16);
                                                                                            i16 += 20;
                                                                                            if (cursor2 != null) {
                                                                                            }
                                                                                            if (sQLiteDatabase == null) {
                                                                                            }
                                                                                            i15 = i9 + 1;
                                                                                            str6 = str2;
                                                                                            str7 = str3;
                                                                                            c0817r03 = c0817r0;
                                                                                            str5 = str;
                                                                                        } catch (SQLiteFullException e22) {
                                                                                            e = e22;
                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                            Z z10222222 = c0817r04.f12150y;
                                                                                            C0817r0.k(z10222222);
                                                                                            z10222222.f11875v.c(e, "Error reading entries from local database");
                                                                                            sO.f11704t = true;
                                                                                            if (cursor2 != null) {
                                                                                            }
                                                                                            if (sQLiteDatabase == null) {
                                                                                            }
                                                                                            i15 = i9 + 1;
                                                                                            str6 = str2;
                                                                                            str7 = str3;
                                                                                            c0817r03 = c0817r0;
                                                                                            str5 = str;
                                                                                        } catch (SQLiteException e23) {
                                                                                            e = e23;
                                                                                            sQLiteDatabase = sQLiteDatabaseI;
                                                                                            if (sQLiteDatabase != null) {
                                                                                            }
                                                                                            Z z11222222 = c0817r04.f12150y;
                                                                                            C0817r0.k(z11222222);
                                                                                            z11222222.f11875v.c(e, "Error reading entries from local database");
                                                                                            sO.f11704t = true;
                                                                                            if (cursor2 != null) {
                                                                                            }
                                                                                            if (sQLiteDatabase == null) {
                                                                                            }
                                                                                            i15 = i9 + 1;
                                                                                            str6 = str2;
                                                                                            str7 = str3;
                                                                                            c0817r03 = c0817r0;
                                                                                            str5 = str;
                                                                                        }
                                                                                    } else {
                                                                                        c3 = 3;
                                                                                        if (i19 == 3) {
                                                                                            C0817r0.k(z8);
                                                                                            z8.f11878y.b("Skipping app launch break");
                                                                                        } else {
                                                                                            C0817r0.k(z8);
                                                                                            z8.f11875v.b("Unknown record type in local database");
                                                                                        }
                                                                                        str6 = str2;
                                                                                        str7 = str3;
                                                                                        cursorQuery2 = cursor2;
                                                                                        c0817r03 = c0817r0;
                                                                                        i18 = 4;
                                                                                    }
                                                                                }
                                                                                c3 = 3;
                                                                                str6 = str2;
                                                                                str7 = str3;
                                                                                cursorQuery2 = cursor2;
                                                                                c0817r03 = c0817r0;
                                                                                i18 = 4;
                                                                            } catch (SQLiteDatabaseLockedException unused15) {
                                                                                cursor2 = cursorQuery2;
                                                                                c0817r0 = c0817r03;
                                                                            } catch (SQLiteFullException e24) {
                                                                                e = e24;
                                                                                cursor2 = cursorQuery2;
                                                                                c0817r0 = c0817r03;
                                                                            } catch (SQLiteException e25) {
                                                                                e = e25;
                                                                                cursor2 = cursorQuery2;
                                                                                c0817r0 = c0817r03;
                                                                            }
                                                                        } catch (SQLiteFullException e26) {
                                                                            e = e26;
                                                                            cursor2 = cursorQuery2;
                                                                            c0817r0 = c0817r03;
                                                                            str3 = str7;
                                                                        } catch (SQLiteException e27) {
                                                                            e = e27;
                                                                            cursor2 = cursorQuery2;
                                                                            c0817r0 = c0817r03;
                                                                            str3 = str7;
                                                                        }
                                                                    } catch (SQLiteDatabaseLockedException unused16) {
                                                                        cursor2 = cursorQuery2;
                                                                        c0817r0 = c0817r03;
                                                                        str3 = str7;
                                                                        sQLiteDatabase = sQLiteDatabaseI;
                                                                        SystemClock.sleep(i16);
                                                                        i16 += 20;
                                                                        if (cursor2 != null) {
                                                                            cursor2.close();
                                                                        }
                                                                        if (sQLiteDatabase == null) {
                                                                            sQLiteDatabase.close();
                                                                        }
                                                                        i15 = i9 + 1;
                                                                        str6 = str2;
                                                                        str7 = str3;
                                                                        c0817r03 = c0817r0;
                                                                        str5 = str;
                                                                    }
                                                                } catch (SQLiteFullException e28) {
                                                                    e = e28;
                                                                    cursor2 = cursorQuery2;
                                                                    c0817r0 = c0817r03;
                                                                    str3 = str7;
                                                                    sQLiteDatabase = sQLiteDatabaseI;
                                                                    Z z102222222 = c0817r04.f12150y;
                                                                    C0817r0.k(z102222222);
                                                                    z102222222.f11875v.c(e, "Error reading entries from local database");
                                                                    sO.f11704t = true;
                                                                    if (cursor2 != null) {
                                                                    }
                                                                    if (sQLiteDatabase == null) {
                                                                    }
                                                                    i15 = i9 + 1;
                                                                    str6 = str2;
                                                                    str7 = str3;
                                                                    c0817r03 = c0817r0;
                                                                    str5 = str;
                                                                } catch (SQLiteException e29) {
                                                                    e = e29;
                                                                    cursor2 = cursorQuery2;
                                                                    c0817r0 = c0817r03;
                                                                    str3 = str7;
                                                                    sQLiteDatabase = sQLiteDatabaseI;
                                                                    if (sQLiteDatabase != null) {
                                                                        sQLiteDatabase.endTransaction();
                                                                    }
                                                                    Z z112222222 = c0817r04.f12150y;
                                                                    C0817r0.k(z112222222);
                                                                    z112222222.f11875v.c(e, "Error reading entries from local database");
                                                                    sO.f11704t = true;
                                                                    if (cursor2 != null) {
                                                                    }
                                                                    if (sQLiteDatabase == null) {
                                                                    }
                                                                    i15 = i9 + 1;
                                                                    str6 = str2;
                                                                    str7 = str3;
                                                                    c0817r03 = c0817r0;
                                                                    str5 = str;
                                                                }
                                                            } catch (SQLiteDatabaseLockedException unused17) {
                                                                cursor2 = cursorQuery2;
                                                                c0817r0 = c0817r03;
                                                                str2 = str6;
                                                            } catch (SQLiteFullException e30) {
                                                                e = e30;
                                                                cursor2 = cursorQuery2;
                                                                c0817r0 = c0817r03;
                                                                str2 = str6;
                                                            } catch (SQLiteException e31) {
                                                                e = e31;
                                                                cursor2 = cursorQuery2;
                                                                c0817r0 = c0817r03;
                                                                str2 = str6;
                                                            }
                                                        } catch (SQLiteDatabaseLockedException unused18) {
                                                            cursor2 = cursorQuery2;
                                                            c0817r0 = c0817r03;
                                                            str2 = str6;
                                                            str3 = str7;
                                                        } catch (SQLiteFullException e32) {
                                                            e = e32;
                                                            cursor2 = cursorQuery2;
                                                            c0817r0 = c0817r03;
                                                            str2 = str6;
                                                            str3 = str7;
                                                        } catch (SQLiteException e33) {
                                                            e = e33;
                                                            cursor2 = cursorQuery2;
                                                            c0817r0 = c0817r03;
                                                            str2 = str6;
                                                            str3 = str7;
                                                        }
                                                    } catch (Throwable th10) {
                                                        th = th10;
                                                        cursor2 = cursorQuery2;
                                                    }
                                                } catch (SQLiteDatabaseLockedException unused19) {
                                                    cursor2 = cursorQuery2;
                                                    c0817r0 = c0817r03;
                                                    str2 = str6;
                                                    str3 = str7;
                                                } catch (SQLiteFullException e34) {
                                                    e = e34;
                                                    cursor2 = cursorQuery2;
                                                    c0817r0 = c0817r03;
                                                    str2 = str6;
                                                    str3 = str7;
                                                } catch (SQLiteException e35) {
                                                    e = e35;
                                                    cursor2 = cursorQuery2;
                                                    c0817r0 = c0817r03;
                                                    str2 = str6;
                                                    str3 = str7;
                                                }
                                            }
                                            cursor2 = cursorQuery2;
                                            c0817r0 = c0817r03;
                                            str2 = str6;
                                            str3 = str7;
                                            i8 = 0;
                                            sQLiteDatabase = sQLiteDatabaseI;
                                            try {
                                                if (sQLiteDatabase.delete("messages", "rowid <= ?", new String[]{Long.toString(j11)}) < arrayList.size()) {
                                                    C0817r0.k(z8);
                                                    z8.f11875v.b("Fewer entries removed from local database than expected");
                                                }
                                                sQLiteDatabase.setTransactionSuccessful();
                                                sQLiteDatabase.endTransaction();
                                                cursor2.close();
                                                sQLiteDatabase.close();
                                            } catch (SQLiteDatabaseLockedException unused20) {
                                                SystemClock.sleep(i16);
                                                i16 += 20;
                                                if (cursor2 != null) {
                                                }
                                                if (sQLiteDatabase == null) {
                                                }
                                                i15 = i9 + 1;
                                                str6 = str2;
                                                str7 = str3;
                                                c0817r03 = c0817r0;
                                                str5 = str;
                                            } catch (SQLiteFullException e36) {
                                                e = e36;
                                                Z z1022222222 = c0817r04.f12150y;
                                                C0817r0.k(z1022222222);
                                                z1022222222.f11875v.c(e, "Error reading entries from local database");
                                                sO.f11704t = true;
                                                if (cursor2 != null) {
                                                }
                                                if (sQLiteDatabase == null) {
                                                }
                                                i15 = i9 + 1;
                                                str6 = str2;
                                                str7 = str3;
                                                c0817r03 = c0817r0;
                                                str5 = str;
                                            } catch (SQLiteException e37) {
                                                e = e37;
                                                if (sQLiteDatabase != null) {
                                                }
                                                Z z1122222222 = c0817r04.f12150y;
                                                C0817r0.k(z1122222222);
                                                z1122222222.f11875v.c(e, "Error reading entries from local database");
                                                sO.f11704t = true;
                                                if (cursor2 != null) {
                                                }
                                                if (sQLiteDatabase == null) {
                                                }
                                                i15 = i9 + 1;
                                                str6 = str2;
                                                str7 = str3;
                                                c0817r03 = c0817r0;
                                                str5 = str;
                                            }
                                        } catch (SQLiteDatabaseLockedException unused21) {
                                            c0817r0 = c0817r03;
                                            str2 = str6;
                                            str3 = str7;
                                            sQLiteDatabase = sQLiteDatabaseI;
                                            cursor2 = null;
                                            SystemClock.sleep(i16);
                                            i16 += 20;
                                            if (cursor2 != null) {
                                            }
                                            if (sQLiteDatabase == null) {
                                            }
                                            i15 = i9 + 1;
                                            str6 = str2;
                                            str7 = str3;
                                            c0817r03 = c0817r0;
                                            str5 = str;
                                        } catch (SQLiteFullException e38) {
                                            e = e38;
                                            c0817r0 = c0817r03;
                                            str2 = str6;
                                            str3 = str7;
                                            sQLiteDatabase = sQLiteDatabaseI;
                                            cursor2 = null;
                                            Z z10222222222 = c0817r04.f12150y;
                                            C0817r0.k(z10222222222);
                                            z10222222222.f11875v.c(e, "Error reading entries from local database");
                                            sO.f11704t = true;
                                            if (cursor2 != null) {
                                            }
                                            if (sQLiteDatabase == null) {
                                            }
                                            i15 = i9 + 1;
                                            str6 = str2;
                                            str7 = str3;
                                            c0817r03 = c0817r0;
                                            str5 = str;
                                        } catch (SQLiteException e39) {
                                            e = e39;
                                            c0817r0 = c0817r03;
                                            str2 = str6;
                                            str3 = str7;
                                            sQLiteDatabase = sQLiteDatabaseI;
                                            cursor2 = null;
                                            if (sQLiteDatabase != null) {
                                            }
                                            Z z11222222222 = c0817r04.f12150y;
                                            C0817r0.k(z11222222222);
                                            z11222222222.f11875v.c(e, "Error reading entries from local database");
                                            sO.f11704t = true;
                                            if (cursor2 != null) {
                                            }
                                            if (sQLiteDatabase == null) {
                                            }
                                            i15 = i9 + 1;
                                            str6 = str2;
                                            str7 = str3;
                                            c0817r03 = c0817r0;
                                            str5 = str;
                                        }
                                    } catch (Throwable th11) {
                                        th = th11;
                                        i9 = i15;
                                    }
                                } catch (Throwable th12) {
                                    th = th12;
                                    i9 = i15;
                                    c0817r0 = c0817r03;
                                    str = str5;
                                    str2 = str6;
                                    str3 = str7;
                                    sQLiteDatabase = sQLiteDatabaseI;
                                    cursorQuery = null;
                                }
                            }
                        } catch (SQLiteDatabaseLockedException unused22) {
                            i9 = i15;
                            c0817r0 = c0817r03;
                            str = str5;
                            str2 = str6;
                            str3 = str7;
                            sQLiteDatabase = null;
                        } catch (SQLiteFullException e40) {
                            e = e40;
                            i9 = i15;
                            c0817r0 = c0817r03;
                            str = str5;
                            str2 = str6;
                            str3 = str7;
                            sQLiteDatabase = null;
                        } catch (SQLiteException e41) {
                            e = e41;
                            i9 = i15;
                            c0817r0 = c0817r03;
                            str = str5;
                            str2 = str6;
                            str3 = str7;
                            sQLiteDatabase = null;
                        } catch (Throwable th13) {
                            th = th13;
                            sQLiteDatabase = null;
                        }
                    }
                    c0817r0 = c0817r03;
                    i8 = 0;
                    Z z12 = c0817r04.f12150y;
                    C0817r0.k(z12);
                    z12.f11878y.b("Failed to read events from database in reasonable time");
                    arrayList = null;
                } else {
                    c0817r0 = c0817r03;
                    i5 = i13;
                    i8 = 0;
                }
                if (arrayList == null) {
                    arrayList2.addAll(arrayList);
                    size = arrayList.size();
                } else {
                    size = i8;
                }
                int i20 = i;
                if (aVar2 != null && size < i20) {
                    arrayList2.add(new Q(aVar2, x14.f11833s, x14.f11840z));
                }
                H h8 = I.f11527V0;
                C0817r0 c0817r05 = c0817r0;
                C0784g c0784g = c0817r05.f12148w;
                String str8 = null;
                boolean zR = c0784g.R(null, h8);
                size2 = arrayList2.size();
                X1 x15 = x14;
                i10 = i8;
                while (i10 < size2) {
                    Q q8 = (Q) arrayList2.get(i10);
                    Q2.a aVar3 = q8.f11652a;
                    H h9 = I.f11570m1;
                    if (c0784g.R(str8, h9)) {
                        String str9 = q8.f11653b;
                        x13 = !TextUtils.isEmpty(str9) ? new X1(x15.f11831q, x15.f11832r, str9, q8.f11654c, x15.f11834t, x15.f11835u, x15.f11836v, x15.f11837w, x15.f11838x, x15.f11839y, x15.f11810A, x15.f11811B, x15.f11812C, x15.D, x15.f11813E, x15.f11814F, x15.f11815G, x15.H, x15.f11816I, x15.f11817J, x15.f11818K, x15.f11819L, x15.f11820M, x15.f11821N, x15.f11822O, x15.f11823P, x15.f11824Q, x15.f11825R, x15.f11826S, x15.f11827T, x15.f11828U, x15.f11829V, x15.f11830W) : x15;
                    }
                    boolean z13 = aVar3 instanceof C0828v;
                    Z z14 = c0817r05.f12150y;
                    if (z13) {
                        Context context = c0817r05.f12142q;
                        T2.a aVar4 = c0817r05.D;
                        if (zR) {
                            try {
                                aVar4.getClass();
                                jCurrentTimeMillis = System.currentTimeMillis();
                            } catch (RemoteException e42) {
                                e = e42;
                                z9 = zR;
                                i11 = i10;
                                jElapsedRealtime = 0;
                                j10 = 0;
                            }
                            try {
                                aVar4.getClass();
                                j10 = jCurrentTimeMillis;
                                jElapsedRealtime = SystemClock.elapsedRealtime();
                            } catch (RemoteException e43) {
                                e = e43;
                                z9 = zR;
                                i11 = i10;
                                j10 = jCurrentTimeMillis;
                                jElapsedRealtime = 0;
                                C0817r0.k(z14);
                                z14.f11875v.c(e, "Failed to send event to the service");
                                if (z9) {
                                }
                                str8 = null;
                                i10 = i11 + 1;
                                x15 = x13;
                                zR = z9;
                            }
                        } else {
                            jElapsedRealtime = 0;
                            j10 = 0;
                        }
                        try {
                            try {
                                k8.j((C0828v) aVar3, x13);
                                if (zR) {
                                    C0817r0.k(z14);
                                    z14.D.b("Logging telemetry for logEvent from database");
                                    if (com.google.android.material.datepicker.c.f10217u == null) {
                                        com.google.android.material.datepicker.c.f10217u = new com.google.android.material.datepicker.c(context, c0817r05);
                                    }
                                    com.google.android.material.datepicker.c cVar = com.google.android.material.datepicker.c.f10217u;
                                    aVar4.getClass();
                                    long jCurrentTimeMillis2 = System.currentTimeMillis();
                                    aVar4.getClass();
                                    z9 = zR;
                                    i11 = i10;
                                    try {
                                        cVar.G(0, (int) (SystemClock.elapsedRealtime() - jElapsedRealtime), j10, jCurrentTimeMillis2);
                                    } catch (RemoteException e44) {
                                        e = e44;
                                        C0817r0.k(z14);
                                        z14.f11875v.c(e, "Failed to send event to the service");
                                        if (z9) {
                                            if (com.google.android.material.datepicker.c.f10217u == null) {
                                            }
                                            com.google.android.material.datepicker.c cVar2 = com.google.android.material.datepicker.c.f10217u;
                                            aVar4.getClass();
                                            long jCurrentTimeMillis3 = System.currentTimeMillis();
                                            aVar4.getClass();
                                            cVar2.G(13, (int) (SystemClock.elapsedRealtime() - jElapsedRealtime), j10, jCurrentTimeMillis3);
                                        }
                                    }
                                } else {
                                    z9 = zR;
                                    i11 = i10;
                                }
                            } catch (RemoteException e45) {
                                e = e45;
                                z9 = zR;
                                i11 = i10;
                                C0817r0.k(z14);
                                z14.f11875v.c(e, "Failed to send event to the service");
                                if (z9 && j10 != 0) {
                                    if (com.google.android.material.datepicker.c.f10217u == null) {
                                        com.google.android.material.datepicker.c.f10217u = new com.google.android.material.datepicker.c(context, c0817r05);
                                    }
                                    com.google.android.material.datepicker.c cVar22 = com.google.android.material.datepicker.c.f10217u;
                                    aVar4.getClass();
                                    long jCurrentTimeMillis32 = System.currentTimeMillis();
                                    aVar4.getClass();
                                    cVar22.G(13, (int) (SystemClock.elapsedRealtime() - jElapsedRealtime), j10, jCurrentTimeMillis32);
                                }
                                str8 = null;
                                i10 = i11 + 1;
                                x15 = x13;
                                zR = z9;
                            }
                        } catch (RemoteException e46) {
                            e = e46;
                        }
                    } else {
                        z9 = zR;
                        i11 = i10;
                        if (aVar3 instanceof T1) {
                            try {
                                k8.h((T1) aVar3, x13);
                            } catch (RemoteException e47) {
                                C0817r0.k(z14);
                                z14.f11875v.c(e47, "Failed to send user property to the service");
                            }
                        } else if (aVar3 instanceof C0778e) {
                            try {
                                k8.C((C0778e) aVar3, x13);
                            } catch (RemoteException e48) {
                                C0817r0.k(z14);
                                z14.f11875v.c(e48, "Failed to send conditional user property to the service");
                            }
                        } else {
                            str8 = null;
                            if (c0784g.R(null, h9) && (aVar3 instanceof C0825u)) {
                                try {
                                    k8.r(((C0825u) aVar3).a(), x13);
                                } catch (RemoteException e49) {
                                    C0817r0.k(z14);
                                    z14.f11875v.c(e49, "Failed to send default event parameters to the service");
                                }
                            } else {
                                C0817r0.k(z14);
                                z14.f11875v.b("Discarding data. Unrecognized parcel type.");
                            }
                            i10 = i11 + 1;
                            x15 = x13;
                            zR = z9;
                        }
                    }
                    str8 = null;
                    i10 = i11 + 1;
                    x15 = x13;
                    zR = z9;
                }
                i13 = i5 + 1;
                aVar2 = aVar;
                x14 = x15;
                i12 = size;
                c0817r03 = c0817r05;
            }
            i8 = 0;
            arrayList = null;
            if (arrayList == null) {
            }
            int i202 = i;
            if (aVar2 != null) {
                arrayList2.add(new Q(aVar2, x14.f11833s, x14.f11840z));
            }
            H h82 = I.f11527V0;
            C0817r0 c0817r052 = c0817r0;
            C0784g c0784g2 = c0817r052.f12148w;
            String str82 = null;
            boolean zR2 = c0784g2.R(null, h82);
            size2 = arrayList2.size();
            X1 x152 = x14;
            i10 = i8;
            while (i10 < size2) {
            }
            i13 = i5 + 1;
            aVar2 = aVar;
            x14 = x152;
            i12 = size;
            c0817r03 = c0817r052;
        }
    }

    public final void M(C0778e c0778e) {
        boolean zL;
        E();
        F();
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        c0817r0.getClass();
        S sO = c0817r0.o();
        C0817r0 c0817r02 = (C0817r0) sO.f5146q;
        C0817r0.i(c0817r02.f12122B);
        byte[] bArrF0 = W1.F0(c0778e);
        if (bArrF0.length > 131072) {
            Z z8 = c0817r02.f12150y;
            C0817r0.k(z8);
            z8.f11876w.b("Conditional user property too long for local database. Sending directly to service");
            zL = false;
        } else {
            zL = sO.L(2, bArrF0);
        }
        boolean z9 = zL;
        V(new RunnableC0810o1(this, S(true), z9, new C0778e(c0778e), 2));
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0056  */
    /* JADX WARN: Removed duplicated region for block: B:14:0x0059  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void N(Bundle bundle) {
        boolean z8;
        boolean zL;
        E();
        F();
        C0825u c0825u = new C0825u(bundle);
        W();
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (c0817r0.f12148w.R(null, I.f11570m1)) {
            S sO = c0817r0.o();
            C0817r0 c0817r02 = (C0817r0) sO.f5146q;
            C0817r0.i(c0817r02.f12122B);
            byte[] bArrF0 = W1.F0(c0825u);
            Z z9 = c0817r02.f12150y;
            if (bArrF0 == null) {
                C0817r0.k(z9);
                z9.f11876w.b("Null default event parameters; not writing to database");
            } else if (bArrF0.length > 131072) {
                C0817r0.k(z9);
                z9.f11876w.b("Default event parameters too long for local database. Sending directly to service");
            } else {
                zL = sO.L(4, bArrF0);
                z8 = !zL;
            }
            zL = false;
            if (!zL) {
            }
        }
        V(new U0(this, S(false), z8, c0825u, bundle));
    }

    public final boolean O() {
        E();
        F();
        return this.f12179t != null;
    }

    public final boolean P() {
        E();
        F();
        if (!R()) {
            return true;
        }
        W1 w12 = ((C0817r0) this.f5146q).f12122B;
        C0817r0.i(w12);
        return w12.M0() >= ((Integer) I.f11504J0.a(null)).intValue();
    }

    public final boolean Q() {
        E();
        F();
        if (!R()) {
            return true;
        }
        W1 w12 = ((C0817r0) this.f5146q).f12122B;
        C0817r0.i(w12);
        return w12.M0() >= 241200;
    }

    /* JADX WARN: Removed duplicated region for block: B:42:0x00ff  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x0114  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0116  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean R() {
        E();
        F();
        if (this.f12180u == null) {
            E();
            F();
            C0817r0 c0817r0 = (C0817r0) this.f5146q;
            C0785g0 c0785g0 = c0817r0.f12149x;
            C0817r0.i(c0785g0);
            c0785g0.E();
            boolean z8 = false;
            Boolean boolValueOf = !c0785g0.J().contains("use_service") ? null : Boolean.valueOf(c0785g0.J().getBoolean("use_service", false));
            if (boolValueOf == null || !boolValueOf.booleanValue()) {
                P pN = ((C0817r0) this.f5146q).n();
                pN.F();
                if (pN.f11635C == 1) {
                    z8 = true;
                    if (!z8 && c0817r0.f12148w.H()) {
                        Z z9 = c0817r0.f12150y;
                        C0817r0.k(z9);
                        z9.f11875v.b("No way to upload. Consider using the full version of Analytics");
                    } else if (z) {
                        C0785g0 c0785g02 = c0817r0.f12149x;
                        C0817r0.i(c0785g02);
                        c0785g02.E();
                        SharedPreferences.Editor editorEdit = c0785g02.J().edit();
                        editorEdit.putBoolean("use_service", z8);
                        editorEdit.apply();
                    }
                    z = z8;
                } else {
                    Z z10 = c0817r0.f12150y;
                    C0817r0.k(z10);
                    z10.D.b("Checking service availability");
                    W1 w12 = c0817r0.f12122B;
                    C0817r0.i(w12);
                    int iB = M2.f.f4167b.b(((C0817r0) w12.f5146q).f12142q, 12451000);
                    if (iB != 0) {
                        if (iB == 1) {
                            Z z11 = c0817r0.f12150y;
                            C0817r0.k(z11);
                            z11.D.b("Service missing");
                        } else if (iB != 2) {
                            if (iB == 3) {
                                Z z12 = c0817r0.f12150y;
                                C0817r0.k(z12);
                                z12.f11878y.b("Service disabled");
                            } else if (iB == 9) {
                                Z z13 = c0817r0.f12150y;
                                C0817r0.k(z13);
                                z13.f11878y.b("Service invalid");
                            } else if (iB != 18) {
                                Z z14 = c0817r0.f12150y;
                                C0817r0.k(z14);
                                z14.f11878y.c(Integer.valueOf(iB), "Unexpected service status");
                            } else {
                                Z z15 = c0817r0.f12150y;
                                C0817r0.k(z15);
                                z15.f11878y.b("Service updating");
                            }
                            z = false;
                        } else {
                            Z z16 = c0817r0.f12150y;
                            C0817r0.k(z16);
                            z16.f11871C.b("Service container out of date");
                            W1 w13 = c0817r0.f12122B;
                            C0817r0.i(w13);
                            if (w13.M0() >= 17443) {
                                z8 = boolValueOf == null;
                                z = false;
                            }
                        }
                        if (!z8) {
                            if (z) {
                            }
                            z = z8;
                        }
                    } else {
                        Z z17 = c0817r0.f12150y;
                        C0817r0.k(z17);
                        z17.D.b("Service available");
                    }
                    z8 = true;
                    if (!z8) {
                    }
                }
            }
            this.f12180u = Boolean.valueOf(z);
        }
        return this.f12180u.booleanValue();
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x00a1  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final X1 S(boolean z8) {
        long jAbs;
        Pair pair;
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        c0817r0.getClass();
        P pN = c0817r0.n();
        String str = null;
        if (z8) {
            Z z9 = c0817r0.f12150y;
            C0817r0.k(z9);
            C0817r0 c0817r02 = (C0817r0) z9.f5146q;
            C0785g0 c0785g0 = c0817r02.f12149x;
            C0817r0.i(c0785g0);
            if (c0785g0.f11974v != null) {
                C0785g0 c0785g02 = c0817r02.f12149x;
                C0817r0.i(c0785g02);
                C0782f0 c0782f0 = c0785g02.f11974v;
                C0785g0 c0785g03 = (C0785g0) c0782f0.f11943e;
                c0785g03.E();
                c0785g03.E();
                long j8 = ((C0785g0) c0782f0.f11943e).J().getLong((String) c0782f0.f11940b, 0L);
                if (j8 == 0) {
                    c0782f0.b();
                    jAbs = 0;
                } else {
                    ((C0817r0) c0785g03.f5146q).D.getClass();
                    jAbs = Math.abs(j8 - System.currentTimeMillis());
                }
                long j9 = c0782f0.f11939a;
                if (jAbs < j9) {
                    pair = null;
                    if (pair != null) {
                    }
                } else if (jAbs > j9 + j9) {
                    c0782f0.b();
                    pair = null;
                    if (pair != null && pair != C0785g0.f11956Q) {
                        str = String.valueOf(pair.second) + ":" + ((String) pair.first);
                    }
                } else {
                    String string = c0785g03.J().getString((String) c0782f0.f11942d, null);
                    long j10 = c0785g03.J().getLong((String) c0782f0.f11941c, 0L);
                    c0782f0.b();
                    pair = (string == null || j10 <= 0) ? C0785g0.f11956Q : new Pair(string, Long.valueOf(j10));
                    if (pair != null) {
                        str = String.valueOf(pair.second) + ":" + ((String) pair.first);
                    }
                }
            }
        }
        return pN.I(str);
    }

    public final void T() {
        E();
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        Z z8 = c0817r0.f12150y;
        C0817r0.k(z8);
        ArrayList arrayList = this.f12184y;
        z8.D.c(Integer.valueOf(arrayList.size()), "Processing queued up service tasks");
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            try {
                ((Runnable) obj).run();
            } catch (RuntimeException e8) {
                Z z9 = c0817r0.f12150y;
                C0817r0.k(z9);
                z9.f11875v.c(e8, "Task exception while flushing queue");
            }
        }
        arrayList.clear();
        this.f12185z.a();
    }

    public final void U() {
        E();
        C0207h c0207h = this.f12183x;
        ((T2.a) c0207h.f4548s).getClass();
        c0207h.f4547r = SystemClock.elapsedRealtime();
        ((C0817r0) this.f5146q).getClass();
        this.f12181v.c(((Long) I.f11530Y.a(null)).longValue());
    }

    public final void V(Runnable runnable) {
        E();
        if (O()) {
            runnable.run();
            return;
        }
        ArrayList arrayList = this.f12184y;
        long size = arrayList.size();
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        c0817r0.getClass();
        if (size >= 1000) {
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11875v.b("Discarding data. Max runnable queue size reached");
        } else {
            arrayList.add(runnable);
            this.f12185z.c(60000L);
            I();
        }
    }

    public final void W() {
        ((C0817r0) this.f5146q).getClass();
    }
}
