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