Skip to content

Commit 3cb8080

Browse files
authored
Add option to disable RootChecker (#2735)
1 parent fe90ed9 commit 3cb8080

File tree

7 files changed

+71
-11
lines changed

7 files changed

+71
-11
lines changed

CHANGELOG.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
## Unreleased
44

55
### Features
6+
67
- Add support for Sentry Kotlin Compiler Plugin ([#2695](https://github.com/getsentry/sentry-java/pull/2695))
78
- In conjunction with our sentry-kotlin-compiler-plugin we improved Jetpack Compose support for
89
- [View Hierarchy](https://docs.sentry.io/platforms/android/enriching-events/viewhierarchy/) support for Jetpack Compose screens
910
- Automatic breadcrumbs for [user interactions](https://docs.sentry.io/platforms/android/performance/instrumentation/automatic-instrumentation/#user-interaction-instrumentation)
11+
- More granular http requests instrumentation with a new SentryOkHttpEventListener ([#2659](https://github.com/getsentry/sentry-java/pull/2659))
12+
- Create spans for time spent on:
13+
- Proxy selection
14+
- DNS resolution
15+
- HTTPS setup
16+
- Connection
17+
- Requesting headers
18+
- Receiving response
19+
- You can attach the event listener to your OkHttpClient through `client.eventListener(new SentryOkHttpEventListener()).addInterceptor(new SentryOkHttpInterceptor()).build();`
20+
- In case you already have an event listener you can use the SentryOkHttpEventListener as well through `client.eventListener(new SentryOkHttpEventListener(myListener)).addInterceptor(new SentryOkHttpInterceptor()).build();`
21+
- Add a new option to disable `RootChecker` ([#2735](https://github.com/getsentry/sentry-java/pull/2735))
1022

1123
### Fixes
1224

@@ -24,16 +36,6 @@
2436

2537
### Features
2638

27-
- More granular http requests instrumentation with a new SentryOkHttpEventListener ([#2659](https://github.com/getsentry/sentry-java/pull/2659))
28-
- Create spans for time spent on:
29-
- Proxy selection
30-
- DNS resolution
31-
- HTTPS setup
32-
- Connection
33-
- Requesting headers
34-
- Receiving response
35-
- You can attach the event listener to your OkHttpClient through `client.eventListener(new SentryOkHttpEventListener()).addInterceptor(new SentryOkHttpInterceptor()).build();`
36-
- In case you already have an event listener you can use the SentryOkHttpEventListener as well through `client.eventListener(new SentryOkHttpEventListener(myListener)).addInterceptor(new SentryOkHttpInterceptor()).build();`
3739
- Add Screenshot and ViewHierarchy to integrations list ([#2698](https://github.com/getsentry/sentry-java/pull/2698))
3840
- New ANR detection based on [ApplicationExitInfo API](https://developer.android.com/reference/android/app/ApplicationExitInfo) ([#2697](https://github.com/getsentry/sentry-java/pull/2697))
3941
- This implementation completely replaces the old one (based on a watchdog) on devices running Android 11 and above:

sentry-android-core/api/sentry-android-core.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
224224
public fun isEnableAutoActivityLifecycleTracing ()Z
225225
public fun isEnableFramesTracking ()Z
226226
public fun isEnableNetworkEventBreadcrumbs ()Z
227+
public fun isEnableRootCheck ()Z
227228
public fun isEnableSystemEventBreadcrumbs ()Z
228229
public fun setAnrEnabled (Z)V
229230
public fun setAnrReportInDebug (Z)V
@@ -239,6 +240,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
239240
public fun setEnableAutoActivityLifecycleTracing (Z)V
240241
public fun setEnableFramesTracking (Z)V
241242
public fun setEnableNetworkEventBreadcrumbs (Z)V
243+
public fun setEnableRootCheck (Z)V
242244
public fun setEnableSystemEventBreadcrumbs (Z)V
243245
public fun setNativeSdkName (Ljava/lang/String;)V
244246
public fun setProfilingTracesHz (I)V

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public DefaultAndroidEventProcessor(
102102
private @NotNull Map<String, Object> loadContextData() {
103103
Map<String, Object> map = new HashMap<>();
104104

105-
map.put(ROOTED, rootChecker.isDeviceRooted());
105+
if (options.isEnableRootCheck()) {
106+
map.put(ROOTED, rootChecker.isDeviceRooted());
107+
}
106108

107109
final String kernelVersion = ContextUtils.getKernelVersion(options.getLogger());
108110
if (kernelVersion != null) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ final class ManifestMetadataReader {
9090

9191
static final String SENTRY_GRADLE_PLUGIN_INTEGRATIONS = "io.sentry.gradle-plugin-integrations";
9292

93+
static final String ENABLE_ROOT_CHECK = "io.sentry.enable-root-check";
94+
9395
/** ManifestMetadataReader ctor */
9496
private ManifestMetadataReader() {}
9597

@@ -341,6 +343,9 @@ static void applyMetadata(
341343
SentryIntegrationPackageStorage.getInstance().addIntegration(integration);
342344
}
343345
}
346+
347+
options.setEnableRootCheck(
348+
readBool(metadata, logger, ENABLE_ROOT_CHECK, options.isEnableRootCheck()));
344349
}
345350

346351
options

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.sentry.Sentry;
66
import io.sentry.SentryOptions;
77
import io.sentry.SpanStatus;
8+
import io.sentry.android.core.internal.util.RootChecker;
89
import io.sentry.protocol.SdkVersion;
910
import org.jetbrains.annotations.ApiStatus;
1011
import org.jetbrains.annotations.NotNull;
@@ -136,6 +137,12 @@ public final class SentryAndroidOptions extends SentryOptions {
136137

137138
private @Nullable String nativeSdkName = null;
138139

140+
/**
141+
* Controls whether to enable the {@link RootChecker}, which can potentially make apps to be
142+
* flagged by some app stores as harmful.
143+
*/
144+
private boolean enableRootCheck = true;
145+
139146
public SentryAndroidOptions() {
140147
setSentryClientName(BuildConfig.SENTRY_ANDROID_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
141148
setSdkVersion(createSdkVersion());
@@ -426,4 +433,12 @@ public void setNativeSdkName(final @Nullable String nativeSdkName) {
426433
public @Nullable String getNativeSdkName() {
427434
return nativeSdkName;
428435
}
436+
437+
public boolean isEnableRootCheck() {
438+
return enableRootCheck;
439+
}
440+
441+
public void setEnableRootCheck(final boolean enableRootCheck) {
442+
this.enableRootCheck = enableRootCheck;
443+
}
429444
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,13 @@ class DefaultAndroidEventProcessorTest {
576576
assertNull(thread.isMain)
577577
}
578578
}
579+
580+
@Test
581+
fun `does not perform root check if root checker is disabled`() {
582+
fixture.options.isEnableRootCheck = false
583+
val sut = fixture.getSut(context)
584+
585+
val contextData = sut.contextData.get()
586+
assertNull(contextData[ROOTED])
587+
}
579588
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,4 +1243,29 @@ class ManifestMetadataReaderTest {
12431243
assertNotNull(resultingSet)
12441244
assert(resultingSet.containsAll(listOf("Database Instrumentation", "OkHttp Instrumentation")))
12451245
}
1246+
1247+
@Test
1248+
fun `applyMetadata reads enable root checker to options`() {
1249+
// Arrange
1250+
val bundle = bundleOf(ManifestMetadataReader.ENABLE_ROOT_CHECK to false)
1251+
val context = fixture.getContext(metaData = bundle)
1252+
1253+
// Act
1254+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1255+
1256+
// Assert
1257+
assertFalse(fixture.options.isEnableRootCheck)
1258+
}
1259+
1260+
@Test
1261+
fun `applyMetadata reads enable root check and keep default value if not found`() {
1262+
// Arrange
1263+
val context = fixture.getContext()
1264+
1265+
// Act
1266+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1267+
1268+
// Assert
1269+
assertTrue(fixture.options.isEnableRootCheck)
1270+
}
12461271
}

0 commit comments

Comments
 (0)