apkfuckery/com.discord/smali/androidx/appcompat/app/TwilightManager.smali

488 lines
12 KiB
Smali
Raw Normal View History

2019-12-06 03:29:40 +00:00
.class public Landroidx/appcompat/app/TwilightManager;
2019-07-24 11:27:29 +00:00
.super Ljava/lang/Object;
.source "TwilightManager.java"
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Landroidx/appcompat/app/TwilightManager$TwilightState;
}
.end annotation
# static fields
2019-12-06 03:29:40 +00:00
.field public static final SUNRISE:I = 0x6
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
.field public static final SUNSET:I = 0x16
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
.field public static final TAG:Ljava/lang/String; = "TwilightManager"
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
.field public static sInstance:Landroidx/appcompat/app/TwilightManager;
2019-07-24 11:27:29 +00:00
# instance fields
2019-12-06 03:29:40 +00:00
.field public final mContext:Landroid/content/Context;
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
.field public final mLocationManager:Landroid/location/LocationManager;
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
.field public final mTwilightState:Landroidx/appcompat/app/TwilightManager$TwilightState;
2019-07-24 11:27:29 +00:00
# direct methods
2019-12-06 03:29:40 +00:00
.method public constructor <init>(Landroid/content/Context;Landroid/location/LocationManager;)V
2019-07-24 11:27:29 +00:00
.locals 1
2019-12-06 03:29:40 +00:00
.param p1 # Landroid/content/Context;
.annotation build Landroidx/annotation/NonNull;
.end annotation
.end param
.param p2 # Landroid/location/LocationManager;
.annotation build Landroidx/annotation/NonNull;
.end annotation
.end param
.annotation build Landroidx/annotation/VisibleForTesting;
.end annotation
2019-07-24 11:27:29 +00:00
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
new-instance v0, Landroidx/appcompat/app/TwilightManager$TwilightState;
invoke-direct {v0}, Landroidx/appcompat/app/TwilightManager$TwilightState;-><init>()V
iput-object v0, p0, Landroidx/appcompat/app/TwilightManager;->mTwilightState:Landroidx/appcompat/app/TwilightManager$TwilightState;
iput-object p1, p0, Landroidx/appcompat/app/TwilightManager;->mContext:Landroid/content/Context;
iput-object p2, p0, Landroidx/appcompat/app/TwilightManager;->mLocationManager:Landroid/location/LocationManager;
return-void
.end method
2019-12-06 03:29:40 +00:00
.method public static getInstance(Landroid/content/Context;)Landroidx/appcompat/app/TwilightManager;
2019-07-24 11:27:29 +00:00
.locals 2
2019-12-06 03:29:40 +00:00
.param p0 # Landroid/content/Context;
.annotation build Landroidx/annotation/NonNull;
.end annotation
.end param
2019-07-24 11:27:29 +00:00
sget-object v0, Landroidx/appcompat/app/TwilightManager;->sInstance:Landroidx/appcompat/app/TwilightManager;
if-nez v0, :cond_0
invoke-virtual {p0}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;
move-result-object p0
new-instance v0, Landroidx/appcompat/app/TwilightManager;
const-string v1, "location"
invoke-virtual {p0, v1}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;
move-result-object v1
check-cast v1, Landroid/location/LocationManager;
invoke-direct {v0, p0, v1}, Landroidx/appcompat/app/TwilightManager;-><init>(Landroid/content/Context;Landroid/location/LocationManager;)V
sput-object v0, Landroidx/appcompat/app/TwilightManager;->sInstance:Landroidx/appcompat/app/TwilightManager;
:cond_0
sget-object p0, Landroidx/appcompat/app/TwilightManager;->sInstance:Landroidx/appcompat/app/TwilightManager;
return-object p0
.end method
.method private getLastKnownLocation()Landroid/location/Location;
.locals 7
2019-12-06 03:29:40 +00:00
.annotation build Landroid/annotation/SuppressLint;
value = {
"MissingPermission"
}
.end annotation
2019-07-24 11:27:29 +00:00
iget-object v0, p0, Landroidx/appcompat/app/TwilightManager;->mContext:Landroid/content/Context;
const-string v1, "android.permission.ACCESS_COARSE_LOCATION"
invoke-static {v0, v1}, Landroidx/core/content/PermissionChecker;->checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I
move-result v0
const/4 v1, 0x0
if-nez v0, :cond_0
const-string v0, "network"
invoke-direct {p0, v0}, Landroidx/appcompat/app/TwilightManager;->getLastKnownLocationForProvider(Ljava/lang/String;)Landroid/location/Location;
move-result-object v0
goto :goto_0
:cond_0
move-object v0, v1
:goto_0
iget-object v2, p0, Landroidx/appcompat/app/TwilightManager;->mContext:Landroid/content/Context;
const-string v3, "android.permission.ACCESS_FINE_LOCATION"
invoke-static {v2, v3}, Landroidx/core/content/PermissionChecker;->checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I
move-result v2
if-nez v2, :cond_1
const-string v1, "gps"
invoke-direct {p0, v1}, Landroidx/appcompat/app/TwilightManager;->getLastKnownLocationForProvider(Ljava/lang/String;)Landroid/location/Location;
move-result-object v1
:cond_1
if-eqz v1, :cond_3
if-eqz v0, :cond_3
invoke-virtual {v1}, Landroid/location/Location;->getTime()J
move-result-wide v2
invoke-virtual {v0}, Landroid/location/Location;->getTime()J
move-result-wide v4
cmp-long v6, v2, v4
if-lez v6, :cond_2
2019-12-06 03:29:40 +00:00
move-object v0, v1
2019-07-24 11:27:29 +00:00
:cond_2
return-object v0
:cond_3
if-eqz v1, :cond_4
2019-12-06 03:29:40 +00:00
move-object v0, v1
2019-07-24 11:27:29 +00:00
:cond_4
return-object v0
.end method
.method private getLastKnownLocationForProvider(Ljava/lang/String;)Landroid/location/Location;
.locals 2
2019-12-06 03:29:40 +00:00
.annotation build Landroidx/annotation/RequiresPermission;
anyOf = {
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION"
}
.end annotation
2019-07-24 11:27:29 +00:00
:try_start_0
iget-object v0, p0, Landroidx/appcompat/app/TwilightManager;->mLocationManager:Landroid/location/LocationManager;
invoke-virtual {v0, p1}, Landroid/location/LocationManager;->isProviderEnabled(Ljava/lang/String;)Z
move-result v0
if-eqz v0, :cond_0
iget-object v0, p0, Landroidx/appcompat/app/TwilightManager;->mLocationManager:Landroid/location/LocationManager;
invoke-virtual {v0, p1}, Landroid/location/LocationManager;->getLastKnownLocation(Ljava/lang/String;)Landroid/location/Location;
move-result-object p1
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
return-object p1
:catch_0
move-exception p1
const-string v0, "TwilightManager"
const-string v1, "Failed to get last known location"
invoke-static {v0, v1, p1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
:cond_0
const/4 p1, 0x0
return-object p1
.end method
.method private isStateValid()Z
.locals 5
iget-object v0, p0, Landroidx/appcompat/app/TwilightManager;->mTwilightState:Landroidx/appcompat/app/TwilightManager$TwilightState;
iget-wide v0, v0, Landroidx/appcompat/app/TwilightManager$TwilightState;->nextUpdate:J
invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
move-result-wide v2
cmp-long v4, v0, v2
if-lez v4, :cond_0
const/4 v0, 0x1
2019-12-06 03:29:40 +00:00
goto :goto_0
2019-07-24 11:27:29 +00:00
:cond_0
const/4 v0, 0x0
2019-12-06 03:29:40 +00:00
:goto_0
2019-07-24 11:27:29 +00:00
return v0
.end method
2019-12-06 03:29:40 +00:00
.method public static setInstance(Landroidx/appcompat/app/TwilightManager;)V
2019-07-24 11:27:29 +00:00
.locals 0
2019-12-06 03:29:40 +00:00
.annotation build Landroidx/annotation/VisibleForTesting;
.end annotation
2019-07-24 11:27:29 +00:00
sput-object p0, Landroidx/appcompat/app/TwilightManager;->sInstance:Landroidx/appcompat/app/TwilightManager;
return-void
.end method
.method private updateState(Landroid/location/Location;)V
.locals 22
2019-12-06 03:29:40 +00:00
.param p1 # Landroid/location/Location;
.annotation build Landroidx/annotation/NonNull;
.end annotation
.end param
2019-07-24 11:27:29 +00:00
move-object/from16 v0, p0
iget-object v1, v0, Landroidx/appcompat/app/TwilightManager;->mTwilightState:Landroidx/appcompat/app/TwilightManager$TwilightState;
invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
move-result-wide v9
invoke-static {}, Landroidx/appcompat/app/TwilightCalculator;->getInstance()Landroidx/appcompat/app/TwilightCalculator;
move-result-object v11
const-wide/32 v12, 0x5265c00
sub-long v3, v9, v12
invoke-virtual/range {p1 .. p1}, Landroid/location/Location;->getLatitude()D
move-result-wide v5
invoke-virtual/range {p1 .. p1}, Landroid/location/Location;->getLongitude()D
move-result-wide v7
move-object v2, v11
invoke-virtual/range {v2 .. v8}, Landroidx/appcompat/app/TwilightCalculator;->calculateTwilight(JDD)V
iget-wide v14, v11, Landroidx/appcompat/app/TwilightCalculator;->sunset:J
invoke-virtual/range {p1 .. p1}, Landroid/location/Location;->getLatitude()D
move-result-wide v5
invoke-virtual/range {p1 .. p1}, Landroid/location/Location;->getLongitude()D
move-result-wide v7
move-wide v3, v9
invoke-virtual/range {v2 .. v8}, Landroidx/appcompat/app/TwilightCalculator;->calculateTwilight(JDD)V
iget v2, v11, Landroidx/appcompat/app/TwilightCalculator;->state:I
const/4 v3, 0x1
if-ne v2, v3, :cond_0
const/4 v7, 0x1
goto :goto_0
:cond_0
const/4 v3, 0x0
const/4 v7, 0x0
:goto_0
iget-wide v5, v11, Landroidx/appcompat/app/TwilightCalculator;->sunrise:J
iget-wide v3, v11, Landroidx/appcompat/app/TwilightCalculator;->sunset:J
add-long/2addr v12, v9
invoke-virtual/range {p1 .. p1}, Landroid/location/Location;->getLatitude()D
move-result-wide v16
invoke-virtual/range {p1 .. p1}, Landroid/location/Location;->getLongitude()D
move-result-wide v18
move-object v2, v11
move-wide/from16 v20, v14
move-wide v14, v3
move-wide v3, v12
move-wide v12, v5
move-wide/from16 v5, v16
move v0, v7
move-wide/from16 v7, v18
invoke-virtual/range {v2 .. v8}, Landroidx/appcompat/app/TwilightCalculator;->calculateTwilight(JDD)V
iget-wide v2, v11, Landroidx/appcompat/app/TwilightCalculator;->sunrise:J
2019-12-06 03:29:40 +00:00
const-wide/16 v4, 0x0
const-wide/16 v6, -0x1
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
cmp-long v8, v12, v6
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
if-eqz v8, :cond_4
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
cmp-long v8, v14, v6
2019-07-24 11:27:29 +00:00
2019-12-06 03:29:40 +00:00
if-nez v8, :cond_1
2019-07-24 11:27:29 +00:00
goto :goto_2
:cond_1
cmp-long v6, v9, v14
if-lez v6, :cond_2
add-long/2addr v4, v2
goto :goto_1
:cond_2
cmp-long v6, v9, v12
if-lez v6, :cond_3
add-long/2addr v4, v14
goto :goto_1
:cond_3
add-long/2addr v4, v12
:goto_1
const-wide/32 v6, 0xea60
add-long/2addr v4, v6
goto :goto_3
:cond_4
:goto_2
const-wide/32 v4, 0x2932e00
add-long/2addr v4, v9
:goto_3
iput-boolean v0, v1, Landroidx/appcompat/app/TwilightManager$TwilightState;->isNight:Z
move-wide/from16 v6, v20
iput-wide v6, v1, Landroidx/appcompat/app/TwilightManager$TwilightState;->yesterdaySunset:J
iput-wide v12, v1, Landroidx/appcompat/app/TwilightManager$TwilightState;->todaySunrise:J
iput-wide v14, v1, Landroidx/appcompat/app/TwilightManager$TwilightState;->todaySunset:J
iput-wide v2, v1, Landroidx/appcompat/app/TwilightManager$TwilightState;->tomorrowSunrise:J
iput-wide v4, v1, Landroidx/appcompat/app/TwilightManager$TwilightState;->nextUpdate:J
return-void
.end method
# virtual methods
2019-12-06 03:29:40 +00:00
.method public isNight()Z
2019-07-24 11:27:29 +00:00
.locals 2
iget-object v0, p0, Landroidx/appcompat/app/TwilightManager;->mTwilightState:Landroidx/appcompat/app/TwilightManager$TwilightState;
invoke-direct {p0}, Landroidx/appcompat/app/TwilightManager;->isStateValid()Z
move-result v1
if-eqz v1, :cond_0
iget-boolean v0, v0, Landroidx/appcompat/app/TwilightManager$TwilightState;->isNight:Z
return v0
:cond_0
invoke-direct {p0}, Landroidx/appcompat/app/TwilightManager;->getLastKnownLocation()Landroid/location/Location;
move-result-object v1
if-eqz v1, :cond_1
invoke-direct {p0, v1}, Landroidx/appcompat/app/TwilightManager;->updateState(Landroid/location/Location;)V
iget-boolean v0, v0, Landroidx/appcompat/app/TwilightManager$TwilightState;->isNight:Z
return v0
:cond_1
const-string v0, "TwilightManager"
const-string v1, "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."
invoke-static {v0, v1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I
invoke-static {}, Ljava/util/Calendar;->getInstance()Ljava/util/Calendar;
move-result-object v0
const/16 v1, 0xb
invoke-virtual {v0, v1}, Ljava/util/Calendar;->get(I)I
move-result v0
const/4 v1, 0x6
if-lt v0, v1, :cond_3
const/16 v1, 0x16
if-lt v0, v1, :cond_2
goto :goto_0
:cond_2
const/4 v0, 0x0
2019-12-06 03:29:40 +00:00
goto :goto_1
2019-07-24 11:27:29 +00:00
:cond_3
:goto_0
const/4 v0, 0x1
2019-12-06 03:29:40 +00:00
:goto_1
2019-07-24 11:27:29 +00:00
return v0
.end method