Trying to set the device owner, but device owner is already set.解決方法
阿新 • • 發佈:2018-12-22
在測試CTS Verifier 中Device Owner Test 的時候報錯:
$ adb shell dpm set-device-owner 'com.android.cts.emptydeviceowner/.EmptyDeviceAdmin' $ adb shell dpm set-device-owner 'com.android.cts.verifier/com.android.cts.verifier.managedprovisioning.DeviceAdminTestReceiver' java.lang.IllegalStateException: Trying to set the device owner, but device owner is already set. at android.os.Parcel.createException(Parcel.java:1958) at android.os.Parcel.readException(Parcel.java:1918) at android.os.Parcel.readException(Parcel.java:1868) at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:5863) at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:176) at com.android.commands.dpm.Dpm.onRun(Dpm.java:106) 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:351) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.devicepolicy.DevicePolicyManagerService.enforceCanSetDeviceOwnerLocked(DevicePolicyManagerService.java:7881) at com.android.server.devicepolicy.DevicePolicyManagerService.setDeviceOwner(DevicePolicyManagerService.java:7187) at android.app.admin.IDevicePolicyManager$Stub.onTransact(IDevicePolicyManager.java:1095) at android.os.Binder.execTransact(Binder.java:756)
解決方法:移除admin
$ adb shell dpm remove-active-admin 'com.android.cts.emptydeviceowner/.EmptyDeviceAdmin'
$ adb shell dpm remove-active-admin 'com.android.cts.verifier/com.android.cts.verifier.managedprovisioning.DeviceAdminTestReceiver'
推薦一個指令碼:
runDevice.sh
#!/bin/sh echo "use it by : runDevice.sh -s series_number & runDevice.sh" adb_options=" " if [ "$1" = "-s" ]; then adb_options=""$1" "$2"" fi #adb $adb_options shell dpm remove-active-admin 'com.android.cts.verifier/com.android.cts.verifier.managedprovisioning.DeviceAdminTestReceiver' #adb $adb_options shell dpm set-device-owner 'com.android.cts.verifier/com.android.cts.verifier.managedprovisioning.DeviceAdminTestReceiver' #adb $adb_options shell dpm remove-active-admin 'com.android.cts.emptydeviceowner/.EmptyDeviceAdmin' adb $adb_options shell dpm set-device-owner 'com.android.cts.emptydeviceowner/.EmptyDeviceAdmin'