@@ -2,7 +2,6 @@ package com.bugsnag.android
22
33import android.content.Context
44import android.net.ConnectivityManager
5- import com.bugsnag.android.Bugsnag.client
65
76/* *
87 * Accesses the session tracker and flushes all stored sessions
@@ -11,31 +10,62 @@ internal fun flushAllSessions() {
1110 Bugsnag .getClient().sessionTracker.flushStoredSessions()
1211}
1312
14- internal fun flushErrorStoreAsync (client : Client , apiClient : ErrorReportApiClient ) {
15- client.errorStore.flushAsync(apiClient )
13+ internal fun flushErrorStoreAsync (client : Client ) {
14+ client.errorStore.flushAsync()
1615}
1716
18- internal fun flushErrorStoreOnLaunch (client : Client , apiClient : ErrorReportApiClient ) {
19- client.errorStore.flushOnLaunch(apiClient )
17+ internal fun flushErrorStoreOnLaunch (client : Client ) {
18+ client.errorStore.flushOnLaunch()
2019}
2120
2221/* *
23- * Creates an error API client with a 500ms delay, emulating poor network connectivity
22+ * Creates a delivery API client with a 500ms delay, emulating poor network connectivity
2423 */
25- internal fun createSlowErrorApiClient (context : Context ): ErrorReportApiClient {
24+ internal fun createSlowDelivery (context : Context ): Delivery {
2625 val cm = context.getSystemService(Context .CONNECTIVITY_SERVICE ) as ConnectivityManager ?
27- val defaultHttpClient = DefaultHttpClient (cm)
28-
29- return ErrorReportApiClient ({ url: String? ,
30- report: Report ? ,
31- headers: MutableMap <String , String >? ->
32- Thread .sleep(500 )
33- defaultHttpClient.postReport(url, report, headers)
34- })
26+ val delivery = DefaultDelivery (cm)
27+
28+ return object : Delivery {
29+ override fun deliver (payload : SessionTrackingPayload ? , config : Configuration ? ) {
30+ Thread .sleep(500 )
31+ delivery.deliver(payload, config)
32+ }
33+
34+ override fun deliver (report : Report ? , config : Configuration ? ) {
35+ Thread .sleep(500 )
36+ delivery.deliver(report, config)
37+ }
38+ }
39+ }
40+
41+ internal fun createDefaultDelivery (context : Context ): DefaultDelivery {
42+ val cm = context.getSystemService(Context .CONNECTIVITY_SERVICE ) as ConnectivityManager ?
43+ return DefaultDelivery (cm)
44+ }
45+
46+ internal fun createCustomHeaderDelivery (context : Context ): Delivery {
47+ return object : Delivery {
48+ val delivery: DefaultDelivery = createDefaultDelivery(context)
49+
50+ override fun deliver (payload : SessionTrackingPayload ? , config : Configuration ? ) {
51+ deliver(config?.sessionEndpoint, payload, config?.sessionApiHeaders)
52+ }
53+
54+ override fun deliver (report : Report ? , config : Configuration ? ) {
55+ deliver(config?.endpoint, report, config?.errorApiHeaders)
56+ }
57+
58+ fun deliver (endpoint : String? ,
59+ streamable : JsonStream .Streamable ? ,
60+ headers : MutableMap <String , String >? ) {
61+ headers!! [" Custom-Client" ] = " Hello World"
62+ delivery.deliver(endpoint, streamable, headers)
63+ }
64+ }
3565}
3666
67+
3768internal fun writeErrorToStore (client : Client ) {
3869 val error = Error .Builder (Configuration (" api-key" ), RuntimeException (), null ).build()
3970 client.errorStore.write(error)
4071}
41-
0 commit comments