@@ -93,7 +93,7 @@ public DefaultAndroidEventProcessor(
9393 this .options = Objects .requireNonNull (options , "The options object is required." );
9494
9595 ExecutorService executorService = Executors .newSingleThreadExecutor ();
96- // dont ref. to method reference, theres a bug on it
96+ // don't ref. to method reference, theres a bug on it
9797 //noinspection Convert2MethodRef
9898 contextData = executorService .submit (() -> loadContextData ());
9999
@@ -128,8 +128,8 @@ public DefaultAndroidEventProcessor(
128128 // we only set memory data if it's not a hard crash, when it's a hard crash the event is
129129 // enriched on restart, so non static data might be wrong, eg lowMemory or availMem will
130130 // be different if the App. crashes because of OOM.
131- processNonCachedEvent (event );
132- setThreads (event );
131+ processNonCachedEvent (event , hint );
132+ setThreads (event , hint );
133133 }
134134
135135 setCommons (event , true , applyScopeData );
@@ -201,23 +201,34 @@ private void mergeOS(final @NotNull SentryBaseEvent event) {
201201 }
202202
203203 // Data to be applied to events that was created in the running process
204- private void processNonCachedEvent (final @ NotNull SentryBaseEvent event ) {
204+ private void processNonCachedEvent (
205+ final @ NotNull SentryBaseEvent event , final @ NotNull Hint hint ) {
205206 App app = event .getContexts ().getApp ();
206207 if (app == null ) {
207208 app = new App ();
208209 }
209- setAppExtras (app );
210+ setAppExtras (app , hint );
210211
211212 setPackageInfo (event , app );
212213
213214 event .getContexts ().setApp (app );
214215 }
215216
216- private void setThreads (final @ NotNull SentryEvent event ) {
217+ private void setThreads (final @ NotNull SentryEvent event , final @ NotNull Hint hint ) {
217218 if (event .getThreads () != null ) {
218- for (SentryThread thread : event .getThreads ()) {
219+ final boolean isHybridSDK = HintUtils .isFromHybridSdk (hint );
220+
221+ for (final SentryThread thread : event .getThreads ()) {
222+ final boolean isMainThread = AndroidMainThreadChecker .getInstance ().isMainThread (thread );
223+
224+ // TODO: Fix https://github.com/getsentry/team-mobile/issues/47
219225 if (thread .isCurrent () == null ) {
220- thread .setCurrent (AndroidMainThreadChecker .getInstance ().isMainThread (thread ));
226+ thread .setCurrent (isMainThread );
227+ }
228+
229+ // This should not be set by Hybrid SDKs since they have their own threading model
230+ if (!isHybridSDK && thread .isMain () == null ) {
231+ thread .setMain (isMainThread );
221232 }
222233 }
223234 }
@@ -241,9 +252,19 @@ private void setDist(final @NotNull SentryBaseEvent event, final @NotNull String
241252 }
242253 }
243254
244- private void setAppExtras (final @ NotNull App app ) {
255+ private void setAppExtras (final @ NotNull App app , final @ NotNull Hint hint ) {
245256 app .setAppName (getApplicationName ());
246257 app .setAppStartTime (DateUtils .toUtilDate (AppStartState .getInstance ().getAppStartTime ()));
258+
259+ // This should not be set by Hybrid SDKs since they have their own app's lifecycle
260+ if (!HintUtils .isFromHybridSdk (hint ) && app .getInForeground () == null ) {
261+ // This feature depends on the AppLifecycleIntegration being installed, so only if
262+ // enableAutoSessionTracking or enableAppLifecycleBreadcrumbs are enabled.
263+ final @ Nullable Boolean isBackground = AppState .getInstance ().isInBackground ();
264+ if (isBackground != null ) {
265+ app .setInForeground (!isBackground );
266+ }
267+ }
247268 }
248269
249270 @ SuppressWarnings ("deprecation" )
@@ -256,21 +277,21 @@ private void setAppExtras(final @NotNull App app) {
256277 return Build .CPU_ABI2 ;
257278 }
258279
259- @ SuppressWarnings ({"ObsoleteSdkInt" , "deprecation" })
280+ @ SuppressWarnings ({"ObsoleteSdkInt" , "deprecation" , "NewApi" })
260281 private void setArchitectures (final @ NotNull Device device ) {
261- if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) {
262- String [] supportedAbis = Build .SUPPORTED_ABIS ;
263- device . setArchs ( supportedAbis ) ;
282+ final String [] supportedAbis ;
283+ if ( buildInfoProvider . getSdkInfoVersion () > = Build .VERSION_CODES . LOLLIPOP ) {
284+ supportedAbis = Build . SUPPORTED_ABIS ;
264285 } else {
265- String [] supportedAbis = {getAbi (), getAbi2 ()};
266- device .setArchs (supportedAbis );
286+ supportedAbis = new String [] {getAbi (), getAbi2 ()};
267287 // we were not checking CPU_ABI2, but I've added to the list now
268288 }
289+ device .setArchs (supportedAbis );
269290 }
270291
271- @ SuppressWarnings ("ObsoleteSdkInt" )
292+ @ SuppressWarnings ({ "ObsoleteSdkInt" , "NewApi" } )
272293 private @ NotNull Long getMemorySize (final @ NotNull ActivityManager .MemoryInfo memInfo ) {
273- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .JELLY_BEAN ) {
294+ if (buildInfoProvider . getSdkInfoVersion () >= Build .VERSION_CODES .JELLY_BEAN ) {
274295 return memInfo .totalMem ;
275296 }
276297 // using Runtime as a fallback
@@ -393,17 +414,18 @@ private void setDeviceIO(final @NotNull Device device, final boolean applyScopeD
393414 }
394415 }
395416
396- @ SuppressWarnings ("ObsoleteSdkInt" )
417+ @ SuppressWarnings ({ "ObsoleteSdkInt" , "NewApi" } )
397418 private @ Nullable String getDeviceName () {
398- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
419+ if (buildInfoProvider . getSdkInfoVersion () >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
399420 return Settings .Global .getString (context .getContentResolver (), "device_name" );
400421 } else {
401422 return null ;
402423 }
403424 }
404425
426+ @ SuppressWarnings ("NewApi" )
405427 private TimeZone getTimeZone () {
406- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .N ) {
428+ if (buildInfoProvider . getSdkInfoVersion () >= Build .VERSION_CODES .N ) {
407429 LocaleList locales = context .getResources ().getConfiguration ().getLocales ();
408430 if (!locales .isEmpty ()) {
409431 Locale locale = locales .get (0 );
@@ -557,9 +579,9 @@ private TimeZone getTimeZone() {
557579 }
558580 }
559581
560- @ SuppressWarnings ("ObsoleteSdkInt" )
582+ @ SuppressWarnings ({ "ObsoleteSdkInt" , "NewApi" } )
561583 private long getBlockSizeLong (final @ NotNull StatFs stat ) {
562- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
584+ if (buildInfoProvider . getSdkInfoVersion () >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
563585 return stat .getBlockSizeLong ();
564586 }
565587 return getBlockSizeDep (stat );
@@ -570,9 +592,9 @@ private int getBlockSizeDep(final @NotNull StatFs stat) {
570592 return stat .getBlockSize ();
571593 }
572594
573- @ SuppressWarnings ("ObsoleteSdkInt" )
595+ @ SuppressWarnings ({ "ObsoleteSdkInt" , "NewApi" } )
574596 private long getBlockCountLong (final @ NotNull StatFs stat ) {
575- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
597+ if (buildInfoProvider . getSdkInfoVersion () >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
576598 return stat .getBlockCountLong ();
577599 }
578600 return getBlockCountDep (stat );
@@ -583,9 +605,9 @@ private int getBlockCountDep(final @NotNull StatFs stat) {
583605 return stat .getBlockCount ();
584606 }
585607
586- @ SuppressWarnings ("ObsoleteSdkInt" )
608+ @ SuppressWarnings ({ "ObsoleteSdkInt" , "NewApi" } )
587609 private long getAvailableBlocksLong (final @ NotNull StatFs stat ) {
588- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
610+ if (buildInfoProvider . getSdkInfoVersion () >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
589611 return stat .getAvailableBlocksLong ();
590612 }
591613 return getAvailableBlocksDep (stat );
@@ -627,9 +649,9 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
627649 return null ;
628650 }
629651
630- @ SuppressWarnings ("ObsoleteSdkInt" )
652+ @ SuppressWarnings ({ "ObsoleteSdkInt" , "NewApi" } )
631653 private @ Nullable File [] getExternalFilesDirs () {
632- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .KITKAT ) {
654+ if (buildInfoProvider . getSdkInfoVersion () >= Build .VERSION_CODES .KITKAT ) {
633655 return context .getExternalFilesDirs (null );
634656 } else {
635657 File single = context .getExternalFilesDir (null );
@@ -907,7 +929,7 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) {
907929 final boolean applyScopeData = shouldApplyScopeData (transaction , hint );
908930
909931 if (applyScopeData ) {
910- processNonCachedEvent (transaction );
932+ processNonCachedEvent (transaction , hint );
911933 }
912934
913935 setCommons (transaction , false , applyScopeData );
0 commit comments