package d3;

import android.content.Context;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.AbstractBinderC0720x;
import com.google.android.gms.internal.measurement.AbstractC0725y;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/* JADX INFO: renamed from: d3.z0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class BinderC0841z0 extends AbstractBinderC0720x implements K {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Q1 f12234e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public String f12236g;

    public BinderC0841z0(Q1 q12) {
        super("com.google.android.gms.measurement.internal.IMeasurementService");
        P2.w.f(q12);
        this.f12234e = q12;
        this.f12236g = null;
    }

    @Override // d3.K
    public final byte[] B(C0828v c0828v, String str) {
        P2.w.c(str);
        P2.w.f(c0828v);
        L(str, true);
        Q1 q12 = this.f12234e;
        Z zE = q12.e();
        C0817r0 c0817r0 = q12.f11659B;
        T t6 = c0817r0.f12123C;
        String str2 = c0828v.f12193q;
        zE.f11871C.c(t6.d(str2), "Log and bundle. event");
        q12.d().getClass();
        long jNanoTime = System.nanoTime() / 1000000;
        try {
            byte[] bArr = (byte[]) q12.c().L(new CallableC0797k0(this, c0828v, str)).get();
            if (bArr == null) {
                q12.e().f11875v.c(Z.M(str), "Log and bundle returned null. appId");
                bArr = new byte[0];
            }
            q12.d().getClass();
            q12.e().f11871C.e("Log and bundle processed. event, size, time_ms", c0817r0.f12123C.d(str2), Integer.valueOf(bArr.length), Long.valueOf((System.nanoTime() / 1000000) - jNanoTime));
            return bArr;
        } catch (InterruptedException e8) {
            e = e8;
            Z zE2 = q12.e();
            zE2.f11875v.e("Failed to log and bundle. appId, event, error", Z.M(str), c0817r0.f12123C.d(str2), e);
            return null;
        } catch (ExecutionException e9) {
            e = e9;
            Z zE22 = q12.e();
            zE22.f11875v.e("Failed to log and bundle. appId, event, error", Z.M(str), c0817r0.f12123C.d(str2), e);
            return null;
        }
    }

    @Override // d3.K
    public final void C(C0778e c0778e, X1 x12) {
        P2.w.f(c0778e);
        P2.w.f(c0778e.f11920s);
        K(x12);
        C0778e c0778e2 = new C0778e(c0778e);
        c0778e2.f11918q = x12.f11831q;
        e(new J.m((Object) this, (Object) c0778e2, (Object) x12, 2));
    }

    @Override // d3.K
    public final void D(X1 x12) {
        P2.w.c(x12.f11831q);
        P2.w.f(x12.f11818K);
        d(new RunnableC0823t0(this, x12, 0));
    }

    @Override // d3.K
    public final void E(X1 x12) {
        K(x12);
        e(new RunnableC0823t0(this, x12, 3));
    }

    @Override // d3.K
    public final void F(X1 x12, I1 i12, O o8) {
        Q1 q12 = this.f12234e;
        if (q12.h0().R(null, I.f11517Q0)) {
            K(x12);
            String str = x12.f11831q;
            P2.w.f(str);
            q12.c().O(new O1.C(this, str, i12, o8, 1));
            return;
        }
        try {
            o8.A(new J1(Collections.EMPTY_LIST));
            q12.e().D.b("[sgtm] Client upload is not enabled on the service side.");
        } catch (RemoteException e8) {
            q12.e().f11878y.c(e8, "[sgtm] UploadBatchesCallback failed.");
        }
    }

    @Override // d3.K
    public final void H(long j8, String str, String str2, String str3) {
        e(new RunnableC0829v0(this, str2, str3, str, j8, 0));
    }

    @Override // d3.K
    public final void I(X1 x12) {
        K(x12);
        e(new RunnableC0823t0(this, x12, 4));
    }

    @Override // d3.K
    public final List J(String str, String str2, String str3, boolean z8) {
        L(str, true);
        Q1 q12 = this.f12234e;
        try {
            List<U1> list = (List) q12.c().K(new CallableC0835x0(this, str, str2, str3, 1)).get();
            ArrayList arrayList = new ArrayList(list.size());
            for (U1 u12 : list) {
                if (z8 || !W1.y0(u12.f11737c)) {
                    arrayList.add(new T1(u12));
                }
            }
            return arrayList;
        } catch (InterruptedException e8) {
            e = e8;
            Object obj = e;
            Z zE = q12.e();
            zE.f11875v.d("Failed to get user properties as. appId", Z.M(str), obj);
            return Collections.EMPTY_LIST;
        } catch (ExecutionException e9) {
            e = e9;
            Object obj2 = e;
            Z zE2 = q12.e();
            zE2.f11875v.d("Failed to get user properties as. appId", Z.M(str), obj2);
            return Collections.EMPTY_LIST;
        }
    }

    public final void K(X1 x12) {
        P2.w.f(x12);
        String str = x12.f11831q;
        P2.w.c(str);
        L(str, false);
        this.f12234e.g().n0(x12.f11832r, x12.f11814F);
    }

    public final void L(String str, boolean z8) {
        boolean zIsEmpty = TextUtils.isEmpty(str);
        Q1 q12 = this.f12234e;
        if (zIsEmpty) {
            q12.e().f11875v.b("Measurement Service called without app package");
            throw new SecurityException("Measurement Service called without app package");
        }
        if (z8) {
            try {
                if (this.f12235f == null) {
                    boolean z9 = true;
                    if (!"com.google.android.gms".equals(this.f12236g) && !T2.b.e(q12.f11659B.f12142q, Binder.getCallingUid()) && !M2.h.a(q12.f11659B.f12142q).b(Binder.getCallingUid())) {
                        z9 = false;
                    }
                    this.f12235f = Boolean.valueOf(z9);
                }
                if (this.f12235f.booleanValue()) {
                    return;
                }
            } catch (SecurityException e8) {
                q12.e().f11875v.c(Z.M(str), "Measurement Service called with invalid calling package. appId");
                throw e8;
            }
        }
        if (this.f12236g == null) {
            Context context = q12.f11659B.f12142q;
            int callingUid = Binder.getCallingUid();
            int i = M2.g.f4172e;
            if (T2.b.g(callingUid, context, str)) {
                this.f12236g = str;
            }
        }
        if (str.equals(this.f12236g)) {
            return;
        }
        throw new SecurityException("Unknown calling package name '" + str + "'.");
    }

    public final void M(C0828v c0828v, X1 x12) {
        Q1 q12 = this.f12234e;
        q12.j();
        q12.q(c0828v, x12);
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // com.google.android.gms.internal.measurement.AbstractBinderC0720x
    public final boolean c(int i, Parcel parcel, Parcel parcel2) {
        List list;
        Q1 q12 = this.f12234e;
        ArrayList arrayList = null;
        M l8 = null;
        O n8 = null;
        switch (i) {
            case 1:
                C0828v c0828v = (C0828v) AbstractC0725y.a(parcel, C0828v.CREATOR);
                X1 x12 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                j(c0828v, x12);
                parcel2.writeNoException();
                return true;
            case 2:
                T1 t12 = (T1) AbstractC0725y.a(parcel, T1.CREATOR);
                X1 x13 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                h(t12, x13);
                parcel2.writeNoException();
                return true;
            case 3:
            case Z.g.BYTES_FIELD_NUMBER /* 8 */:
            case 22:
            case 23:
            case 28:
            default:
                return false;
            case 4:
                X1 x14 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                n(x14);
                parcel2.writeNoException();
                return true;
            case 5:
                C0828v c0828v2 = (C0828v) AbstractC0725y.a(parcel, C0828v.CREATOR);
                String string = parcel.readString();
                parcel.readString();
                AbstractC0725y.b(parcel);
                P2.w.f(c0828v2);
                P2.w.c(string);
                L(string, true);
                e(new J.m(this, c0828v2, string, 4));
                parcel2.writeNoException();
                return true;
            case Z.g.STRING_SET_FIELD_NUMBER /* 6 */:
                X1 x15 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                I(x15);
                parcel2.writeNoException();
                return true;
            case Z.g.DOUBLE_FIELD_NUMBER /* 7 */:
                X1 x16 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                Object[] objArr = parcel.readInt() != 0;
                AbstractC0725y.b(parcel);
                K(x16);
                String str = x16.f11831q;
                P2.w.f(str);
                try {
                    List<U1> list2 = (List) q12.c().K(new CallableC0826u0(this, z ? 1 : 0, str)).get();
                    ArrayList arrayList2 = new ArrayList(list2.size());
                    for (U1 u12 : list2) {
                        if (objArr != false || !W1.y0(u12.f11737c)) {
                            arrayList2.add(new T1(u12));
                        }
                        break;
                    }
                    arrayList = arrayList2;
                } catch (InterruptedException e8) {
                    e = e8;
                    q12.e().f11875v.d("Failed to get user properties. appId", Z.M(str), e);
                } catch (ExecutionException e9) {
                    e = e9;
                    q12.e().f11875v.d("Failed to get user properties. appId", Z.M(str), e);
                }
                parcel2.writeNoException();
                parcel2.writeTypedList(arrayList);
                return true;
            case 9:
                C0828v c0828v3 = (C0828v) AbstractC0725y.a(parcel, C0828v.CREATOR);
                String string2 = parcel.readString();
                AbstractC0725y.b(parcel);
                byte[] bArrB = B(c0828v3, string2);
                parcel2.writeNoException();
                parcel2.writeByteArray(bArrB);
                return true;
            case 10:
                long j8 = parcel.readLong();
                String string3 = parcel.readString();
                String string4 = parcel.readString();
                String string5 = parcel.readString();
                AbstractC0725y.b(parcel);
                H(j8, string3, string4, string5);
                parcel2.writeNoException();
                return true;
            case 11:
                X1 x17 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                String strF = f(x17);
                parcel2.writeNoException();
                parcel2.writeString(strF);
                return true;
            case 12:
                C0778e c0778e = (C0778e) AbstractC0725y.a(parcel, C0778e.CREATOR);
                X1 x18 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                C(c0778e, x18);
                parcel2.writeNoException();
                return true;
            case 13:
                C0778e c0778e2 = (C0778e) AbstractC0725y.a(parcel, C0778e.CREATOR);
                AbstractC0725y.b(parcel);
                P2.w.f(c0778e2);
                P2.w.f(c0778e2.f11920s);
                P2.w.c(c0778e2.f11918q);
                L(c0778e2.f11918q, true);
                e(new G3.b(this, new C0778e(c0778e2), 10, false));
                parcel2.writeNoException();
                return true;
            case 14:
                String string6 = parcel.readString();
                String string7 = parcel.readString();
                ClassLoader classLoader = AbstractC0725y.f10069a;
                z = parcel.readInt() != 0;
                X1 x19 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                List listU = u(string6, string7, z, x19);
                parcel2.writeNoException();
                parcel2.writeTypedList(listU);
                return true;
            case 15:
                String string8 = parcel.readString();
                String string9 = parcel.readString();
                String string10 = parcel.readString();
                ClassLoader classLoader2 = AbstractC0725y.f10069a;
                boolean z8 = parcel.readInt() != 0;
                AbstractC0725y.b(parcel);
                List listJ = J(string8, string9, string10, z8);
                parcel2.writeNoException();
                parcel2.writeTypedList(listJ);
                return true;
            case 16:
                String string11 = parcel.readString();
                String string12 = parcel.readString();
                X1 x110 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                List listG = g(string11, string12, x110);
                parcel2.writeNoException();
                parcel2.writeTypedList(listG);
                return true;
            case 17:
                String string13 = parcel.readString();
                String string14 = parcel.readString();
                String string15 = parcel.readString();
                AbstractC0725y.b(parcel);
                List listO = o(string13, string14, string15);
                parcel2.writeNoException();
                parcel2.writeTypedList(listO);
                return true;
            case 18:
                X1 x111 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                i(x111);
                parcel2.writeNoException();
                return true;
            case 19:
                Bundle bundle = (Bundle) AbstractC0725y.a(parcel, Bundle.CREATOR);
                X1 x112 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                r(bundle, x112);
                parcel2.writeNoException();
                return true;
            case 20:
                X1 x113 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                t(x113);
                parcel2.writeNoException();
                return true;
            case 21:
                X1 x114 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                C0790i c0790iW = w(x114);
                parcel2.writeNoException();
                if (c0790iW == null) {
                    parcel2.writeInt(0);
                    return true;
                }
                parcel2.writeInt(1);
                c0790iW.writeToParcel(parcel2, 1);
                return true;
            case 24:
                X1 x115 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                Bundle bundle2 = (Bundle) AbstractC0725y.a(parcel, Bundle.CREATOR);
                AbstractC0725y.b(parcel);
                K(x115);
                String str2 = x115.f11831q;
                P2.w.f(str2);
                if (!q12.h0().R(null, I.f11558i1)) {
                    try {
                        list = (List) q12.c().K(new CallableC0838y0(this, x115, bundle2, 1)).get();
                    } catch (InterruptedException | ExecutionException e10) {
                        q12.e().f11875v.d("Failed to get trigger URIs. appId", Z.M(str2), e10);
                        list = Collections.EMPTY_LIST;
                    }
                    break;
                } else {
                    try {
                        list = (List) q12.c().L(new CallableC0838y0(this, x115, bundle2, 0)).get(10000L, TimeUnit.MILLISECONDS);
                    } catch (InterruptedException | ExecutionException | TimeoutException e11) {
                        q12.e().f11875v.d("Failed to get trigger URIs. appId", Z.M(str2), e11);
                        list = Collections.EMPTY_LIST;
                    }
                    break;
                }
                parcel2.writeNoException();
                parcel2.writeTypedList(list);
                return true;
            case 25:
                X1 x116 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                D(x116);
                parcel2.writeNoException();
                return true;
            case 26:
                X1 x117 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                q(x117);
                parcel2.writeNoException();
                return true;
            case 27:
                X1 x118 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                AbstractC0725y.b(parcel);
                E(x118);
                parcel2.writeNoException();
                return true;
            case 29:
                X1 x119 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                I1 i12 = (I1) AbstractC0725y.a(parcel, I1.CREATOR);
                IBinder strongBinder = parcel.readStrongBinder();
                if (strongBinder != null) {
                    IInterface iInterfaceQueryLocalInterface = strongBinder.queryLocalInterface("com.google.android.gms.measurement.internal.IUploadBatchesCallback");
                    n8 = iInterfaceQueryLocalInterface instanceof O ? (O) iInterfaceQueryLocalInterface : new N(strongBinder, "com.google.android.gms.measurement.internal.IUploadBatchesCallback", 1);
                }
                AbstractC0725y.b(parcel);
                F(x119, i12, n8);
                parcel2.writeNoException();
                return true;
            case 30:
                X1 x120 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                C0775d c0775d = (C0775d) AbstractC0725y.a(parcel, C0775d.CREATOR);
                AbstractC0725y.b(parcel);
                s(x120, c0775d);
                parcel2.writeNoException();
                return true;
            case 31:
                X1 x121 = (X1) AbstractC0725y.a(parcel, X1.CREATOR);
                Bundle bundle3 = (Bundle) AbstractC0725y.a(parcel, Bundle.CREATOR);
                IBinder strongBinder2 = parcel.readStrongBinder();
                if (strongBinder2 != null) {
                    IInterface iInterfaceQueryLocalInterface2 = strongBinder2.queryLocalInterface("com.google.android.gms.measurement.internal.ITriggerUrisCallback");
                    l8 = iInterfaceQueryLocalInterface2 instanceof M ? (M) iInterfaceQueryLocalInterface2 : new L(strongBinder2, "com.google.android.gms.measurement.internal.ITriggerUrisCallback", 1);
                }
                AbstractC0725y.b(parcel);
                k(x121, bundle3, l8);
                parcel2.writeNoException();
                return true;
        }
    }

    public final void d(Runnable runnable) {
        Q1 q12 = this.f12234e;
        if (q12.c().Q()) {
            runnable.run();
        } else {
            q12.c().P(runnable);
        }
    }

    public final void e(Runnable runnable) {
        Q1 q12 = this.f12234e;
        if (q12.c().Q()) {
            runnable.run();
        } else {
            q12.c().O(runnable);
        }
    }

    @Override // d3.K
    public final String f(X1 x12) {
        K(x12);
        Q1 q12 = this.f12234e;
        try {
            return (String) q12.c().K(new CallableC0826u0(q12, 2, x12)).get(30000L, TimeUnit.MILLISECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException e8) {
            Z zE = q12.e();
            zE.f11875v.d("Failed to get app instance id. appId", Z.M(x12.f11831q), e8);
            return null;
        }
    }

    @Override // d3.K
    public final List g(String str, String str2, X1 x12) {
        K(x12);
        String str3 = x12.f11831q;
        P2.w.f(str3);
        Q1 q12 = this.f12234e;
        try {
            return (List) q12.c().K(new CallableC0835x0(this, str3, str, str2, 2)).get();
        } catch (InterruptedException | ExecutionException e8) {
            q12.e().f11875v.c(e8, "Failed to get conditional user properties");
            return Collections.EMPTY_LIST;
        }
    }

    @Override // d3.K
    public final void h(T1 t12, X1 x12) {
        P2.w.f(t12);
        K(x12);
        e(new J.m((Object) this, (Object) t12, (Object) x12, 5));
    }

    @Override // d3.K
    public final void i(X1 x12) {
        String str = x12.f11831q;
        P2.w.c(str);
        L(str, false);
        e(new RunnableC0823t0(this, x12, 5));
    }

    @Override // d3.K
    public final void j(C0828v c0828v, X1 x12) {
        P2.w.f(c0828v);
        K(x12);
        e(new J.m((Object) this, (Object) c0828v, (Object) x12, 3));
    }

    @Override // d3.K
    public final void k(X1 x12, Bundle bundle, M m8) {
        K(x12);
        String str = x12.f11831q;
        P2.w.f(str);
        this.f12234e.c().O(new RunnableC0820s0(this, x12, bundle, m8, str));
    }

    @Override // d3.K
    public final void n(X1 x12) {
        K(x12);
        e(new RunnableC0823t0(this, x12, 2));
    }

    @Override // d3.K
    public final List o(String str, String str2, String str3) {
        L(str, true);
        Q1 q12 = this.f12234e;
        try {
            return (List) q12.c().K(new CallableC0835x0(this, str, str2, str3, 3)).get();
        } catch (InterruptedException | ExecutionException e8) {
            q12.e().f11875v.c(e8, "Failed to get conditional user properties as");
            return Collections.EMPTY_LIST;
        }
    }

    @Override // d3.K
    public final void q(X1 x12) {
        P2.w.c(x12.f11831q);
        P2.w.f(x12.f11818K);
        d(new RunnableC0823t0(this, x12, 1));
    }

    @Override // d3.K
    public final void r(Bundle bundle, X1 x12) {
        K(x12);
        String str = x12.f11831q;
        P2.w.f(str);
        e(new O1.C(this, bundle, str, x12, 2));
    }

    @Override // d3.K
    public final void s(X1 x12, C0775d c0775d) {
        if (this.f12234e.h0().R(null, I.f11517Q0)) {
            K(x12);
            e(new J.m((Object) this, (Object) x12, (Parcelable) c0775d, 1));
        }
    }

    @Override // d3.K
    public final void t(X1 x12) {
        P2.w.c(x12.f11831q);
        P2.w.f(x12.f11818K);
        d(new RunnableC0823t0(this, x12, 6));
    }

    @Override // d3.K
    public final List u(String str, String str2, boolean z8, X1 x12) {
        K(x12);
        String str3 = x12.f11831q;
        P2.w.f(str3);
        Q1 q12 = this.f12234e;
        try {
            List<U1> list = (List) q12.c().K(new CallableC0835x0(this, str3, str, str2, 0)).get();
            ArrayList arrayList = new ArrayList(list.size());
            for (U1 u12 : list) {
                if (z8 || !W1.y0(u12.f11737c)) {
                    arrayList.add(new T1(u12));
                }
            }
            return arrayList;
        } catch (InterruptedException e8) {
            e = e8;
            Object obj = e;
            Z zE = q12.e();
            zE.f11875v.d("Failed to query user properties. appId", Z.M(str3), obj);
            return Collections.EMPTY_LIST;
        } catch (ExecutionException e9) {
            e = e9;
            Object obj2 = e;
            Z zE2 = q12.e();
            zE2.f11875v.d("Failed to query user properties. appId", Z.M(str3), obj2);
            return Collections.EMPTY_LIST;
        }
    }

    @Override // d3.K
    public final C0790i w(X1 x12) {
        K(x12);
        String str = x12.f11831q;
        P2.w.c(str);
        Q1 q12 = this.f12234e;
        try {
            return (C0790i) q12.c().L(new CallableC0826u0(this, 1, x12)).get(10000L, TimeUnit.MILLISECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException e8) {
            Z zE = q12.e();
            zE.f11875v.d("Failed to get consent. appId", Z.M(str), e8);
            return new C0790i(null);
        }
    }
}
