Skip to content

Commit bba4efe

Browse files
committed
Do not cache importance
1 parent fde11a2 commit bba4efe

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/ContextUtils.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,6 @@ private ContextUtils() {}
9191
// to avoid doing a bunch of Binder calls we use LazyEvaluator to cache the values that are static
9292
// during the app process running
9393

94-
private static final @NotNull LazyEvaluator<Boolean> isForegroundImportance =
95-
new LazyEvaluator<>(
96-
() -> {
97-
try {
98-
final ActivityManager.RunningAppProcessInfo appProcessInfo =
99-
new ActivityManager.RunningAppProcessInfo();
100-
ActivityManager.getMyMemoryState(appProcessInfo);
101-
return appProcessInfo.importance == IMPORTANCE_FOREGROUND;
102-
} catch (Throwable ignored) {
103-
// should never happen
104-
}
105-
return false;
106-
});
107-
10894
/**
10995
* Since this packageInfo uses flags 0 we can assume it's static and cache it as the package name
11096
* or version code cannot change during runtime, only after app update (which will spin up a new
@@ -284,7 +270,15 @@ static String getVersionName(final @NotNull PackageInfo packageInfo) {
284270
*/
285271
@ApiStatus.Internal
286272
public static boolean isForegroundImportance() {
287-
return isForegroundImportance.getValue();
273+
try {
274+
final ActivityManager.RunningAppProcessInfo appProcessInfo =
275+
new ActivityManager.RunningAppProcessInfo();
276+
ActivityManager.getMyMemoryState(appProcessInfo);
277+
return appProcessInfo.importance == IMPORTANCE_FOREGROUND;
278+
} catch (Throwable ignored) {
279+
// should never happen
280+
}
281+
return false;
288282
}
289283

290284
/**
@@ -544,7 +538,6 @@ public static Context getApplicationContext(final @NotNull Context context) {
544538

545539
@TestOnly
546540
static void resetInstance() {
547-
isForegroundImportance.resetValue();
548541
staticPackageInfo33.resetValue();
549542
staticPackageInfo.resetValue();
550543
applicationName.resetValue();

sentry-android-core/src/main/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProvider.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import io.sentry.IConnectionStatusProvider;
1414
import io.sentry.ILogger;
1515
import io.sentry.ISentryLifecycleToken;
16-
import io.sentry.Sentry;
1716
import io.sentry.SentryLevel;
1817
import io.sentry.SentryOptions;
1918
import io.sentry.android.core.AppState;
@@ -23,8 +22,6 @@
2322
import io.sentry.util.AutoClosableReentrantLock;
2423
import java.util.ArrayList;
2524
import java.util.List;
26-
import java.util.concurrent.ExecutorService;
27-
import java.util.concurrent.Executors;
2825
import java.util.concurrent.ThreadFactory;
2926
import java.util.concurrent.atomic.AtomicBoolean;
3027
import org.jetbrains.annotations.ApiStatus;

0 commit comments

Comments
 (0)