@@ -27,12 +27,19 @@ public class DecagonMobileAdsClient : AndroidJavaProxy, IMobileAdsClient
2727 {
2828 private static readonly DecagonMobileAdsClient _instance = new DecagonMobileAdsClient ( ) ;
2929 private readonly AndroidJavaObject _mobileAdsClass ;
30+ // Ensures InsightsEmitter is initialized from the main thread to handle CUIs.
31+ private readonly IInsightsEmitter _insightsEmitter = InsightsEmitter . Instance ;
32+ private readonly ITracer _tracer ;
3033 private Action < IInitializationStatusClient > _initCompleteAction ;
3134
3235 private DecagonMobileAdsClient ( )
3336 : base ( DecagonUtils . OnInitializationCompleteListenerClassName )
3437 {
3538 _mobileAdsClass = new AndroidJavaClass ( DecagonUtils . UnityMobileAdsClassName ) ;
39+ _tracer = new Tracer ( _insightsEmitter ) ;
40+ // Ensures GlobalExceptionHandler is initialized from the main thread to handle Android
41+ // untrapped exceptions.
42+ var _ = GlobalExceptionHandler . Instance ;
3643 }
3744
3845 public static DecagonMobileAdsClient Instance
@@ -42,26 +49,36 @@ public static DecagonMobileAdsClient Instance
4249
4350 public void Initialize ( Action < IInitializationStatusClient > initCompleteAction )
4451 {
45- _initCompleteAction = initCompleteAction ;
46-
47- Task . Run ( ( ) => {
48- int env = AndroidJNI . AttachCurrentThread ( ) ;
49- if ( env < 0 )
50- {
51- UnityEngine . Debug . LogError ( "Failed to attach current thread to JVM." ) ;
52- return ;
53- }
54-
55- try
56- {
57- _mobileAdsClass . CallStatic ( "initialize" ,
58- Utils . GetCurrentActivityAndroidJavaObject ( ) ,
59- this ) ;
60- }
61- finally
62- {
63- AndroidJNI . DetachCurrentThread ( ) ;
64- }
52+ using ( _tracer . StartTrace ( "DecagonMobileAdsClient.Initialize" ) )
53+ {
54+ _initCompleteAction = initCompleteAction ;
55+
56+ Task . Run ( ( ) => {
57+ using ( _tracer . StartTrace ( "AttachCurrentThread" ) )
58+ {
59+ int env = AndroidJNI . AttachCurrentThread ( ) ;
60+ if ( env < 0 )
61+ {
62+ UnityEngine . Debug . LogError ( "Failed to attach current thread to JVM." ) ;
63+ return ;
64+ }
65+ }
66+
67+ try
68+ {
69+ _mobileAdsClass . CallStatic ( "initialize" ,
70+ Utils . GetCurrentActivityAndroidJavaObject ( ) ,
71+ this ) ;
72+ }
73+ finally
74+ {
75+ AndroidJNI . DetachCurrentThread ( ) ;
76+ }
77+ } ) ;
78+ }
79+ _insightsEmitter . Emit ( new Insight ( )
80+ {
81+ Name = Insight . CuiName . SdkInitialized
6582 } ) ;
6683 }
6784
0 commit comments