package X6FRs_4.KQgRr5e_0.Nm6q_10;

import android.annotation.SuppressLint;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;
import java.util.Calendar;
/* compiled from: TwilightManager.java */
/* loaded from: classes.dex */
public class XnFJ5_9 {
    public static XnFJ5_9 KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final KQgRr5e_0 f821KQgRr5e_0 = new KQgRr5e_0();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Context f822KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final LocationManager f823KQgRr5e_0;

    /* compiled from: TwilightManager.java */
    /* loaded from: classes.dex */
    public static class KQgRr5e_0 {
        public long KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public boolean f824KQgRr5e_0;

        /* renamed from: Mqv2r_3  reason: collision with root package name */
        public long f3187Mqv2r_3;
        public long PGPF6hQ_2;
        public long QxJ9d_1;

        /* renamed from: X6FRs_4  reason: collision with root package name */
        public long f3188X6FRs_4;
    }

    public XnFJ5_9(Context context, LocationManager locationManager) {
        this.f822KQgRr5e_0 = context;
        this.f823KQgRr5e_0 = locationManager;
    }

    public static XnFJ5_9 KQgRr5e_0(Context context) {
        if (KQgRr5e_0 == null) {
            Context applicationContext = context.getApplicationContext();
            KQgRr5e_0 = new XnFJ5_9(applicationContext, (LocationManager) applicationContext.getSystemService("location"));
        }
        return KQgRr5e_0;
    }

    public final boolean QxJ9d_1() {
        return this.f821KQgRr5e_0.f3188X6FRs_4 > System.currentTimeMillis();
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public boolean m457KQgRr5e_0() {
        KQgRr5e_0 kQgRr5e_0 = this.f821KQgRr5e_0;
        if (QxJ9d_1()) {
            return kQgRr5e_0.f824KQgRr5e_0;
        }
        Location KQgRr5e_02 = KQgRr5e_0();
        if (KQgRr5e_02 != null) {
            KQgRr5e_0(KQgRr5e_02);
            return kQgRr5e_0.f824KQgRr5e_0;
        }
        Log.i("TwilightManager", "Could not get last known location. This is probably because the app does not have any location permissions. Falling back to hardcoded sunrise/sunset values.");
        int i = Calendar.getInstance().get(11);
        return i < 6 || i >= 22;
    }

    @SuppressLint({"MissingPermission"})
    public final Location KQgRr5e_0() {
        Location KQgRr5e_02 = X6FRs_4.IMuAHx_6.X6FRs_4.QxJ9d_1.KQgRr5e_0(this.f822KQgRr5e_0, "android.permission.ACCESS_COARSE_LOCATION") == 0 ? KQgRr5e_0("network") : null;
        Location KQgRr5e_03 = X6FRs_4.IMuAHx_6.X6FRs_4.QxJ9d_1.KQgRr5e_0(this.f822KQgRr5e_0, "android.permission.ACCESS_FINE_LOCATION") == 0 ? KQgRr5e_0("gps") : null;
        return (KQgRr5e_03 == null || KQgRr5e_02 == null) ? KQgRr5e_03 != null ? KQgRr5e_03 : KQgRr5e_02 : KQgRr5e_03.getTime() > KQgRr5e_02.getTime() ? KQgRr5e_03 : KQgRr5e_02;
    }

    public final Location KQgRr5e_0(String str) {
        try {
            if (this.f823KQgRr5e_0.isProviderEnabled(str)) {
                return this.f823KQgRr5e_0.getLastKnownLocation(str);
            }
            return null;
        } catch (Exception e) {
            Log.d("TwilightManager", "Failed to get last known location", e);
            return null;
        }
    }

    public final void KQgRr5e_0(Location location) {
        long j;
        KQgRr5e_0 kQgRr5e_0 = this.f821KQgRr5e_0;
        long currentTimeMillis = System.currentTimeMillis();
        Xgtqvk_8 KQgRr5e_02 = Xgtqvk_8.KQgRr5e_0();
        KQgRr5e_02.KQgRr5e_0(currentTimeMillis - 86400000, location.getLatitude(), location.getLongitude());
        long j2 = KQgRr5e_02.f820KQgRr5e_0;
        KQgRr5e_02.KQgRr5e_0(currentTimeMillis, location.getLatitude(), location.getLongitude());
        boolean z = KQgRr5e_02.f819KQgRr5e_0 == 1;
        long j3 = KQgRr5e_02.QxJ9d_1;
        long j4 = KQgRr5e_02.f820KQgRr5e_0;
        boolean z2 = z;
        KQgRr5e_02.KQgRr5e_0(86400000 + currentTimeMillis, location.getLatitude(), location.getLongitude());
        long j5 = KQgRr5e_02.QxJ9d_1;
        if (j3 == -1 || j4 == -1) {
            j = 43200000 + currentTimeMillis;
        } else {
            j = (currentTimeMillis > j4 ? 0 + j5 : currentTimeMillis > j3 ? 0 + j4 : 0 + j3) + 60000;
        }
        kQgRr5e_0.f824KQgRr5e_0 = z2;
        kQgRr5e_0.KQgRr5e_0 = j2;
        kQgRr5e_0.QxJ9d_1 = j3;
        kQgRr5e_0.PGPF6hQ_2 = j4;
        kQgRr5e_0.f3187Mqv2r_3 = j5;
        kQgRr5e_0.f3188X6FRs_4 = j;
    }
}
