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

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorManager;

/* JADX INFO: loaded from: classes2.dex */
public final class js0 extends wi1 {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public float f13006c = 0.0f;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Float f13007d = Float.valueOf(0.0f);

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

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

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

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

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

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

    public js0(Context context) {
        m7.n.C.f30472k.getClass();
        this.f13008e = System.currentTimeMillis();
        this.f13009f = 0;
        this.f13010g = false;
        this.f13011h = false;
        this.f13012i = null;
        this.f13013j = false;
        SensorManager sensorManager = (SensorManager) context.getSystemService("sensor");
        this.f13004a = sensorManager;
        if (sensorManager != null) {
            this.f13005b = sensorManager.getDefaultSensor(4);
        } else {
            this.f13005b = null;
        }
    }

    @Override // com.google.android.gms.internal.ads.wi1
    public final void a(SensorEvent sensorEvent) {
        tn tnVar = ao.f9004oa;
        n7.y yVar = n7.y.f31093e;
        if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
            m7.n.C.f30472k.getClass();
            long jCurrentTimeMillis = System.currentTimeMillis();
            long j10 = this.f13008e;
            tn tnVar2 = ao.f9038qa;
            yn ynVar = yVar.f31096c;
            if (j10 + ((long) ((Integer) ynVar.b(tnVar2)).intValue()) < jCurrentTimeMillis) {
                this.f13009f = 0;
                this.f13008e = jCurrentTimeMillis;
                this.f13010g = false;
                this.f13011h = false;
                this.f13006c = this.f13007d.floatValue();
            }
            Float fValueOf = Float.valueOf(this.f13007d.floatValue() + (sensorEvent.values[1] * 4.0f));
            this.f13007d = fValueOf;
            float fFloatValue = fValueOf.floatValue();
            float f10 = this.f13006c;
            tn tnVar3 = ao.f9021pa;
            if (fFloatValue > ((Float) ynVar.b(tnVar3)).floatValue() + f10) {
                this.f13006c = this.f13007d.floatValue();
                this.f13011h = true;
            } else if (this.f13007d.floatValue() < this.f13006c - ((Float) ynVar.b(tnVar3)).floatValue()) {
                this.f13006c = this.f13007d.floatValue();
                this.f13010g = true;
            }
            if (this.f13007d.isInfinite()) {
                this.f13007d = Float.valueOf(0.0f);
                this.f13006c = 0.0f;
            }
            if (this.f13010g && this.f13011h) {
                p7.l0.g("Flick detected.");
                this.f13008e = jCurrentTimeMillis;
                int i10 = this.f13009f + 1;
                this.f13009f = i10;
                this.f13010g = false;
                this.f13011h = false;
                is0 is0Var = this.f13012i;
                if (is0Var == null || i10 != ((Integer) ynVar.b(ao.f9055ra)).intValue()) {
                    return;
                }
                ps0 ps0Var = (ps0) is0Var;
                ps0Var.e(new os0(ps0Var, 1), zzebe.f19668c);
            }
        }
    }

    public final void b() {
        SensorManager sensorManager;
        Sensor sensor;
        synchronized (this) {
            try {
                if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9004oa)).booleanValue()) {
                    if (!this.f13013j && (sensorManager = this.f13004a) != null && (sensor = this.f13005b) != null) {
                        sensorManager.registerListener(this, sensor, 2);
                        this.f13013j = true;
                        p7.l0.g("Listening for flick gestures.");
                    }
                    if (this.f13004a == null || this.f13005b == null) {
                        q7.j.d("Flick detection failed to initialize. Failed to obtain gyroscope.");
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
