package androidx.work.impl.workers;

import android.content.Context;
import android.database.Cursor;
import android.os.CancellationSignal;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.datastore.preferences.core.c;
import androidx.room.RoomDatabase;
import androidx.room.s0;
import androidx.room.util.a;
import androidx.room.util.b;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import androidx.work.e;
import androidx.work.i;
import androidx.work.impl.WorkDatabase;
import androidx.work.s;
import androidx.work.u;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import n4.g;
import n4.h;
import n4.j;
import n4.o;
import n4.p;
import n4.r;
import n4.t;
import xyz.stream.download.config.InnerConstant;
import xyz.stream.utils.f;

/* JADX INFO: loaded from: classes.dex */
@RestrictTo({RestrictTo.Scope.f556b})
public class DiagnosticsWorker extends Worker {
    static {
        u.e("DiagnosticsWrkr");
    }

    public DiagnosticsWorker(@NonNull Context context, @NonNull WorkerParameters workerParameters) {
        super(context, workerParameters);
    }

    public static String a(j jVar, t tVar, h hVar, ArrayList arrayList) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\n Id \t Class Name\t %s\t State\t Unique Name\t Tags\t", "Job Id"));
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            o oVar = (o) it.next();
            g systemIdInfo = ((xyz.stream.utils.t) hVar).getSystemIdInfo(oVar.f30818a);
            Integer numValueOf = systemIdInfo != null ? Integer.valueOf(systemIdInfo.f30809b) : null;
            String str = oVar.f30818a;
            fe.h hVar2 = (fe.h) jVar;
            hVar2.getClass();
            s0 s0VarK = s0.k(1, "SELECT name FROM workname WHERE work_spec_id=?");
            if (str == null) {
                s0VarK.d(1);
            } else {
                s0VarK.l(1, str);
            }
            ((RoomDatabase) hVar2.f26080b).assertNotSuspendingTransaction();
            Cursor cursorC = b.c((RoomDatabase) hVar2.f26080b, s0VarK);
            try {
                ArrayList arrayList2 = new ArrayList(cursorC.getCount());
                while (cursorC.moveToNext()) {
                    arrayList2.add(cursorC.getString(0));
                }
                cursorC.close();
                s0VarK.m();
                sb.append(workSpecRow(oVar, TextUtils.join(",", arrayList2), numValueOf, TextUtils.join(",", ((f) tVar).u(oVar.f30818a))));
            } catch (Throwable th) {
                cursorC.close();
                s0VarK.m();
                throw th;
            }
        }
        return sb.toString();
    }

    @NonNull
    private static String workSpecRow(@NonNull o oVar, @Nullable String str, @Nullable Integer num, @NonNull String str2) {
        return String.format("\n%s\t %s\t %s\t %s\t %s\t %s\t", oVar.f30818a, oVar.f30820c, num, oVar.f30819b.name(), str, str2);
    }

    @Override // androidx.work.Worker
    public final s doWork() throws Throwable {
        s0 s0Var;
        int iA;
        int iA2;
        int iA3;
        int iA4;
        int iA5;
        int iA6;
        int iA7;
        int iA8;
        int iA9;
        int iA10;
        int iA11;
        int iA12;
        int iA13;
        int iA14;
        ArrayList arrayList;
        h hVar;
        j jVar;
        t tVar;
        int i10;
        WorkDatabase workDatabase = androidx.work.impl.o.b(getApplicationContext()).f4625c;
        p pVarWorkSpecDao = workDatabase.workSpecDao();
        j jVarWorkNameDao = workDatabase.workNameDao();
        t tVarWorkTagDao = workDatabase.workTagDao();
        h hVarSystemIdInfoDao = workDatabase.systemIdInfoDao();
        long jCurrentTimeMillis = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1L);
        r rVar = (r) pVarWorkSpecDao;
        rVar.getClass();
        s0 s0VarK = s0.k(1, "SELECT `required_network_type`, `requires_charging`, `requires_device_idle`, `requires_battery_not_low`, `requires_storage_not_low`, `trigger_content_update_delay`, `trigger_max_content_delay`, `content_uri_triggers`, `WorkSpec`.`id` AS `id`, `WorkSpec`.`state` AS `state`, `WorkSpec`.`worker_class_name` AS `worker_class_name`, `WorkSpec`.`input_merger_class_name` AS `input_merger_class_name`, `WorkSpec`.`input` AS `input`, `WorkSpec`.`output` AS `output`, `WorkSpec`.`initial_delay` AS `initial_delay`, `WorkSpec`.`interval_duration` AS `interval_duration`, `WorkSpec`.`flex_duration` AS `flex_duration`, `WorkSpec`.`run_attempt_count` AS `run_attempt_count`, `WorkSpec`.`backoff_policy` AS `backoff_policy`, `WorkSpec`.`backoff_delay_duration` AS `backoff_delay_duration`, `WorkSpec`.`period_start_time` AS `period_start_time`, `WorkSpec`.`minimum_retention_duration` AS `minimum_retention_duration`, `WorkSpec`.`schedule_requested_at` AS `schedule_requested_at`, `WorkSpec`.`run_in_foreground` AS `run_in_foreground`, `WorkSpec`.`out_of_quota_policy` AS `out_of_quota_policy` FROM workspec WHERE period_start_time >= ? AND state IN (2, 3, 5) ORDER BY period_start_time DESC");
        s0VarK.a(1, jCurrentTimeMillis);
        RoomDatabase roomDatabase = (RoomDatabase) rVar.f30838b;
        roomDatabase.assertNotSuspendingTransaction();
        Cursor cursorQuery = roomDatabase.query(s0VarK, (CancellationSignal) null);
        try {
            iA = a.a(cursorQuery, "required_network_type");
            iA2 = a.a(cursorQuery, "requires_charging");
            iA3 = a.a(cursorQuery, "requires_device_idle");
            iA4 = a.a(cursorQuery, "requires_battery_not_low");
            iA5 = a.a(cursorQuery, "requires_storage_not_low");
            iA6 = a.a(cursorQuery, "trigger_content_update_delay");
            iA7 = a.a(cursorQuery, "trigger_max_content_delay");
            iA8 = a.a(cursorQuery, "content_uri_triggers");
            iA9 = a.a(cursorQuery, InnerConstant.Db.f36069id);
            iA10 = a.a(cursorQuery, "state");
            iA11 = a.a(cursorQuery, "worker_class_name");
            iA12 = a.a(cursorQuery, "input_merger_class_name");
            iA13 = a.a(cursorQuery, "input");
            iA14 = a.a(cursorQuery, "output");
            s0Var = s0VarK;
        } catch (Throwable th) {
            th = th;
            s0Var = s0VarK;
        }
        try {
            int iA15 = a.a(cursorQuery, "initial_delay");
            int iA16 = a.a(cursorQuery, "interval_duration");
            int iA17 = a.a(cursorQuery, "flex_duration");
            int iA18 = a.a(cursorQuery, "run_attempt_count");
            int iA19 = a.a(cursorQuery, "backoff_policy");
            int iA20 = a.a(cursorQuery, "backoff_delay_duration");
            int iA21 = a.a(cursorQuery, "period_start_time");
            int iA22 = a.a(cursorQuery, "minimum_retention_duration");
            int iA23 = a.a(cursorQuery, "schedule_requested_at");
            int iA24 = a.a(cursorQuery, "run_in_foreground");
            int iA25 = a.a(cursorQuery, "out_of_quota_policy");
            int i11 = iA14;
            ArrayList arrayList2 = new ArrayList(cursorQuery.getCount());
            while (true) {
                arrayList = arrayList2;
                if (!cursorQuery.moveToNext()) {
                    break;
                }
                String string = cursorQuery.getString(iA9);
                String string2 = cursorQuery.getString(iA11);
                int i12 = iA11;
                e eVar = new e();
                int i13 = iA;
                eVar.f4549a = c.j(cursorQuery.getInt(iA));
                eVar.f4550b = cursorQuery.getInt(iA2) != 0;
                eVar.f4551c = cursorQuery.getInt(iA3) != 0;
                eVar.f4552d = cursorQuery.getInt(iA4) != 0;
                eVar.f4553e = cursorQuery.getInt(iA5) != 0;
                int i14 = iA2;
                int i15 = iA3;
                eVar.f4554f = cursorQuery.getLong(iA6);
                eVar.f4555g = cursorQuery.getLong(iA7);
                eVar.setContentUriTriggers(c.a(cursorQuery.getBlob(iA8)));
                o oVar = new o(string, string2);
                oVar.f30819b = c.l(cursorQuery.getInt(iA10));
                oVar.f30821d = cursorQuery.getString(iA12);
                oVar.f30822e = i.a(cursorQuery.getBlob(iA13));
                int i16 = i11;
                oVar.f30823f = i.a(cursorQuery.getBlob(i16));
                i11 = i16;
                int i17 = iA12;
                int i18 = iA15;
                oVar.f30824g = cursorQuery.getLong(i18);
                int i19 = iA13;
                int i20 = iA16;
                oVar.f30825h = cursorQuery.getLong(i20);
                int i21 = iA10;
                int i22 = iA17;
                oVar.f30826i = cursorQuery.getLong(i22);
                int i23 = iA18;
                oVar.f30828k = cursorQuery.getInt(i23);
                int i24 = iA19;
                oVar.f30829l = c.i(cursorQuery.getInt(i24));
                iA17 = i22;
                int i25 = iA20;
                oVar.f30830m = cursorQuery.getLong(i25);
                int i26 = iA21;
                oVar.f30831n = cursorQuery.getLong(i26);
                iA21 = i26;
                int i27 = iA22;
                oVar.f30832o = cursorQuery.getLong(i27);
                int i28 = iA23;
                oVar.f30833p = cursorQuery.getLong(i28);
                int i29 = iA24;
                oVar.f30834q = cursorQuery.getInt(i29) != 0;
                int i30 = iA25;
                oVar.f30835r = c.k(cursorQuery.getInt(i30));
                oVar.f30827j = eVar;
                arrayList.add(oVar);
                iA25 = i30;
                iA13 = i19;
                iA2 = i14;
                iA16 = i20;
                iA18 = i23;
                iA23 = i28;
                iA24 = i29;
                iA22 = i27;
                iA15 = i18;
                iA12 = i17;
                iA3 = i15;
                iA = i13;
                arrayList2 = arrayList;
                iA11 = i12;
                iA20 = i25;
                iA10 = i21;
                iA19 = i24;
            }
            cursorQuery.close();
            s0Var.m();
            ArrayList arrayListJ = rVar.j();
            ArrayList arrayListG = rVar.g();
            if (arrayList.isEmpty()) {
                hVar = hVarSystemIdInfoDao;
                jVar = jVarWorkNameDao;
                tVar = tVarWorkTagDao;
                i10 = 0;
            } else {
                i10 = 0;
                u.c().d(new Throwable[0]);
                u uVarC = u.c();
                hVar = hVarSystemIdInfoDao;
                jVar = jVarWorkNameDao;
                tVar = tVarWorkTagDao;
                a(jVar, tVar, hVar, arrayList);
                uVarC.d(new Throwable[0]);
            }
            if (!arrayListJ.isEmpty()) {
                u.c().d(new Throwable[i10]);
                u uVarC2 = u.c();
                a(jVar, tVar, hVar, arrayListJ);
                uVarC2.d(new Throwable[i10]);
            }
            if (!arrayListG.isEmpty()) {
                u.c().d(new Throwable[i10]);
                u uVarC3 = u.c();
                a(jVar, tVar, hVar, arrayListG);
                uVarC3.d(new Throwable[i10]);
            }
            return new androidx.work.r(i.f4564b);
        } catch (Throwable th2) {
            th = th2;
            cursorQuery.close();
            s0Var.m();
            throw th;
        }
    }
}
