PC端出现如下log:

D:\workspace\AndroidO\CTS\CTS_Verifier>adb shell dpm set-device-owner 'com.android.cts.verifier/com.android.cts.verifier.managedprovisioning.DeviceAdminTestReceiver'
java.lang.IllegalStateException: Not allowed to set the device owner because there are already some accounts on the device
at android.os.Parcel.readException(Parcel.java:2012)
at android.os.Parcel.readException(Parcel.java:1950)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:5176)
at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:148)
at com.android.commands.dpm.Dpm.onRun(Dpm.java:96)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:54)
at com.android.commands.dpm.Dpm.main(Dpm.java:41)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285)

目标设备端出现如下log:

05-04 07:43:00.705 788 1904 W DevicePolicyManager: Non test-only owner can't be installed with existing accounts.
05-04 07:43:00.746 788 788 I DevicePolicyManager: Device admin ComponentInfo{com.android.cts.verifier/com.android.cts.verifier.managedprovisioning.DeviceAdminTestReceiver} removed from user 0

分析DevicePolicyManagerService.java的代码找到里面的hasIncompatibleAccountsOrNonAdbNoLock(

int userId, @Nullable ComponentName owner)方法,该方法中有一个条件判断if (owner == null || !isAdminTestOnlyLocked(owner, userId)) 。

添加之后重新编译,再次执行 success。

 

相关文章:

  • 2021-10-29
  • 2021-07-30
  • 2022-12-23
  • 2021-05-11
  • 2021-10-21
  • 2021-10-21
  • 2021-08-14
猜你喜欢
  • 2021-11-26
  • 2021-08-16
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-11-19
相关资源
相似解决方案