@@ -15,20 +15,6 @@ internal static class MauiDeviceData
1515 public static void ApplyMauiDeviceData ( this Device device , IDiagnosticLogger ? logger ,
1616 INetworkStatusListener ? networkStatusListener )
1717 {
18- #if ANDROID
19- // Accessing device information on Android doesn't have to happen on the UI thread, but it's not threadsafe.
20- // See: https://github.com/getsentry/sentry-dotnet/issues/3627
21- lock ( JniLock )
22- {
23- ApplyMauiDeviceDataInternal ( device , logger , networkStatusListener ) ;
24- }
25- #else
26- ApplyMauiDeviceDataInternal ( device , logger , networkStatusListener ) ;
27- #endif
28- }
29-
30- private static void ApplyMauiDeviceDataInternal ( Device device , IDiagnosticLogger ? logger , INetworkStatusListener ? networkStatusListener )
31- {
3218 try
3319 {
3420 // TODO: Add more device data where indicated
@@ -43,7 +29,17 @@ private static void ApplyMauiDeviceDataInternal(Device device, IDiagnosticLogger
4329 device . Name ??= deviceInfo . Name ;
4430 device . Manufacturer ??= deviceInfo . Manufacturer ;
4531 device . Model ??= deviceInfo . Model ;
32+ #if ANDROID
33+ // DeviceInfo.Idiom is not threadsafe on Android
34+ // See: https://github.com/getsentry/sentry-dotnet/issues/3627
35+ lock ( JniLock )
36+ {
37+ device . DeviceType ??= deviceInfo . Idiom . ToString ( ) ;
38+ }
39+ #else
4640 device . DeviceType ??= deviceInfo . Idiom . ToString ( ) ;
41+ #endif
42+
4743 device . Simulator ??= deviceInfo . DeviceType switch
4844 {
4945 DeviceType . Virtual => true ,
@@ -77,6 +73,9 @@ private static void ApplyMauiDeviceDataInternal(Device device, IDiagnosticLogger
7773
7874 try
7975 {
76+ // Note: Connectivity.NetworkAccess is not threadsafe on Android. As we already have a network listener
77+ // monitoring the status of the network, we get the online satus from there instead (on all platforms)
78+ // See: https://github.com/getsentry/sentry-dotnet/issues/3627
8079 device . IsOnline ??= networkStatusListener ? . Online ;
8180 }
8281 catch ( PermissionException )
@@ -99,6 +98,13 @@ private static void ApplyMauiDeviceDataInternal(Device device, IDiagnosticLogger
9998 MainThread . BeginInvokeOnMainThread ( ( ) => CaptureDisplayInfo ( resetEvent ) ) ;
10099 resetEvent . Wait ( ) ;
101100 }
101+ #elif ANDROID
102+ // DeviceDisplay.Current is not threadsafe on Android.
103+ // See: https://github.com/getsentry/sentry-dotnet/issues/3627
104+ lock ( JniLock )
105+ {
106+ CaptureDisplayInfo ( ) ;
107+ }
102108#else
103109 CaptureDisplayInfo ( ) ;
104110#endif
0 commit comments