package com.google.ads.interactivemedia.v3.internal;

import android.os.Bundle;
import android.os.RemoteException;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.google.android.gms.common.api.internal.p;
import com.google.android.gms.common.api.internal.r;
import com.google.android.gms.common.api.internal.s;
import e8.c;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import w8.i;
import w8.k;

/* JADX INFO: loaded from: classes2.dex */
public final class zzej {
    private final zznf zza;
    private final zzfd zzb;
    private final int zzc;

    public zzej(zzei zzeiVar) {
        this.zza = new zznm(zzeiVar.zza);
        this.zzb = zzeiVar.zzc;
        this.zzc = zzeiVar.zzb;
    }

    @WorkerThread
    public final String zza(@Nullable com.google.ads.interactivemedia.v3.impl.zzau zzauVar, String str) {
        if (this.zzc <= 0) {
            zzfk.zzc("AdsIdentityTokenLoader: invalid parameter for gksTimeoutMs");
            return "";
        }
        long jCurrentTimeMillis = System.currentTimeMillis();
        try {
            final Bundle bundle = new Bundle();
            if (zzauVar != null) {
                Bundle bundle2 = new Bundle();
                bundle2.putString("x-afma-token-requester-type", zzauVar.toString());
                bundle.putBundle("extra_headers", bundle2);
            }
            zznf zznfVar = this.zza;
            r rVarA = s.a();
            rVarA.f8283b = false;
            rVarA.f8285d = new c[]{zzpo.zza};
            final zznm zznmVar = (zznm) zznfVar;
            rVarA.f8284c = new p() { // from class: com.google.ads.interactivemedia.v3.internal.zzni
                @Override // com.google.android.gms.common.api.internal.p
                public final void accept(Object obj, Object obj2) throws RemoteException {
                    ((zzna) ((zznn) obj).getService()).zzf(bundle, new zznk(zznmVar, (i) obj2));
                }
            };
            return (String) k.b(((zznm) zznfVar).doRead(rVarA.a()), this.zzc, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e10) {
            e = e10;
            this.zzb.zzg(com.google.ads.interactivemedia.v3.impl.data.zzbp.ADS_IDENTITY_TOKEN_LOADER, com.google.ads.interactivemedia.v3.impl.data.zzbq.GET_ADSIDENTITY_TOKEN, e);
            this.zzb.zzc(str).zzk(zzfd.zza(jCurrentTimeMillis, System.currentTimeMillis()));
            return "";
        } catch (ExecutionException e11) {
            e = e11;
            this.zzb.zzg(com.google.ads.interactivemedia.v3.impl.data.zzbp.ADS_IDENTITY_TOKEN_LOADER, com.google.ads.interactivemedia.v3.impl.data.zzbq.GET_ADSIDENTITY_TOKEN, e);
            this.zzb.zzc(str).zzk(zzfd.zza(jCurrentTimeMillis, System.currentTimeMillis()));
            return "";
        } catch (TimeoutException e12) {
            e = e12;
            this.zzb.zzg(com.google.ads.interactivemedia.v3.impl.data.zzbp.ADS_IDENTITY_TOKEN_LOADER, com.google.ads.interactivemedia.v3.impl.data.zzbq.GET_ADSIDENTITY_TOKEN, e);
            this.zzb.zzc(str).zzk(zzfd.zza(jCurrentTimeMillis, System.currentTimeMillis()));
            return "";
        }
    }
}
