package com.basic.security.utils;
|
|
public class LztekAndroidRoot{
|
/* It is sample code for Lztek Android 7.1 and 8.1 root
|
|
*/
|
public static void SafeClose(java.io.Closeable closeable) {
|
if (null != closeable) {
|
try {
|
closeable.close();
|
} catch (java.io.IOException e) {
|
}
|
}
|
}
|
|
/* The command sequence is like "su root chmod 666 /dev/i2c-1".
|
* Each command should be executed in this strange way :-)
|
*/
|
|
public static String SuExec(String command, java.io.File workingDirectory) {
|
if (null == command || (command=command.trim()).length() == 0) {
|
return null;
|
}
|
if (null == workingDirectory) {
|
workingDirectory = new java.io.File("/");
|
}
|
java.io.OutputStream out = null;
|
java.io.InputStream in = null;
|
java.io.InputStream err = null;
|
try {
|
Runtime runtime = Runtime.getRuntime();
|
Process process = runtime.exec("su root " + command, null, workingDirectory);
|
StringBuffer inString = new StringBuffer();
|
StringBuffer errString = new StringBuffer();
|
out = process.getOutputStream();
|
|
in = process.getInputStream();
|
err = process.getErrorStream();
|
while (in.available() > 0) {
|
inString.append((char)in.read());
|
}
|
while (err.available() > 0) {
|
errString.append((char)err.read());
|
}
|
return inString.toString();
|
} catch (Exception ioex) {
|
return null;
|
} finally {
|
SafeClose(out);
|
SafeClose(in);
|
SafeClose(err);
|
}
|
}
|
}
|