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

import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Handler;
import android.os.IBinder;
import android.os.IInterface;
import androidx.annotation.Nullable;
import java.util.ArrayList;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Context f11837b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final hq1 f11838c;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f11841f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Intent f11842g;

    @Nullable
    private ServiceConnection zzi;

    @Nullable
    private IInterface zzj;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ArrayList f11840e = new ArrayList();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final String f11839d = "OverlayDisplayService";

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final uq1 f11836a = za2.e(new ff0());

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final eq1 f11843h = new IBinder.DeathRecipient() { // from class: com.google.android.gms.internal.ads.eq1
        @Override // android.os.IBinder.DeathRecipient
        public final /* synthetic */ void binderDied() {
            gq1 gq1Var = this.f10899a;
            gq1Var.f11838c.zza("%s : Binder has died.", gq1Var.f11839d);
            ArrayList arrayList = gq1Var.f11840e;
            synchronized (arrayList) {
                arrayList.clear();
            }
        }
    };

    /* JADX WARN: Type inference failed for: r2v4, types: [com.google.android.gms.internal.ads.eq1] */
    public gq1(Context context, hq1 hq1Var, Intent intent) {
        this.f11837b = context;
        this.f11838c = hq1Var;
        this.f11842g = intent;
    }

    public final /* synthetic */ void a(Runnable runnable) {
        if (this.zzj != null || this.f11841f) {
            if (!this.f11841f) {
                runnable.run();
                return;
            }
            this.f11838c.zza("Waiting to bind to the service.", new Object[0]);
            ArrayList arrayList = this.f11840e;
            synchronized (arrayList) {
                arrayList.add(runnable);
            }
            return;
        }
        this.f11838c.zza("Initiate binding to the service.", new Object[0]);
        ArrayList arrayList2 = this.f11840e;
        synchronized (arrayList2) {
            arrayList2.add(runnable);
        }
        cq1 cq1Var = new cq1(this);
        this.zzi = cq1Var;
        this.f11841f = true;
        if (this.f11837b.bindService(this.f11842g, cq1Var, 1)) {
            return;
        }
        this.f11838c.zza("Failed to bind to the service.", new Object[0]);
        this.f11841f = false;
        ArrayList arrayList3 = this.f11840e;
        synchronized (arrayList3) {
            arrayList3.clear();
        }
    }

    public final /* synthetic */ void b() {
        if (this.zzj != null) {
            this.f11838c.zza("Unbind from service.", new Object[0]);
            Context context = this.f11837b;
            ServiceConnection serviceConnection = this.zzi;
            serviceConnection.getClass();
            context.unbindService(serviceConnection);
            this.f11841f = false;
            this.zzj = null;
            this.zzi = null;
            ArrayList arrayList = this.f11840e;
            synchronized (arrayList) {
                arrayList.clear();
            }
        }
    }

    public final /* synthetic */ IInterface c() {
        return this.zzj;
    }

    public final /* synthetic */ void d(np1 np1Var) {
        this.zzj = np1Var;
    }

    public final void e(Runnable runnable) {
        ((Handler) this.f11836a.zza()).post(new fq1(this, runnable, 1));
    }

    @Nullable
    public final IInterface zzc() {
        return this.zzj;
    }
}
