使用Runtime.exec(...)运行dpm [英] Running dpm with Runtime.exec(...)
问题描述
此答案表明Android应用可以运行 dpm
像这样:
This answer suggests that an Android app can run dpm
like this:
Runtime.getRuntime().exec("dpm set-device-owner com.test.my_device_owner_app");
这在运行5.1.1的Nexus 4上无提示地失败了。外壳程序返回错误代码0(成功),并且没有控制台输出。尽管取得了明显的成功,但我的应用并未成为设备所有者。该设备是从出厂重置中恢复的,未配置任何用户帐户。
This fails silently on my Nexus 4 running 5.1.1. The shell returns an error code of 0 (success) and there is no console output. Despite the apparent success, my app does not become the device owner. The device is fresh from a factory reset, with no user account configured.
作为控件,我尝试运行垃圾命令而不是 dpm
。它会按预期失败。
As a control, I tried running a garbage command instead of dpm
. It fails as expected.
这曾经奏效吗?
推荐答案
dpm
错误地退出并显示状态代码错误的命令语法时为0。正确的语法是 dpm set-device-owner package / .ComponentName
。当正确使用语法时, exec(...)
会引发 SecurityException
:
dpm
incorrectly exits with a status code of 0 when you get the command syntax wrong. The correct syntax is dpm set-device-owner package/.ComponentName
. When you get the syntax right, exec(...)
throws a SecurityException
:
java.lang.SecurityException: Neither user 10086 nor current process has android.permission.MANAGE_DEVICE_ADMINS.
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.setActiveAdmin(IDevicePolicyManager.java:2993)
at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:110)
at com.android.commands.dpm.Dpm.onRun(Dpm.java:82)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.dpm.Dpm.main(Dpm.java:38)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:249)
将此权限添加到清单中无济于事,因此它可能是系统权限。
Adding this permission to the manifest does not help, so maybe it's a system-only permission.
在没有NFC的设备上部署信息亭模式的应用程序已经很麻烦了,因为您必须启用开发人员模式并通过 adb
。我想配置者将只需要手动运行 dpm
。
It's already a pain in the butt to deploy a kiosk mode app on a device without NFC, since you have to enable developer mode and install the app via adb
. I guess the provisioner will just have to run dpm
manually.
这篇关于使用Runtime.exec(...)运行dpm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!