4
4
import android .content .pm .PackageInfo ;
5
5
import android .content .pm .PackageManager ;
6
6
import android .os .Build ;
7
- import io .sentry .DateUtils ;
8
- import io .sentry .EventProcessor ;
9
- import io .sentry .Hint ;
10
- import io .sentry .IpAddressUtils ;
11
- import io .sentry .NoOpLogger ;
12
- import io .sentry .SentryAttributeType ;
13
- import io .sentry .SentryBaseEvent ;
14
- import io .sentry .SentryEvent ;
15
- import io .sentry .SentryLevel ;
16
- import io .sentry .SentryLogEvent ;
17
- import io .sentry .SentryLogEventAttributeValue ;
18
- import io .sentry .SentryReplayEvent ;
7
+ import io .sentry .*;
19
8
import io .sentry .android .core .internal .util .AndroidThreadChecker ;
20
9
import io .sentry .android .core .performance .AppStartMetrics ;
21
10
import io .sentry .android .core .performance .TimeSpan ;
37
26
import java .util .concurrent .ExecutorService ;
38
27
import java .util .concurrent .Executors ;
39
28
import java .util .concurrent .Future ;
29
+ import java .util .concurrent .RejectedExecutionException ;
40
30
import org .jetbrains .annotations .NotNull ;
41
31
import org .jetbrains .annotations .Nullable ;
42
32
import org .jetbrains .annotations .TestOnly ;
@@ -47,7 +37,7 @@ final class DefaultAndroidEventProcessor implements EventProcessor {
47
37
48
38
private final @ NotNull BuildInfoProvider buildInfoProvider ;
49
39
private final @ NotNull SentryAndroidOptions options ;
50
- private final @ NotNull Future <DeviceInfoUtil > deviceInfoUtil ;
40
+ private final @ Nullable Future <DeviceInfoUtil > deviceInfoUtil ;
51
41
private final @ NotNull LazyEvaluator <String > deviceFamily =
52
42
new LazyEvaluator <>(() -> ContextUtils .getFamily (NoOpLogger .getInstance ()));
53
43
@@ -65,9 +55,16 @@ public DefaultAndroidEventProcessor(
65
55
// don't ref. to method reference, theres a bug on it
66
56
// noinspection Convert2MethodRef
67
57
// some device info performs disk I/O, but it's result is cached, let's pre-cache it
58
+ @ Nullable Future <DeviceInfoUtil > deviceInfoUtil ;
68
59
final @ NotNull ExecutorService executorService = Executors .newSingleThreadExecutor ();
69
- this .deviceInfoUtil =
70
- executorService .submit (() -> DeviceInfoUtil .getInstance (this .context , options ));
60
+ try {
61
+ deviceInfoUtil =
62
+ executorService .submit (() -> DeviceInfoUtil .getInstance (this .context , options ));
63
+ } catch (RejectedExecutionException e ) {
64
+ deviceInfoUtil = null ;
65
+ options .getLogger ().log (SentryLevel .WARNING , "Device info caching task rejected." , e );
66
+ }
67
+ this .deviceInfoUtil = deviceInfoUtil ;
71
68
executorService .shutdown ();
72
69
}
73
70
@@ -181,25 +178,34 @@ private void setDevice(
181
178
final boolean errorEvent ,
182
179
final boolean applyScopeData ) {
183
180
if (event .getContexts ().getDevice () == null ) {
184
- try {
185
- event
186
- .getContexts ()
187
- .setDevice (deviceInfoUtil .get ().collectDeviceInformation (errorEvent , applyScopeData ));
188
- } catch (Throwable e ) {
189
- options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" , e );
181
+ if (deviceInfoUtil != null ) {
182
+ try {
183
+ event
184
+ .getContexts ()
185
+ .setDevice (deviceInfoUtil .get ().collectDeviceInformation (errorEvent , applyScopeData ));
186
+ } catch (Throwable e ) {
187
+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" , e );
188
+ }
189
+ } else {
190
+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" );
190
191
}
191
192
mergeOS (event );
192
193
}
193
194
}
194
195
195
196
private void mergeOS (final @ NotNull SentryBaseEvent event ) {
196
197
final OperatingSystem currentOS = event .getContexts ().getOperatingSystem ();
197
- try {
198
- final OperatingSystem androidOS = deviceInfoUtil .get ().getOperatingSystem ();
199
- // make Android OS the main OS using the 'os' key
200
- event .getContexts ().setOperatingSystem (androidOS );
201
- } catch (Throwable e ) {
202
- options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve os system" , e );
198
+
199
+ if (deviceInfoUtil != null ) {
200
+ try {
201
+ final OperatingSystem androidOS = deviceInfoUtil .get ().getOperatingSystem ();
202
+ // make Android OS the main OS using the 'os' key
203
+ event .getContexts ().setOperatingSystem (androidOS );
204
+ } catch (Throwable e ) {
205
+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve os system" , e );
206
+ }
207
+ } else {
208
+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" );
203
209
}
204
210
205
211
if (currentOS != null ) {
@@ -284,10 +290,14 @@ private void setPackageInfo(final @NotNull SentryBaseEvent event, final @NotNull
284
290
setDist (event , versionCode );
285
291
286
292
@ Nullable DeviceInfoUtil deviceInfoUtil = null ;
287
- try {
288
- deviceInfoUtil = this .deviceInfoUtil .get ();
289
- } catch (Throwable e ) {
290
- options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" , e );
293
+ if (this .deviceInfoUtil != null ) {
294
+ try {
295
+ deviceInfoUtil = this .deviceInfoUtil .get ();
296
+ } catch (Throwable e ) {
297
+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" , e );
298
+ }
299
+ } else {
300
+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" );
291
301
}
292
302
293
303
ContextUtils .setAppPackageInfo (packageInfo , buildInfoProvider , deviceInfoUtil , app );
@@ -331,16 +341,20 @@ private void setAppExtras(final @NotNull App app, final @NotNull Hint hint) {
331
341
}
332
342
333
343
private void setSideLoadedInfo (final @ NotNull SentryBaseEvent event ) {
334
- try {
335
- final ContextUtils .SideLoadedInfo sideLoadedInfo = deviceInfoUtil .get ().getSideLoadedInfo ();
336
- if (sideLoadedInfo != null ) {
337
- final @ NotNull Map <String , String > tags = sideLoadedInfo .asTags ();
338
- for (Map .Entry <String , String > entry : tags .entrySet ()) {
339
- event .setTag (entry .getKey (), entry .getValue ());
344
+ if (deviceInfoUtil != null ) {
345
+ try {
346
+ final ContextUtils .SideLoadedInfo sideLoadedInfo = deviceInfoUtil .get ().getSideLoadedInfo ();
347
+ if (sideLoadedInfo != null ) {
348
+ final @ NotNull Map <String , String > tags = sideLoadedInfo .asTags ();
349
+ for (Map .Entry <String , String > entry : tags .entrySet ()) {
350
+ event .setTag (entry .getKey (), entry .getValue ());
351
+ }
340
352
}
353
+ } catch (Throwable e ) {
354
+ options .getLogger ().log (SentryLevel .ERROR , "Error getting side loaded info." , e );
341
355
}
342
- } catch ( Throwable e ) {
343
- options .getLogger ().log (SentryLevel .ERROR , "Error getting side loaded info." , e );
356
+ } else {
357
+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" );
344
358
}
345
359
}
346
360
0 commit comments