From f1190ac4497d967ccc9c97123697de2c2988edcb Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Thu, 24 Jun 2021 17:12:10 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Jason --- .../java/com/bugsnag/android/MemoryTrimTest.java | 3 +++ .../src/main/java/com/bugsnag/android/Client.java | 10 +++++----- .../com/bugsnag/android/SystemBroadcastReceiver.kt | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/MemoryTrimTest.java b/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/MemoryTrimTest.java index 9d6cfe6cf7..8d8799b65d 100644 --- a/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/MemoryTrimTest.java +++ b/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/MemoryTrimTest.java @@ -36,6 +36,9 @@ public void onLowMemoryEvent() { when(context.getApplicationContext()).thenReturn(context); Client client = new Client(context, BugsnagTestUtils.generateConfiguration()); + // block until observer is registered + client.bgTaskService.shutdown(); + // capture the registered ComponentCallbacks verify(context, times(1)).registerComponentCallbacks(componentCallbacksCaptor.capture()); diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/Client.java b/bugsnag-android-core/src/main/java/com/bugsnag/android/Client.java index 98408712d3..8907151d87 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/Client.java +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/Client.java @@ -220,11 +220,6 @@ public Unit invoke(String activity, Map metadata) { exceptionHandler.install(); } - // register listeners for system events in the background. - systemBroadcastReceiver = new SystemBroadcastReceiver(this, logger); - registerComponentCallbacks(); - registerListenersInBackground(); - // load last run info lastRunInfoStore = new LastRunInfoStore(immutableConfig); lastRunInfo = loadLastRunInfo(); @@ -237,6 +232,11 @@ public Unit invoke(String activity, Map metadata) { eventStore.flushAsync(); sessionTracker.flushAsync(); + // register listeners for system events in the background. + systemBroadcastReceiver = new SystemBroadcastReceiver(this, logger); + registerComponentCallbacks(); + registerListenersInBackground(); + // leave auto breadcrumb Map data = Collections.emptyMap(); leaveAutoBreadcrumb("Bugsnag loaded", BreadcrumbType.STATE, data); diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/SystemBroadcastReceiver.kt b/bugsnag-android-core/src/main/java/com/bugsnag/android/SystemBroadcastReceiver.kt index 4e2d57d86a..ac8e309ccb 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/SystemBroadcastReceiver.kt +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/SystemBroadcastReceiver.kt @@ -35,7 +35,7 @@ internal class SystemBroadcastReceiver( fun shortenActionNameIfNeeded(action: String): String { return if (isAndroidKey(action)) { - action.substring(action.lastIndexOf(".") + 1) + action.substringAfterLast('.') } else { action }