package com.google.ads.interactivemedia.pal;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.internal.pal.q9;
import com.google.android.gms.internal.pal.z4;
import com.google.android.gms.internal.pal.zzagc;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import w8.b;
import w8.h;
import w8.j;
import w8.k;
import w8.t;

/* JADX INFO: loaded from: classes2.dex */
public final class NonceManager {

    @VisibleForTesting
    static final zzagc zza = new zzagc(q9.c(1000, 3));

    @VisibleForTesting
    static final zzagc zzb = new zzagc(q9.c(1000, 5));
    public static final /* synthetic */ int zzc = 0;
    private final Context zzd;
    private final ExecutorService zze;
    private final h zzf;
    private final zzax zzg;
    private final zzav zzh;
    private final String zzi;
    private boolean zzj = false;

    @Nullable
    private String zzk;

    public NonceManager(@NonNull Context context, @NonNull Handler handler, @NonNull ExecutorService executorService, @NonNull h hVar, @NonNull zzax zzaxVar, @NonNull String str) {
        this.zzd = context;
        this.zze = executorService;
        this.zzf = hVar;
        this.zzg = zzaxVar;
        this.zzh = new zzav(handler, zzb);
        this.zzi = str;
    }

    public static /* bridge */ /* synthetic */ Activity zza(NonceManager nonceManager) {
        Context context = nonceManager.zzd;
        if (context instanceof Activity) {
            return (Activity) context;
        }
        return null;
    }

    @NonNull
    public String getNonce() {
        return this.zzi;
    }

    public void sendAdClick() {
        k.f(this.zzf.e(this.zze, new b() { // from class: com.google.ads.interactivemedia.pal.zzan
            @Override // w8.b
            public final Object then(h hVar) {
                return this.zza.zzc(hVar);
            }
        }), zza.a(), TimeUnit.MILLISECONDS).e(this.zze, new b() { // from class: com.google.ads.interactivemedia.pal.zzao
            @Override // w8.b
            public final Object then(h hVar) throws Exception {
                this.zza.zzd(hVar);
                return null;
            }
        });
    }

    @Deprecated
    public void sendAdImpression() {
    }

    public void sendAdTouch(@NonNull final MotionEvent motionEvent) {
        k.f(this.zzf.e(this.zze, new b() { // from class: com.google.ads.interactivemedia.pal.zzal
            @Override // w8.b
            public final Object then(h hVar) {
                MotionEvent motionEvent2 = motionEvent;
                int i10 = NonceManager.zzc;
                z4 z4Var = (z4) hVar.g();
                z4Var.getClass();
                z4Var.f21400a.zzl(new k8.b(motionEvent2));
                return null;
            }
        }), zza.a(), TimeUnit.MILLISECONDS).e(this.zze, new b() { // from class: com.google.ads.interactivemedia.pal.zzam
            @Override // w8.b
            public final Object then(h hVar) throws Exception {
                this.zza.zze(hVar);
                return null;
            }
        });
    }

    public void sendPlaybackEnd() {
        this.zzh.zzd();
        if (this.zzj) {
            this.zzj = false;
            this.zzg.zza(8, this.zzk);
        }
    }

    public void sendPlaybackStart() {
        if (this.zzj) {
            return;
        }
        this.zzj = true;
        t tVarF = k.f(this.zzf.e(this.zze, new zzas(this)), zza.a(), TimeUnit.MILLISECONDS);
        tVarF.e(this.zze, new b() { // from class: com.google.ads.interactivemedia.pal.zzap
            @Override // w8.b
            public final Object then(h hVar) throws Exception {
                this.zza.zzf(hVar);
                return null;
            }
        });
        tVarF.e(j.f34225a, new b() { // from class: com.google.ads.interactivemedia.pal.zzaq
            @Override // w8.b
            public final Object then(h hVar) throws Exception {
                this.zza.zzg(hVar);
                return null;
            }
        });
    }

    public final String zzc(h hVar) throws Exception {
        z4 z4Var = (z4) hVar.g();
        Context context = this.zzd;
        z4Var.getClass();
        return z4Var.f21400a.zze(new k8.b(context), "");
    }

    public final /* synthetic */ Void zzd(h hVar) throws Exception {
        this.zzg.zza(4, hVar.j() ? (String) hVar.g() : null);
        return null;
    }

    public final /* synthetic */ Void zze(h hVar) throws Exception {
        this.zzg.zza(5, null);
        return null;
    }

    public final /* synthetic */ Void zzf(h hVar) throws Exception {
        String str = hVar.j() ? (String) hVar.g() : null;
        this.zzk = str;
        this.zzg.zza(6, str);
        return null;
    }

    public final /* synthetic */ Void zzg(h hVar) throws Exception {
        if (!this.zzj) {
            return null;
        }
        this.zzh.zzc(new zzar(this));
        return null;
    }
}
