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

import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.google.ads.interactivemedia.v3.api.BaseRequest;
import com.google.ads.interactivemedia.v3.impl.data.TestingConfiguration;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import n8.h;
import w8.k;

/* JADX INFO: loaded from: classes2.dex */
public final class zzez {
    private final Context zza;
    private final boolean zzb;
    private final long zzc;
    private final TestingConfiguration zzd;
    private final zzfd zze;
    private final zzew zzf;
    private final zzej zzg;

    public zzez(Context context, zzew zzewVar, zzfd zzfdVar, @Nullable Map map, TestingConfiguration testingConfiguration) {
        int i10;
        this.zza = context;
        this.zzb = !zzewVar.zza;
        long j10 = zzewVar.zzb;
        this.zzc = j10 <= 0 ? 150L : j10;
        this.zzf = zzewVar;
        this.zzd = testingConfiguration;
        this.zze = zzfdVar;
        int i11 = zzewVar.zze;
        if (map != null) {
            try {
                i10 = Integer.parseInt((String) map.get("IDENTITY_TOKEN_CUSTOM_TIMEOUT_AND_MEASUREMENT"));
            } catch (NumberFormatException unused) {
                i10 = 0;
            }
            if (i10 > 0) {
                i11 = i10;
            }
        }
        this.zzg = new zzej(new zzei(context, i11, zzfdVar));
    }

    @WorkerThread
    private final Boolean zzb(zzeu zzeuVar) {
        try {
            return (Boolean) zzeuVar.zzc().get();
        } catch (InterruptedException | CancellationException | ExecutionException e10) {
            this.zze.zzg(com.google.ads.interactivemedia.v3.impl.data.zzbp.IDENTIFIER_INFO_FACTORY, com.google.ads.interactivemedia.v3.impl.data.zzbq.SAFE_BLOCKING_GET_IDLESS, e10);
            return Boolean.TRUE;
        }
    }

    /* JADX WARN: Unreachable blocks removed: 1, instructions: 1 */
    @Nullable
    @WorkerThread
    public final com.google.ads.interactivemedia.v3.impl.data.zzbn zza(BaseRequest baseRequest, zzeu zzeuVar, String str) {
        String str2;
        boolean z10;
        String string;
        String str3;
        String str4;
        int i10;
        String str5;
        String strZza = "";
        if (zzb(zzeuVar).booleanValue()) {
            return null;
        }
        int i11 = 0;
        try {
            com.google.android.gms.ads.identifier.a aVarA = com.google.android.gms.ads.identifier.b.a(this.zza);
            String id2 = aVarA.getId();
            str3 = "adid";
            z10 = aVarA.f7871a;
            string = id2;
        } catch (Exception | NoClassDefFoundError unused) {
            try {
                ContentResolver contentResolver = this.zza.getContentResolver();
                string = Settings.Secure.getString(contentResolver, "advertising_id");
                boolean z11 = Settings.Secure.getInt(contentResolver, "limit_ad_tracking") == 1;
                str3 = "afai";
                z10 = z11;
            } catch (Settings.SettingNotFoundException unused2) {
                zzfk.zzd("Failed to get advertising ID.");
                str2 = "";
                z10 = false;
                string = "";
            }
        }
        str2 = str3;
        if (this.zzb) {
            try {
                z7.b bVar = (z7.b) k.b(new h(this.zza).a(), this.zzc, TimeUnit.MILLISECONDS);
                str4 = bVar.f37064a;
                try {
                    i11 = bVar.f37065b;
                } catch (InterruptedException | ExecutionException | TimeoutException unused3) {
                    zzfk.zzd("Timeout getting AppSet ID.");
                } catch (Exception | NoClassDefFoundError | NoSuchMethodError unused4) {
                    zzfk.zzd("Unable to contact the App Set SDK.");
                }
            } catch (InterruptedException | ExecutionException | TimeoutException unused5) {
                str4 = "";
            } catch (Exception | NoClassDefFoundError | NoSuchMethodError unused6) {
                str4 = "";
            }
            i10 = i11;
            str5 = str4;
        } else {
            i10 = 0;
            str5 = "";
        }
        boolean zZzc = zzel.zzc(this.zza, this.zzd);
        if (baseRequest.zza().zza(this.zzf, this.zza, z10, zZzc)) {
            strZza = this.zzg.zza(Boolean.valueOf(zZzc).booleanValue() ? com.google.ads.interactivemedia.v3.impl.zzau.GTV : null, str);
        }
        return com.google.ads.interactivemedia.v3.impl.data.zzbn.create(string, str2, z10, str5, i10, strZza);
    }
}
