Skip to content

Commit aba16f7

Browse files
committed
[DEV] Added isRoot check if process is started with su command
1 parent 6ad683b commit aba16f7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

library/src/main/java/ashell/ShellFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@
2222

2323
public class ShellFactory {
2424

25+
private boolean isRoot = false;
2526
private AShell shell;
2627

27-
private ShellFactory(AShell shell) {
28+
public ShellFactory(AShell shell, boolean isRoot) {
2829
this.shell = shell;
30+
this.isRoot = isRoot;
2931
}
3032

3133
public AShell getShell() {
3234
return shell;
3335
}
3436

37+
public boolean isRoot() {
38+
return isRoot;
39+
}
40+
3541
@SuppressWarnings("unchecked") // Single-interface proxy creation guarded by parameter safety.
3642
public <T> T create(final Class<T> shellModel) {
3743
//Utils.validateServiceInterface(service);
@@ -97,12 +103,13 @@ public ShellFactory build() throws IOException {
97103
}
98104

99105
public ShellFactory build(boolean runAsSuperuser) throws IOException {
100-
106+
boolean isRoot = false;
101107
if (processBuilder == null) {
102108
processBuilder = ProcessUtils.getDefaultProcessBuilder("sh");
103109
if (runAsSuperuser) {
104110
try {
105111
processBuilder = ProcessUtils.getDefaultProcessBuilder("su");
112+
isRoot = true;
106113
} catch (Exception e) {
107114
e.printStackTrace();
108115
}
@@ -134,7 +141,7 @@ public ShellFactory build(boolean runAsSuperuser) throws IOException {
134141

135142
shell.start();
136143

137-
return new ShellFactory(shell);
144+
return new ShellFactory(shell, isRoot);
138145
}
139146
}
140147
}

0 commit comments

Comments
 (0)