android - DeviceOwner: Trying to set device owner but device is already provisioned

客户写了一个apk要成为device owner;
之后apk联网更新升级;
强制卸载安装,导致无法再次成为DeviceOwner。

原因:当一个app成为DeviceOwner后,这个app是不能被卸载,但是由于应用更新,强制卸载之前没有注销DeviceOwner,导致异常。

解决方案:
https://blog.csdn.net/u011068702/article/details/53191952

针对问题进行解决的过程:
1.adb shell dpm set-device-owner io.shoonya.shoonyadpc/com.shoonyaos.shoonyadpc.receivers.AdminReceiver
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 S t u b Stub StubProxy.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)

2.adb shell dumpsys account
User UserInfo{0:机主:13}:
Accounts: 1
Account {name=PHONE, type=com.android.localphone}

Active Sessions: 0

RegisteredServicesCache: 4 services
ServiceInfo: AuthenticatorDescription {type=com.qualcomm.RIDL}, ComponentInfo{com.qualcomm.RIDL/com.qualcomm.RIDL.cService}, uid 1000
ServiceInfo: AuthenticatorDescription {type=com.android.localphone}, ComponentInfo{com.qualcomm.simcontacts/com.qualcomm.simcontacts.PhoneAuthenticateService}, uid 1000
ServiceInfo: AuthenticatorDescription {type=com.android.sim}, ComponentInfo{com.qualcomm.simcontacts/com.qualcomm.simcontacts.SimAuthenticateService}, uid 1000
ServiceInfo: AuthenticatorDescription {type=com.qualcomm.qti.calendarlocalaccount}, ComponentInfo{com.qualcomm.qti.calendarlocalaccount/com.qualcomm.qti.calendarlocalaccount.AuthenticationService}, uid 10024

3.adb shell pm hide com.qualcomm.simcontacts
Package com.qualcomm.simcontacts new hidden state: true

4.adb shell dpm set-device-owner io.shoonya.shoonyadpc/com.shoonyaos.shoonyadpc.receivers.AdminReceiver
Success: Device owner set to package io.shoonya.shoonyadpc
Active admin set to component {io.shoonya.shoonyadpc/com.shoonyaos.shoonyadpc.receivers.AdminReceiver}

5.adb shell pm unhide com.qualcomm.simcontacts
Package com.qualcomm.simcontacts new hidden state: false

这个临时方案是在设备有adb的情况下,但是根据复现问题的现象来看,每次应用更新就要操作一边很麻烦,并且以后发布user版本没有adb就无法解决这个问题。

最好的方法是应用在更新之前调用:
devicePolicyManager.clearDeviceOwnerApp(getPackageName());
解除Device Owner身份

另外,
adb shell dpm remove-active-admin 指令需要android:testOnly才能移除。

移除DeviceOwner
当一个app成为DeviceOwner后,这个app是不能被卸载,也无法在设置->安全中关闭其权限。要想DeviceOwner后还能卸载这个app,也就是退出DeviceOwner,有如下方法:

devicePolicyManager.clearDeviceOwnerApp(packageName)
1,在AndroidManifest.xml中的<application/>节点添加android:testOnly="true";
2,通过命令adb install -t examole.apk安装该app;
3,通过命令adb shell dpm set-device-owner com.example.sample/.MyDeviceAdminReceiver成为DeviceOwner;
4,通过命令adb shell dpm remove-active-admin com.example.sample/.MyDeviceAdminReceive退出DeviceOwner;

偶然百度到了一个DEMO:
https://github.com/ddssingsong/DevicePolicyManager

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值