package androidx.work.impl.workers;

import android.content.Context;
import android.text.TextUtils;
import androidx.work.ListenableWorker;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import androidx.work.impl.WorkDatabase;
import h6.i;
import h6.j;
import h6.m;
import h6.r;
import h6.s;
import h6.v;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import z5.k;

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

    /* renamed from: v, reason: collision with root package name */
    private static final String f6039v = k.f("DiagnosticsWrkr");

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

    private static String s(r rVar, String str, Integer num, String str2) {
        return String.format("\n%s\t %s\t %s\t %s\t %s\t %s\t", rVar.f20890a, rVar.f20892c, num, rVar.f20891b.name(), str, str2);
    }

    private static String t(m mVar, v vVar, j jVar, List list) {
        StringBuilder sb2 = new StringBuilder();
        sb2.append(String.format("\n Id \t Class Name\t %s\t State\t Unique Name\t Tags\t", "Job Id"));
        Iterator it = list.iterator();
        while (it.hasNext()) {
            r rVar = (r) it.next();
            i c10 = jVar.c(rVar.f20890a);
            sb2.append(s(rVar, TextUtils.join(",", mVar.b(rVar.f20890a)), c10 != null ? Integer.valueOf(c10.f20868b) : null, TextUtils.join(",", vVar.a(rVar.f20890a))));
        }
        return sb2.toString();
    }

    @Override // androidx.work.Worker
    public ListenableWorker.a r() {
        WorkDatabase s10 = a6.i.o(c()).s();
        s O = s10.O();
        m M = s10.M();
        v P = s10.P();
        j L = s10.L();
        List d10 = O.d(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1L));
        List j10 = O.j();
        List u10 = O.u(200);
        if (d10 != null && !d10.isEmpty()) {
            k c10 = k.c();
            String str = f6039v;
            c10.d(str, "Recently completed work:\n\n", new Throwable[0]);
            k.c().d(str, t(M, P, L, d10), new Throwable[0]);
        }
        if (j10 != null && !j10.isEmpty()) {
            k c11 = k.c();
            String str2 = f6039v;
            c11.d(str2, "Running work:\n\n", new Throwable[0]);
            k.c().d(str2, t(M, P, L, j10), new Throwable[0]);
        }
        if (u10 != null && !u10.isEmpty()) {
            k c12 = k.c();
            String str3 = f6039v;
            c12.d(str3, "Enqueued work:\n\n", new Throwable[0]);
            k.c().d(str3, t(M, P, L, u10), new Throwable[0]);
        }
        return ListenableWorker.a.e();
    }
}
