-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manage ReplayIntegration lifecycle properly
- Loading branch information
Showing
6 changed files
with
481 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayLifecycle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.sentry.android.replay | ||
|
||
enum class ReplayState { | ||
/** | ||
* Initial state of a Replay session. This is the state when ReplayIntegration is constructed | ||
* but has not been started yet. | ||
*/ | ||
INITIAL, | ||
|
||
/** | ||
* Started state for a Replay session. This state is reached after the start() method is called | ||
* and the recording is initialized successfully. | ||
*/ | ||
STARTED, | ||
|
||
/** | ||
* Resumed state for a Replay session. This state is reached after resume() is called on an | ||
* already started recording. | ||
*/ | ||
RESUMED, | ||
|
||
/** | ||
* Paused state for a Replay session. This state is reached after pause() is called on a | ||
* resumed recording. | ||
*/ | ||
PAUSED, | ||
|
||
/** | ||
* Stopped state for a Replay session. This state is reached after stop() is called. | ||
* The recording can be started again from this state. | ||
*/ | ||
STOPPED, | ||
|
||
/** | ||
* Closed state for a Replay session. This is the terminal state reached after close() is called. | ||
* No further state transitions are possible after this. | ||
*/ | ||
CLOSED; | ||
} | ||
|
||
/** | ||
* Class to manage state transitions for ReplayIntegration | ||
*/ | ||
internal class ReplayLifecycle { | ||
@field:Volatile | ||
internal var currentState = ReplayState.INITIAL | ||
|
||
fun isAllowed(newState: ReplayState): Boolean = when (currentState) { | ||
ReplayState.INITIAL -> newState == ReplayState.STARTED || newState == ReplayState.CLOSED | ||
ReplayState.STARTED -> newState == ReplayState.PAUSED || newState == ReplayState.STOPPED || newState == ReplayState.CLOSED | ||
ReplayState.RESUMED -> newState == ReplayState.PAUSED || newState == ReplayState.STOPPED || newState == ReplayState.CLOSED | ||
ReplayState.PAUSED -> newState == ReplayState.RESUMED || newState == ReplayState.STOPPED || newState == ReplayState.CLOSED | ||
ReplayState.STOPPED -> newState == ReplayState.STARTED || newState == ReplayState.CLOSED | ||
ReplayState.CLOSED -> false | ||
} | ||
|
||
fun isTouchRecordingAllowed(): Boolean = currentState == ReplayState.STARTED || currentState == ReplayState.RESUMED | ||
} |
Oops, something went wrong.