package w8;

import androidx.annotation.Nullable;
import com.google.android.gms.common.internal.w;
import com.google.android.gms.tasks.DuplicateTaskCompletionException;
import com.google.android.gms.tasks.RuntimeExecutionException;
import java.io.IOException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;

/* JADX INFO: loaded from: classes2.dex */
public final class t extends h {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f34250a = new Object();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final n5.s f34251b = new n5.s(8);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f34252c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public volatile boolean f34253d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Exception f34254e;

    @Nullable
    private Object zze;

    @Override // w8.h
    public final t a(Executor executor, d dVar) {
        this.f34251b.f(new q(executor, dVar));
        m();
        return this;
    }

    @Override // w8.h
    public final t b(d dVar) {
        this.f34251b.f(new q(j.f34225a, dVar));
        m();
        return this;
    }

    @Override // w8.h
    public final t c(Executor executor, e eVar) {
        this.f34251b.f(new q(executor, eVar));
        m();
        return this;
    }

    @Override // w8.h
    public final t d(Executor executor, f fVar) {
        this.f34251b.f(new q(executor, fVar));
        m();
        return this;
    }

    @Override // w8.h
    public final t e(Executor executor, b bVar) {
        t tVar = new t();
        this.f34251b.f(new o(executor, bVar, tVar, 0));
        m();
        return tVar;
    }

    @Override // w8.h
    public final t f(Executor executor, b bVar) {
        t tVar = new t();
        this.f34251b.f(new o(executor, bVar, tVar, 1));
        m();
        return tVar;
    }

    @Override // w8.h
    public final Object g() {
        Object obj;
        synchronized (this.f34250a) {
            try {
                w.h(this.f34252c, "Task is not yet complete");
                if (this.f34253d) {
                    throw new CancellationException("Task is already canceled.");
                }
                Exception exc = this.f34254e;
                if (exc != null) {
                    throw new RuntimeExecutionException(exc);
                }
                obj = this.zze;
            } catch (Throwable th) {
                throw th;
            }
        }
        return obj;
    }

    @Override // w8.h
    @Nullable
    public final Exception getException() {
        Exception exc;
        synchronized (this.f34250a) {
            exc = this.f34254e;
        }
        return exc;
    }

    @Override // w8.h
    public final Object h() {
        Object obj;
        synchronized (this.f34250a) {
            try {
                w.h(this.f34252c, "Task is not yet complete");
                if (this.f34253d) {
                    throw new CancellationException("Task is already canceled.");
                }
                if (IOException.class.isInstance(this.f34254e)) {
                    throw ((Throwable) IOException.class.cast(this.f34254e));
                }
                Exception exc = this.f34254e;
                if (exc != null) {
                    throw new RuntimeExecutionException(exc);
                }
                obj = this.zze;
            } catch (Throwable th) {
                throw th;
            }
        }
        return obj;
    }

    @Override // w8.h
    public final boolean i() {
        boolean z10;
        synchronized (this.f34250a) {
            z10 = this.f34252c;
        }
        return z10;
    }

    @Override // w8.h
    public final boolean j() {
        boolean z10;
        synchronized (this.f34250a) {
            try {
                z10 = false;
                if (this.f34252c && !this.f34253d && this.f34254e == null) {
                    z10 = true;
                }
            } finally {
            }
        }
        return z10;
    }

    public final void k(Exception exc) {
        if (exc == null) {
            throw new NullPointerException("Exception must not be null");
        }
        synchronized (this.f34250a) {
            if (this.f34252c) {
                throw DuplicateTaskCompletionException.a(this);
            }
            this.f34252c = true;
            this.f34254e = exc;
        }
        this.f34251b.g(this);
    }

    public final void l() {
        synchronized (this.f34250a) {
            try {
                if (this.f34252c) {
                    return;
                }
                this.f34252c = true;
                this.f34253d = true;
                this.f34251b.g(this);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void m() {
        synchronized (this.f34250a) {
            try {
                if (this.f34252c) {
                    this.f34251b.g(this);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void zzb(@Nullable Object obj) {
        synchronized (this.f34250a) {
            if (this.f34252c) {
                throw DuplicateTaskCompletionException.a(this);
            }
            this.f34252c = true;
            this.zze = obj;
        }
        this.f34251b.g(this);
    }

    public final boolean zze(@Nullable Object obj) {
        synchronized (this.f34250a) {
            try {
                if (this.f34252c) {
                    return false;
                }
                this.f34252c = true;
                this.zze = obj;
                this.f34251b.g(this);
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
