package o;

import com.google.android.gms.common.internal.Preconditions;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Hw0 extends Pc0 {
    public final Object a = new Object();
    public final C2513tI b = new C2513tI();
    public boolean c;
    public volatile boolean d;
    public Object e;
    public Exception f;

    @Override // o.Pc0
    public final Hw0 a(Executor executor, HT ht) {
        this.b.e(new Yq0(executor, ht));
        q();
        return this;
    }

    @Override // o.Pc0
    public final Hw0 b(Executor executor, LT lt) {
        this.b.e(new Yq0(executor, lt));
        q();
        return this;
    }

    @Override // o.Pc0
    public final Hw0 c(Executor executor, ST st) {
        this.b.e(new Yq0(executor, st));
        q();
        return this;
    }

    @Override // o.Pc0
    public final Hw0 d(Executor executor, InterfaceC0246Jm interfaceC0246Jm) {
        Hw0 hw0 = new Hw0();
        this.b.e(new C2847wp0(executor, interfaceC0246Jm, hw0, 1));
        q();
        return hw0;
    }

    @Override // o.Pc0
    public final Exception e() {
        Exception exc;
        synchronized (this.a) {
            exc = this.f;
        }
        return exc;
    }

    @Override // o.Pc0
    public final Object f() {
        Object obj;
        synchronized (this.a) {
            try {
                Preconditions.checkState(this.c, "Task is not yet complete");
                if (this.d) {
                    throw new CancellationException("Task is already canceled.");
                }
                Exception exc = this.f;
                if (exc != null) {
                    throw new G30(exc);
                }
                obj = this.e;
            } catch (Throwable th) {
                throw th;
            }
        }
        return obj;
    }

    @Override // o.Pc0
    public final boolean g() {
        boolean z;
        synchronized (this.a) {
            z = this.c;
        }
        return z;
    }

    @Override // o.Pc0
    public final boolean h() {
        boolean z;
        synchronized (this.a) {
            try {
                z = false;
                if (this.c && !this.d && this.f == null) {
                    z = true;
                }
            } finally {
            }
        }
        return z;
    }

    @Override // o.Pc0
    public final Hw0 i(Executor executor, InterfaceC2439sb0 interfaceC2439sb0) {
        Hw0 hw0 = new Hw0();
        this.b.e(new Yq0(executor, interfaceC2439sb0, hw0));
        q();
        return hw0;
    }

    @Override // o.Pc0
    public final Hw0 j(InterfaceC2439sb0 interfaceC2439sb0) {
        ExecutorC1921n20 executorC1921n20 = Rc0.a;
        Hw0 hw0 = new Hw0();
        this.b.e(new Yq0(executorC1921n20, interfaceC2439sb0, hw0));
        q();
        return hw0;
    }

    public final Hw0 k(Executor executor, InterfaceC0246Jm interfaceC0246Jm) {
        Hw0 hw0 = new Hw0();
        this.b.e(new C2847wp0(executor, interfaceC0246Jm, hw0, 0));
        q();
        return hw0;
    }

    public final void l(Exception exc) {
        Preconditions.checkNotNull(exc, "Exception must not be null");
        synchronized (this.a) {
            p();
            this.c = true;
            this.f = exc;
        }
        this.b.f(this);
    }

    public final void m(Object obj) {
        synchronized (this.a) {
            p();
            this.c = true;
            this.e = obj;
        }
        this.b.f(this);
    }

    public final void n() {
        synchronized (this.a) {
            try {
                if (this.c) {
                    return;
                }
                this.c = true;
                this.d = true;
                this.b.f(this);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final boolean o(Object obj) {
        synchronized (this.a) {
            try {
                if (this.c) {
                    return false;
                }
                this.c = true;
                this.e = obj;
                this.b.f(this);
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void p() {
        if (this.c) {
            int i = C2263qi.l;
            if (!g()) {
                throw new IllegalStateException("DuplicateTaskCompletionException can only be created from completed Task.");
            }
            Exception excE = e();
        }
    }

    public final void q() {
        synchronized (this.a) {
            try {
                if (this.c) {
                    this.b.f(this);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
