@@ -29,6 +29,8 @@ import io.sentry.protocol.DebugImage
29
29
import io.sentry.protocol.SentryId
30
30
import io.sentry.protocol.User
31
31
import io.sentry.transport.CurrentDateProvider
32
+ import org.json.JSONObject
33
+ import org.json.JSONArray
32
34
import java.lang.ref.WeakReference
33
35
import kotlin.math.roundToInt
34
36
@@ -50,6 +52,7 @@ class SentryFlutterPlugin :
50
52
pluginRegistrationTime = System .currentTimeMillis()
51
53
52
54
context = flutterPluginBinding.applicationContext
55
+ applicationContext = context
53
56
channel = MethodChannel (flutterPluginBinding.binaryMessenger, " sentry_flutter" )
54
57
channel.setMethodCallHandler(this )
55
58
@@ -63,7 +66,6 @@ class SentryFlutterPlugin :
63
66
) {
64
67
when (call.method) {
65
68
" initNativeSdk" -> initNativeSdk(call, result)
66
- " loadImageList" -> loadImageList(call, result)
67
69
" closeNativeSdk" -> closeNativeSdk(result)
68
70
" fetchNativeAppStart" -> fetchNativeAppStart(result)
69
71
" setContexts" -> setContexts(call.argument(" key" ), call.argument(" value" ), result)
@@ -75,7 +77,6 @@ class SentryFlutterPlugin :
75
77
" removeExtra" -> removeExtra(call.argument(" key" ), result)
76
78
" setTag" -> setTag(call.argument(" key" ), call.argument(" value" ), result)
77
79
" removeTag" -> removeTag(call.argument(" key" ), result)
78
- " loadContexts" -> loadContexts(result)
79
80
" displayRefreshRate" -> displayRefreshRate(result)
80
81
" nativeCrash" -> crash()
81
82
" setReplayConfig" -> setReplayConfig(call, result)
@@ -90,6 +91,7 @@ class SentryFlutterPlugin :
90
91
}
91
92
92
93
channel.setMethodCallHandler(null )
94
+ applicationContext = null
93
95
}
94
96
95
97
override fun onAttachedToActivity (binding : ActivityPluginBinding ) {
@@ -367,42 +369,6 @@ class SentryFlutterPlugin :
367
369
368
370
result.success(" " )
369
371
}
370
- private fun loadImageList (
371
- call : MethodCall ,
372
- result : Result ,
373
- ) {
374
- val options = HubAdapter .getInstance().options as SentryAndroidOptions
375
-
376
- val addresses = call.arguments() as List <String >? ? : listOf ()
377
- val debugImages =
378
- if (addresses.isEmpty()) {
379
- options.debugImagesLoader
380
- .loadDebugImages()
381
- ?.toList()
382
- .serialize()
383
- } else {
384
- options.debugImagesLoader
385
- .loadDebugImagesForAddresses(addresses.toSet())
386
- ?.ifEmpty { options.debugImagesLoader.loadDebugImages() }
387
- ?.toList()
388
- .serialize()
389
- }
390
-
391
- result.success(debugImages)
392
- }
393
-
394
- private fun List<DebugImage>?.serialize () = this ?.map { it.serialize() }
395
-
396
- private fun DebugImage.serialize () =
397
- mapOf (
398
- " image_addr" to imageAddr,
399
- " image_size" to imageSize,
400
- " code_file" to codeFile,
401
- " type" to type,
402
- " debug_id" to debugId,
403
- " code_id" to codeId,
404
- " debug_file" to debugFile,
405
- )
406
372
407
373
private fun closeNativeSdk (result : Result ) {
408
374
HubAdapter .getInstance().close()
@@ -414,11 +380,70 @@ class SentryFlutterPlugin :
414
380
@SuppressLint(" StaticFieldLeak" )
415
381
private var replay: ReplayIntegration ? = null
416
382
383
+ @SuppressLint(" StaticFieldLeak" )
384
+ private var applicationContext: Context ? = null
385
+
417
386
private const val NATIVE_CRASH_WAIT_TIME = 500L
418
387
419
388
@JvmStatic
420
389
fun privateSentryGetReplayIntegration (): ReplayIntegration ? = replay
421
390
391
+ @JvmStatic
392
+ fun getApplicationContext (): Context ? = applicationContext
393
+
394
+ @JvmStatic
395
+ fun loadContextsAsBytes (): ByteArray? {
396
+ val options = HubAdapter .getInstance().options
397
+ val context = getApplicationContext()
398
+ if (options !is SentryAndroidOptions || context == null ) {
399
+ return null
400
+ }
401
+ val currentScope = InternalSentrySdk .getCurrentScope()
402
+ val serializedScope =
403
+ InternalSentrySdk .serializeScope(
404
+ context,
405
+ options,
406
+ currentScope,
407
+ )
408
+ val json = JSONObject (serializedScope).toString()
409
+ return json.toByteArray(Charsets .UTF_8 )
410
+ }
411
+
412
+ @JvmStatic
413
+ fun loadDebugImagesAsBytes (addresses : Set <String >): ByteArray? {
414
+ val options = HubAdapter .getInstance().options as SentryAndroidOptions
415
+
416
+ val debugImages =
417
+ if (addresses.isEmpty()) {
418
+ options.debugImagesLoader
419
+ .loadDebugImages()
420
+ ?.toList()
421
+ .serialize()
422
+ } else {
423
+ options.debugImagesLoader
424
+ .loadDebugImagesForAddresses(addresses)
425
+ ?.ifEmpty { options.debugImagesLoader.loadDebugImages() }
426
+ ?.toList()
427
+ .serialize()
428
+ }
429
+
430
+ val json = JSONArray (debugImages).toString()
431
+ return json.toByteArray(Charsets .UTF_8 )
432
+ }
433
+
434
+ private fun List<DebugImage>?.serialize () = this ?.map { it.serialize() }
435
+
436
+ private fun DebugImage.serialize () =
437
+ mapOf (
438
+ " image_addr" to imageAddr,
439
+ " image_size" to imageSize,
440
+ " code_file" to codeFile,
441
+ " type" to type,
442
+ " debug_id" to debugId,
443
+ " code_id" to codeId,
444
+ " debug_file" to debugFile,
445
+ )
446
+
422
447
private fun crash () {
423
448
val exception = RuntimeException (" FlutterSentry Native Integration: Sample RuntimeException" )
424
449
val mainThread = Looper .getMainLooper().thread
@@ -436,22 +461,6 @@ class SentryFlutterPlugin :
436
461
}
437
462
}
438
463
439
- private fun loadContexts (result : Result ) {
440
- val options = HubAdapter .getInstance().options
441
- if (options !is SentryAndroidOptions ) {
442
- result.success(null )
443
- return
444
- }
445
- val currentScope = InternalSentrySdk .getCurrentScope()
446
- val serializedScope =
447
- InternalSentrySdk .serializeScope(
448
- context,
449
- options,
450
- currentScope,
451
- )
452
- result.success(serializedScope)
453
- }
454
-
455
464
private fun setReplayConfig (
456
465
call : MethodCall ,
457
466
result : Result ,
0 commit comments