package d3;

import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* JADX INFO: renamed from: d3.l, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0799l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f12036a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public long f12037b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ C0805n f12038c;

    public C0799l(C0805n c0805n, String str) {
        this.f12038c = c0805n;
        P2.w.c(str);
        this.f12036a = str;
        this.f12037b = -1L;
    }

    public final List a() {
        List list;
        C0805n c0805n = this.f12038c;
        ArrayList arrayList = new ArrayList();
        String strValueOf = String.valueOf(this.f12037b);
        String str = this.f12036a;
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = c0805n.A0().query("raw_events", new String[]{"rowid", "name", "timestamp", "metadata_fingerprint", "data", "realtime"}, "app_id = ? and rowid > ?", new String[]{str, strValueOf}, null, null, "rowid", "1000");
                if (cursorQuery.moveToFirst()) {
                    do {
                        long j8 = cursorQuery.getLong(0);
                        long j9 = cursorQuery.getLong(3);
                        boolean z8 = cursorQuery.getLong(5) == 1;
                        byte[] blob = cursorQuery.getBlob(4);
                        if (j8 > this.f12037b) {
                            this.f12037b = j8;
                        }
                        try {
                            com.google.android.gms.internal.measurement.V0 v02 = (com.google.android.gms.internal.measurement.V0) C0773c0.k0(com.google.android.gms.internal.measurement.W0.r(), blob);
                            String string = cursorQuery.getString(1);
                            if (string == null) {
                                string = "";
                            }
                            v02.k();
                            com.google.android.gms.internal.measurement.W0.z((com.google.android.gms.internal.measurement.W0) v02.f9801r, string);
                            long j10 = cursorQuery.getLong(2);
                            v02.k();
                            com.google.android.gms.internal.measurement.W0.C(j10, (com.google.android.gms.internal.measurement.W0) v02.f9801r);
                            arrayList.add(new C0796k(j8, j9, z8, (com.google.android.gms.internal.measurement.W0) v02.h()));
                        } catch (IOException e8) {
                            Z z9 = ((C0817r0) c0805n.f5146q).f12150y;
                            C0817r0.k(z9);
                            z9.f11875v.d("Data loss. Failed to merge raw event. appId", Z.M(str), e8);
                        }
                    } while (cursorQuery.moveToNext());
                } else {
                    list = Collections.EMPTY_LIST;
                }
            } catch (SQLiteException e9) {
                Z z10 = ((C0817r0) c0805n.f5146q).f12150y;
                C0817r0.k(z10);
                z10.f11875v.d("Data loss. Error querying raw events batch. appId", Z.M(str), e9);
                list = arrayList;
            }
            return list;
        } finally {
            if (0 != 0) {
                cursorQuery.close();
            }
        }
    }

    public C0799l(C0805n c0805n, String str, long j8) {
        this.f12038c = c0805n;
        P2.w.c(str);
        this.f12036a = str;
        this.f12037b = c0805n.w0(-1L, "select rowid from raw_events where app_id = ? and timestamp < ? order by rowid desc limit 1", new String[]{str, String.valueOf(j8)});
    }
}
