Skip to content

Commit d2ac06f

Browse files
committed
perf(init): Do not retrieve ActivityManager if API < 35
1 parent 2195398 commit d2ac06f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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)