Skip to content

Commit 983ac90

Browse files
lcianromtsn
andauthored
ref(core): Replace RootChecker with MIT licensed version (#4698)
Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
1 parent d611745 commit 983ac90

File tree

1 file changed

+39
-12
lines changed
  • sentry-android-core/src/main/java/io/sentry/android/core/internal/util

1 file changed

+39
-12
lines changed

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

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
/*
2+
* Root detection implementation adapted from Ravencoin Android:
3+
* https://github.com/Menwitz/ravencoin-android/blob/7b68378c046e2fd0d6f30cea59cbd87fcb6db12d/app/src/main/java/com/ravencoin/tools/security/RootHelper.java
4+
*
5+
* RavenWallet
6+
* <p/>
7+
* Created by Mihail Gutan <mihail@breadwallet.com> on 5/19/16.
8+
* Copyright (c) 2016 breadwallet LLC
9+
* <p/>
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
* <p/>
17+
* The above copyright notice and this permission notice shall be included in
18+
* all copies or substantial portions of the Software.
19+
* <p/>
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
* THE SOFTWARE.
27+
*/
28+
129
package io.sentry.android.core.internal.util;
230

331
import android.annotation.SuppressLint;
@@ -42,12 +70,12 @@ public RootChecker(
4270
buildInfoProvider,
4371
logger,
4472
new String[] {
45-
"/system/app/Superuser.apk",
4673
"/sbin/su",
74+
"/data/local/xbin/su",
4775
"/system/bin/su",
4876
"/system/xbin/su",
49-
"/data/local/xbin/su",
5077
"/data/local/bin/su",
78+
"/system/app/Superuser.apk",
5179
"/system/sd/xbin/su",
5280
"/system/bin/failsafe/su",
5381
"/data/local/su",
@@ -84,12 +112,11 @@ public RootChecker(
84112

85113
/**
86114
* Check if the device is rooted or not
87-
* https://medium.com/@thehimanshugoel/10-best-security-practices-in-android-applications-that-every-developer-must-know-99c8cd07c0bb
88115
*
89116
* @return whether the device is rooted or not
90117
*/
91118
public boolean isDeviceRooted() {
92-
return checkTestKeys() || checkRootFiles() || checkSUExist() || checkRootPackages(logger);
119+
return checkRootA() || checkRootB() || checkRootC() || checkRootPackages(logger);
93120
}
94121

95122
/**
@@ -99,7 +126,7 @@ public boolean isDeviceRooted() {
99126
*
100127
* @return whether if it contains test keys or not
101128
*/
102-
private boolean checkTestKeys() {
129+
private boolean checkRootA() {
103130
final String buildTags = buildInfoProvider.getBuildTags();
104131
return buildTags != null && buildTags.contains("test-keys");
105132
}
@@ -110,7 +137,7 @@ private boolean checkTestKeys() {
110137
*
111138
* @return whether if the root files exist or not
112139
*/
113-
private boolean checkRootFiles() {
140+
private boolean checkRootB() {
114141
for (final String path : rootFiles) {
115142
try {
116143
if (new File(path).exists()) {
@@ -129,24 +156,24 @@ private boolean checkRootFiles() {
129156
*
130157
* @return whether su exists or not
131158
*/
132-
private boolean checkSUExist() {
133-
Process process = null;
159+
private boolean checkRootC() {
160+
Process p = null;
134161
final String[] su = {"/system/xbin/which", "su"};
135162

136163
try {
137-
process = runtime.exec(su);
164+
p = runtime.exec(su);
138165

139166
try (final BufferedReader reader =
140-
new BufferedReader(new InputStreamReader(process.getInputStream(), UTF_8))) {
167+
new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8))) {
141168
return reader.readLine() != null;
142169
}
143170
} catch (IOException e) {
144171
logger.log(SentryLevel.DEBUG, "SU isn't found on this Device.");
145172
} catch (Throwable e) {
146173
logger.log(SentryLevel.DEBUG, "Error when trying to check if SU exists.", e);
147174
} finally {
148-
if (process != null) {
149-
process.destroy();
175+
if (p != null) {
176+
p.destroy();
150177
}
151178
}
152179
return false;

0 commit comments

Comments
 (0)