Skip to content

Commit b4acc8f

Browse files
authored
Merge branch 'main' into markushi/canvas-approach
2 parents c5de3e0 + cf708bd commit b4acc8f

File tree

31 files changed

+420
-99
lines changed

31 files changed

+420
-99
lines changed

.craft.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ targets:
3434
maven:io.sentry:sentry-apache-http-client-5:
3535
maven:io.sentry:sentry-android:
3636
maven:io.sentry:sentry-android-core:
37+
maven:io.sentry:sentry-android-distribution:
3738
maven:io.sentry:sentry-android-ndk:
3839
maven:io.sentry:sentry-android-timber:
3940
maven:io.sentry:sentry-kotlin-extensions:

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
3737

3838
- name: Initialize CodeQL
39-
uses: github/codeql-action/init@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # pin@v2
39+
uses: github/codeql-action/init@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # pin@v2
4040
with:
4141
languages: 'java'
4242

@@ -45,4 +45,4 @@ jobs:
4545
./gradlew buildForCodeQL --no-build-cache
4646
4747
- name: Perform CodeQL Analysis
48-
uses: github/codeql-action/analyze@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # pin@v2
48+
uses: github/codeql-action/analyze@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # pin@v2

.github/workflows/danger.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ on:
66

77
jobs:
88
danger:
9-
uses: getsentry/github-workflows/.github/workflows/danger.yml@v2
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: getsentry/github-workflows/danger@v3

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Add experimental Sentry Android Distribution module for integrating with Sentry Build Distribution to check for and install updates ([#4804](https://github.com/getsentry/sentry-java/pull/4804))
78
- Session Replay: Add new experimental Canvas Capture Strategy ([#4777](https://github.com/getsentry/sentry-java/pull/4777))
89
- A new screenshot capture strategy that uses Android's Canvas API for more accurate text masking
910
- Any `.drawText()` calls are replaced with rectangles to ensure no text is not captured
@@ -15,6 +16,7 @@
1516

1617
### Fixes
1718

19+
- Avoid StrictMode warnings ([#4724](https://github.com/getsentry/sentry-java/pull/4724))
1820
- Use logger from options for JVM profiler ([#4771](https://github.com/getsentry/sentry-java/pull/4771))
1921
- Session Replay: Avoid deadlock when pausing replay if no connection ([#4788](https://github.com/getsentry/sentry-java/pull/4788))
2022

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Sentry SDK for Java and Android
2020
|-----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------- |
2121
| sentry-android | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android) | 21 |
2222
| sentry-android-core | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-core) | 21 |
23+
| sentry-android-distribution | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-distribution/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-distribution) | 21 |
2324
| sentry-android-ndk | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-ndk/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-ndk) | 21 |
2425
| sentry-android-timber | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-timber/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-timber) | 21 |
2526
| sentry-android-fragment | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-fragment/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-android-fragment) | 21 |

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ subprojects {
161161
}
162162
}
163163

164-
if (!this.name.contains("sample") && !this.name.contains("integration-tests") && this.name != "sentry-system-test-support" && this.name != "sentry-test-support" && this.name != "sentry-android-distribution") {
164+
if (!this.name.contains("sample") && !this.name.contains("integration-tests") && this.name != "sentry-system-test-support" && this.name != "sentry-test-support") {
165165
apply<DistributionPlugin>()
166166
apply<com.vanniktech.maven.publish.MavenPublishPlugin>()
167167

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.sentry.android.core.internal.modules.AssetsModulesLoader;
3131
import io.sentry.android.core.internal.util.AndroidConnectionStatusProvider;
3232
import io.sentry.android.core.internal.util.AndroidCurrentDateProvider;
33+
import io.sentry.android.core.internal.util.AndroidRuntimeManager;
3334
import io.sentry.android.core.internal.util.AndroidThreadChecker;
3435
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
3536
import io.sentry.android.core.performance.AppStartMetrics;
@@ -108,7 +109,7 @@ static void loadDefaultAndMetadataOptions(
108109
final @NotNull BuildInfoProvider buildInfoProvider) {
109110
Objects.requireNonNull(context, "The context is required.");
110111

111-
context = ContextUtils.getApplicationContext(context);
112+
@NotNull final Context finalContext = ContextUtils.getApplicationContext(context);
112113

113114
Objects.requireNonNull(options, "The options object is required.");
114115
Objects.requireNonNull(logger, "The ILogger object is required.");
@@ -120,17 +121,22 @@ static void loadDefaultAndMetadataOptions(
120121
options.setDefaultScopeType(ScopeType.CURRENT);
121122
options.setOpenTelemetryMode(SentryOpenTelemetryMode.OFF);
122123
options.setDateProvider(new SentryAndroidDateProvider());
124+
options.setRuntimeManager(new AndroidRuntimeManager());
123125

124126
// set a lower flush timeout on Android to avoid ANRs
125127
options.setFlushTimeoutMillis(DEFAULT_FLUSH_TIMEOUT_MS);
126128

127129
options.setFrameMetricsCollector(
128-
new SentryFrameMetricsCollector(context, logger, buildInfoProvider));
130+
new SentryFrameMetricsCollector(finalContext, logger, buildInfoProvider));
129131

130-
ManifestMetadataReader.applyMetadata(context, options, buildInfoProvider);
131-
options.setCacheDirPath(getCacheDir(context).getAbsolutePath());
132+
ManifestMetadataReader.applyMetadata(finalContext, options, buildInfoProvider);
132133

133-
readDefaultOptionValues(options, context, buildInfoProvider);
134+
options.setCacheDirPath(
135+
options
136+
.getRuntimeManager()
137+
.runWithRelaxedPolicy(() -> getCacheDir(finalContext).getAbsolutePath()));
138+
139+
readDefaultOptionValues(options, finalContext, buildInfoProvider);
134140
AppState.getInstance().registerLifecycleObserver(options);
135141
}
136142

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import io.sentry.SentryOptions;
2121
import io.sentry.TracesSampler;
2222
import io.sentry.TracesSamplingDecision;
23+
import io.sentry.android.core.internal.util.AndroidRuntimeManager;
2324
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
2425
import io.sentry.android.core.performance.AppStartMetrics;
2526
import io.sentry.android.core.performance.TimeSpan;
2627
import io.sentry.util.AutoClosableReentrantLock;
28+
import io.sentry.util.runtime.IRuntimeManager;
2729
import java.io.BufferedReader;
2830
import java.io.File;
2931
import java.io.FileInputStream;
@@ -108,7 +110,9 @@ private void launchAppStartProfiler(final @NotNull AppStartMetrics appStartMetri
108110
return;
109111
}
110112

111-
final @NotNull File cacheDir = AndroidOptionsInitializer.getCacheDir(context);
113+
final @NotNull IRuntimeManager runtimeManager = new AndroidRuntimeManager();
114+
final @NotNull File cacheDir =
115+
runtimeManager.runWithRelaxedPolicy(() -> AndroidOptionsInitializer.getCacheDir(context));
112116
final @NotNull File configFile = new File(cacheDir, APP_START_PROFILING_CONFIG_FILE_NAME);
113117

114118
// No config exists: app start profiling is not enabled

sentry-android-core/src/main/java/io/sentry/android/core/cache/AndroidEnvelopeCache.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.sentry.util.HintUtils;
2020
import io.sentry.util.Objects;
2121
import java.io.File;
22+
import java.io.FileNotFoundException;
2223
import java.io.FileOutputStream;
2324
import java.io.OutputStream;
2425
import org.jetbrains.annotations.ApiStatus;
@@ -157,18 +158,18 @@ public static boolean hasStartupCrashMarker(final @NotNull SentryOptions options
157158

158159
final File lastAnrMarker = new File(cacheDirPath, LAST_ANR_REPORT);
159160
try {
160-
if (lastAnrMarker.exists() && lastAnrMarker.canRead()) {
161-
final String content = FileUtils.readText(lastAnrMarker);
162-
// we wrapped into try-catch already
163-
//noinspection ConstantConditions
164-
return content.equals("null") ? null : Long.parseLong(content.trim());
165-
} else {
161+
final String content = FileUtils.readText(lastAnrMarker);
162+
// we wrapped into try-catch already
163+
//noinspection ConstantConditions
164+
return content.equals("null") ? null : Long.parseLong(content.trim());
165+
} catch (Throwable e) {
166+
if (e instanceof FileNotFoundException) {
166167
options
167168
.getLogger()
168169
.log(DEBUG, "Last ANR marker does not exist. %s.", lastAnrMarker.getAbsolutePath());
170+
} else {
171+
options.getLogger().log(ERROR, "Error reading last ANR marker", e);
169172
}
170-
} catch (Throwable e) {
171-
options.getLogger().log(ERROR, "Error reading last ANR marker", e);
172173
}
173174
return null;
174175
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.sentry.android.core.internal.util;
2+
3+
import android.os.StrictMode;
4+
import io.sentry.util.runtime.IRuntimeManager;
5+
import org.jetbrains.annotations.ApiStatus;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
@ApiStatus.Internal
9+
public final class AndroidRuntimeManager implements IRuntimeManager {
10+
@Override
11+
public <T> T runWithRelaxedPolicy(final @NotNull IRuntimeManagerCallback<T> toRun) {
12+
final @NotNull StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
13+
final @NotNull StrictMode.VmPolicy oldVmPolicy = StrictMode.getVmPolicy();
14+
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX);
15+
StrictMode.setVmPolicy(StrictMode.VmPolicy.LAX);
16+
try {
17+
return toRun.run();
18+
} finally {
19+
StrictMode.setThreadPolicy(oldPolicy);
20+
StrictMode.setVmPolicy(oldVmPolicy);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)