From 6e0c173c718e44169077d9ff6147787f931cb236 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Wed, 9 Jan 2019 13:40:16 +0000 Subject: [PATCH] fix: prevent unnecessary free disk calculations 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. --- .../com/bugsnag/android/ndk/NativeBridge.java | 23 +++++++++++-------- .../main/java/com/bugsnag/android/Client.java | 2 +- .../java/com/bugsnag/android/DeviceData.java | 4 ++++ .../com/bugsnag/android/NativeInterface.java | 9 ++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ndk/src/main/java/com/bugsnag/android/ndk/NativeBridge.java b/ndk/src/main/java/com/bugsnag/android/ndk/NativeBridge.java index aeeebb43bc..a073fea2d4 100644 --- a/ndk/src/main/java/com/bugsnag/android/ndk/NativeBridge.java +++ b/ndk/src/main/java/com/bugsnag/android/ndk/NativeBridge.java @@ -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; diff --git a/sdk/src/main/java/com/bugsnag/android/Client.java b/sdk/src/main/java/com/bugsnag/android/Client.java index 80b554b2a9..d15c2dd260 100644 --- a/sdk/src/main/java/com/bugsnag/android/Client.java +++ b/sdk/src/main/java/com/bugsnag/android/Client.java @@ -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 diff --git a/sdk/src/main/java/com/bugsnag/android/DeviceData.java b/sdk/src/main/java/com/bugsnag/android/DeviceData.java index 9d444c925a..e168b68598 100644 --- a/sdk/src/main/java/com/bugsnag/android/DeviceData.java +++ b/sdk/src/main/java/com/bugsnag/android/DeviceData.java @@ -127,6 +127,10 @@ Map getDeviceMetaData() { return map; } + String getId() { + return id; + } + /** * Check if the current Android device is rooted */ diff --git a/sdk/src/main/java/com/bugsnag/android/NativeInterface.java b/sdk/src/main/java/com/bugsnag/android/NativeInterface.java index 4f552b234f..fd4eed4bf2 100644 --- a/sdk/src/main/java/com/bugsnag/android/NativeInterface.java +++ b/sdk/src/main/java/com/bugsnag/android/NativeInterface.java @@ -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 @@ -233,6 +234,14 @@ public static Map 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 */