为什么getRuntime().exec("/system/bin/am")总是返回"Operation not permitted"?



我的Android应用程序以Android 5.0为目标,包含以下代码:

try
{
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("/system/bin/am switch-user 0");
    proc.waitFor();
    proc.destroy();
}
catch (Exception e)
{}

上面最简单的代码总是返回proc.exitValue的1,这意味着不允许操作

然而,我通过adb shell检查了/system/bin/am switch-user 0的权限,结果如下:

shell@hammerhead:/system/bin $ ll am
ll am
-rwxr-xr-x root shell 210 2015-03-23 15:10 am

显然,权限表示任何用户都可以执行am

更奇怪的是:我可以成功地从adb shell调用am(在未展开模式下)。

我还尝试在根模式下禁用SELinux。测试表明setenforce 0在安卓5.0上没有任何影响,即SELinux在安卓5.0。我可以毫无错误地调用setenforce 0,但sestatus仍然显示"SELinux Enabled"。

根本原因是什么?

我在安卓L模拟器上做了一些测试,如果你执行/system/bin/am,它会返回0;如果执行/system/bin/am switch-user 0,则返回1。

这意味着您确实有执行am的权限,但没有在应用程序中执行命令am switch-user 0的权限。

可能是SELinux问题,请尝试"setenforce 0",但您需要root权限。此外,检查stderr可能会有所帮助http://pastebin.com/BeRYG1Hi

但是,应用程序不能具有root权限。它只能是一个系统应用程序,但与root不是一回事。

最新更新