【发布时间】:2012-07-09 08:06:12
【问题描述】:
我的应用要做的第一件事是检查“su”,因为它是应用运行所必需的。即使它有时会起作用,通常是在终端中键入“killall packageName”之后。我做了一个简单的测试应用程序,但我不能让它每次都工作。 发生的代码:
String[] args = new String[] { "su" };
Log.v(TAG, "run(" + Arrays.toString(args) + ")");
FutureTask<Process> task = new FutureTask<Process>(new Callable<Process>() {
@Override
public Process call() throws Exception {
return Runtime.getRuntime().exec(args);
}
});
try {
Executors.newSingleThreadExecutor().execute(task);
return task.get(10, TimeUnit.SECONDS);
} catch (Throwable t) {
task.cancel(true);
throw new IOException("failed to start process within 10 seconds", t);
}
完成项目:https://github.com/chrulri/android_testexec
由于此应用程序首先运行 exec(),因此我无法关闭任何以前打开的文件描述符,如另一个 stackoverflow 问题中提到的:https://stackoverflow.com/a/11317150/1145705
PS:我在不同的设备上运行 Android 4.0.3 / 4.0.4。
【问题讨论】:
标签: android runtime.exec