File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
RootCommands Library/src/org/rootcommands Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,16 @@ You can enable debug logging in RootCommands by the following line:
22
22
RootCommands . DEBUG = true ;
23
23
```
24
24
25
+ ## Root Access check
26
+
27
+ This tries to find the su binary, opens a root shell and checks for root uid.
28
+
29
+ ``` java
30
+ if (RootCommands . rootAccessGiven()) {
31
+ // your code
32
+ }
33
+ ```
34
+
25
35
## Simple Commands
26
36
27
37
You can instantiate SimpleCommands with the shell commands you want to execute. This is a very basic approach of executing something on a shell.
Original file line number Diff line number Diff line change 16
16
17
17
package org .rootcommands ;
18
18
19
+ import org .rootcommands .util .Log ;
20
+
19
21
public class RootCommands {
20
22
public static boolean DEBUG = false ;
21
23
public static int DEFAULT_TIMEOUT = 10000 ;
22
24
23
- public static String TAG = "RootCommands" ;
25
+ public static final String TAG = "RootCommands" ;
26
+
27
+ /**
28
+ * General method to check if user has su binary and accepts root access for this program!
29
+ *
30
+ * @return true if everything worked
31
+ */
32
+ public static boolean rootAccessGiven () {
33
+ boolean rootAccess = false ;
34
+
35
+ try {
36
+ Shell rootShell = Shell .startRootShell ();
37
+
38
+ Toolbox tb = new Toolbox (rootShell );
39
+ if (tb .isRootAccessGiven ()) {
40
+ rootAccess = true ;
41
+ }
42
+
43
+ rootShell .close ();
44
+ } catch (Exception e ) {
45
+ Log .e (TAG , "Problem while checking for root access!" , e );
46
+ }
47
+
48
+ return rootAccess ;
49
+ }
24
50
}
You can’t perform that action at this time.
0 commit comments