From 555deb742da3d82a3fd924255f22d36fe558159e Mon Sep 17 00:00:00 2001 From: James Smith Date: Tue, 9 Jan 2018 17:25:37 -0800 Subject: [PATCH] Fix crash when enabling auto session capture, remove encapsulation breaking from Configuration --- .../java/com/bugsnag/android/Bugsnag.java | 12 +++++++++++ .../main/java/com/bugsnag/android/Client.java | 20 +++++++++++++++++++ .../com/bugsnag/android/Configuration.java | 9 --------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/sdk/src/main/java/com/bugsnag/android/Bugsnag.java b/sdk/src/main/java/com/bugsnag/android/Bugsnag.java index 3d4b6e46c9..ae86b5080f 100644 --- a/sdk/src/main/java/com/bugsnag/android/Bugsnag.java +++ b/sdk/src/main/java/com/bugsnag/android/Bugsnag.java @@ -218,6 +218,18 @@ public static void setSendThreads(final boolean sendThreads) { getClient().setSendThreads(sendThreads); } + /** + * Sets whether or not Bugsnag should automatically capture and report User sessions whenever + * the app enters the foreground. + *

+ * By default this behavior is disabled. + * + * @param autoCapture whether sessions should be captured automatically + */ + public static void setAutoCaptureSessions(boolean autoCapture) { + getClient().setAutoCaptureSessions(autoCapture); + } + /** * Set details of the user currently using your application. * You can search for this information in your Bugsnag dashboard. diff --git a/sdk/src/main/java/com/bugsnag/android/Client.java b/sdk/src/main/java/com/bugsnag/android/Client.java index 56f494a96e..9d925c32c1 100644 --- a/sdk/src/main/java/com/bugsnag/android/Client.java +++ b/sdk/src/main/java/com/bugsnag/android/Client.java @@ -484,6 +484,26 @@ public void setSendThreads(boolean sendThreads) { config.setSendThreads(sendThreads); } + + /** + * Sets whether or not Bugsnag should automatically capture and report User sessions whenever + * the app enters the foreground. + *

+ * By default this behavior is disabled. + * + * @param autoCapture whether sessions should be captured automatically + */ + public void setAutoCaptureSessions(boolean autoCapture) { + config.setAutoCaptureSessions(autoCapture); + + if (autoCapture) { // track any existing sessions + //noinspection ConstantConditions + if (sessionTracker != null) { + sessionTracker.onAutoCaptureEnabled(); + } + } + } + /** * Set details of the user currently using your application. * You can search for this information in your Bugsnag dashboard. diff --git a/sdk/src/main/java/com/bugsnag/android/Configuration.java b/sdk/src/main/java/com/bugsnag/android/Configuration.java index 9fd18ae37b..4c33e70f4c 100644 --- a/sdk/src/main/java/com/bugsnag/android/Configuration.java +++ b/sdk/src/main/java/com/bugsnag/android/Configuration.java @@ -357,15 +357,6 @@ public boolean shouldAutoCaptureSessions() { */ public void setAutoCaptureSessions(boolean autoCapture) { this.autoCaptureSessions = autoCapture; - - if (autoCapture) { // track any existing sessions - Client client = Bugsnag.getClient(); - - //noinspection ConstantConditions - if (client != null && client.sessionTracker != null) { - client.sessionTracker.onAutoCaptureEnabled(); - } - } } /**