From ffb74468c9319b171ed382c7b0e1bd6976c6dd10 Mon Sep 17 00:00:00 2001 From: YYChen01988 Date: Tue, 16 Apr 2024 11:24:10 +0100 Subject: [PATCH] feat(session) Make isPaused private --- .../src/main/java/com/bugsnag/android/Session.java | 12 ++++++++++-- .../java/com/bugsnag/android/SessionTracker.java | 6 +++--- .../src/test/java/com/bugsnag/android/SessionTest.kt | 2 ++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/Session.java b/bugsnag-android-core/src/main/java/com/bugsnag/android/Session.java index d078f75607..5081ad22e7 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/Session.java +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/Session.java @@ -32,7 +32,7 @@ public final class Session implements JsonStream.Streamable, UserAware { private final AtomicInteger unhandledCount = new AtomicInteger(); private final AtomicInteger handledCount = new AtomicInteger(); private final AtomicBoolean tracked = new AtomicBoolean(false); - final AtomicBoolean isPaused = new AtomicBoolean(false); + private final AtomicBoolean isPaused = new AtomicBoolean(false); private String apiKey; @@ -202,10 +202,18 @@ boolean markTracked() { return tracked.compareAndSet(false, true); } - boolean markPaused() { + boolean markResumed() { return isPaused.compareAndSet(true, false); } + void markPaused() { + isPaused.set(true); + } + + boolean isPaused() { + return isPaused.get(); + } + boolean isAutoCaptured() { return autoCaptured; } diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/SessionTracker.java b/bugsnag-android-core/src/main/java/com/bugsnag/android/SessionTracker.java index 34ce9bfe4d..9fc2747f5b 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/SessionTracker.java +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/SessionTracker.java @@ -120,7 +120,7 @@ void pauseSession() { Session session = currentSession; if (session != null) { - session.isPaused.set(true); + session.markPaused(); updateState(StateEvent.PauseSession.INSTANCE); } } @@ -133,7 +133,7 @@ boolean resumeSession() { session = startSession(false); resumed = false; } else { - resumed = session.markPaused(); + resumed = session.markResumed(); } if (session != null) { @@ -205,7 +205,7 @@ private boolean trackSessionIfNeeded(final Session session) { Session getCurrentSession() { Session session = currentSession; - if (session != null && !session.isPaused.get()) { + if (session != null && !session.isPaused()) { return session; } return null; diff --git a/bugsnag-android-core/src/test/java/com/bugsnag/android/SessionTest.kt b/bugsnag-android-core/src/test/java/com/bugsnag/android/SessionTest.kt index d4abf791c7..ae7c0f6fcd 100644 --- a/bugsnag-android-core/src/test/java/com/bugsnag/android/SessionTest.kt +++ b/bugsnag-android-core/src/test/java/com/bugsnag/android/SessionTest.kt @@ -142,6 +142,8 @@ class SessionTest { assertEquals(getUser(), copy.getUser()) // make a shallow copy assertEquals(isAutoCaptured, copy.isAutoCaptured) assertEquals(markTracked(), copy.markTracked()) + assertEquals(markResumed(), copy.markResumed()) + assertEquals(isPaused, copy.isPaused) assertEquals(markPaused(), copy.markPaused()) assertEquals(session.unhandledCount, copy.unhandledCount) assertEquals(session.handledCount, copy.handledCount)