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

import android.os.Parcel;
import android.os.RemoteException;
import android.os.SystemClock;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class j01 extends zi implements gx {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final /* synthetic */ int f12671e = 0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final e30 f12672a;

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

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

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

    public j01(String str, ex exVar, e30 e30Var, long j10) {
        super("com.google.android.gms.ads.internal.mediation.client.rtb.ISignalsCallback");
        JSONObject jSONObject = new JSONObject();
        this.f12673b = jSONObject;
        this.f12675d = false;
        this.f12672a = e30Var;
        this.f12674c = j10;
        try {
            jSONObject.put("adapter_version", exVar.zzf().toString());
            jSONObject.put("sdk_version", exVar.zzg().toString());
            jSONObject.put("name", str);
        } catch (RemoteException | NullPointerException | JSONException unused) {
        }
    }

    @Override // com.google.android.gms.internal.ads.zi
    public final boolean Q2(int i10, Parcel parcel, Parcel parcel2) {
        if (i10 == 1) {
            String string = parcel.readString();
            aj.e(parcel);
            synchronized (this) {
                if (!this.f12675d) {
                    if (string == null) {
                        synchronized (this) {
                            R2(2, "Adapter returned null signals");
                        }
                    } else {
                        try {
                            JSONObject jSONObject = this.f12673b;
                            jSONObject.put("signals", string);
                            tn tnVar = ao.Y1;
                            n7.y yVar = n7.y.f31093e;
                            if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                                m7.n.C.f30472k.getClass();
                                jSONObject.put("latency", SystemClock.elapsedRealtime() - this.f12674c);
                            }
                            if (((Boolean) yVar.f31096c.b(ao.X1)).booleanValue()) {
                                jSONObject.put("signal_error_code", 0);
                            }
                        } catch (JSONException unused) {
                        }
                        this.f12672a.zzc(this.f12673b);
                        this.f12675d = true;
                    }
                }
            }
        } else if (i10 == 2) {
            String string2 = parcel.readString();
            aj.e(parcel);
            synchronized (this) {
                R2(2, string2);
            }
        } else {
            if (i10 != 3) {
                return false;
            }
            n7.l2 l2Var = (n7.l2) aj.a(parcel, n7.l2.CREATOR);
            aj.e(parcel);
            synchronized (this) {
                R2(2, l2Var.f30998b);
            }
        }
        parcel2.writeNoException();
        return true;
    }

    public final synchronized void R2(int i10, String str) {
        try {
            if (this.f12675d) {
                return;
            }
            try {
                JSONObject jSONObject = this.f12673b;
                jSONObject.put("signal_error", str);
                tn tnVar = ao.Y1;
                n7.y yVar = n7.y.f31093e;
                if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                    m7.n.C.f30472k.getClass();
                    jSONObject.put("latency", SystemClock.elapsedRealtime() - this.f12674c);
                }
                if (((Boolean) yVar.f31096c.b(ao.X1)).booleanValue()) {
                    jSONObject.put("signal_error_code", i10);
                }
            } catch (JSONException unused) {
            }
            this.f12672a.zzc(this.f12673b);
            this.f12675d = true;
        } catch (Throwable th) {
            throw th;
        }
    }
}
