package com.google.ads.interactivemedia.v3.internal;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.media3.exoplayer.analytics.AnalyticsListener;
import java.util.Iterator;
import java.util.LinkedList;

/* JADX INFO: loaded from: classes2.dex */
public abstract class zzib implements zzia {
    protected static volatile zzjj zza;
    protected MotionEvent zzb;
    protected double zzk;
    protected float zzl;
    protected float zzm;
    protected float zzn;
    protected float zzo;
    protected DisplayMetrics zzq;

    @Nullable
    protected zzjb zzr;
    private double zzs;
    private double zzt;
    protected final LinkedList zzc = new LinkedList();
    protected long zzd = 0;
    protected long zze = 0;
    protected long zzf = 0;
    protected long zzg = 0;
    protected long zzh = 0;
    protected long zzi = 0;
    protected long zzj = 0;
    private boolean zzu = false;
    protected boolean zzp = false;

    public zzib(Context context) {
        try {
            zzgt.zzd();
            this.zzq = context.getResources().getDisplayMetrics();
            if (((Boolean) zzls.zzc().zza(zzmj.zzs)).booleanValue()) {
                this.zzr = new zzjb();
            }
        } catch (Throwable unused) {
        }
    }

    private final void zzj() {
        this.zzh = 0L;
        this.zzd = 0L;
        this.zze = 0L;
        this.zzf = 0L;
        this.zzg = 0L;
        this.zzi = 0L;
        this.zzj = 0L;
        if (this.zzc.isEmpty()) {
            MotionEvent motionEvent = this.zzb;
            if (motionEvent != null) {
                motionEvent.recycle();
            }
        } else {
            Iterator it = this.zzc.iterator();
            while (it.hasNext()) {
                ((MotionEvent) it.next()).recycle();
            }
            this.zzc.clear();
        }
        this.zzb = null;
    }

