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

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Looper;
import android.os.Parcel;
import android.view.MotionEvent;
import android.view.View;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.util.Iterator;

/* JADX INFO: loaded from: classes2.dex */
public final class a5 extends com.google.android.gms.internal.common.e implements d5 {

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final m3 f20686d;

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

    public a5(Context context) {
        super("com.google.android.gms.ads.adshield.internal.IAdShieldClient", 1);
        this.f20687e = false;
        int i10 = l3.C;
        k3.m(context, false);
        l3 l3Var = new l3(context, 0);
        this.f20684b = l3Var;
        this.f20686d = new m3(l3Var);
        int i11 = j3.D;
        k3.m(context, true);
        this.f20685c = new j3(context);
    }

    @Override // com.google.android.gms.internal.common.e
    public final boolean G(int i10, Parcel parcel, Parcel parcel2) {
        int i11 = 0;
        switch (i10) {
            case 1:
                parcel2.writeNoException();
                parcel2.writeString("ms");
                return true;
            case 2:
                String string = parcel.readString();
                String string2 = parcel.readString();
                y4.a(parcel);
                m3 m3Var = this.f20686d;
                m3Var.f21074a = string;
                m3Var.f21075b = string2;
                parcel2.writeNoException();
                return true;
            case 3:
                k8.a aVarM = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                Uri uri = (Uri) k8.b.O(aVarM);
                m3 m3Var2 = this.f20686d;
                m3Var2.getClass();
                uri.getClass();
                try {
                    if (uri.getHost().equals(m3Var2.f21074a)) {
                        if (uri.getPath().equals(m3Var2.f21075b)) {
                            i11 = 1;
                        }
                    }
                } catch (NullPointerException unused) {
                }
                parcel2.writeNoException();
                parcel2.writeInt(i11);
                return true;
            case 4:
                k8.a aVarM2 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                Uri uri2 = (Uri) k8.b.O(aVarM2);
                m3 m3Var3 = this.f20686d;
                m3Var3.getClass();
                uri2.getClass();
                try {
                    String host = uri2.getHost();
                    String[] strArr = m3Var3.f21076c;
                    int length = strArr.length;
                    int i12 = 0;
                    while (true) {
                        if (i12 < length) {
                            if (host.endsWith(strArr[i12])) {
                                i11 = 1;
                            } else {
                                i12++;
                            }
                        }
                    }
                } catch (NullPointerException unused2) {
                }
                parcel2.writeNoException();
                parcel2.writeInt(i11);
                return true;
            case 5:
                String string3 = parcel.readString();
                y4.a(parcel);
                m3 m3Var4 = this.f20686d;
                m3Var4.getClass();
                m3Var4.f21076c = string3.split(",");
                parcel2.writeNoException();
                return true;
            case 6:
                k8.a aVarM3 = k8.b.M(parcel.readStrongBinder());
                k8.a aVarM4 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                k8.b bVarM = M(aVarM3, aVarM4, true);
                parcel2.writeNoException();
                y4.b(parcel2, bVarM);
                return true;
            case 7:
                k8.a aVarM5 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                String strZzg = zzg(aVarM5, null);
                parcel2.writeNoException();
                parcel2.writeString(strZzg);
                return true;
            case 8:
                k8.a aVarM6 = k8.b.M(parcel.readStrongBinder());
                String string4 = parcel.readString();
                y4.a(parcel);
                String strZze = zze(aVarM6, string4);
                parcel2.writeNoException();
                parcel2.writeString(strZze);
                return true;
            case 9:
                k8.a aVarM7 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                zzl(aVarM7);
                parcel2.writeNoException();
                return true;
            case 10:
                k8.a aVarM8 = k8.b.M(parcel.readStrongBinder());
                k8.a aVarM9 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                k8.b bVarM2 = M(aVarM8, aVarM9, false);
                parcel2.writeNoException();
                y4.b(parcel2, bVarM2);
                return true;
            case 11:
                String string5 = parcel.readString();
                int i13 = y4.f21365a;
                boolean z10 = parcel.readInt() != 0;
                y4.a(parcel);
                j3 j3Var = this.f20685c;
                if (j3Var != null) {
                    j3Var.C = new com.google.android.gms.ads.identifier.a(string5, z10);
                    this.f20687e = true;
                    i11 = 1;
                }
                parcel2.writeNoException();
                parcel2.writeInt(i11);
                return true;
            case 12:
                k8.a aVarM10 = k8.b.M(parcel.readStrongBinder());
                byte[] bArrCreateByteArray = parcel.createByteArray();
                y4.a(parcel);
                String strZzg2 = zzg(aVarM10, bArrCreateByteArray);
                parcel2.writeNoException();
                parcel2.writeString(strZzg2);
                return true;
            case 13:
                k8.a aVarM11 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                l3 l3Var = this.f20684b;
                Context context = (Context) k8.b.O(aVarM11);
                l3Var.getClass();
                char[] cArr = a4.f20683a;
                if (Looper.myLooper() == Looper.getMainLooper()) {
                    throw new IllegalStateException("The caller must not be called from the UI thread.");
                }
                String strF = l3Var.f(context, null, 1, null, null, null);
                parcel2.writeNoException();
                parcel2.writeString(strF);
                return true;
            case 14:
                k8.a aVarM12 = k8.b.M(parcel.readStrongBinder());
                k8.a aVarM13 = k8.b.M(parcel.readStrongBinder());
                k8.a aVarM14 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                String strZzk = zzk(aVarM12, aVarM13, aVarM14);
                parcel2.writeNoException();
                parcel2.writeString(strZzk);
                return true;
            case 15:
                k8.a aVarM15 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                l3 l3Var2 = this.f20684b;
                View view = (View) k8.b.O(aVarM15);
                l3Var2.getClass();
                if (((Boolean) f5.f20904d.f20907c.b(l5.f21045j)).booleanValue()) {
                    if (l3Var2.f21013v == null) {
                        y3 y3Var = i3.f20961t;
                        l3Var2.f21013v = new d4(y3Var.f21348a, y3Var.f21364q);
                    }
                    l3Var2.f21013v.a(view);
                }
                parcel2.writeNoException();
                return true;
            case 16:
            default:
                return false;
            case 17:
                k8.a aVarM16 = k8.b.M(parcel.readStrongBinder());
                k8.a aVarM17 = k8.b.M(parcel.readStrongBinder());
                k8.a aVarM18 = k8.b.M(parcel.readStrongBinder());
                k8.a aVarM19 = k8.b.M(parcel.readStrongBinder());
                y4.a(parcel);
                String strF2 = this.f20684b.f((Context) k8.b.O(aVarM16), (String) k8.b.O(aVarM17), 3, (View) k8.b.O(aVarM18), (Activity) k8.b.O(aVarM19), null);
                parcel2.writeNoException();
                parcel2.writeString(strF2);
                return true;
            case 18:
                parcel2.writeNoException();
                int i14 = y4.f21365a;
                parcel2.writeInt(1);
                return true;
            case 19:
                parcel2.writeNoException();
                int i15 = y4.f21365a;
                parcel2.writeInt(1);
                return true;
            case 20:
                int i16 = this.f20684b instanceof l3 ? 1 : -1;
                parcel2.writeNoException();
                parcel2.writeInt(i16);
                return true;
        }
    }

