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

import android.content.Context;
import android.hardware.SensorEvent;
import android.hardware.SensorManager;
import android.view.Display;
import android.view.WindowManager;

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public float[] f19077f;

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final float[] f19075d = new float[9];

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final float[] f19076e = new float[9];

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f19073b = new Object();

    public z30(Context context) {
        this.f19072a = (SensorManager) context.getSystemService("sensor");
        this.f19074c = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    }

    @Override // com.google.android.gms.internal.ads.wi1
    public final void a(SensorEvent sensorEvent) {
        float[] fArr = sensorEvent.values;
        if (fArr[0] == 0.0f && fArr[1] == 0.0f && fArr[2] == 0.0f) {
            return;
        }
        synchronized (this.f19073b) {
            try {
                if (this.f19077f == null) {
                    this.f19077f = new float[9];
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        float[] fArr2 = this.f19075d;
        SensorManager.getRotationMatrixFromVector(fArr2, fArr);
        int rotation = this.f19074c.getRotation();
        if (rotation == 1) {
            SensorManager.remapCoordinateSystem(fArr2, 2, 129, this.f19076e);
        } else if (rotation == 2) {
            SensorManager.remapCoordinateSystem(fArr2, 129, 130, this.f19076e);
        } else if (rotation != 3) {
            System.arraycopy(fArr2, 0, this.f19076e, 0, 9);
        } else {
            SensorManager.remapCoordinateSystem(fArr2, 130, 1, this.f19076e);
        }
        float[] fArr3 = this.f19076e;
        float f10 = fArr3[1];
        fArr3[1] = fArr3[3];
        fArr3[3] = f10;
        float f11 = fArr3[2];
        fArr3[2] = fArr3[6];
        fArr3[6] = f11;
        float f12 = fArr3[5];
        fArr3[5] = fArr3[7];
        fArr3[7] = f12;
        synchronized (this.f19073b) {
            System.arraycopy(fArr3, 0, this.f19077f, 0, 9);
        }
        y30 y30Var = this.f19079h;
        if (y30Var != null) {
            Object obj = ((a40) y30Var).X;
            synchronized (obj) {
                obj.notifyAll();
            }
        }
    }

    public final void b() {
        if (this.f19078g == null) {
            return;
        }
        this.f19072a.unregisterListener(this);
        this.f19078g.post(new ig(this));
        this.f19078g = null;
    }

    public final boolean c(float[] fArr) {
        synchronized (this.f19073b) {
            try {
                float[] fArr2 = this.f19077f;
                if (fArr2 == null) {
                    return false;
                }
                System.arraycopy(fArr2, 0, fArr, 0, 9);
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
