package com.google.android.gms.internal.ads;

import android.content.Context;
import android.os.Binder;
import android.os.Parcel;
import android.os.RemoteException;
import androidx.annotation.Nullable;
import java.util.concurrent.ScheduledFuture;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public ScheduledFuture f17289a = null;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final mv1 f17290b = new mv1(this);

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

    @Nullable
    private xk zzd;

    @Nullable
    private Context zze;

    @Nullable
    private zk zzf;

    public final void a(Context context) {
        if (context == null) {
            return;
        }
        synchronized (this.f17291c) {
            try {
                if (this.zze != null) {
                    return;
                }
                this.zze = context.getApplicationContext();
                tn tnVar = ao.W4;
                n7.y yVar = n7.y.f31093e;
                if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                    h();
                } else {
                    if (((Boolean) yVar.f31096c.b(ao.V4)).booleanValue()) {
                        m7.n.C.f30468g.b(new rk(this));
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final vk b(yk ykVar) {
        synchronized (this.f17291c) {
            if (this.zzf == null) {
                return new vk();
            }
            try {
                if (this.zzd.c()) {
                    zk zkVar = this.zzf;
                    Parcel parcelO = zkVar.O();
                    aj.b(parcelO, ykVar);
                    Parcel parcelB0 = zkVar.B0(2, parcelO);
                    vk vkVar = (vk) aj.a(parcelB0, vk.CREATOR);
                    parcelB0.recycle();
                    return vkVar;
                }
                zk zkVar2 = this.zzf;
                Parcel parcelO2 = zkVar2.O();
                aj.b(parcelO2, ykVar);
                Parcel parcelB02 = zkVar2.B0(1, parcelO2);
                vk vkVar2 = (vk) aj.a(parcelB02, vk.CREATOR);
                parcelB02.recycle();
                return vkVar2;
            } catch (RemoteException unused) {
                return new vk();
            }
        }
    }

    public final long c(yk ykVar) {
        synchronized (this.f17291c) {
            try {
                if (this.zzf == null) {
                    return -2L;
                }
                if (this.zzd.c()) {
                    try {
                        zk zkVar = this.zzf;
                        Parcel parcelO = zkVar.O();
                        aj.b(parcelO, ykVar);
                        Parcel parcelB0 = zkVar.B0(3, parcelO);
                        long j10 = parcelB0.readLong();
                        parcelB0.recycle();
                        return j10;
                    } catch (RemoteException unused) {
                    }
                }
                return -2L;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final /* synthetic */ void d() {
        synchronized (this.f17291c) {
            try {
                xk xkVar = this.zzd;
                if (xkVar == null) {
                    return;
                }
                if (xkVar.isConnected() || this.zzd.isConnecting()) {
                    this.zzd.disconnect();
                }
                this.zzd = null;
                this.zzf = null;
                Binder.flushPendingCommands();
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final /* synthetic */ xk e() {
        return this.zzd;
    }

    public final /* synthetic */ void f() {
        this.zzd = null;
    }

    public final /* synthetic */ void g(zk zkVar) {
        this.zzf = zkVar;
    }

    public final void h() {
        xk xkVar;
        synchronized (this.f17291c) {
            try {
                if (this.zze != null && this.zzd == null) {
                    sk skVar = new sk(this);
                    tk tkVar = new tk(this);
                    synchronized (this) {
                        xkVar = new xk(this.zze, m7.n.C.f30481t.e(), skVar, tkVar);
                    }
                    this.zzd = xkVar;
                    xkVar.checkAvailabilityAndConnect();
                }
            } finally {
            }
        }
    }
}
