package m6;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.SystemClock;
import java.util.ArrayList;
import l6.h;
import tv.danmaku.ijk.media.player.IMediaPlayer;

/* JADX INFO: loaded from: classes.dex */
public final class e implements Runnable {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ int f30405b;

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

    public e(f fVar, a aVar, int i10) {
        this.f30406c = fVar;
        this.f30404a = aVar;
        this.f30405b = i10;
        SystemClock.elapsedRealtime();
    }

    /* JADX WARN: Removed duplicated region for block: B:55:0x00dd A[Catch: all -> 0x00f2, TRY_LEAVE, TryCatch #0 {all -> 0x00f2, blocks: (B:53:0x00d9, B:55:0x00dd), top: B:72:0x00d9 }] */
    /* JADX WARN: Removed duplicated region for block: B:61:0x00ee  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x00e4 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:93:? A[RETURN, SYNTHETIC] */
    @Override // java.lang.Runnable
    /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void run() {
        boolean z10;
        Cursor cursorQuery;
        n6.a aVar;
        int iA;
        SystemClock.elapsedRealtime();
        f fVar = this.f30406c;
        h hVar = fVar.f30409c;
        a aVar2 = this.f30404a;
        int i10 = this.f30405b;
        ArrayList arrayList = new ArrayList();
        boolean z11 = true;
        try {
            SQLiteDatabase readableDatabase = aVar2.getReadableDatabase();
            iA = fVar.a();
            cursorQuery = readableDatabase.query(fVar.f30409c.yz(), null, null, null, null, null, "priority DESC, create_time DESC", i10 + "," + iA);
        } catch (Throwable unused) {
            z10 = true;
            cursorQuery = null;
        }
        if (cursorQuery != null) {
            try {
                if (!cursorQuery.moveToFirst()) {
                    try {
                        cursorQuery.close();
                        return;
                    } catch (Exception unused2) {
                        return;
                    }
                }
                z10 = cursorQuery.getCount() >= iA;
                try {
                    int columnIndexOrThrow = cursorQuery.getColumnIndexOrThrow("data");
                    int columnIndexOrThrow2 = cursorQuery.getColumnIndexOrThrow("data_id");
                    int columnIndexOrThrow3 = cursorQuery.getColumnIndexOrThrow("priority");
                    int columnIndexOrThrow4 = cursorQuery.getColumnIndexOrThrow("upload_retry_count");
                    do {
                        String string = cursorQuery.getString(columnIndexOrThrow2);
                        synchronized (fVar.f30410d) {
                            try {
                                if (!fVar.f30410d.contains(string)) {
                                    fVar.f30410d.add(string);
                                    byte[] blob = cursorQuery.getBlob(columnIndexOrThrow);
                                    l6.c cVarYz = fVar.f30408b.f30398b.yz();
                                    if (cVarYz != null) {
                                        blob = cVarYz.ro(blob);
                                        n6.a aVar3 = fVar.f30416j;
                                        if (aVar3 != null) {
                                            aVar3.a(blob != null ? 7 : 8, 1);
                                        }
                                    }
                                    l6.b bVarFm = fVar.f30409c.fm(string, blob, cursorQuery.getInt(columnIndexOrThrow3), cursorQuery.getInt(columnIndexOrThrow4));
                                    if (bVarFm == null) {
                                        synchronized (fVar.f30410d) {
                                            fVar.f30410d.remove(string);
                                        }
                                    } else {
                                        arrayList.add(bVarFm);
                                    }
                                }
                            } finally {
                            }
                        }
                    } while (cursorQuery.moveToNext());
                    z11 = z10;
                } catch (Throwable unused3) {
                    aVar = fVar.f30416j;
                    if (aVar != null) {
                    }
                    if (cursorQuery != null) {
                    }
                    z11 = z10;
                }
            } catch (Throwable unused4) {
                z10 = true;
            }
            try {
                aVar = fVar.f30416j;
                if (aVar != null) {
                    aVar.a(IMediaPlayer.MEDIA_INFO_OPEN_INPUT, 1);
                }
                if (cursorQuery != null) {
                    try {
                        cursorQuery.close();
                    } catch (Exception unused5) {
                    }
                }
                z11 = z10;
                if (arrayList.isEmpty()) {
                    fVar.c(arrayList, z11, null);
                    return;
                }
                return;
            } catch (Throwable th) {
                if (cursorQuery != null) {
                    try {
                        cursorQuery.close();
                    } catch (Exception unused6) {
                    }
                }
                throw th;
            }
        }
        if (cursorQuery != null) {
            try {
                cursorQuery.close();
            } catch (Exception unused7) {
            }
        }
        if (arrayList.isEmpty()) {
        }
    }
}
