package o;

import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import com.google.android.gms.common.internal.Preconditions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.nj0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1981nj0 {
    public long a;
    public final Object b;
    public final Object c;

    public C1981nj0(C2940xo0 c2940xo0, String str) {
        this.c = c2940xo0;
        Preconditions.checkNotEmpty(str);
        this.b = str;
        this.a = -1L;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r3v2, types: [java.util.List] */
    public List a() {
        ArrayList arrayList;
        C2940xo0 c2940xo0 = (C2940xo0) this.c;
        ArrayList arrayList2 = new ArrayList();
        String str = (String) this.b;
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = c2940xo0.h0().query("raw_events", new String[]{"rowid", "name", "timestamp", "metadata_fingerprint", "data", "realtime"}, "app_id = ? and rowid > ?", new String[]{str, String.valueOf(this.a)}, null, null, "rowid", "1000");
                if (cursorQuery.moveToFirst()) {
                    do {
                        long j = cursorQuery.getLong(0);
                        long j2 = cursorQuery.getLong(3);
                        boolean z = cursorQuery.getLong(5) == 1;
                        byte[] blob = cursorQuery.getBlob(4);
                        if (j > this.a) {
                            this.a = j;
                        }
                        try {
                            C2661ur0 c2661ur0 = (C2661ur0) C1720kv0.a0(C2756vr0.z(), blob);
                            String string = cursorQuery.getString(1);
                            if (string == null) {
                                string = "";
                            }
                            c2661ur0.b();
                            ((C2756vr0) c2661ur0.m).F(string);
                            long j3 = cursorQuery.getLong(2);
                            c2661ur0.b();
                            ((C2756vr0) c2661ur0.m).G(j3);
                            arrayList2.add(new C2465so0(j, j2, z, (C2756vr0) c2661ur0.e()));
                        } catch (IOException e) {
                            Nq0 nq0 = ((Kr0) c2940xo0.a).f;
                            Kr0.l(nq0);
                            nq0.f.d("Data loss. Failed to merge raw event. appId", Nq0.A(str), e);
                        }
                    } while (cursorQuery.moveToNext());
                } else {
                    arrayList = Collections.EMPTY_LIST;
                }
            } catch (SQLiteException e2) {
                Nq0 nq02 = ((Kr0) c2940xo0.a).f;
                Kr0.l(nq02);
                nq02.f.d("Data loss. Error querying raw events batch. appId", Nq0.A(str), e2);
                arrayList = arrayList2;
            }
            return arrayList;
        } finally {
            if (0 != 0) {
                cursorQuery.close();
            }
        }
    }

    public C1981nj0(C2940xo0 c2940xo0, String str, long j) {
        this.c = c2940xo0;
        Preconditions.checkNotEmpty(str);
        this.b = str;
        this.a = c2940xo0.d0("select rowid from raw_events where app_id = ? and timestamp < ? order by rowid desc limit 1", new String[]{str, String.valueOf(j)}, -1L);
    }

    public C1981nj0() {
        this.b = new C1886mj0();
        this.c = new C1886mj0();
    }
}
