- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
110 lines
4.8 KiB
Java
110 lines
4.8 KiB
Java
package androidx.appcompat.app;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.location.Location;
|
|
import android.location.LocationManager;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.RequiresPermission;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.core.content.PermissionChecker;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.source.chunk.ChunkedTrackBlacklistUtil;
|
|
import com.vungle.ads.internal.signals.SignalManager;
|
|
import java.util.Calendar;
|
|
|
|
/* loaded from: classes.dex */
|
|
class TwilightManager {
|
|
private static final int SUNRISE = 6;
|
|
private static final int SUNSET = 22;
|
|
private static final String TAG = "TwilightManager";
|
|
private static TwilightManager sInstance;
|
|
private final Context mContext;
|
|
private final LocationManager mLocationManager;
|
|
private final TwilightState mTwilightState = new TwilightState();
|
|
|
|
public static class TwilightState {
|
|
boolean isNight;
|
|
long nextUpdate;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public static void setInstance(TwilightManager twilightManager) {
|
|
sInstance = twilightManager;
|
|
}
|
|
|
|
public static TwilightManager getInstance(@NonNull Context context) {
|
|
if (sInstance == null) {
|
|
Context applicationContext = context.getApplicationContext();
|
|
sInstance = new TwilightManager(applicationContext, (LocationManager) applicationContext.getSystemService("location"));
|
|
}
|
|
return sInstance;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public TwilightManager(@NonNull Context context, @NonNull LocationManager locationManager) {
|
|
this.mContext = context;
|
|
this.mLocationManager = locationManager;
|
|
}
|
|
|
|
public boolean isNight() {
|
|
TwilightState twilightState = this.mTwilightState;
|
|
if (isStateValid()) {
|
|
return twilightState.isNight;
|
|
}
|
|
Location lastKnownLocation = getLastKnownLocation();
|
|
if (lastKnownLocation != null) {
|
|
updateState(lastKnownLocation);
|
|
return twilightState.isNight;
|
|
}
|
|
int i = Calendar.getInstance().get(11);
|
|
return i < 6 || i >= 22;
|
|
}
|
|
|
|
@SuppressLint({"MissingPermission"})
|
|
private Location getLastKnownLocation() {
|
|
Location lastKnownLocationForProvider = PermissionChecker.checkSelfPermission(this.mContext, "android.permission.ACCESS_COARSE_LOCATION") == 0 ? getLastKnownLocationForProvider("network") : null;
|
|
Location lastKnownLocationForProvider2 = PermissionChecker.checkSelfPermission(this.mContext, "android.permission.ACCESS_FINE_LOCATION") == 0 ? getLastKnownLocationForProvider("gps") : null;
|
|
return (lastKnownLocationForProvider2 == null || lastKnownLocationForProvider == null) ? lastKnownLocationForProvider2 != null ? lastKnownLocationForProvider2 : lastKnownLocationForProvider : lastKnownLocationForProvider2.getTime() > lastKnownLocationForProvider.getTime() ? lastKnownLocationForProvider2 : lastKnownLocationForProvider;
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
private Location getLastKnownLocationForProvider(String str) {
|
|
try {
|
|
if (this.mLocationManager.isProviderEnabled(str)) {
|
|
return this.mLocationManager.getLastKnownLocation(str);
|
|
}
|
|
return null;
|
|
} catch (Exception unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private boolean isStateValid() {
|
|
return this.mTwilightState.nextUpdate > System.currentTimeMillis();
|
|
}
|
|
|
|
private void updateState(@NonNull Location location) {
|
|
long j;
|
|
TwilightState twilightState = this.mTwilightState;
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
TwilightCalculator twilightCalculator = TwilightCalculator.getInstance();
|
|
twilightCalculator.calculateTwilight(currentTimeMillis - SignalManager.TWENTY_FOUR_HOURS_MILLIS, location.getLatitude(), location.getLongitude());
|
|
twilightCalculator.calculateTwilight(currentTimeMillis, location.getLatitude(), location.getLongitude());
|
|
boolean z = twilightCalculator.state == 1;
|
|
long j2 = twilightCalculator.sunrise;
|
|
long j3 = twilightCalculator.sunset;
|
|
twilightCalculator.calculateTwilight(currentTimeMillis + SignalManager.TWENTY_FOUR_HOURS_MILLIS, location.getLatitude(), location.getLongitude());
|
|
long j4 = twilightCalculator.sunrise;
|
|
if (j2 == -1 || j3 == -1) {
|
|
j = currentTimeMillis + 43200000;
|
|
} else {
|
|
if (currentTimeMillis <= j3) {
|
|
j4 = currentTimeMillis > j2 ? j3 : j2;
|
|
}
|
|
j = j4 + ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS;
|
|
}
|
|
twilightState.isNight = z;
|
|
twilightState.nextUpdate = j;
|
|
}
|
|
}
|