APK获取ROOT权限后,无法运行uiautomator Jar包
不知取啥名 2015-06-04 02:39:54 1.PC通过ADB连接手机后,执行adb shell uiautomator runtest XXX.jar -c com.XXX,可以正常运行uiautomator的jar文件程序。
2.通过APK调用以下方法一,在android 4.4和android 5.0上都提示:
Error running exec(). Command: [su] Working Directory: null Environment: null
通过方法二,在android4.4上可以正常调用uiautomator程序,但是在android 5.0上却无法调用uiautomator jar,也不会报错。
方法一:
public boolean runRootCommand(String command){
Process process = null;
DataOutputStream os = null;
try{
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
}catch(Exception e){
Log.e("**dbg***", e.getMessage());
return false;
}finally{
try{
if(os!=null){
os.close();
}
process.destroy();
}catch(Exception e){}
}
return true;
}
方法二:
public void startOtherProcess(int maxTime,String exec){
try
{
final Process starter=Runtime.getRuntime().exec(exec);
final BufferedReader br = new BufferedReader(new InputStreamReader(starter.getInputStream()));
String line=null;
while((line=br.readLine())!=null)
{}
if(starter!=null){
try {
br.close();
starter.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
}catch(Throwable e){
Log.e("**dbg***", e.getMessage());
}
}
PS:APK使用的是:android:sharedUserId="android.uid.system",eclipse—运行—android application打包生成APK时,用的也是公司提供的系统签名文件(签名文件是OK的)。
开始怀疑手机没有root,把手机root开关也打开了。但是/system/bin目录下没有su文件
C:\Documents and Settings\Administrator>adb shell
root@A51:/ # cd /system/bin
cd /system/bin
root@A51:/system/bin # ls
ls
ATFWD-daemon
PktRspTest
StoreKeybox
WifiLogger_app
adb
……
求大神支招,问题到底出现在哪里了?怎样在android 5.0上也能通过APK启动uiautomator?