    public final k8.b M(k8.a aVar, k8.a aVar2, boolean z10) {
        Uri uriA;
        try {
            Uri uri = (Uri) k8.b.O(aVar);
            Context context = (Context) k8.b.O(aVar2);
            m3 m3Var = this.f20686d;
            if (z10) {
                i3 i3Var = (i3) m3Var.f21077d;
                i3Var.getClass();
                char[] cArr = a4.f20683a;
                if (Looper.myLooper() == Looper.getMainLooper()) {
                    throw new IllegalStateException("The caller must not be called from the UI thread.");
                }
                uriA = m3.a(uri, i3Var.f(context, null, 1, null, null, null));
            } else {
                m3Var.getClass();
                try {
                    uriA = m3.a(uri, ((i3) m3Var.f21077d).f(context, uri.getQueryParameter("ai"), 3, null, null, null));
                } catch (UnsupportedOperationException unused) {
                    throw new zzcw("Provided Uri is not in a valid state");
                }
            }
            return new k8.b(uriA);
        } catch (zzcw unused2) {
            return null;
        }
    }

    @Override // com.google.android.gms.internal.pal.d5
    public final String zze(k8.a aVar, String str) {
        return this.f20684b.f((Context) k8.b.O(aVar), str, 3, null, null, null);
    }

    @Override // com.google.android.gms.internal.pal.d5
    public final String zzg(k8.a aVar, byte[] bArr) {
        byte[] bArrC;
        Context context = (Context) k8.b.O(aVar);
        l3 l3Var = this.f20684b;
        l3Var.getClass();
        char[] cArr = a4.f20683a;
        if (Looper.myLooper() == Looper.getMainLooper()) {
            throw new IllegalStateException("The caller must not be called from the UI thread.");
        }
        String strF = l3Var.f(context, null, 1, null, null, bArr);
        j3 j3Var = this.f20685c;
        if (j3Var == null || !this.f20687e) {
            return strF;
        }
        if (Looper.myLooper() == Looper.getMainLooper()) {
            throw new IllegalStateException("The caller must not be called from the UI thread.");
        }
        String strF2 = j3Var.f(context, null, 1, null, null, bArr);
        boolean z10 = c3.f20735a;
        b2 b2VarN = c2.n();
        try {
            byte[] bytes = strF.length() < 3 ? strF.getBytes("ISO-8859-1") : q9.O(strF, true);
            zzaby zzabyVarK = zzaby.k(0, bytes.length, bytes);
            if (b2VarN.f20700c) {
                b2VarN.i();
                b2VarN.f20700c = false;
            }
            c2.o((c2) b2VarN.f20699b, zzabyVarK);
            byte[] bytes2 = strF2.length() < 3 ? strF2.getBytes("ISO-8859-1") : q9.O(strF2, true);
            zzaby zzabyVarK2 = zzaby.k(0, bytes2.length, bytes2);
            if (b2VarN.f20700c) {
                b2VarN.i();
                b2VarN.f20700c = false;
            }
            c2.p((c2) b2VarN.f20699b, zzabyVarK2);
            bArrC = ((c2) b2VarN.g()).c();
        } catch (UnsupportedEncodingException | GeneralSecurityException unused) {
            bArrC = null;
        }
        String strP = bArrC != null ? q9.p(bArrC, true) : Integer.toString(7);
        this.f20687e = false;
        return strP;
    }

