Skip to content

Commit

Permalink
fix: prevent unnecessary free disk calculations
Browse files Browse the repository at this point in the history
on initialisation calculateFreeDisk was indirectly invoked, which performs IO on the main thread.
This change avoids calls to getDeviceData() which would trigger these calculations, and adds getters
for the necessary fields instead. This stops StrictMode violations being reported when initialising
the SDK.
  • Loading branch information
fractalwrench committed Jan 9, 2019
1 parent 9f69368 commit 6e0c173
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
23 changes: 14 additions & 9 deletions ndk/src/main/java/com/bugsnag/android/ndk/NativeBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,26 @@ private void handleInstallMessage(Object arg) {
return;
}
String reportPath = reportDirectory + UUID.randomUUID().toString() + ".crash";
String[] abis = (String[])NativeInterface.getDeviceData().get("cpuAbi");
boolean is32bit = true;
for (String abi : abis) {
if (abi.contains("64")) {
is32bit = false;
break;
}
}
install(reportPath, true, Build.VERSION.SDK_INT, is32bit);
install(reportPath, true, Build.VERSION.SDK_INT, is32bit());
installed.set(true);
} finally {
lock.unlock();
}
}

private boolean is32bit() {
String[] abis = NativeInterface.getCpuAbi();

boolean is32bit = true;
for (String abi : abis) {
if (abi.contains("64")) {
is32bit = false;
break;
}
}
return is32bit;
}

private void handleAddBreadcrumb(Object arg) {
if (arg instanceof Breadcrumb) {
Breadcrumb crumb = (Breadcrumb) arg;
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public Client(@NonNull Context androidContext, @NonNull Configuration configurat
// Set sensible defaults
setProjectPackages(appContext.getPackageName());

String deviceId = getStringFromMap("id", deviceData.getDeviceData());
String deviceId = deviceData.getId();

if (config.getPersistUserBetweenSessions()) {
// Check to see if a user was stored in the SharedPreferences
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/main/java/com/bugsnag/android/DeviceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Map<String, Object> getDeviceMetaData() {
return map;
}

String getId() {
return id;
}

/**
* Check if the current Android device is rooted
*/
Expand Down
9 changes: 9 additions & 0 deletions sdk/src/main/java/com/bugsnag/android/NativeInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Used as the entry point for native code to allow proguard to obfuscate other areas if needed
*/
public class NativeInterface {

public enum MessageType {
/**
* Add a breadcrumb. The Message object should be the breadcrumb
Expand Down Expand Up @@ -233,6 +234,14 @@ public static Map<String,Object> getDeviceData() {
return deviceData;
}

/**
* Retrieve the CPU ABI(s) for the current device
*/
@NonNull
public static String[] getCpuAbi() {
return getClient().deviceData.cpuAbi;
}

/**
* Retrieves global metadata from the static Client instance as a Map
*/
Expand Down

0 comments on commit 6e0c173

Please sign in to comment.