-
-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add main
flag to threads and in_foreground
flag for app contexts
#2516
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b7da780
Add flag for is main thread and is app in foreground
marandaneto ba8c711
sentry api
marandaneto 4319ed5
add tests
marandaneto 1e7b54f
fix
marandaneto f5602f0
Merge branch 'main' into feat/main-thread-foreground-app
marandaneto 5a19204
fix tests
marandaneto 3fa6824
Merge branch 'feat/main-thread-foreground-app' of https://github.com/…
marandaneto c3e3112
add missing test
marandaneto 47d0c2c
Merge branch 'main' into feat/main-thread-foreground-app
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ public DefaultAndroidEventProcessor( | |
this.options = Objects.requireNonNull(options, "The options object is required."); | ||
|
||
ExecutorService executorService = Executors.newSingleThreadExecutor(); | ||
// dont ref. to method reference, theres a bug on it | ||
// don't ref. to method reference, theres a bug on it | ||
//noinspection Convert2MethodRef | ||
contextData = executorService.submit(() -> loadContextData()); | ||
|
||
|
@@ -128,8 +128,8 @@ public DefaultAndroidEventProcessor( | |
// we only set memory data if it's not a hard crash, when it's a hard crash the event is | ||
// enriched on restart, so non static data might be wrong, eg lowMemory or availMem will | ||
// be different if the App. crashes because of OOM. | ||
processNonCachedEvent(event); | ||
setThreads(event); | ||
processNonCachedEvent(event, hint); | ||
setThreads(event, hint); | ||
} | ||
|
||
setCommons(event, true, applyScopeData); | ||
|
@@ -201,23 +201,34 @@ private void mergeOS(final @NotNull SentryBaseEvent event) { | |
} | ||
|
||
// Data to be applied to events that was created in the running process | ||
private void processNonCachedEvent(final @NotNull SentryBaseEvent event) { | ||
private void processNonCachedEvent( | ||
final @NotNull SentryBaseEvent event, final @NotNull Hint hint) { | ||
App app = event.getContexts().getApp(); | ||
if (app == null) { | ||
app = new App(); | ||
} | ||
setAppExtras(app); | ||
setAppExtras(app, hint); | ||
|
||
setPackageInfo(event, app); | ||
|
||
event.getContexts().setApp(app); | ||
} | ||
|
||
private void setThreads(final @NotNull SentryEvent event) { | ||
private void setThreads(final @NotNull SentryEvent event, final @NotNull Hint hint) { | ||
if (event.getThreads() != null) { | ||
for (SentryThread thread : event.getThreads()) { | ||
final boolean isHybridSDK = HintUtils.isFromHybridSdk(hint); | ||
|
||
for (final SentryThread thread : event.getThreads()) { | ||
final boolean isMainThread = AndroidMainThreadChecker.getInstance().isMainThread(thread); | ||
|
||
// TODO: Fix https://github.com/getsentry/team-mobile/issues/47 | ||
if (thread.isCurrent() == null) { | ||
thread.setCurrent(AndroidMainThreadChecker.getInstance().isMainThread(thread)); | ||
thread.setCurrent(isMainThread); | ||
} | ||
|
||
// This should not be set by Hybrid SDKs since they have their own threading model | ||
if (!isHybridSDK && thread.isMain() == null) { | ||
thread.setMain(isMainThread); | ||
} | ||
} | ||
} | ||
|
@@ -241,9 +252,19 @@ private void setDist(final @NotNull SentryBaseEvent event, final @NotNull String | |
} | ||
} | ||
|
||
private void setAppExtras(final @NotNull App app) { | ||
private void setAppExtras(final @NotNull App app, final @NotNull Hint hint) { | ||
app.setAppName(getApplicationName()); | ||
app.setAppStartTime(DateUtils.toUtilDate(AppStartState.getInstance().getAppStartTime())); | ||
|
||
// This should not be set by Hybrid SDKs since they have their own app's lifecycle | ||
if (!HintUtils.isFromHybridSdk(hint) && app.getInForeground() == null) { | ||
Comment on lines
+259
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running into #2525 |
||
// This feature depends on the AppLifecycleIntegration being installed, so only if | ||
// enableAutoSessionTracking or enableAppLifecycleBreadcrumbs are enabled. | ||
final @Nullable Boolean isBackground = AppState.getInstance().isInBackground(); | ||
if (isBackground != null) { | ||
app.setInForeground(!isBackground); | ||
} | ||
} | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
|
@@ -256,21 +277,21 @@ private void setAppExtras(final @NotNull App app) { | |
return Build.CPU_ABI2; | ||
} | ||
|
||
@SuppressWarnings({"ObsoleteSdkInt", "deprecation"}) | ||
@SuppressWarnings({"ObsoleteSdkInt", "deprecation", "NewApi"}) | ||
private void setArchitectures(final @NotNull Device device) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
String[] supportedAbis = Build.SUPPORTED_ABIS; | ||
device.setArchs(supportedAbis); | ||
final String[] supportedAbis; | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.LOLLIPOP) { | ||
supportedAbis = Build.SUPPORTED_ABIS; | ||
} else { | ||
String[] supportedAbis = {getAbi(), getAbi2()}; | ||
device.setArchs(supportedAbis); | ||
supportedAbis = new String[] {getAbi(), getAbi2()}; | ||
// we were not checking CPU_ABI2, but I've added to the list now | ||
} | ||
device.setArchs(supportedAbis); | ||
} | ||
|
||
@SuppressWarnings("ObsoleteSdkInt") | ||
@SuppressWarnings({"ObsoleteSdkInt", "NewApi"}) | ||
private @NotNull Long getMemorySize(final @NotNull ActivityManager.MemoryInfo memInfo) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN) { | ||
return memInfo.totalMem; | ||
} | ||
// using Runtime as a fallback | ||
|
@@ -393,17 +414,18 @@ private void setDeviceIO(final @NotNull Device device, final boolean applyScopeD | |
} | ||
} | ||
|
||
@SuppressWarnings("ObsoleteSdkInt") | ||
@SuppressWarnings({"ObsoleteSdkInt", "NewApi"}) | ||
private @Nullable String getDeviceName() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
return Settings.Global.getString(context.getContentResolver(), "device_name"); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@SuppressWarnings("NewApi") | ||
private TimeZone getTimeZone() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.N) { | ||
LocaleList locales = context.getResources().getConfiguration().getLocales(); | ||
if (!locales.isEmpty()) { | ||
Locale locale = locales.get(0); | ||
|
@@ -557,9 +579,9 @@ private TimeZone getTimeZone() { | |
} | ||
} | ||
|
||
@SuppressWarnings("ObsoleteSdkInt") | ||
@SuppressWarnings({"ObsoleteSdkInt", "NewApi"}) | ||
private long getBlockSizeLong(final @NotNull StatFs stat) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
return stat.getBlockSizeLong(); | ||
} | ||
return getBlockSizeDep(stat); | ||
|
@@ -570,9 +592,9 @@ private int getBlockSizeDep(final @NotNull StatFs stat) { | |
return stat.getBlockSize(); | ||
} | ||
|
||
@SuppressWarnings("ObsoleteSdkInt") | ||
@SuppressWarnings({"ObsoleteSdkInt", "NewApi"}) | ||
private long getBlockCountLong(final @NotNull StatFs stat) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
return stat.getBlockCountLong(); | ||
} | ||
return getBlockCountDep(stat); | ||
|
@@ -583,9 +605,9 @@ private int getBlockCountDep(final @NotNull StatFs stat) { | |
return stat.getBlockCount(); | ||
} | ||
|
||
@SuppressWarnings("ObsoleteSdkInt") | ||
@SuppressWarnings({"ObsoleteSdkInt", "NewApi"}) | ||
private long getAvailableBlocksLong(final @NotNull StatFs stat) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
return stat.getAvailableBlocksLong(); | ||
} | ||
return getAvailableBlocksDep(stat); | ||
|
@@ -627,9 +649,9 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) { | |
return null; | ||
} | ||
|
||
@SuppressWarnings("ObsoleteSdkInt") | ||
@SuppressWarnings({"ObsoleteSdkInt", "NewApi"}) | ||
private @Nullable File[] getExternalFilesDirs() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.KITKAT) { | ||
return context.getExternalFilesDirs(null); | ||
} else { | ||
File single = context.getExternalFilesDir(null); | ||
|
@@ -907,7 +929,7 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) { | |
final boolean applyScopeData = shouldApplyScopeData(transaction, hint); | ||
|
||
if (applyScopeData) { | ||
processNonCachedEvent(transaction); | ||
processNonCachedEvent(transaction, hint); | ||
} | ||
|
||
setCommons(transaction, false, applyScopeData); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to https://github.com/getsentry/sentry-java/pull/2516/files#r1099000230