@@ -29,6 +29,8 @@ import io.sentry.protocol.DebugImage
2929import io.sentry.protocol.SentryId
3030import io.sentry.protocol.User
3131import io.sentry.transport.CurrentDateProvider
32+ import org.json.JSONObject
33+ import org.json.JSONArray
3234import java.lang.ref.WeakReference
3335import kotlin.math.roundToInt
3436
@@ -50,6 +52,7 @@ class SentryFlutterPlugin :
5052 pluginRegistrationTime = System .currentTimeMillis()
5153
5254 context = flutterPluginBinding.applicationContext
55+ applicationContext = context
5356 channel = MethodChannel (flutterPluginBinding.binaryMessenger, " sentry_flutter" )
5457 channel.setMethodCallHandler(this )
5558
@@ -63,7 +66,6 @@ class SentryFlutterPlugin :
6366 ) {
6467 when (call.method) {
6568 " initNativeSdk" -> initNativeSdk(call, result)
66- " loadImageList" -> loadImageList(call, result)
6769 " closeNativeSdk" -> closeNativeSdk(result)
6870 " fetchNativeAppStart" -> fetchNativeAppStart(result)
6971 " setContexts" -> setContexts(call.argument(" key" ), call.argument(" value" ), result)
@@ -75,7 +77,6 @@ class SentryFlutterPlugin :
7577 " removeExtra" -> removeExtra(call.argument(" key" ), result)
7678 " setTag" -> setTag(call.argument(" key" ), call.argument(" value" ), result)
7779 " removeTag" -> removeTag(call.argument(" key" ), result)
78- " loadContexts" -> loadContexts(result)
7980 " displayRefreshRate" -> displayRefreshRate(result)
8081 " nativeCrash" -> crash()
8182 " setReplayConfig" -> setReplayConfig(call, result)
@@ -90,6 +91,7 @@ class SentryFlutterPlugin :
9091 }
9192
9293 channel.setMethodCallHandler(null )
94+ applicationContext = null
9395 }
9496
9597 override fun onAttachedToActivity (binding : ActivityPluginBinding ) {
@@ -367,42 +369,6 @@ class SentryFlutterPlugin :
367369
368370 result.success(" " )
369371 }
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- )
406372
407373 private fun closeNativeSdk (result : Result ) {
408374 HubAdapter .getInstance().close()
@@ -414,11 +380,70 @@ class SentryFlutterPlugin :
414380 @SuppressLint(" StaticFieldLeak" )
415381 private var replay: ReplayIntegration ? = null
416382
383+ @SuppressLint(" StaticFieldLeak" )
384+ private var applicationContext: Context ? = null
385+
417386 private const val NATIVE_CRASH_WAIT_TIME = 500L
418387
419388 @JvmStatic
420389 fun privateSentryGetReplayIntegration (): ReplayIntegration ? = replay
421390
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+
422447 private fun crash () {
423448 val exception = RuntimeException (" FlutterSentry Native Integration: Sample RuntimeException" )
424449 val mainThread = Looper .getMainLooper().thread
@@ -436,22 +461,6 @@ class SentryFlutterPlugin :
436461 }
437462 }
438463
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-
455464 private fun setReplayConfig (
456465 call : MethodCall ,
457466 result : Result ,
0 commit comments