package androidx.work.impl;

import androidx.work.s;
import androidx.work.u;
import com.google.common.util.concurrent.w;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f4632a = 1;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f4633b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f4634c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Object f4635d;

    public p(r rVar, androidx.work.impl.utils.futures.i iVar, androidx.work.impl.utils.futures.i iVar2) {
        this.f4635d = rVar;
        this.f4633b = iVar;
        this.f4634c = iVar2;
    }

    @Override // java.lang.Runnable
    public final void run() {
        boolean zBooleanValue = true;
        try {
            switch (this.f4632a) {
                case 0:
                    try {
                        ((w) this.f4633b).get();
                        u uVarC = u.c();
                        int i10 = r.V;
                        String.format("Starting work for %s", ((r) this.f4635d).f4648e.f30820c);
                        uVarC.a(new Throwable[0]);
                        Object obj = this.f4635d;
                        ((r) obj).mInnerFuture = ((r) obj).f4649f.startWork();
                        ((androidx.work.impl.utils.futures.i) this.f4634c).j(((r) this.f4635d).mInnerFuture);
                        return;
                    } catch (Throwable th) {
                        ((androidx.work.impl.utils.futures.i) this.f4634c).i(th);
                        return;
                    }
                case 1:
                    try {
                        zBooleanValue = ((Boolean) ((w) this.f4633b).get()).booleanValue();
                        break;
                    } catch (InterruptedException | ExecutionException unused) {
                    }
                    ((b) this.f4634c).onExecuted((String) this.f4635d, zBooleanValue);
                    return;
                default:
                    try {
                        s sVar = (s) ((androidx.work.impl.utils.futures.i) this.f4634c).get();
                        if (sVar == null) {
                            u uVarC2 = u.c();
                            int i11 = r.V;
                            String.format("%s returned a null result. Treating it as a failure.", ((r) this.f4635d).f4648e.f30820c);
                            uVarC2.b(new Throwable[0]);
                        } else {
                            u uVarC3 = u.c();
                            int i12 = r.V;
                            String.format("%s returned a %s result.", ((r) this.f4635d).f4648e.f30820c, sVar);
                            uVarC3.a(new Throwable[0]);
                            ((r) this.f4635d).f4651h = sVar;
                        }
                        break;
                    } catch (InterruptedException e10) {
                        e = e10;
                        u uVarC4 = u.c();
                        int i13 = r.V;
                        String.format("%s failed because it threw an exception/error", (String) this.f4633b);
                        uVarC4.b(e);
                    } catch (CancellationException e11) {
                        u uVarC5 = u.c();
                        int i14 = r.V;
                        String.format("%s was cancelled", (String) this.f4633b);
                        uVarC5.d(e11);
                    } catch (ExecutionException e12) {
                        e = e12;
                        u uVarC42 = u.c();
                        int i132 = r.V;
                        String.format("%s failed because it threw an exception/error", (String) this.f4633b);
                        uVarC42.b(e);
                    }
                    ((r) this.f4635d).c();
                    return;
            }
        } catch (Throwable th2) {
            ((r) this.f4635d).c();
            throw th2;
        }
        ((r) this.f4635d).c();
        throw th2;
    }

    public p(r rVar, androidx.work.impl.utils.futures.i iVar, String str) {
        this.f4635d = rVar;
        this.f4634c = iVar;
        this.f4633b = str;
    }

    public p(b bVar, String str, androidx.work.impl.utils.futures.i iVar) {
        this.f4634c = bVar;
        this.f4635d = str;
        this.f4633b = iVar;
    }
}
