gpt4 book ai didi

android - 如何将 device_owner 设置为我的 android 应用程序?

转载 作者:太空狗 更新时间:2023-10-29 14:46:51 26 4
gpt4 key购买 nike

我尝试使用以下命令将我的应用程序设置为平板电脑的设备所有者(没有 ROOT 或 NFC):

adb shell dpm set-device-owner com.test.my_device_owner_app/.MyDeviceAdminReceiver

like 写在很多网站上(因为我必须制作一个 KIOSK APP)。首先我恢复出厂设置,然后我安装了我的应用程序,然后我在 shell 上写了这个命令,但答案是:

java.lang.IllegalStateException: Trying to set device owner but device is already provisioned.
  at android.os.Parcel.readException(Parcel.java:1554)
  at android.os.Parcel.readException(Parcel.java:1499)
  at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:3212)
  at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:114)
  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)

现在,我如何在不对平板电脑进行 root 的情况下解决这个问题?

最佳答案

我在联想 Yoga 2 平板电脑上遇到了同样的问题。

这是我在研究这个问题时发现的 dpm 源代码的一些 fragment 。

    if (!allowedToSetDeviceOwnerOnDevice()) {
throw new IllegalStateException(
"Trying to set device owner but device is already provisioned.");
}

if (mDeviceOwner != null && mDeviceOwner.hasDeviceOwner()) {
throw new IllegalStateException(
"Trying to set device owner but device owner is already set.");
}

这里是allowedToSetDeviceOwnerOnDevice实现

/**
* Device owner can only be set on an unprovisioned device, unless it was initiated by "adb", in
* which case we allow it if no account is associated with the device.
*/
private boolean allowedToSetDeviceOwnerOnDevice() {
int callingId = Binder.getCallingUid();
if (callingId == Process.SHELL_UID || callingId == Process.ROOT_UID) {
return AccountManager.get(mContext).getAccounts().length == 0;
} else {
return Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 0) == 0;
}
}

因此,首先确保所有帐户都已删除。检查设置 > 帐户。 Lenovo 的臃肿软件默认创建了Local Calendar 帐户。你必须删除它。

对于那些拥有 root 权限的人

参见 SO answer for manually creating the device_owner.xml .正如我从实现中看到的那样,dpm 正在做与答案中描述的相同的事情。顺便说一下,我保留 name 属性没有问题。

当您查看else 情况时,您可以通过调用来绕过测试

settings put global device_provisioned 0

我对 Yoga 平板电脑的体验

即使我有 root 访问权限,恢复出厂设置并尝试 device_owner.xml 方法我昨天也没有成功。

我今天所做的是使用谷歌帐户登录(昨天我跳过了这部分),然后在“设置”>“帐户”中也删除了这个帐户,我能够(以 su 身份)成功运行 dpm 命令。

更新

我有另一台 Yoga 2 平板电脑,没有 root 访问权限,也没有使用我的谷歌帐户登录,但已成功设置设备所有者。

有人认为我可以建议您:在安装信息亭模式应用后尝试关闭 Android Studio。也许这会导致另一个 Binder.getCallingUid()

关于android - 如何将 device_owner 设置为我的 android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39164066/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com