-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae00e42
commit f348f0c
Showing
5 changed files
with
54 additions
and
30 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
31 changes: 31 additions & 0 deletions
31
...ures/mazerunner/app/src/main/java/com/bugsnag/android/mazerunner/StartSessionBehaviour.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,31 @@ | ||
package com.bugsnag.android.mazerunner | ||
|
||
import android.app.Application | ||
import com.bugsnag.android.Bugsnag | ||
import com.bugsnag.android.Configuration | ||
import com.bugsnag.android.EndpointConfiguration | ||
|
||
fun Application.triggerManualSessionIfRequired() { | ||
val prefs = getSharedPreferences("SessionPreferences", android.content.Context.MODE_PRIVATE) | ||
val manualSession = prefs.getBoolean("manualSession", false) | ||
|
||
if (manualSession) { | ||
val notifyEndpoint = prefs.getString("notify", null) | ||
val sessionsEndpoint = prefs.getString("sessions", null) | ||
|
||
// we remove the preferences so that we don't affect any future startup | ||
prefs.edit() | ||
.remove("notify") | ||
.remove("sessions") | ||
.commit() | ||
|
||
// we have to startup Bugsnag at this point | ||
val config = Configuration.load(this) | ||
if (!notifyEndpoint.isNullOrBlank() && !sessionsEndpoint.isNullOrBlank()) { | ||
config.endpoints = EndpointConfiguration(notifyEndpoint, sessionsEndpoint) | ||
} | ||
|
||
Bugsnag.start(this, config) | ||
Bugsnag.startSession() | ||
} | ||
} |
33 changes: 12 additions & 21 deletions
33
...os/src/main/java/com/bugsnag/android/mazerunner/scenarios/StartSessionAutoModeScenario.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 |
---|---|---|
@@ -1,36 +1,27 @@ | ||
package com.bugsnag.android.mazerunner.scenarios | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import com.bugsnag.android.Bugsnag | ||
import com.bugsnag.android.Configuration | ||
import com.bugsnag.android.createDefaultDelivery | ||
import com.bugsnag.android.mazerunner.InterceptingDelivery | ||
import kotlin.system.exitProcess | ||
|
||
/** | ||
* Sends an automated session payload to Bugsnag. | ||
*/ | ||
internal class StartSessionAutoModeScenario( | ||
config: Configuration, | ||
context: Context, | ||
eventMetadata: String? | ||
) : Scenario(config, context, eventMetadata) { | ||
override fun startScenario() { | ||
context.applicationContext | ||
.getSharedPreferences("SessionPreferences", Context.MODE_PRIVATE) | ||
.edit() | ||
.putBoolean("manualSession", MANUAL_START) | ||
.putString("notify", config.endpoints.notify) | ||
.putString("sessions", config.endpoints.sessions) | ||
.commit() | ||
|
||
init { | ||
val baseDelivery = createDefaultDelivery() | ||
var intercept = true | ||
config.autoTrackSessions = true | ||
config.delivery = InterceptingDelivery(baseDelivery) { | ||
if (intercept) { | ||
intercept = false | ||
continueScenario() | ||
} | ||
} | ||
exitProcess(0) | ||
} | ||
|
||
private fun continueScenario() { | ||
Bugsnag.startSession() | ||
registerActivityLifecycleCallbacks() | ||
context.startActivity(Intent("com.bugsnag.android.mazerunner.UPDATE_CONTEXT")) | ||
companion object { | ||
private const val MANUAL_START = true | ||
} | ||
} |
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