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

import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.bytedance.sdk.component.pglcrypt.PglCryptUtils;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.b30;
import com.google.android.gms.internal.ads.fq1;
import com.google.android.gms.internal.ads.gq1;
import com.google.android.gms.internal.ads.iq1;
import com.google.android.gms.internal.ads.jc1;
import com.google.android.gms.internal.ads.lo;
import com.google.android.gms.internal.ads.m1;
import com.google.android.gms.internal.ads.op1;
import com.google.android.gms.internal.ads.rp1;
import com.google.android.gms.internal.ads.sp1;
import com.google.android.gms.internal.ads.up1;
import com.google.android.gms.internal.ads.x50;
import com.google.android.gms.internal.ads.yp1;
import com.google.android.gms.internal.ads.zp1;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import n7.y;
import p7.l0;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import xyz.stream.utils.a0;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public a0 f7956b;

    @Nullable
    private x50 zzc = null;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public boolean f7955a = false;

    @Nullable
    private String zza = null;

    @Nullable
    private up1 zzd = null;

    @Nullable
    private String zzb = null;

    public final synchronized boolean a(Context context) {
        if (!iq1.a(context)) {
            return false;
        }
        try {
            Context applicationContext = context.getApplicationContext();
            if (applicationContext != null) {
                context = applicationContext;
            }
            this.zzd = new jc1(new yp1(context), 10);
        } catch (NullPointerException e10) {
            l0.g("Error connecting LMD Overlay service");
            m7.n.C.f30469h.d("LastMileDeliveryOverlay.bindLastMileDeliveryService", e10);
        }
        if (this.zzd == null) {
            this.f7955a = false;
            return false;
        }
        if (this.f7956b == null) {
            a0 a0Var = new a0();
            a0Var.f36098a = this;
            this.f7956b = a0Var;
        }
        this.f7955a = true;
        return true;
    }

    public final void b() {
        up1 up1Var;
        if (!this.f7955a || (up1Var = this.zzd) == null) {
            l0.g("LastMileDelivery not connected");
        } else {
            ((yp1) ((jc1) up1Var).f12808b).a(1, i(), this.f7956b);
            f("onLMDOverlayExpand", new HashMap());
        }
    }

    public final void c() {
        up1 up1Var;
        if (!this.f7955a || (up1Var = this.zzd) == null) {
            l0.g("LastMileDelivery not connected");
        } else {
            ((yp1) ((jc1) up1Var).f12808b).a(2, i(), this.f7956b);
            f("onLMDOverlayCollapse", new HashMap());
        }
    }

    public final void d() {
        up1 up1Var;
        if (!this.f7955a || (up1Var = this.zzd) == null) {
            l0.g("LastMileDelivery not connected");
            return;
        }
        lo loVar = new lo(5);
        if (!((Boolean) y.f31093e.f31096c.b(ao.Jc)).booleanValue() || TextUtils.isEmpty(this.zzb)) {
            String str = this.zza;
            if (str != null) {
                loVar.f13799b = str;
            } else {
                e("Missing session token and/or appId", "onLMDupdate");
            }
        } else {
            loVar.f13800c = this.zzb;
        }
        op1 op1Var = new op1(loVar.f13799b, loVar.f13800c);
        a0 a0Var = this.f7956b;
        yp1 yp1Var = (yp1) ((jc1) up1Var).f12808b;
        gq1 gq1Var = yp1Var.f18927a;
        if (gq1Var == null) {
            yp1.f18925c.zzc("error: %s", "Play Store not found.");
        } else if (yp1.c(a0Var, "Failed to apply OverlayDisplayDismissRequest: missing appId and sessionToken.", Arrays.asList(op1Var.zza(), op1Var.zzb()))) {
            gq1Var.e(new fq1(gq1Var, new m1(yp1Var, op1Var, a0Var, 9), 0));
        }
    }

    public final void e(String str, String str2) {
        l0.g(str);
        if (this.zzc != null) {
            f("onError", defpackage.e.u(PglCryptUtils.KEY_MESSAGE, str, "action", str2));
        }
    }

    public final void f(String str, HashMap map) {
        b30.f9364f.execute(new n0.a(this, str, map, 4, 0));
    }

    public final void g(rp1 rp1Var) {
        if (!TextUtils.isEmpty(rp1Var.zzb())) {
            if (!((Boolean) y.f31093e.f31096c.b(ao.Jc)).booleanValue()) {
                this.zza = rp1Var.zzb();
            }
        }
        int i10 = rp1Var.f16193a;
        switch (i10) {
            case 8152:
                f("onLMDOverlayOpened", new HashMap());
                break;
            case 8153:
                f("onLMDOverlayClicked", new HashMap());
                break;
            case 8155:
                f("onLMDOverlayClose", new HashMap());
                break;
            case 8157:
                this.zza = null;
                this.zzb = null;
                this.f7955a = false;
                break;
            case 8160:
            case 8161:
            case 8162:
                HashMap map = new HashMap();
                map.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, String.valueOf(i10));
                f("onLMDOverlayFailedToOpen", map);
                break;
        }
    }

    public final /* synthetic */ void h(String str, Map map) {
        x50 x50Var = this.zzc;
        if (x50Var != null) {
            x50Var.d(str, map);
        }
    }

    public final sp1 i() {
        lo loVar = new lo(6);
        if (!((Boolean) y.f31093e.f31096c.b(ao.Jc)).booleanValue() || TextUtils.isEmpty(this.zzb)) {
            String str = this.zza;
            if (str != null) {
                loVar.f13799b = str;
            } else {
                e("Missing session token and/or appId", "onLMDupdate");
            }
        } else {
            loVar.f13800c = this.zzb;
        }
        return new sp1(loVar.f13799b, loVar.f13800c);
    }

    public final synchronized void zza(@Nullable x50 x50Var, Context context) {
        this.zzc = x50Var;
        if (!a(context)) {
            e("Unable to bind", "on_play_store_bind");
            return;
        }
        HashMap map = new HashMap();
        map.put("action", "fetch_completed");
        f("on_play_store_bind", map);
    }

    public final void zzc(@Nullable x50 x50Var, @Nullable zp1 zp1Var) {
        if (x50Var == null) {
            e("adWebview missing", "onLMDShow");
            return;
        }
        this.zzc = x50Var;
        if (!this.f7955a && !a(x50Var.getContext())) {
            e("LMDOverlay not bound", "on_play_store_bind");
            return;
        }
        if (((Boolean) y.f31093e.f31096c.b(ao.Jc)).booleanValue()) {
            this.zzb = zp1Var.zzb();
        }
        if (this.f7956b == null) {
            a0 a0Var = new a0();
            a0Var.f36098a = this;
            this.f7956b = a0Var;
        }
        up1 up1Var = this.zzd;
        if (up1Var != null) {
            a0 a0Var2 = this.f7956b;
            yp1 yp1Var = (yp1) ((jc1) up1Var).f12808b;
            gq1 gq1Var = yp1Var.f18927a;
            if (gq1Var == null) {
                yp1.f18925c.zzc("error: %s", "Play Store not found.");
            } else if (yp1.c(a0Var2, "Failed to apply OverlayDisplayShowRequest: missing appId and sessionToken.", Arrays.asList(null, zp1Var.zzb()))) {
                gq1Var.e(new fq1(gq1Var, new m1(yp1Var, zp1Var, a0Var2, 10), 0));
            }
        }
    }
}
