Skip to content

Commit 0ed09ae

Browse files
cursoragent43jay
andcommitted
Guard continuous profiling below API 35
Co-authored-by: Matthew Jay Williams <43jay@users.noreply.github.com>
1 parent cd0981b commit 0ed09ae

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,16 @@ private static void setupProfiler(
326326
if (appStartTransactionProfiler != null) {
327327
appStartTransactionProfiler.close();
328328
}
329+
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
330+
options
331+
.getLogger()
332+
.log(SentryLevel.INFO, "Continuous profiling is disabled on API levels below 35.");
333+
if (appStartContinuousProfiler != null) {
334+
appStartContinuousProfiler.close(true);
335+
}
336+
options.setContinuousProfiler(NoOpContinuousProfiler.getInstance());
337+
return;
338+
}
329339
if (appStartContinuousProfiler != null) {
330340
options.setContinuousProfiler(appStartContinuousProfiler);
331341
// If the profiler is running, we start the performance collector too, otherwise we'd miss

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ private void createAndStartContinuousProfiler(
155155
final @NotNull Context context,
156156
final @NotNull SentryAppStartProfilingOptions profilingOptions,
157157
final @NotNull AppStartMetrics appStartMetrics) {
158+
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
159+
logger.log(SentryLevel.INFO, "Continuous profiling is disabled on API levels below 35.");
160+
return;
161+
}
158162

159163
if (!profilingOptions.isContinuousProfileSampled()) {
160164
logger.log(SentryLevel.DEBUG, "App start profiling was not sampled. It will not start.");

sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,15 @@ class AndroidOptionsInitializerTest {
497497
assertNull(AppStartMetrics.getInstance().appStartContinuousProfiler)
498498
}
499499

500+
@Config(sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE])
501+
@Test
502+
fun `init with continuous profiling on API below 35 sets no-op continuous profiler`() {
503+
fixture.initSut(useRealContext = true)
504+
505+
assertEquals(NoOpTransactionProfiler.getInstance(), fixture.sentryOptions.transactionProfiler)
506+
assertEquals(NoOpContinuousProfiler.getInstance(), fixture.sentryOptions.continuousProfiler)
507+
}
508+
500509
@Test
501510
fun `NdkIntegration will load SentryNdk class and add to the integration list`() {
502511
fixture.initSutWithClassLoader(

sentry-android-core/src/test/java/io/sentry/android/core/SentryPerformanceProviderTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ class SentryPerformanceProviderTest {
290290
assertNull(AppStartMetrics.getInstance().appStartContinuousProfiler)
291291
}
292292

293+
@Test
294+
fun `when sdk is below api 35, continuous profiler is not started`() {
295+
fixture.getSut(sdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { config ->
296+
writeConfig(config, profilingEnabled = false, continuousProfilingEnabled = true)
297+
}
298+
assertNull(AppStartMetrics.getInstance().appStartContinuousProfiler)
299+
verify(fixture.logger)
300+
.log(eq(SentryLevel.INFO), eq("Continuous profiling is disabled on API levels below 35."))
301+
}
302+
293303
@Test
294304
fun `when provider is closed, continuous profiler is stopped`() {
295305
val provider = fixture.getSut { config -> writeConfig(config, profilingEnabled = false) }

0 commit comments

Comments
 (0)