package androidx.work.impl.workers;

import android.content.Context;
import android.database.Cursor;
import android.os.Build;
import android.text.TextUtils;
import androidx.work.ListenableWorker;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import androidx.work.impl.WorkDatabase;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import p037.p041.p042.LayoutInflaterFactory2C1494;
import p037.p109.C2409;
import p037.p109.p111.C2421;
import p037.p123.AbstractC2562;
import p037.p123.C2547;
import p037.p123.C2552;
import p037.p123.p124.C2604;
import p037.p123.p124.p133.C2661;
import p037.p123.p124.p133.C2663;
import p037.p123.p124.p133.C2668;
import p037.p123.p124.p133.C2676;
import p037.p123.p124.p133.C2682;
import p037.p123.p124.p133.C2694;
import p037.p123.p124.p133.InterfaceC2662;
import p037.p123.p124.p133.InterfaceC2667;
import p037.p123.p124.p133.InterfaceC2680;
import p037.p123.p124.p133.InterfaceC2693;

/* JADX INFO: loaded from: classes.dex */
public class DiagnosticsWorker extends Worker {

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public static final String f1489 = AbstractC2562.m4622("DiagnosticsWrkr");

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

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static String m884(InterfaceC2667 interfaceC2667, InterfaceC2693 interfaceC2693, InterfaceC2662 interfaceC2662, List<C2676> list) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\n Id \t Class Name\t %s\t State\t Unique Name\t Tags\t", Build.VERSION.SDK_INT >= 23 ? "Job Id" : "Alarm Id"));
        for (C2676 c2676 : list) {
            C2661 c2661M4739 = ((C2663) interfaceC2662).m4739(c2676.f8320);
            Integer numValueOf = c2661M4739 != null ? Integer.valueOf(c2661M4739.f8305) : null;
            String str = c2676.f8320;
            C2668 c2668 = (C2668) interfaceC2667;
            if (c2668 == null) {
                throw null;
            }
            C2409 c2409M4490 = C2409.m4490("SELECT name FROM workname WHERE work_spec_id=?", 1);
            if (str == null) {
                c2409M4490.bindNull(1);
            } else {
                c2409M4490.bindString(1, str);
            }
            c2668.f8311.m4478();
            Cursor cursorM4504 = C2421.m4504(c2668.f8311, c2409M4490, false, null);
            try {
                ArrayList arrayList = new ArrayList(cursorM4504.getCount());
                while (cursorM4504.moveToNext()) {
                    arrayList.add(cursorM4504.getString(0));
                }
                cursorM4504.close();
                c2409M4490.m4493();
                sb.append(String.format("\n%s\t %s\t %s\t %s\t %s\t %s\t", c2676.f8320, c2676.f8322, numValueOf, c2676.f8321.name(), TextUtils.join(",", arrayList), TextUtils.join(",", ((C2694) interfaceC2693).m4765(c2676.f8320))));
            } catch (Throwable th) {
                cursorM4504.close();
                c2409M4490.m4493();
                throw th;
            }
        }
        return sb.toString();
    }

    @Override // androidx.work.Worker
    /* JADX INFO: renamed from: ނ */
    public ListenableWorker.AbstractC0240 mo842() throws Throwable {
        C2409 c2409;
        InterfaceC2662 interfaceC2662;
        InterfaceC2667 interfaceC2667;
        InterfaceC2693 interfaceC2693;
        int i;
        WorkDatabase workDatabase = C2604.m4662(this.f1421).f8140;
        InterfaceC2680 interfaceC2680Mo850 = workDatabase.mo850();
        InterfaceC2667 interfaceC2667Mo848 = workDatabase.mo848();
        InterfaceC2693 interfaceC2693Mo851 = workDatabase.mo851();
        InterfaceC2662 interfaceC2662Mo847 = workDatabase.mo847();
        long jCurrentTimeMillis = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1L);
        C2682 c2682 = (C2682) interfaceC2680Mo850;
        if (c2682 == null) {
            throw null;
        }
        C2409 c2409M4490 = C2409.m4490("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` FROM workspec WHERE period_start_time >= ? AND state IN (2, 3, 5) ORDER BY period_start_time DESC", 1);
        c2409M4490.bindLong(1, jCurrentTimeMillis);
        c2682.f8347.m4478();
        Cursor cursorM4504 = C2421.m4504(c2682.f8347, c2409M4490, false, null);
        try {
            int iM2969 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "required_network_type");
            int iM29692 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "requires_charging");
            int iM29693 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "requires_device_idle");
            int iM29694 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "requires_battery_not_low");
            int iM29695 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "requires_storage_not_low");
            int iM29696 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "trigger_content_update_delay");
            int iM29697 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "trigger_max_content_delay");
            int iM29698 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "content_uri_triggers");
            int iM29699 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "id");
            int iM296910 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "state");
            int iM296911 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "worker_class_name");
            int iM296912 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "input_merger_class_name");
            int iM296913 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "input");
            int iM296914 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "output");
            c2409 = c2409M4490;
            try {
                int iM296915 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "initial_delay");
                int iM296916 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "interval_duration");
                int iM296917 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "flex_duration");
                int iM296918 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "run_attempt_count");
                int iM296919 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "backoff_policy");
                int iM296920 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "backoff_delay_duration");
                int iM296921 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "period_start_time");
                int iM296922 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "minimum_retention_duration");
                int iM296923 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "schedule_requested_at");
                int iM296924 = LayoutInflaterFactory2C1494.C1505.m2969(cursorM4504, "run_in_foreground");
                int i2 = iM296914;
                ArrayList arrayList = new ArrayList(cursorM4504.getCount());
                while (cursorM4504.moveToNext()) {
                    String string = cursorM4504.getString(iM29699);
                    int i3 = iM29699;
                    String string2 = cursorM4504.getString(iM296911);
                    int i4 = iM296911;
                    C2547 c2547 = new C2547();
                    int i5 = iM2969;
                    c2547.f8025 = LayoutInflaterFactory2C1494.C1505.m2984(cursorM4504.getInt(iM2969));
                    c2547.f8026 = cursorM4504.getInt(iM29692) != 0;
                    c2547.f8027 = cursorM4504.getInt(iM29693) != 0;
                    c2547.f8028 = cursorM4504.getInt(iM29694) != 0;
                    c2547.f8029 = cursorM4504.getInt(iM29695) != 0;
                    int i6 = iM29692;
                    c2547.f8030 = cursorM4504.getLong(iM29696);
                    c2547.f8031 = cursorM4504.getLong(iM29697);
                    c2547.f8032 = LayoutInflaterFactory2C1494.C1505.m2931(cursorM4504.getBlob(iM29698));
                    C2676 c2676 = new C2676(string, string2);
                    c2676.f8321 = LayoutInflaterFactory2C1494.C1505.m2988(cursorM4504.getInt(iM296910));
                    c2676.f8323 = cursorM4504.getString(iM296912);
                    c2676.f8324 = C2552.m4616(cursorM4504.getBlob(iM296913));
                    int i7 = i2;
                    c2676.f8325 = C2552.m4616(cursorM4504.getBlob(i7));
                    int i8 = iM296910;
                    i2 = i7;
                    int i9 = iM296915;
                    c2676.f8326 = cursorM4504.getLong(i9);
                    int i10 = iM296912;
                    int i11 = iM296916;
                    c2676.f8327 = cursorM4504.getLong(i11);
                    int i12 = iM296913;
                    int i13 = iM296917;
                    c2676.f8328 = cursorM4504.getLong(i13);
                    int i14 = iM296918;
                    c2676.f8330 = cursorM4504.getInt(i14);
                    int i15 = iM296919;
                    c2676.f8331 = LayoutInflaterFactory2C1494.C1505.m2977(cursorM4504.getInt(i15));
                    iM296917 = i13;
                    int i16 = iM296920;
                    c2676.f8332 = cursorM4504.getLong(i16);
                    int i17 = iM296921;
                    c2676.f8333 = cursorM4504.getLong(i17);
                    iM296921 = i17;
                    int i18 = iM296922;
                    c2676.f8334 = cursorM4504.getLong(i18);
                    iM296922 = i18;
                    int i19 = iM296923;
                    c2676.f8335 = cursorM4504.getLong(i19);
                    int i20 = iM296924;
                    c2676.f8336 = cursorM4504.getInt(i20) != 0;
                    c2676.f8329 = c2547;
                    arrayList.add(c2676);
                    iM296923 = i19;
                    iM296924 = i20;
                    iM296910 = i8;
                    iM296912 = i10;
                    iM296911 = i4;
                    iM29692 = i6;
                    iM2969 = i5;
                    iM296915 = i9;
                    iM29699 = i3;
                    iM296920 = i16;
                    iM296913 = i12;
                    iM296916 = i11;
                    iM296918 = i14;
                    iM296919 = i15;
                }
                cursorM4504.close();
                c2409.m4493();
                C2682 c26822 = (C2682) interfaceC2680Mo850;
                List<C2676> listM4758 = c26822.m4758();
                List<C2676> listM4749 = c26822.m4749();
                if (arrayList.isEmpty()) {
                    interfaceC2662 = interfaceC2662Mo847;
                    interfaceC2667 = interfaceC2667Mo848;
                    interfaceC2693 = interfaceC2693Mo851;
                    i = 0;
                } else {
                    i = 0;
                    AbstractC2562.m4623().mo4627(f1489, "Recently completed work:\n\n", new Throwable[0]);
                    interfaceC2662 = interfaceC2662Mo847;
                    interfaceC2667 = interfaceC2667Mo848;
                    interfaceC2693 = interfaceC2693Mo851;
                    AbstractC2562.m4623().mo4627(f1489, m884(interfaceC2667, interfaceC2693, interfaceC2662, arrayList), new Throwable[0]);
                }
                if (!((ArrayList) listM4758).isEmpty()) {
                    AbstractC2562.m4623().mo4627(f1489, "Running work:\n\n", new Throwable[i]);
                    AbstractC2562.m4623().mo4627(f1489, m884(interfaceC2667, interfaceC2693, interfaceC2662, listM4758), new Throwable[i]);
                }
                if (!((ArrayList) listM4749).isEmpty()) {
                    AbstractC2562.m4623().mo4627(f1489, "Enqueued work:\n\n", new Throwable[i]);
                    AbstractC2562.m4623().mo4627(f1489, m884(interfaceC2667, interfaceC2693, interfaceC2662, listM4749), new Throwable[i]);
                }
                return new ListenableWorker.AbstractC0240.C0243();
            } catch (Throwable th) {
                th = th;
                cursorM4504.close();
                c2409.m4493();
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
            c2409 = c2409M4490;
        }
    }
}
