Update libsuperuser to bc71c5afeb9952cd
This commit is contained in:
parent
c5ed7699d6
commit
26894fcb01
@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 21
|
compileSdkVersion 21
|
||||||
buildToolsVersion '22.0.1'
|
buildToolsVersion "21.1.0"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 4
|
minSdkVersion 4
|
||||||
@ -20,6 +20,9 @@ android {
|
|||||||
assets.srcDirs = ['assets']
|
assets.srcDirs = ['assets']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_6
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "1.0.0." + (new Date()).format('yyyyMMddHHmm')
|
version = "1.0.0." + (new Date()).format('yyyyMMddHHmm')
|
||||||
|
@ -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
|
// this makes sure AsyncTask's internal handler is created from the right (main) thread
|
||||||
Class.forName("android.os.AsyncTask");
|
Class.forName("android.os.AsyncTask");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
// will never happen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class Debug {
|
|||||||
* builds and disabled for exported APKs - see
|
* builds and disabled for exported APKs - see
|
||||||
* BuildConfig.DEBUG</p>
|
* BuildConfig.DEBUG</p>
|
||||||
*
|
*
|
||||||
* @param enabled Enable debug mode ?
|
* @param enable Enable debug mode ?
|
||||||
*/
|
*/
|
||||||
public static void setDebug(boolean enable) {
|
public static void setDebug(boolean enable) {
|
||||||
debug = enable;
|
debug = enable;
|
||||||
@ -53,7 +53,7 @@ public class Debug {
|
|||||||
// ----- LOGGING -----
|
// ----- LOGGING -----
|
||||||
|
|
||||||
public interface OnLogListener {
|
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";
|
public static final String TAG = "libsuperuser";
|
||||||
@ -130,7 +130,7 @@ public class Debug {
|
|||||||
* occur.</p>
|
* occur.</p>
|
||||||
*
|
*
|
||||||
* @param type LOG_* constants
|
* @param type LOG_* constants
|
||||||
* @param enabled Enable or disable
|
* @param enable Enable or disable
|
||||||
*/
|
*/
|
||||||
public static void setLogTypeEnabled(int type, boolean enable) {
|
public static void setLogTypeEnabled(int type, boolean enable) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
@ -199,7 +199,7 @@ public class Debug {
|
|||||||
* <p>Enables or disables the library crashing when su is called
|
* <p>Enables or disables the library crashing when su is called
|
||||||
* from the main thread.</p>
|
* from the main thread.</p>
|
||||||
*
|
*
|
||||||
* @param enabled Enable or disable
|
* @param enable Enable or disable
|
||||||
*/
|
*/
|
||||||
public static void setSanityChecksEnabled(boolean enable) {
|
public static void setSanityChecksEnabled(boolean enable) {
|
||||||
sanityChecks = enable;
|
sanityChecks = enable;
|
||||||
|
@ -177,6 +177,7 @@ public class Shell {
|
|||||||
try {
|
try {
|
||||||
STDIN.close();
|
STDIN.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// might be closed already
|
||||||
}
|
}
|
||||||
STDOUT.join();
|
STDOUT.join();
|
||||||
STDERR.join();
|
STDERR.join();
|
||||||
@ -368,7 +369,7 @@ public class Shell {
|
|||||||
if (ret != null) {
|
if (ret != null) {
|
||||||
for (String line : ret) {
|
for (String line : ret) {
|
||||||
if (!internal) {
|
if (!internal) {
|
||||||
if (line.contains(".")) {
|
if (!line.trim().equals("")) {
|
||||||
version = line;
|
version = line;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -379,6 +380,7 @@ public class Shell {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
// should be parsable, try next line otherwise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -474,7 +476,6 @@ public class Shell {
|
|||||||
// leak
|
// leak
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 17) {
|
if (android.os.Build.VERSION.SDK_INT >= 17) {
|
||||||
// Detect enforcing through sysfs, not always present
|
// Detect enforcing through sysfs, not always present
|
||||||
if (enforcing == null) {
|
|
||||||
File f = new File("/sys/fs/selinux/enforce");
|
File f = new File("/sys/fs/selinux/enforce");
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
try {
|
try {
|
||||||
@ -485,7 +486,7 @@ public class Shell {
|
|||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
// we might not be allowed to read, thanks SELinux
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,13 +525,13 @@ public class Shell {
|
|||||||
|
|
||||||
private interface OnResult {
|
private interface OnResult {
|
||||||
// for any onCommandResult callback
|
// for any onCommandResult callback
|
||||||
public static final int WATCHDOG_EXIT = -1;
|
int WATCHDOG_EXIT = -1;
|
||||||
public static final int SHELL_DIED = -2;
|
int SHELL_DIED = -2;
|
||||||
|
|
||||||
// for Interactive.open() callbacks only
|
// for Interactive.open() callbacks only
|
||||||
public static final int SHELL_EXEC_FAILED = -3;
|
int SHELL_EXEC_FAILED = -3;
|
||||||
public static final int SHELL_WRONG_UID = -4;
|
int SHELL_WRONG_UID = -4;
|
||||||
public static final int SHELL_RUNNING = 0;
|
int SHELL_RUNNING = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -557,7 +558,7 @@ public class Shell {
|
|||||||
* @param exitCode Exit code of the last command in the block
|
* @param exitCode Exit code of the last command in the block
|
||||||
* @param output All output generated by the command block
|
* @param output All output generated by the command block
|
||||||
*/
|
*/
|
||||||
public void onCommandResult(int commandCode, int exitCode, List<String> output);
|
void onCommandResult(int commandCode, int exitCode, List<String> output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -584,7 +585,7 @@ public class Shell {
|
|||||||
* @param commandCode Value previously supplied to addCommand
|
* @param commandCode Value previously supplied to addCommand
|
||||||
* @param exitCode Exit code of the last command in the block
|
* @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 callbacks = 0;
|
||||||
private volatile int watchdogCount;
|
private volatile int watchdogCount;
|
||||||
|
|
||||||
private Object idleSync = new Object();
|
private final Object idleSync = new Object();
|
||||||
private Object callbackSync = new Object();
|
private final Object callbackSync = new Object();
|
||||||
|
|
||||||
private volatile int lastExitCode = 0;
|
private volatile int lastExitCode = 0;
|
||||||
private volatile String lastMarkerSTDOUT = null;
|
private volatile String lastMarkerSTDOUT = null;
|
||||||
@ -1036,8 +1037,8 @@ public class Shell {
|
|||||||
watchdogTimeout = 60;
|
watchdogTimeout = 60;
|
||||||
commands.add(0, new Command(Shell.availableTestCommands, 0, new OnCommandResultListener() {
|
commands.add(0, new Command(Shell.availableTestCommands, 0, new OnCommandResultListener() {
|
||||||
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
|
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
|
||||||
if (exitCode == OnCommandResultListener.SHELL_RUNNING &&
|
if ((exitCode == OnCommandResultListener.SHELL_RUNNING) &&
|
||||||
Shell.parseAvailableResult(output, Shell.SU.isSU(shell)) != true) {
|
!Shell.parseAvailableResult(output, Shell.SU.isSU(shell))) {
|
||||||
// shell is up, but it's brain-damaged
|
// shell is up, but it's brain-damaged
|
||||||
exitCode = OnCommandResultListener.SHELL_WRONG_UID;
|
exitCode = OnCommandResultListener.SHELL_WRONG_UID;
|
||||||
}
|
}
|
||||||
@ -1327,6 +1328,7 @@ public class Shell {
|
|||||||
STDIN.write(("echo " + command.marker + " >&2\n").getBytes("UTF-8"));
|
STDIN.write(("echo " + command.marker + " >&2\n").getBytes("UTF-8"));
|
||||||
STDIN.flush();
|
STDIN.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// STDIN might have closed
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runNextCommand(false);
|
runNextCommand(false);
|
||||||
@ -1497,6 +1499,8 @@ public class Shell {
|
|||||||
lastExitCode = Integer.valueOf(
|
lastExitCode = Integer.valueOf(
|
||||||
line.substring(command.marker.length() + 1), 10);
|
line.substring(command.marker.length() + 1), 10);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// this really shouldn't happen
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
lastMarkerSTDOUT = command.marker;
|
lastMarkerSTDOUT = command.marker;
|
||||||
processMarker();
|
processMarker();
|
||||||
@ -1624,10 +1628,12 @@ public class Shell {
|
|||||||
try {
|
try {
|
||||||
STDIN.close();
|
STDIN.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// in case it was closed
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
process.destroy();
|
process.destroy();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// in case it was already destroyed or can't be
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1641,10 +1647,10 @@ public class Shell {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// if this throws, we're still running
|
|
||||||
process.exitValue();
|
process.exitValue();
|
||||||
return false;
|
return false;
|
||||||
} catch (IllegalThreadStateException e) {
|
} catch (IllegalThreadStateException e) {
|
||||||
|
// if this is thrown, we're still running
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class StreamGobbler extends Thread {
|
|||||||
*
|
*
|
||||||
* @param line String that was gobbled
|
* @param line String that was gobbled
|
||||||
*/
|
*/
|
||||||
public void onLine(String line);
|
void onLine(String line);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String shell = null;
|
private String shell = null;
|
||||||
@ -85,19 +85,21 @@ public class StreamGobbler extends Thread {
|
|||||||
public void run() {
|
public void run() {
|
||||||
// keep reading the InputStream until it ends (or an error occurs)
|
// keep reading the InputStream until it ends (or an error occurs)
|
||||||
try {
|
try {
|
||||||
String line = null;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
Debug.logOutput(String.format("[%s] %s", shell, line));
|
Debug.logOutput(String.format("[%s] %s", shell, line));
|
||||||
if (writer != null) writer.add(line);
|
if (writer != null) writer.add(line);
|
||||||
if (listener != null) listener.onLine(line);
|
if (listener != null) listener.onLine(line);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// reader probably closed, expected exit condition
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure our stream is closed and resources will be freed
|
// make sure our stream is closed and resources will be freed
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// read already closed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user