package com.google.android.gms.tasks; import android.app.Activity; import com.google.android.gms.common.internal.Preconditions; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public final class zzw extends Task { private final Object zza = new Object(); private final zzr zzb = new zzr(); private boolean zzc; private volatile boolean zzd; private Object zze; private Exception zzf; private final void zzf() { Preconditions.checkState(this.zzc, "Task is not yet complete"); } private final void zzg() { if (this.zzd) { throw new CancellationException("Task is already canceled."); } } private final void zzh() { if (this.zzc) { throw DuplicateTaskCompletionException.of(this); } } private final void zzi() { synchronized (this.zza) { if (this.zzc) { this.zzb.zzb(this); } } } @Override // com.google.android.gms.tasks.Task public final Task addOnCanceledListener(Activity activity, OnCanceledListener onCanceledListener) { zzh zzhVar = new zzh(TaskExecutors.MAIN_THREAD, onCanceledListener); this.zzb.zza(zzhVar); zzv.zza(activity).zzb(zzhVar); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnCompleteListener(Activity activity, OnCompleteListener onCompleteListener) { zzj zzjVar = new zzj(TaskExecutors.MAIN_THREAD, onCompleteListener); this.zzb.zza(zzjVar); zzv.zza(activity).zzb(zzjVar); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnFailureListener(Activity activity, OnFailureListener onFailureListener) { zzl zzlVar = new zzl(TaskExecutors.MAIN_THREAD, onFailureListener); this.zzb.zza(zzlVar); zzv.zza(activity).zzb(zzlVar); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnSuccessListener(Activity activity, OnSuccessListener onSuccessListener) { zzn zznVar = new zzn(TaskExecutors.MAIN_THREAD, onSuccessListener); this.zzb.zza(zznVar); zzv.zza(activity).zzb(zznVar); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final Task continueWith(Continuation continuation) { return continueWith(TaskExecutors.MAIN_THREAD, continuation); } @Override // com.google.android.gms.tasks.Task public final Task continueWithTask(Continuation> continuation) { return continueWithTask(TaskExecutors.MAIN_THREAD, continuation); } @Override // com.google.android.gms.tasks.Task public final Exception getException() { Exception exc; synchronized (this.zza) { exc = this.zzf; } return exc; } @Override // com.google.android.gms.tasks.Task public final TResult getResult() { TResult tresult; synchronized (this.zza) { zzf(); zzg(); Exception exc = this.zzf; if (exc != null) { throw new RuntimeExecutionException(exc); } tresult = (TResult) this.zze; } return tresult; } @Override // com.google.android.gms.tasks.Task public final boolean isComplete() { boolean z; synchronized (this.zza) { z = this.zzc; } return z; } @Override // com.google.android.gms.tasks.Task public final boolean isSuccessful() { boolean z; synchronized (this.zza) { z = this.zzc && !this.zzd && this.zzf == null; } return z; } @Override // com.google.android.gms.tasks.Task public final Task onSuccessTask(SuccessContinuation successContinuation) { Executor executor = TaskExecutors.MAIN_THREAD; zzw zzwVar = new zzw(); this.zzb.zza(new zzp(executor, successContinuation, zzwVar)); zzi(); return zzwVar; } public final void zza(Exception exc) { Preconditions.checkNotNull(exc, "Exception must not be null"); synchronized (this.zza) { zzh(); this.zzc = true; this.zzf = exc; } this.zzb.zzb(this); } public final void zzb(Object obj) { synchronized (this.zza) { zzh(); this.zzc = true; this.zze = obj; } this.zzb.zzb(this); } public final boolean zzc() { synchronized (this.zza) { if (this.zzc) { return false; } this.zzc = true; this.zzd = true; this.zzb.zzb(this); return true; } } public final boolean zzd(Exception exc) { Preconditions.checkNotNull(exc, "Exception must not be null"); synchronized (this.zza) { if (this.zzc) { return false; } this.zzc = true; this.zzf = exc; this.zzb.zzb(this); return true; } } public final boolean zze(Object obj) { synchronized (this.zza) { if (this.zzc) { return false; } this.zzc = true; this.zze = obj; this.zzb.zzb(this); return true; } } @Override // com.google.android.gms.tasks.Task public final Task continueWith(Executor executor, Continuation continuation) { zzw zzwVar = new zzw(); this.zzb.zza(new zzd(executor, continuation, zzwVar)); zzi(); return zzwVar; } @Override // com.google.android.gms.tasks.Task public final Task continueWithTask(Executor executor, Continuation> continuation) { zzw zzwVar = new zzw(); this.zzb.zza(new zzf(executor, continuation, zzwVar)); zzi(); return zzwVar; } @Override // com.google.android.gms.tasks.Task public final Task addOnCanceledListener(OnCanceledListener onCanceledListener) { addOnCanceledListener(TaskExecutors.MAIN_THREAD, onCanceledListener); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnCompleteListener(OnCompleteListener onCompleteListener) { this.zzb.zza(new zzj(TaskExecutors.MAIN_THREAD, onCompleteListener)); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnFailureListener(OnFailureListener onFailureListener) { addOnFailureListener(TaskExecutors.MAIN_THREAD, onFailureListener); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnSuccessListener(OnSuccessListener onSuccessListener) { addOnSuccessListener(TaskExecutors.MAIN_THREAD, onSuccessListener); return this; } @Override // com.google.android.gms.tasks.Task public final Task onSuccessTask(Executor executor, SuccessContinuation successContinuation) { zzw zzwVar = new zzw(); this.zzb.zza(new zzp(executor, successContinuation, zzwVar)); zzi(); return zzwVar; } @Override // com.google.android.gms.tasks.Task public final Task addOnCanceledListener(Executor executor, OnCanceledListener onCanceledListener) { this.zzb.zza(new zzh(executor, onCanceledListener)); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnFailureListener(Executor executor, OnFailureListener onFailureListener) { this.zzb.zza(new zzl(executor, onFailureListener)); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final Task addOnSuccessListener(Executor executor, OnSuccessListener onSuccessListener) { this.zzb.zza(new zzn(executor, onSuccessListener)); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final TResult getResult(Class cls) throws Throwable { TResult tresult; synchronized (this.zza) { zzf(); zzg(); if (cls.isInstance(this.zzf)) { throw cls.cast(this.zzf); } Exception exc = this.zzf; if (exc != null) { throw new RuntimeExecutionException(exc); } tresult = (TResult) this.zze; } return tresult; } @Override // com.google.android.gms.tasks.Task public final Task addOnCompleteListener(Executor executor, OnCompleteListener onCompleteListener) { this.zzb.zza(new zzj(executor, onCompleteListener)); zzi(); return this; } @Override // com.google.android.gms.tasks.Task public final boolean isCanceled() { return this.zzd; } }