    @Override // com.google.android.gms.internal.pal.d5
    public final String zzk(k8.a aVar, k8.a aVar2, k8.a aVar3) {
        return this.f20684b.f((Context) k8.b.O(aVar), null, 2, (View) k8.b.O(aVar2), (Activity) k8.b.O(aVar3), null);
    }

    @Override // com.google.android.gms.internal.pal.d5
    public final void zzl(k8.a aVar) {
        Long l10;
        MotionEvent motionEvent = (MotionEvent) k8.b.O(aVar);
        i3 i3Var = (i3) this.f20686d.f21077d;
        synchronized (i3Var) {
            try {
                if (i3Var.f20978q) {
                    i3Var.f20968g = 0L;
                    i3Var.f20964c = 0L;
                    i3Var.f20965d = 0L;
                    i3Var.f20966e = 0L;
                    i3Var.f20967f = 0L;
                    i3Var.f20969h = 0L;
                    i3Var.f20970i = 0L;
                    if (i3Var.f20963b.size() > 0) {
                        Iterator it = i3Var.f20963b.iterator();
                        while (it.hasNext()) {
                            ((MotionEvent) it.next()).recycle();
                        }
                        i3Var.f20963b.clear();
                    } else {
                        MotionEvent motionEvent2 = i3Var.f20962a;
                        if (motionEvent2 != null) {
                            motionEvent2.recycle();
                        }
                    }
                    i3Var.f20962a = null;
                    i3Var.f20978q = false;
                }
                int action = motionEvent.getAction();
                if (action == 0) {
                    i3Var.f20971j = 0.0d;
                    i3Var.f20972k = motionEvent.getRawX();
                    i3Var.f20973l = motionEvent.getRawY();
                } else if (action == 1 || action == 2) {
                    double rawX = motionEvent.getRawX();
                    double rawY = motionEvent.getRawY();
                    double d10 = rawX - i3Var.f20972k;
                    double d11 = rawY - i3Var.f20973l;
                    i3Var.f20971j += Math.sqrt((d11 * d11) + (d10 * d10));
                    i3Var.f20972k = rawX;
                    i3Var.f20973l = rawY;
                }
                int action2 = motionEvent.getAction();
                if (action2 != 0) {
                    try {
                        if (action2 == 1) {
                            MotionEvent motionEventObtain = MotionEvent.obtain(motionEvent);
                            i3Var.f20962a = motionEventObtain;
                            i3Var.f20963b.add(motionEventObtain);
                            if (i3Var.f20963b.size() > 6) {
                                ((MotionEvent) i3Var.f20963b.remove()).recycle();
                            }
                            i3Var.f20966e++;
                            i3Var.f20968g = i3Var.a(new Throwable().getStackTrace());
                        } else if (action2 == 2) {
                            i3Var.f20965d += (long) (motionEvent.getHistorySize() + 1);
                            z3 z3VarE = i3Var.e(motionEvent);
                            Long l11 = z3VarE.f21392d;
                            if (l11 != null && z3VarE.f21395g != null) {
                                i3Var.f20969h = l11.longValue() + z3VarE.f21395g.longValue() + i3Var.f20969h;
                            }
                            if (i3Var.f20980s != null && (l10 = z3VarE.f21393e) != null && z3VarE.f21396h != null) {
                                i3Var.f20970i = l10.longValue() + z3VarE.f21396h.longValue() + i3Var.f20970i;
                            }
                        } else if (action2 == 3) {
                            i3Var.f20967f++;
                        }
                    } catch (zzdm unused) {
                    }
                } else {
                    i3Var.f20974m = motionEvent.getX();
                    i3Var.f20975n = motionEvent.getY();
                    i3Var.f20976o = motionEvent.getRawX();
                    i3Var.f20977p = motionEvent.getRawY();
                    i3Var.f20964c++;
                }
                i3Var.f20979r = true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
