Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

### Fixes

- Remove `AndroidRuntimeManager` StrictMode relaxation to prevent ANRs during SDK init ([#5127](https://github.com/getsentry/sentry-java/pull/5127))
- Fix crash when unregistering `SystemEventsBroadcastReceiver` with try-catch block. ([#5106](https://github.com/getsentry/sentry-java/pull/5106))

## 8.33.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.sentry.android.core.internal.modules.AssetsModulesLoader;
import io.sentry.android.core.internal.util.AndroidConnectionStatusProvider;
import io.sentry.android.core.internal.util.AndroidCurrentDateProvider;
import io.sentry.android.core.internal.util.AndroidRuntimeManager;
import io.sentry.android.core.internal.util.AndroidThreadChecker;
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
import io.sentry.android.core.performance.AppStartMetrics;
Expand Down Expand Up @@ -123,7 +122,6 @@ static void loadDefaultAndMetadataOptions(
options.setDefaultScopeType(ScopeType.CURRENT);
options.setOpenTelemetryMode(SentryOpenTelemetryMode.OFF);
options.setDateProvider(new SentryAndroidDateProvider());
options.setRuntimeManager(new AndroidRuntimeManager());
options.getLogs().setLoggerBatchProcessorFactory(new AndroidLoggerBatchProcessorFactory());
options.getMetrics().setMetricsBatchProcessorFactory(new AndroidMetricsBatchProcessorFactory());

Expand All @@ -135,10 +133,7 @@ static void loadDefaultAndMetadataOptions(

ManifestMetadataReader.applyMetadata(finalContext, options, buildInfoProvider);

options.setCacheDirPath(
options
.getRuntimeManager()
.runWithRelaxedPolicy(() -> getCacheDir(finalContext).getAbsolutePath()));
options.setCacheDirPath(getCacheDir(finalContext).getAbsolutePath());

readDefaultOptionValues(options, finalContext, buildInfoProvider);
AppState.getInstance().registerLifecycleObserver(options);
Expand Down Expand Up @@ -470,8 +465,7 @@ private static void readDefaultOptionValues(

if (options.getDistinctId() == null) {
try {
options.setDistinctId(
options.getRuntimeManager().runWithRelaxedPolicy(() -> Installation.id(context)));
options.setDistinctId(Installation.id(context));
} catch (RuntimeException e) {
options.getLogger().log(SentryLevel.ERROR, "Could not generate distinct Id.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private void mergeUser(final @NotNull SentryBaseEvent event) {

private @Nullable String getDeviceId() {
try {
return options.getRuntimeManager().runWithRelaxedPolicy(() -> Installation.id(context));
return Installation.id(context);
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error getting installationId.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void mergeUser(final @NotNull SentryBaseEvent event) {

// userId should be set even if event is Cached as the userId is static and won't change anyway.
if (user.getId() == null) {
user.setId(options.getRuntimeManager().runWithRelaxedPolicy(() -> Installation.id(context)));
user.setId(Installation.id(context));
}
if (user.getIpAddress() == null && options.isSendDefaultPii()) {
user.setIpAddress(IpAddressUtils.DEFAULT_IP_ADDRESS);
Expand Down Expand Up @@ -372,7 +372,7 @@ private void setAppExtras(final @NotNull App app, final @NotNull Hint hint) {
*/
public @NotNull User getDefaultUser(final @NotNull Context context) {
final @NotNull User user = new User();
user.setId(options.getRuntimeManager().runWithRelaxedPolicy(() -> Installation.id(context)));
user.setId(Installation.id(context));
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,21 @@ private void setDeviceIO(
// this way of getting the size of storage might be problematic for storages bigger than 2GB
// check the use of
// https://developer.android.com/reference/java/io/File.html#getFreeSpace%28%29
options
.getRuntimeManager()
.runWithRelaxedPolicy(
() -> {
final @Nullable File dataDir = Environment.getDataDirectory();
if (dataDir != null) {
StatFs internalStorageStat = new StatFs(dataDir.getPath());
device.setStorageSize(getTotalInternalStorage(internalStorageStat));
device.setFreeStorage(getUnusedInternalStorage(internalStorageStat));
}

if (includeExternalStorage) {
final @Nullable File internalStorageFile = context.getExternalFilesDir(null);
final @Nullable StatFs externalStorageStat =
getExternalStorageStat(internalStorageFile);
if (externalStorageStat != null) {
device.setExternalStorageSize(getTotalExternalStorage(externalStorageStat));
device.setExternalFreeStorage(getUnusedExternalStorage(externalStorageStat));
}
}
});
final @Nullable File dataDir = Environment.getDataDirectory();
if (dataDir != null) {
StatFs internalStorageStat = new StatFs(dataDir.getPath());
device.setStorageSize(getTotalInternalStorage(internalStorageStat));
device.setFreeStorage(getUnusedInternalStorage(internalStorageStat));
}

if (includeExternalStorage) {
final @Nullable File internalStorageFile = context.getExternalFilesDir(null);
final @Nullable StatFs externalStorageStat = getExternalStorageStat(internalStorageFile);
if (externalStorageStat != null) {
device.setExternalStorageSize(getTotalExternalStorage(externalStorageStat));
device.setExternalFreeStorage(getUnusedExternalStorage(externalStorageStat));
}
}

if (device.getConnectionType() == null) {
// wifi, ethernet or cellular, null if none
Expand Down Expand Up @@ -493,7 +487,7 @@ private Long getUnusedExternalStorage(final @NotNull StatFs stat) {
@Nullable
private String getDeviceId() {
try {
return options.getRuntimeManager().runWithRelaxedPolicy(() -> Installation.id(context));
return Installation.id(context);
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error getting installationId.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public static Map<String, Object> serializeScope(
}
if (user.getId() == null) {
try {
user.setId(
options.getRuntimeManager().runWithRelaxedPolicy(() -> Installation.id(context)));
user.setId(Installation.id(context));
} catch (RuntimeException e) {
logger.log(SentryLevel.ERROR, "Could not retrieve installation ID", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
import io.sentry.SentryOptions;
import io.sentry.TracesSampler;
import io.sentry.TracesSamplingDecision;
import io.sentry.android.core.internal.util.AndroidRuntimeManager;
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
import io.sentry.android.core.performance.AppStartMetrics;
import io.sentry.android.core.performance.TimeSpan;
import io.sentry.util.AutoClosableReentrantLock;
import io.sentry.util.runtime.IRuntimeManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -110,9 +108,7 @@ private void launchAppStartProfiler(final @NotNull AppStartMetrics appStartMetri
return;
}

final @NotNull IRuntimeManager runtimeManager = new AndroidRuntimeManager();
final @NotNull File cacheDir =
runtimeManager.runWithRelaxedPolicy(() -> AndroidOptionsInitializer.getCacheDir(context));
final @NotNull File cacheDir = AndroidOptionsInitializer.getCacheDir(context);
final @NotNull File configFile = new File(cacheDir, APP_START_PROFILING_CONFIG_FILE_NAME);

// No config exists: app start profiling is not enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ public static boolean hasStartupCrashMarker(final @NotNull SentryOptions options

final File crashMarkerFile = new File(outboxPath, STARTUP_CRASH_MARKER_FILE);
try {
final boolean exists =
options.getRuntimeManager().runWithRelaxedPolicy(() -> crashMarkerFile.exists());
final boolean exists = crashMarkerFile.exists();
if (exists) {
if (!options.getRuntimeManager().runWithRelaxedPolicy(() -> crashMarkerFile.delete())) {
if (!crashMarkerFile.delete()) {
options
.getLogger()
.log(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import io.sentry.android.core.internal.debugmeta.AssetsDebugMetaLoader
import io.sentry.android.core.internal.gestures.AndroidViewGestureTargetLocator
import io.sentry.android.core.internal.modules.AssetsModulesLoader
import io.sentry.android.core.internal.util.AndroidConnectionStatusProvider
import io.sentry.android.core.internal.util.AndroidRuntimeManager
import io.sentry.android.core.internal.util.AndroidThreadChecker
import io.sentry.android.core.performance.AppStartMetrics
import io.sentry.android.fragment.FragmentLifecycleIntegration
Expand Down Expand Up @@ -930,10 +929,4 @@ class AndroidOptionsInitializerTest {
fixture.sentryOptions.compositePerformanceCollector is DefaultCompositePerformanceCollector
}
}

@Test
fun `AndroidRuntimeManager is set in the options`() {
fixture.initSut()
assertIs<AndroidRuntimeManager>(fixture.sentryOptions.runtimeManager)
}
}

This file was deleted.

Loading
Loading