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

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public static final boolean f10181p;

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final q7.a f10184c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final x2.j0 f10185d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final long[] f10186e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final String[] f10187f;

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

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

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

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public zzcfk f10193l;

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public long f10196o;

    @Nullable
    private final jo zze;

    @Nullable
    private final mo zzf;

    static {
        f10181p = n7.x.f31085g.f31090e.nextInt(100) < ((Integer) n7.y.f31093e.f31096c.b(ao.Ud)).intValue();
    }

    public d40(Context context, q7.a aVar, String str, @Nullable mo moVar, @Nullable jo joVar) {
        xyz.stream.utils.t tVar = new xyz.stream.utils.t(11);
        tVar.B("min_1", Double.MIN_VALUE, 1.0d);
        tVar.B("1_5", 1.0d, 5.0d);
        tVar.B("5_10", 5.0d, 10.0d);
        tVar.B("10_20", 10.0d, 20.0d);
        tVar.B("20_30", 20.0d, 30.0d);
        tVar.B("30_max", 30.0d, Double.MAX_VALUE);
        this.f10185d = new x2.j0(tVar);
        this.f10188g = false;
        this.f10189h = false;
        this.f10190i = false;
        this.f10191j = false;
        this.f10196o = -1L;
        this.f10182a = context;
        this.f10184c = aVar;
        this.f10183b = str;
        this.zzf = moVar;
        this.zze = joVar;
        String str2 = (String) n7.y.f31093e.f31096c.b(ao.f8779b0);
        if (str2 == null) {
            this.f10187f = new String[0];
            this.f10186e = new long[0];
            return;
        }
        String[] strArrSplit = TextUtils.split(str2, ",");
        int length = strArrSplit.length;
        this.f10187f = new String[length];
        this.f10186e = new long[length];
        for (int i10 = 0; i10 < strArrSplit.length; i10++) {
            try {
                this.f10186e[i10] = Long.parseLong(strArrSplit[i10]);
            } catch (NumberFormatException unused) {
                this.f10186e[i10] = -1;
            }
        }
    }

    public final void a(zzcfk zzcfkVar) {
        mo moVar = this.zzf;
        eo.zza(moVar, this.zze, "vpc2");
        this.f10188g = true;
        moVar.c("vpn", zzcfkVar.i());
        this.f10193l = zzcfkVar;
    }

    public final void b() {
        if (!this.f10188g || this.f10189h) {
            return;
        }
        eo.zza(this.zzf, this.zze, "vfr2");
        this.f10189h = true;
    }

    public final void c() {
        if (!f10181p || this.f10194m) {
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putString("type", "native-player-metrics");
        bundle.putString("request", this.f10183b);
        bundle.putString("player", this.f10193l.i());
        x2.j0 j0Var = this.f10185d;
        String[] strArr = (String[]) j0Var.f34483c;
        ArrayList<p7.q> arrayList = new ArrayList(strArr.length);
        int i10 = 0;
        while (i10 < strArr.length) {
            String str = strArr[i10];
            double[] dArr = (double[]) j0Var.f34485e;
            double[] dArr2 = (double[]) j0Var.f34484d;
            int[] iArr = (int[]) j0Var.f34486f;
            double d10 = dArr[i10];
            double d11 = dArr2[i10];
            int i11 = iArr[i10];
            arrayList.add(new p7.q(str, d10, d11, ((double) i11) / ((double) j0Var.f34482b), i11));
            i10++;
            j0Var = j0Var;
            strArr = strArr;
        }
        for (p7.q qVar : arrayList) {
            String str2 = qVar.f31755a;
            String strValueOf = String.valueOf(str2);
            bundle.putString("fps_c_".concat(strValueOf), Integer.toString(qVar.f31759e));
            String strValueOf2 = String.valueOf(str2);
            bundle.putString("fps_p_".concat(strValueOf2), Double.toString(qVar.f31758d));
        }
        int i12 = 0;
        while (true) {
            long[] jArr = this.f10186e;
            if (i12 >= jArr.length) {
                m7.n.C.f30464c.zzg(this.f10182a, this.f10184c.f32212a, "gmob-apps", bundle, true);
                this.f10194m = true;
                return;
            }
            String str3 = this.f10187f[i12];
            if (str3 != null) {
                Long lValueOf = Long.valueOf(jArr[i12]);
                new StringBuilder(lValueOf.toString().length() + 3);
                bundle.putString("fh_".concat(lValueOf.toString()), str3);
            }
            i12++;
        }
    }

    public final void d(zzcfk zzcfkVar) {
        if (this.f10190i && !this.f10191j) {
            if (p7.l0.h() && !this.f10191j) {
                p7.l0.g("VideoMetricsMixin first frame");
            }
            eo.zza(this.zzf, this.zze, "vff2");
            this.f10191j = true;
        }
        m7.n.C.f30472k.getClass();
        long jNanoTime = System.nanoTime();
        if (this.f10192k && this.f10195n && this.f10196o != -1) {
            double nanos = TimeUnit.SECONDS.toNanos(1L) / (jNanoTime - this.f10196o);
            x2.j0 j0Var = this.f10185d;
            j0Var.f34482b++;
            int i10 = 0;
            while (true) {
                double[] dArr = (double[]) j0Var.f34485e;
                if (i10 >= dArr.length) {
                    break;
                }
                double d10 = dArr[i10];
                if (d10 <= nanos && nanos < ((double[]) j0Var.f34484d)[i10]) {
                    int[] iArr = (int[]) j0Var.f34486f;
                    iArr[i10] = iArr[i10] + 1;
                }
                if (nanos < d10) {
                    break;
                } else {
                    i10++;
                }
            }
        }
        this.f10195n = this.f10192k;
        this.f10196o = jNanoTime;
        long jLongValue = ((Long) n7.y.f31093e.f31096c.b(ao.f8796c0)).longValue();
        long jO = zzcfkVar.o();
        int i11 = 0;
        while (true) {
            String[] strArr = this.f10187f;
            if (i11 >= strArr.length) {
                return;
            }
            if (strArr[i11] == null && jLongValue > Math.abs(jO - this.f10186e[i11])) {
                int i12 = 8;
                Bitmap bitmap = zzcfkVar.getBitmap(8, 8);
                long j10 = 63;
                int i13 = 0;
                long j11 = 0;
                while (i13 < i12) {
                    int i14 = 0;
                    while (i14 < i12) {
                        int pixel = bitmap.getPixel(i14, i13);
                        j11 |= (Color.green(pixel) + (Color.red(pixel) + Color.blue(pixel)) > 128 ? 1L : 0L) << ((int) j10);
                        j10--;
                        i14++;
                        i12 = 8;
                    }
                    i13++;
                    i12 = 8;
                }
                strArr[i11] = String.format("%016X", Long.valueOf(j11));
                return;
            }
            i11++;
        }
    }

    public final void e() {
        this.f10192k = true;
        if (!this.f10189h || this.f10190i) {
            return;
        }
        eo.zza(this.zzf, this.zze, "vfp2");
        this.f10190i = true;
    }
}
