Skip to content

Commit 327ca51

Browse files
authored
perf(init): Do not retrieve ActivityManager if API < 35 (#5275)
* perf(init): Do not retrieve ActivityManager if API < 35 * Changelog
1 parent 2195398 commit 327ca51

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
- Android: Attachments on the scope will now be synced to native ([#5211](https://github.com/getsentry/sentry-java/pull/5211))
1212
- Add THIRD_PARTY_NOTICES.md for vendored third-party code, bundled as SENTRY_THIRD_PARTY_NOTICES.md in the sentry JAR under META-INF ([#5186](https://github.com/getsentry/sentry-java/pull/5186))
1313

14+
### Improvements
15+
16+
- Do not retrieve `ActivityManager` if API < 35 on SDK init ([#5275](https://github.com/getsentry/sentry-java/pull/5275))
17+
1418
## 8.37.1
1519

1620
### Fixes

sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,19 +338,20 @@ public void registerLifecycleCallbacks(final @NotNull Application application) {
338338
appLaunchedInForeground.resetValue();
339339
application.registerActivityLifecycleCallbacks(instance);
340340

341-
final @Nullable ActivityManager activityManager =
342-
(ActivityManager) application.getSystemService(Context.ACTIVITY_SERVICE);
343-
344-
if (activityManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
345-
final List<ApplicationStartInfo> historicalProcessStartReasons =
346-
activityManager.getHistoricalProcessStartReasons(1);
347-
if (!historicalProcessStartReasons.isEmpty()) {
348-
final @NotNull ApplicationStartInfo info = historicalProcessStartReasons.get(0);
349-
if (info.getStartupState() == ApplicationStartInfo.STARTUP_STATE_STARTED) {
350-
if (info.getStartType() == ApplicationStartInfo.START_TYPE_COLD) {
351-
appStartType = AppStartType.COLD;
352-
} else {
353-
appStartType = AppStartType.WARM;
341+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
342+
final @Nullable ActivityManager activityManager =
343+
(ActivityManager) application.getSystemService(Context.ACTIVITY_SERVICE);
344+
if (activityManager != null) {
345+
final List<ApplicationStartInfo> historicalProcessStartReasons =
346+
activityManager.getHistoricalProcessStartReasons(1);
347+
if (!historicalProcessStartReasons.isEmpty()) {
348+
final @NotNull ApplicationStartInfo info = historicalProcessStartReasons.get(0);
349+
if (info.getStartupState() == ApplicationStartInfo.STARTUP_STATE_STARTED) {
350+
if (info.getStartType() == ApplicationStartInfo.START_TYPE_COLD) {
351+
appStartType = AppStartType.COLD;
352+
} else {
353+
appStartType = AppStartType.WARM;
354+
}
354355
}
355356
}
356357
}

0 commit comments

Comments
 (0)