You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.7 KiB

package p010d;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;
import java.util.Calendar;
import p069x.C1803g;
/* renamed from: d.h0 */
/* loaded from: classes.dex */
public class C0572h0 {
/* renamed from: d */
public static C0572h0 f2071d;
/* renamed from: a */
public final Context f2072a;
/* renamed from: b */
public final LocationManager f2073b;
/* renamed from: c */
public final C0573a f2074c = new C0573a();
/* renamed from: d.h0$a */
/* loaded from: classes.dex */
public static class C0573a {
/* renamed from: a */
public boolean f2075a;
/* renamed from: b */
public long f2076b;
}
public C0572h0(Context context, LocationManager locationManager) {
this.f2072a = context;
this.f2073b = locationManager;
}
/* renamed from: a */
public static C0572h0 m3376a(Context context) {
if (f2071d == null) {
Context applicationContext = context.getApplicationContext();
f2071d = new C0572h0(applicationContext, (LocationManager) applicationContext.getSystemService("location"));
}
return f2071d;
}
/* renamed from: b */
public final Location m3375b() {
Location m3374c = C1803g.m372b(this.f2072a, "android.permission.ACCESS_COARSE_LOCATION") == 0 ? m3374c("network") : null;
Location m3374c2 = C1803g.m372b(this.f2072a, "android.permission.ACCESS_FINE_LOCATION") == 0 ? m3374c("gps") : null;
return (m3374c2 == null || m3374c == null) ? m3374c2 != null ? m3374c2 : m3374c : m3374c2.getTime() > m3374c.getTime() ? m3374c2 : m3374c;
}
/* renamed from: c */
public final Location m3374c(String str) {
try {
if (this.f2073b.isProviderEnabled(str)) {
return this.f2073b.getLastKnownLocation(str);
}
return null;
} catch (Exception e) {
Log.d("TwilightManager", "Failed to get last known location", e);
return null;
}
}
/* renamed from: d */
public boolean m3373d() {
C0573a c0573a = this.f2074c;
if (m3372e()) {
return c0573a.f2075a;
}
Location m3375b = m3375b();
if (m3375b != null) {
m3371f(m3375b);
return c0573a.f2075a;
}
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;
}
/* renamed from: e */
public final boolean m3372e() {
return this.f2074c.f2076b > System.currentTimeMillis();
}
/* renamed from: f */
public final void m3371f(Location location) {
long j;
C0573a c0573a = this.f2074c;
long currentTimeMillis = System.currentTimeMillis();
C0570g0 m3378b = C0570g0.m3378b();
m3378b.m3379a(currentTimeMillis - 86400000, location.getLatitude(), location.getLongitude());
m3378b.m3379a(currentTimeMillis, location.getLatitude(), location.getLongitude());
boolean z = m3378b.f2070c == 1;
long j2 = m3378b.f2069b;
long j3 = m3378b.f2068a;
m3378b.m3379a(currentTimeMillis + 86400000, location.getLatitude(), location.getLongitude());
long j4 = m3378b.f2069b;
if (j2 == -1 || j3 == -1) {
j = 43200000 + currentTimeMillis;
} else {
j = (currentTimeMillis > j3 ? j4 + 0 : currentTimeMillis > j2 ? j3 + 0 : j2 + 0) + 60000;
}
c0573a.f2075a = z;
c0573a.f2076b = j;
}
}