RootShell: Improve shell start error handling
No need to catch and re-throw exceptions before starting the process. If running `su` itself fails, there's no (functional) root, so report that. Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
parent
3d6737e32f
commit
ca077dd090
@ -123,7 +123,6 @@ public class RootShell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void start() throws IOException, NoRootException {
|
public synchronized void start() throws IOException, NoRootException {
|
||||||
try {
|
|
||||||
if (isRunning())
|
if (isRunning())
|
||||||
return;
|
return;
|
||||||
if (!localBinaryDir.isDirectory() && !localBinaryDir.mkdirs())
|
if (!localBinaryDir.isDirectory() && !localBinaryDir.mkdirs())
|
||||||
@ -132,9 +131,15 @@ public class RootShell {
|
|||||||
throw new FileNotFoundException("Could not create local temporary directory");
|
throw new FileNotFoundException("Could not create local temporary directory");
|
||||||
if (!isExecutableInPath(SU))
|
if (!isExecutableInPath(SU))
|
||||||
throw new NoRootException(deviceNotRootedMessage);
|
throw new NoRootException(deviceNotRootedMessage);
|
||||||
|
try {
|
||||||
final ProcessBuilder builder = new ProcessBuilder().command(SU);
|
final ProcessBuilder builder = new ProcessBuilder().command(SU);
|
||||||
builder.environment().put("LC_ALL", "C");
|
builder.environment().put("LC_ALL", "C");
|
||||||
|
try {
|
||||||
process = builder.start();
|
process = builder.start();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
// A failure at this stage means the device isn't rooted.
|
||||||
|
throw new NoRootException(deviceNotRootedMessage, e);
|
||||||
|
}
|
||||||
stdin = new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8);
|
stdin = new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8);
|
||||||
stdout = new BufferedReader(new InputStreamReader(process.getInputStream(),
|
stdout = new BufferedReader(new InputStreamReader(process.getInputStream(),
|
||||||
StandardCharsets.UTF_8));
|
StandardCharsets.UTF_8));
|
||||||
|
Loading…
Reference in New Issue
Block a user