apkfuckery/com.discord/smali/com/bugsnag/android/DeviceState.smali
2019-02-04 21:05:16 +01:00

736 lines
20 KiB
Smali

.class Lcom/bugsnag/android/DeviceState;
.super Ljava/lang/Object;
.source "DeviceState.java"
# interfaces
.implements Lcom/bugsnag/android/JsonStream$Streamable;
# instance fields
.field private final batteryLevel:Ljava/lang/Float;
.field private final charging:Ljava/lang/Boolean;
.field private final freeDisk:Ljava/lang/Long;
.field private final freeMemory:Ljava/lang/Long;
.field private final locationStatus:Ljava/lang/String;
.field private final networkAccess:Ljava/lang/String;
.field private final orientation:Ljava/lang/String;
.field private final time:Ljava/lang/String;
# direct methods
.method constructor <init>(Landroid/content/Context;)V
.locals 1
.param p1, "appContext" # Landroid/content/Context;
.annotation build Landroid/support/annotation/NonNull;
.end annotation
.end param
.prologue
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
invoke-static {}, Lcom/bugsnag/android/DeviceState;->getFreeMemory()Ljava/lang/Long;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->freeMemory:Ljava/lang/Long;
invoke-static {p1}, Lcom/bugsnag/android/DeviceState;->getOrientation(Landroid/content/Context;)Ljava/lang/String;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->orientation:Ljava/lang/String;
invoke-static {p1}, Lcom/bugsnag/android/DeviceState;->getBatteryLevel(Landroid/content/Context;)Ljava/lang/Float;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->batteryLevel:Ljava/lang/Float;
invoke-static {}, Lcom/bugsnag/android/DeviceState;->getFreeDisk()Ljava/lang/Long;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->freeDisk:Ljava/lang/Long;
invoke-static {p1}, Lcom/bugsnag/android/DeviceState;->isCharging(Landroid/content/Context;)Ljava/lang/Boolean;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->charging:Ljava/lang/Boolean;
invoke-static {p1}, Lcom/bugsnag/android/DeviceState;->getLocationStatus(Landroid/content/Context;)Ljava/lang/String;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->locationStatus:Ljava/lang/String;
invoke-static {p1}, Lcom/bugsnag/android/DeviceState;->getNetworkAccess(Landroid/content/Context;)Ljava/lang/String;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->networkAccess:Ljava/lang/String;
invoke-direct {p0}, Lcom/bugsnag/android/DeviceState;->getTime()Ljava/lang/String;
move-result-object v0
iput-object v0, p0, Lcom/bugsnag/android/DeviceState;->time:Ljava/lang/String;
return-void
.end method
.method private static getBatteryLevel(Landroid/content/Context;)Ljava/lang/Float;
.locals 7
.param p0, "appContext" # Landroid/content/Context;
.annotation build Landroid/support/annotation/Nullable;
.end annotation
.prologue
const/4 v3, 0x0
:try_start_0
new-instance v2, Landroid/content/IntentFilter;
const-string v4, "android.intent.action.BATTERY_CHANGED"
invoke-direct {v2, v4}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V
.local v2, "ifilter":Landroid/content/IntentFilter;
const/4 v4, 0x0
invoke-virtual {p0, v4, v2}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;
move-result-object v0
.local v0, "batteryStatus":Landroid/content/Intent;
const-string v4, "level"
const/4 v5, -0x1
invoke-virtual {v0, v4, v5}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I
move-result v4
int-to-float v4, v4
const-string v5, "scale"
const/4 v6, -0x1
invoke-virtual {v0, v5, v6}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I
move-result v5
int-to-float v5, v5
div-float/2addr v4, v5
invoke-static {v4}, Ljava/lang/Float;->valueOf(F)Ljava/lang/Float;
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
move-result-object v3
.end local v0 # "batteryStatus":Landroid/content/Intent;
.end local v2 # "ifilter":Landroid/content/IntentFilter;
:goto_0
return-object v3
:catch_0
move-exception v1
.local v1, "e":Ljava/lang/Exception;
const-string v4, "Could not get batteryLevel"
invoke-static {v4}, Lcom/bugsnag/android/Logger;->warn(Ljava/lang/String;)V
goto :goto_0
.end method
.method private static getFreeDisk()Ljava/lang/Long;
.locals 12
.annotation build Landroid/support/annotation/Nullable;
.end annotation
.prologue
:try_start_0
new-instance v1, Landroid/os/StatFs;
invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;
move-result-object v7
invoke-virtual {v7}, Ljava/io/File;->getPath()Ljava/lang/String;
move-result-object v7
invoke-direct {v1, v7}, Landroid/os/StatFs;-><init>(Ljava/lang/String;)V
.local v1, "externalStat":Landroid/os/StatFs;
invoke-virtual {v1}, Landroid/os/StatFs;->getBlockSize()I
move-result v7
int-to-long v8, v7
invoke-virtual {v1}, Landroid/os/StatFs;->getBlockCount()I
move-result v7
int-to-long v10, v7
mul-long v2, v8, v10
.local v2, "externalBytesAvailable":J
new-instance v6, Landroid/os/StatFs;
invoke-static {}, Landroid/os/Environment;->getDataDirectory()Ljava/io/File;
move-result-object v7
invoke-virtual {v7}, Ljava/io/File;->getPath()Ljava/lang/String;
move-result-object v7
invoke-direct {v6, v7}, Landroid/os/StatFs;-><init>(Ljava/lang/String;)V
.local v6, "internalStat":Landroid/os/StatFs;
invoke-virtual {v6}, Landroid/os/StatFs;->getBlockSize()I
move-result v7
int-to-long v8, v7
invoke-virtual {v6}, Landroid/os/StatFs;->getBlockCount()I
move-result v7
int-to-long v10, v7
mul-long v4, v8, v10
.local v4, "internalBytesAvailable":J
invoke-static {v4, v5, v2, v3}, Ljava/lang/Math;->min(JJ)J
move-result-wide v8
invoke-static {v8, v9}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
move-result-object v7
.end local v2 # "externalBytesAvailable":J
.end local v4 # "internalBytesAvailable":J
.end local v6 # "internalStat":Landroid/os/StatFs;
:goto_0
return-object v7
:catch_0
move-exception v0
.local v0, "e":Ljava/lang/Exception;
const-string v7, "Could not get freeDisk"
invoke-static {v7}, Lcom/bugsnag/android/Logger;->warn(Ljava/lang/String;)V
const/4 v7, 0x0
goto :goto_0
.end method
.method private static getFreeMemory()Ljava/lang/Long;
.locals 4
.annotation build Landroid/support/annotation/NonNull;
.end annotation
.prologue
invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;
move-result-object v0
invoke-virtual {v0}, Ljava/lang/Runtime;->maxMemory()J
move-result-wide v0
const-wide v2, 0x7fffffffffffffffL
cmp-long v0, v0, v2
if-eqz v0, :cond_0
invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;
move-result-object v0
invoke-virtual {v0}, Ljava/lang/Runtime;->maxMemory()J
move-result-wide v0
invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;
move-result-object v2
invoke-virtual {v2}, Ljava/lang/Runtime;->totalMemory()J
move-result-wide v2
sub-long/2addr v0, v2
invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;
move-result-object v2
invoke-virtual {v2}, Ljava/lang/Runtime;->freeMemory()J
move-result-wide v2
add-long/2addr v0, v2
invoke-static {v0, v1}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;
move-result-object v0
:goto_0
return-object v0
:cond_0
invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;
move-result-object v0
invoke-virtual {v0}, Ljava/lang/Runtime;->freeMemory()J
move-result-wide v0
invoke-static {v0, v1}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;
move-result-object v0
goto :goto_0
.end method
.method private static getLocationStatus(Landroid/content/Context;)Ljava/lang/String;
.locals 4
.param p0, "appContext" # Landroid/content/Context;
.annotation build Landroid/support/annotation/Nullable;
.end annotation
.prologue
:try_start_0
invoke-virtual {p0}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;
move-result-object v0
.local v0, "cr":Landroid/content/ContentResolver;
const-string v3, "location_providers_allowed"
invoke-static {v0, v3}, Landroid/provider/Settings$Secure;->getString(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;
move-result-object v2
.local v2, "providersAllowed":Ljava/lang/String;
if-eqz v2, :cond_0
invoke-virtual {v2}, Ljava/lang/String;->length()I
move-result v3
if-lez v3, :cond_0
const-string v3, "allowed"
.end local v0 # "cr":Landroid/content/ContentResolver;
.end local v2 # "providersAllowed":Ljava/lang/String;
:goto_0
return-object v3
.restart local v0 # "cr":Landroid/content/ContentResolver;
.restart local v2 # "providersAllowed":Ljava/lang/String;
:cond_0
const-string v3, "disallowed"
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
goto :goto_0
.end local v0 # "cr":Landroid/content/ContentResolver;
.end local v2 # "providersAllowed":Ljava/lang/String;
:catch_0
move-exception v1
.local v1, "e":Ljava/lang/Exception;
const-string v3, "Could not get locationStatus"
invoke-static {v3}, Lcom/bugsnag/android/Logger;->warn(Ljava/lang/String;)V
const/4 v3, 0x0
goto :goto_0
.end method
.method private static getNetworkAccess(Landroid/content/Context;)Ljava/lang/String;
.locals 5
.param p0, "appContext" # Landroid/content/Context;
.annotation build Landroid/support/annotation/Nullable;
.end annotation
.prologue
:try_start_0
const-string v3, "connectivity"
invoke-virtual {p0, v3}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;
move-result-object v1
check-cast v1, Landroid/net/ConnectivityManager;
.local v1, "cm":Landroid/net/ConnectivityManager;
invoke-virtual {v1}, Landroid/net/ConnectivityManager;->getActiveNetworkInfo()Landroid/net/NetworkInfo;
move-result-object v0
.local v0, "activeNetwork":Landroid/net/NetworkInfo;
if-eqz v0, :cond_2
invoke-virtual {v0}, Landroid/net/NetworkInfo;->isConnectedOrConnecting()Z
move-result v3
if-eqz v3, :cond_2
invoke-virtual {v0}, Landroid/net/NetworkInfo;->getType()I
move-result v3
const/4 v4, 0x1
if-ne v3, v4, :cond_0
const-string v3, "wifi"
.end local v0 # "activeNetwork":Landroid/net/NetworkInfo;
.end local v1 # "cm":Landroid/net/ConnectivityManager;
:goto_0
return-object v3
.restart local v0 # "activeNetwork":Landroid/net/NetworkInfo;
.restart local v1 # "cm":Landroid/net/ConnectivityManager;
:cond_0
invoke-virtual {v0}, Landroid/net/NetworkInfo;->getType()I
move-result v3
const/16 v4, 0x9
if-ne v3, v4, :cond_1
const-string v3, "ethernet"
goto :goto_0
:cond_1
const-string v3, "cellular"
goto :goto_0
:cond_2
const-string v3, "none"
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
goto :goto_0
.end local v0 # "activeNetwork":Landroid/net/NetworkInfo;
.end local v1 # "cm":Landroid/net/ConnectivityManager;
:catch_0
move-exception v2
.local v2, "e":Ljava/lang/Exception;
const-string v3, "Could not get network access information, we recommend granting the \'android.permission.ACCESS_NETWORK_STATE\' permission"
invoke-static {v3}, Lcom/bugsnag/android/Logger;->warn(Ljava/lang/String;)V
const/4 v3, 0x0
goto :goto_0
.end method
.method private static getOrientation(Landroid/content/Context;)Ljava/lang/String;
.locals 2
.param p0, "appContext" # Landroid/content/Context;
.annotation build Landroid/support/annotation/Nullable;
.end annotation
.prologue
const/4 v0, 0x0
.local v0, "orientation":Ljava/lang/String;
invoke-virtual {p0}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;
move-result-object v1
invoke-virtual {v1}, Landroid/content/res/Resources;->getConfiguration()Landroid/content/res/Configuration;
move-result-object v1
iget v1, v1, Landroid/content/res/Configuration;->orientation:I
packed-switch v1, :pswitch_data_0
const/4 v0, 0x0
:goto_0
return-object v0
:pswitch_0
const-string v0, "landscape"
goto :goto_0
:pswitch_1
const-string v0, "portrait"
goto :goto_0
:pswitch_data_0
.packed-switch 0x1
:pswitch_1
:pswitch_0
.end packed-switch
.end method
.method private getTime()Ljava/lang/String;
.locals 1
.annotation build Landroid/support/annotation/NonNull;
.end annotation
.prologue
new-instance v0, Ljava/util/Date;
invoke-direct {v0}, Ljava/util/Date;-><init>()V
invoke-static {v0}, Lcom/bugsnag/android/DateUtils;->toISO8601(Ljava/util/Date;)Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method private static isCharging(Landroid/content/Context;)Ljava/lang/Boolean;
.locals 7
.param p0, "appContext" # Landroid/content/Context;
.annotation build Landroid/support/annotation/Nullable;
.end annotation
.prologue
const/4 v4, 0x0
:try_start_0
new-instance v2, Landroid/content/IntentFilter;
const-string v5, "android.intent.action.BATTERY_CHANGED"
invoke-direct {v2, v5}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V
.local v2, "ifilter":Landroid/content/IntentFilter;
const/4 v5, 0x0
invoke-virtual {p0, v5, v2}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;
move-result-object v0
.local v0, "batteryStatus":Landroid/content/Intent;
const-string v5, "status"
const/4 v6, -0x1
invoke-virtual {v0, v5, v6}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I
move-result v3
.local v3, "status":I
const/4 v5, 0x2
if-eq v3, v5, :cond_0
const/4 v5, 0x5
if-ne v3, v5, :cond_1
:cond_0
const/4 v5, 0x1
:goto_0
invoke-static {v5}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
move-result-object v4
.end local v0 # "batteryStatus":Landroid/content/Intent;
.end local v2 # "ifilter":Landroid/content/IntentFilter;
.end local v3 # "status":I
:goto_1
return-object v4
.restart local v0 # "batteryStatus":Landroid/content/Intent;
.restart local v2 # "ifilter":Landroid/content/IntentFilter;
.restart local v3 # "status":I
:cond_1
const/4 v5, 0x0
goto :goto_0
.end local v0 # "batteryStatus":Landroid/content/Intent;
.end local v2 # "ifilter":Landroid/content/IntentFilter;
.end local v3 # "status":I
:catch_0
move-exception v1
.local v1, "e":Ljava/lang/Exception;
const-string v5, "Could not get charging status"
invoke-static {v5}, Lcom/bugsnag/android/Logger;->warn(Ljava/lang/String;)V
goto :goto_1
.end method
# virtual methods
.method public toStream(Lcom/bugsnag/android/JsonStream;)V
.locals 2
.param p1, "writer" # Lcom/bugsnag/android/JsonStream;
.annotation build Landroid/support/annotation/NonNull;
.end annotation
.end param
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.prologue
invoke-virtual {p1}, Lcom/bugsnag/android/JsonStream;->beginObject()Lcom/bugsnag/android/JsonWriter;
const-string v0, "freeMemory"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->freeMemory:Ljava/lang/Long;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/Number;)Lcom/bugsnag/android/JsonWriter;
iget-object v0, p0, Lcom/bugsnag/android/DeviceState;->orientation:Ljava/lang/String;
if-eqz v0, :cond_0
const-string v0, "orientation"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->orientation:Ljava/lang/String;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/String;)Lcom/bugsnag/android/JsonWriter;
:cond_0
iget-object v0, p0, Lcom/bugsnag/android/DeviceState;->batteryLevel:Ljava/lang/Float;
if-eqz v0, :cond_1
const-string v0, "batteryLevel"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->batteryLevel:Ljava/lang/Float;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/Number;)Lcom/bugsnag/android/JsonWriter;
:cond_1
iget-object v0, p0, Lcom/bugsnag/android/DeviceState;->freeDisk:Ljava/lang/Long;
if-eqz v0, :cond_2
const-string v0, "freeDisk"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->freeDisk:Ljava/lang/Long;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/Number;)Lcom/bugsnag/android/JsonWriter;
:cond_2
iget-object v0, p0, Lcom/bugsnag/android/DeviceState;->charging:Ljava/lang/Boolean;
if-eqz v0, :cond_3
const-string v0, "charging"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->charging:Ljava/lang/Boolean;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/Boolean;)V
:cond_3
iget-object v0, p0, Lcom/bugsnag/android/DeviceState;->locationStatus:Ljava/lang/String;
if-eqz v0, :cond_4
const-string v0, "locationStatus"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->locationStatus:Ljava/lang/String;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/String;)Lcom/bugsnag/android/JsonWriter;
:cond_4
iget-object v0, p0, Lcom/bugsnag/android/DeviceState;->networkAccess:Ljava/lang/String;
if-eqz v0, :cond_5
const-string v0, "networkAccess"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->networkAccess:Ljava/lang/String;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/String;)Lcom/bugsnag/android/JsonWriter;
:cond_5
const-string v0, "time"
invoke-virtual {p1, v0}, Lcom/bugsnag/android/JsonStream;->name(Ljava/lang/String;)Lcom/bugsnag/android/JsonStream;
move-result-object v0
iget-object v1, p0, Lcom/bugsnag/android/DeviceState;->time:Ljava/lang/String;
invoke-virtual {v0, v1}, Lcom/bugsnag/android/JsonStream;->value(Ljava/lang/String;)Lcom/bugsnag/android/JsonWriter;
invoke-virtual {p1}, Lcom/bugsnag/android/JsonStream;->endObject()Lcom/bugsnag/android/JsonWriter;
return-void
.end method