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
+
1
29
package io .sentry .android .core .internal .util ;
2
30
3
31
import android .annotation .SuppressLint ;
@@ -42,12 +70,12 @@ public RootChecker(
42
70
buildInfoProvider ,
43
71
logger ,
44
72
new String [] {
45
- "/system/app/Superuser.apk" ,
46
73
"/sbin/su" ,
74
+ "/data/local/xbin/su" ,
47
75
"/system/bin/su" ,
48
76
"/system/xbin/su" ,
49
- "/data/local/xbin/su" ,
50
77
"/data/local/bin/su" ,
78
+ "/system/app/Superuser.apk" ,
51
79
"/system/sd/xbin/su" ,
52
80
"/system/bin/failsafe/su" ,
53
81
"/data/local/su" ,
@@ -84,12 +112,11 @@ public RootChecker(
84
112
85
113
/**
86
114
* 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
88
115
*
89
116
* @return whether the device is rooted or not
90
117
*/
91
118
public boolean isDeviceRooted () {
92
- return checkTestKeys () || checkRootFiles () || checkSUExist () || checkRootPackages (logger );
119
+ return checkRootA () || checkRootB () || checkRootC () || checkRootPackages (logger );
93
120
}
94
121
95
122
/**
@@ -99,7 +126,7 @@ public boolean isDeviceRooted() {
99
126
*
100
127
* @return whether if it contains test keys or not
101
128
*/
102
- private boolean checkTestKeys () {
129
+ private boolean checkRootA () {
103
130
final String buildTags = buildInfoProvider .getBuildTags ();
104
131
return buildTags != null && buildTags .contains ("test-keys" );
105
132
}
@@ -110,7 +137,7 @@ private boolean checkTestKeys() {
110
137
*
111
138
* @return whether if the root files exist or not
112
139
*/
113
- private boolean checkRootFiles () {
140
+ private boolean checkRootB () {
114
141
for (final String path : rootFiles ) {
115
142
try {
116
143
if (new File (path ).exists ()) {
@@ -129,24 +156,24 @@ private boolean checkRootFiles() {
129
156
*
130
157
* @return whether su exists or not
131
158
*/
132
- private boolean checkSUExist () {
133
- Process process = null ;
159
+ private boolean checkRootC () {
160
+ Process p = null ;
134
161
final String [] su = {"/system/xbin/which" , "su" };
135
162
136
163
try {
137
- process = runtime .exec (su );
164
+ p = runtime .exec (su );
138
165
139
166
try (final BufferedReader reader =
140
- new BufferedReader (new InputStreamReader (process .getInputStream (), UTF_8 ))) {
167
+ new BufferedReader (new InputStreamReader (p .getInputStream (), UTF_8 ))) {
141
168
return reader .readLine () != null ;
142
169
}
143
170
} catch (IOException e ) {
144
171
logger .log (SentryLevel .DEBUG , "SU isn't found on this Device." );
145
172
} catch (Throwable e ) {
146
173
logger .log (SentryLevel .DEBUG , "Error when trying to check if SU exists." , e );
147
174
} finally {
148
- if (process != null ) {
149
- process .destroy ();
175
+ if (p != null ) {
176
+ p .destroy ();
150
177
}
151
178
}
152
179
return false ;
0 commit comments