package defpackage;

import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import com.hierynomus.protocol.transport.TransportException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* JADX INFO: renamed from: ːᵝᵸˇ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1983 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final Object f7855;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final /* synthetic */ Object f7856;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public long f7857;

    public C1983(C1694 c1694, String str) {
        this.f7856 = c1694;
        ᵘᵞʿⁱ.ˊᵫᵗ(str);
        this.f7855 = str;
        this.f7857 = -1L;
    }

    public C1983(C1694 c1694, String str, long j) {
        this.f7856 = c1694;
        ᵘᵞʿⁱ.ˊᵫᵗ(str);
        this.f7855 = str;
        this.f7857 = c1694.m4582("select rowid from raw_events where app_id = ? and timestamp < ? order by rowid desc limit 1", new String[]{str, String.valueOf(j)}, -1L);
    }

    public C1983(C5179 c5179, C4144 c4144, long j) {
        this.f7856 = c5179;
        this.f7855 = c4144;
        this.f7857 = j;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public List m5361() {
        List list;
        C1694 c1694 = (C1694) this.f7856;
        ArrayList arrayList = new ArrayList();
        String str = (String) this.f7855;
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = c1694.m4625().query("raw_events", new String[]{"rowid", "name", "timestamp", "metadata_fingerprint", "data", "realtime", "elapsed_time"}, "app_id = ? and rowid > ?", new String[]{str, String.valueOf(this.f7857)}, null, null, "rowid", "1000");
                if (cursorQuery.moveToFirst()) {
                    do {
                        long j = cursorQuery.getLong(0);
                        long j2 = cursorQuery.getLong(3);
                        boolean z = cursorQuery.getLong(5) == 1;
                        long j3 = cursorQuery.getLong(6);
                        byte[] blob = cursorQuery.getBlob(4);
                        if (j > this.f7857) {
                            this.f7857 = j;
                        }
                        try {
                            C4225 c4225 = (C4225) C1962.m5264(C4943.m10252(), blob);
                            String string = cursorQuery.getString(1);
                            if (string == null) {
                                string = "";
                            }
                            c4225.m9178(string);
                            long j4 = cursorQuery.getLong(2);
                            c4225.m9868();
                            ((C4943) c4225.f17955).m10257(j4);
                            c4225.m9868();
                            ((C4943) c4225.f17955).m10265(j3);
                            arrayList.add(new C0755(j, j2, z, (C4943) c4225.m9869()));
                        } catch (IOException e) {
                            C3485 c3485 = ((C1103) ((ᵜᵪʾ) c1694).ˌᴵ).f4729;
                            C1103.m3564(c3485);
                            c3485.f13423.m4475("Data loss. Failed to merge raw event. appId", C3485.m7979(str), e);
                        }
                    } while (cursorQuery.moveToNext());
                } else {
                    list = Collections.EMPTY_LIST;
                }
            } finally {
                if (0 != 0) {
                    cursorQuery.close();
                }
            }
        } catch (SQLiteException e2) {
            C3485 c34852 = ((C1103) ((ᵜᵪʾ) c1694).ˌᴵ).f4729;
            C1103.m3564(c34852);
            c34852.f13423.m4475("Data loss. Error querying raw events batch. appId", C3485.m7979(str), e2);
            list = arrayList;
        }
        return list;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public void m5362() {
        C5179 c5179 = (C5179) this.f7856;
        EnumC3519 enumC3519 = (EnumC3519) ((C4349) c5179.f19498.f19206).f16540;
        C4144 c4144 = (C4144) this.f7855;
        long j = c4144.f15810;
        long j2 = c4144.f15814;
        C3029 c3029 = new C3029(4, enumC3519, EnumC4635.f17624);
        C2964 c2964 = (C2964) ((InterfaceC2684) ((ᵜᵪʾ) c3029).ˌᴵ);
        c2964.f11414 = j;
        if (j2 != 0) {
            c2964.f11411 |= 2;
            c2964.f11410 = j2;
        }
        try {
            c5179.f19497.m8377(Long.valueOf(this.f7857)).m10362(c3029);
        } catch (TransportException unused) {
            C5179.f19488.mo9482(c3029, "Failed to send {}");
        }
    }
}
