diff --git a/extern/libsuperuser/libsuperuser/build.gradle b/extern/libsuperuser/libsuperuser/build.gradle index 14d725df9..109b4cf62 100644 --- a/extern/libsuperuser/libsuperuser/build.gradle +++ b/extern/libsuperuser/libsuperuser/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 21 - buildToolsVersion '22.0.1' + buildToolsVersion "21.1.0" defaultConfig { minSdkVersion 4 @@ -20,6 +20,9 @@ android { assets.srcDirs = ['assets'] } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_6 + } } version = "1.0.0." + (new Date()).format('yyyyMMddHHmm') diff --git a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Application.java b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Application.java index a439517fb..095c7209b 100644 --- a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Application.java +++ b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Application.java @@ -74,6 +74,7 @@ public class Application extends android.app.Application { // this makes sure AsyncTask's internal handler is created from the right (main) thread Class.forName("android.os.AsyncTask"); } catch (ClassNotFoundException e) { + // will never happen } } } diff --git a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Debug.java b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Debug.java index c6f695ca0..6116c9abb 100644 --- a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Debug.java +++ b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Debug.java @@ -35,7 +35,7 @@ public class Debug { * builds and disabled for exported APKs - see * BuildConfig.DEBUG

* - * @param enabled Enable debug mode ? + * @param enable Enable debug mode ? */ public static void setDebug(boolean enable) { debug = enable; @@ -53,7 +53,7 @@ public class Debug { // ----- LOGGING ----- public interface OnLogListener { - public void onLog(int type, String typeIndicator, String message); + void onLog(int type, String typeIndicator, String message); } public static final String TAG = "libsuperuser"; @@ -130,7 +130,7 @@ public class Debug { * occur.

* * @param type LOG_* constants - * @param enabled Enable or disable + * @param enable Enable or disable */ public static void setLogTypeEnabled(int type, boolean enable) { if (enable) { @@ -199,7 +199,7 @@ public class Debug { *

Enables or disables the library crashing when su is called * from the main thread.

* - * @param enabled Enable or disable + * @param enable Enable or disable */ public static void setSanityChecksEnabled(boolean enable) { sanityChecks = enable; diff --git a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java index ebd03cff9..742363a87 100644 --- a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java +++ b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java @@ -177,6 +177,7 @@ public class Shell { try { STDIN.close(); } catch (IOException e) { + // might be closed already } STDOUT.join(); STDERR.join(); @@ -368,7 +369,7 @@ public class Shell { if (ret != null) { for (String line : ret) { if (!internal) { - if (line.contains(".")) { + if (!line.trim().equals("")) { version = line; break; } @@ -379,6 +380,7 @@ public class Shell { break; } } catch (NumberFormatException e) { + // should be parsable, try next line otherwise } } } @@ -474,18 +476,17 @@ public class Shell { // leak if (android.os.Build.VERSION.SDK_INT >= 17) { // Detect enforcing through sysfs, not always present - if (enforcing == null) { - File f = new File("/sys/fs/selinux/enforce"); - if (f.exists()) { + File f = new File("/sys/fs/selinux/enforce"); + if (f.exists()) { + try { + InputStream is = new FileInputStream("/sys/fs/selinux/enforce"); try { - InputStream is = new FileInputStream("/sys/fs/selinux/enforce"); - try { - enforcing = (is.read() == '1'); - } finally { - is.close(); - } - } catch (Exception e) { + enforcing = (is.read() == '1'); + } finally { + is.close(); } + } catch (Exception e) { + // we might not be allowed to read, thanks SELinux } } @@ -524,13 +525,13 @@ public class Shell { private interface OnResult { // for any onCommandResult callback - public static final int WATCHDOG_EXIT = -1; - public static final int SHELL_DIED = -2; + int WATCHDOG_EXIT = -1; + int SHELL_DIED = -2; // for Interactive.open() callbacks only - public static final int SHELL_EXEC_FAILED = -3; - public static final int SHELL_WRONG_UID = -4; - public static final int SHELL_RUNNING = 0; + int SHELL_EXEC_FAILED = -3; + int SHELL_WRONG_UID = -4; + int SHELL_RUNNING = 0; } /** @@ -557,7 +558,7 @@ public class Shell { * @param exitCode Exit code of the last command in the block * @param output All output generated by the command block */ - public void onCommandResult(int commandCode, int exitCode, List output); + void onCommandResult(int commandCode, int exitCode, List output); } /** @@ -584,7 +585,7 @@ public class Shell { * @param commandCode Value previously supplied to addCommand * @param exitCode Exit code of the last command in the block */ - public void onCommandResult(int commandCode, int exitCode); + void onCommandResult(int commandCode, int exitCode); } /** @@ -995,8 +996,8 @@ public class Shell { private volatile int callbacks = 0; private volatile int watchdogCount; - private Object idleSync = new Object(); - private Object callbackSync = new Object(); + private final Object idleSync = new Object(); + private final Object callbackSync = new Object(); private volatile int lastExitCode = 0; private volatile String lastMarkerSTDOUT = null; @@ -1036,8 +1037,8 @@ public class Shell { watchdogTimeout = 60; commands.add(0, new Command(Shell.availableTestCommands, 0, new OnCommandResultListener() { public void onCommandResult(int commandCode, int exitCode, List output) { - if (exitCode == OnCommandResultListener.SHELL_RUNNING && - Shell.parseAvailableResult(output, Shell.SU.isSU(shell)) != true) { + if ((exitCode == OnCommandResultListener.SHELL_RUNNING) && + !Shell.parseAvailableResult(output, Shell.SU.isSU(shell))) { // shell is up, but it's brain-damaged exitCode = OnCommandResultListener.SHELL_WRONG_UID; } @@ -1327,6 +1328,7 @@ public class Shell { STDIN.write(("echo " + command.marker + " >&2\n").getBytes("UTF-8")); STDIN.flush(); } catch (IOException e) { + // STDIN might have closed } } else { runNextCommand(false); @@ -1497,6 +1499,8 @@ public class Shell { lastExitCode = Integer.valueOf( line.substring(command.marker.length() + 1), 10); } catch (Exception e) { + // this really shouldn't happen + e.printStackTrace(); } lastMarkerSTDOUT = command.marker; processMarker(); @@ -1624,10 +1628,12 @@ public class Shell { try { STDIN.close(); } catch (IOException e) { + // in case it was closed } try { process.destroy(); } catch (Exception e) { + // in case it was already destroyed or can't be } } @@ -1641,10 +1647,10 @@ public class Shell { return false; } try { - // if this throws, we're still running process.exitValue(); return false; } catch (IllegalThreadStateException e) { + // if this is thrown, we're still running } return true; } diff --git a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/StreamGobbler.java b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/StreamGobbler.java index 730521545..4ce669742 100644 --- a/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/StreamGobbler.java +++ b/extern/libsuperuser/libsuperuser/src/eu/chainfire/libsuperuser/StreamGobbler.java @@ -39,7 +39,7 @@ public class StreamGobbler extends Thread { * * @param line String that was gobbled */ - public void onLine(String line); + void onLine(String line); } private String shell = null; @@ -85,19 +85,21 @@ public class StreamGobbler extends Thread { public void run() { // keep reading the InputStream until it ends (or an error occurs) try { - String line = null; + String line; while ((line = reader.readLine()) != null) { Debug.logOutput(String.format("[%s] %s", shell, line)); if (writer != null) writer.add(line); if (listener != null) listener.onLine(line); } } catch (IOException e) { + // reader probably closed, expected exit condition } // make sure our stream is closed and resources will be freed try { reader.close(); - } catch (IOException e) { + } catch (IOException e) { + // read already closed } } }