    /* JADX WARN: Removed duplicated region for block: B:60:0x00ec A[Catch: Exception -> 0x00e8, TRY_LEAVE, TryCatch #0 {Exception -> 0x00e8, blocks: (B:45:0x00a7, B:48:0x00b4, B:57:0x00d8, B:60:0x00ec), top: B:74:0x00a7 }] */
    /* JADX WARN: Removed duplicated region for block: B:74:0x00a7 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final String zzm(Context context, String str, int i10, View view, Activity activity, byte[] bArr) {
        zzhz zzhzVarZzd;
        String str2;
        int i11;
        int i12;
        Exception exc;
        int i13;
        int i14;
        String strZza;
        zzan zzanVarZzc;
        int i15;
        int i16;
        int i17 = i10;
        long jCurrentTimeMillis = System.currentTimeMillis();
        boolean zBooleanValue = ((Boolean) zzls.zzc().zza(zzmj.zzj)).booleanValue();
        zzan zzanVarZzb = null;
        if (zBooleanValue) {
            zzhzVarZzd = zza != null ? zza.zzd() : null;
            str2 = "be";
        } else {
            zzhzVarZzd = null;
            str2 = null;
        }
        try {
            if (i17 == 3) {
                zzanVarZzb = zzb(context, view, activity);
                try {
                    this.zzu = true;
                    i16 = 1002;
                } catch (Exception e10) {
                    exc = e10;
                    i11 = 3;
                    i12 = 1;
                    if (!zBooleanValue) {
                    }
                    long jCurrentTimeMillis2 = System.currentTimeMillis();
                    if (zzanVarZzb != null) {
                    }
                    return strZza;
                }
            } else {
                if (i17 == 2) {
                    zzanVarZzc = zzd(context, view, activity);
                    i15 = AnalyticsListener.EVENT_AUDIO_DECODER_INITIALIZED;
                } else {
                    zzanVarZzc = zzc(context, null);
                    i15 = 1000;
                }
                zzanVarZzb = zzanVarZzc;
                i16 = i15;
            }
            if (!zBooleanValue || zzhzVarZzd == null) {
                i11 = 3;
            } else {
                i11 = 3;
                i12 = 1;
                try {
                    zzhzVarZzd.zzc(i16, -1, System.currentTimeMillis() - jCurrentTimeMillis, str2, null);
                } catch (Exception e11) {
                    e = e11;
                    exc = e;
                    if (!zBooleanValue && zzhzVarZzd != null) {
                        if (i17 == i11) {
                            i14 = 1003;
                            i13 = 2;
                        } else {
                            i13 = 2;
                            if (i17 == 2) {
                                i14 = 1009;
                            } else {
                                i14 = 1001;
                                i17 = i12;
                            }
                        }
                        zzhzVarZzd.zzc(i14, -1, System.currentTimeMillis() - jCurrentTimeMillis, str2, exc);
                    }
                    long jCurrentTimeMillis22 = System.currentTimeMillis();
                    if (zzanVarZzb != null) {
                    }
                    return strZza;
                }
            }
        } catch (Exception e12) {
            e = e12;
            i11 = 3;
            i12 = 1;
        }
        i13 = 2;
        long jCurrentTimeMillis222 = System.currentTimeMillis();
        if (zzanVarZzb != null) {
            try {
                if (((zzbp) zzanVarZzb.zzal()).zzax() == 0) {
                    strZza = Integer.toString(5);
                } else {
                    zzbp zzbpVar = (zzbp) zzanVarZzb.zzal();
                    int i18 = zzgt.zzc;
                    strZza = zzgt.zza(zzbpVar.zzav(), str);
                    if (zBooleanValue && zzhzVarZzd != null) {
                        zzhzVarZzd.zzc(i17 == i11 ? AnalyticsListener.EVENT_BANDWIDTH_ESTIMATE : i17 == i13 ? 1010 : 1004, -1, System.currentTimeMillis() - jCurrentTimeMillis222, str2, null);
                    }
                }
            } catch (Exception e13) {
                strZza = Integer.toString(7);
                if (zBooleanValue && zzhzVarZzd != null) {
                    zzhzVarZzd.zzc(i17 == i11 ? AnalyticsListener.EVENT_AUDIO_ENABLED : i17 == i13 ? 1011 : 1005, -1, System.currentTimeMillis() - jCurrentTimeMillis222, str2, e13);
                }
            }
        } else {
            strZza = Integer.toString(5);
        }
        return strZza;
    }

    public abstract long zza(StackTraceElement[] stackTraceElementArr) throws zziz;

    public abstract zzan zzb(Context context, View view, Activity activity);

    public abstract zzan zzc(Context context, zzy zzyVar);

    public abstract zzan zzd(Context context, View view, Activity activity);

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final String zze(Context context, @Nullable String str, @Nullable View view, @Nullable Activity activity) {
        return zzm(context, str, 3, view, activity, null);
    }

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final String zzf(Context context) {
        if (zzjm.zzc()) {
            throw new IllegalStateException("The caller must not be called from the UI thread.");
        }
        return zzm(context, null, 1, null, null, null);
    }

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final String zzg(Context context, byte[] bArr) {
        throw null;
    }

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final String zzh(Context context, @Nullable View view, @Nullable Activity activity) {
        return zzm(context, null, 2, view, activity, null);
    }

    public abstract zzjl zzi(MotionEvent motionEvent) throws zziz;

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final synchronized void zzk(@Nullable MotionEvent motionEvent) {
        Long l10;
        try {
            if (this.zzu) {
                zzj();
                this.zzu = false;
            }
            int action = motionEvent.getAction();
            if (action == 0) {
                this.zzk = 0.0d;
                this.zzs = motionEvent.getRawX();
                this.zzt = motionEvent.getRawY();
            } else if (action == 1 || action == 2) {
                double rawX = motionEvent.getRawX();
                double rawY = motionEvent.getRawY();
                double d10 = rawX - this.zzs;
                double d11 = rawY - this.zzt;
                this.zzk += Math.sqrt((d11 * d11) + (d10 * d10));
                this.zzs = rawX;
                this.zzt = rawY;
            }
            int action2 = motionEvent.getAction();
            if (action2 != 0) {
                try {
                    if (action2 == 1) {
                        MotionEvent motionEventObtain = MotionEvent.obtain(motionEvent);
                        this.zzb = motionEventObtain;
                        this.zzc.add(motionEventObtain);
                        if (this.zzc.size() > 6) {
                            ((MotionEvent) this.zzc.remove()).recycle();
                        }
                        this.zzf++;
                        this.zzh = zza(new Throwable().getStackTrace());
                    } else if (action2 == 2) {
                        this.zze += (long) (motionEvent.getHistorySize() + 1);
                        zzjl zzjlVarZzi = zzi(motionEvent);
                        Long l11 = zzjlVarZzi.zzd;
                        if (l11 != null && zzjlVarZzi.zzg != null) {
                            this.zzi = l11.longValue() + zzjlVarZzi.zzg.longValue() + this.zzi;
                        }
                        if (this.zzq != null && (l10 = zzjlVarZzi.zze) != null && zzjlVarZzi.zzh != null) {
                            this.zzj = l10.longValue() + zzjlVarZzi.zzh.longValue() + this.zzj;
                        }
                    } else if (action2 == 3) {
                        this.zzg++;
                    }
                } catch (zziz unused) {
                }
            } else {
                this.zzl = motionEvent.getX();
                this.zzm = motionEvent.getY();
                this.zzn = motionEvent.getRawX();
                this.zzo = motionEvent.getRawY();
                this.zzd++;
            }
            this.zzp = true;
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final synchronized void zzl(int i10, int i11, int i12) {
        try {
            if (this.zzb != null) {
                if (((Boolean) zzls.zzc().zza(zzmj.zzh)).booleanValue()) {
                    zzj();
                } else {
                    this.zzb.recycle();
                }
            }
            DisplayMetrics displayMetrics = this.zzq;
            if (displayMetrics != null) {
                float f10 = displayMetrics.density;
                this.zzb = MotionEvent.obtain(0L, i12, 1, i10 * f10, i11 * f10, 0.0f, 0.0f, 0, 0.0f, 0.0f, 0, 0);
            } else {
                this.zzb = null;
            }
            this.zzp = false;
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public void zzn(View view) {
    }

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final boolean zzq() {
        return true;
    }

    @Override // com.google.ads.interactivemedia.v3.internal.zzia
    public final boolean zzs() {
        return true;
    }
}
