Android N和O中使用adb shell dpm set-device-owner 'com.android.cts.verifier/com.android.cts.verifier.managedprovisioning.DeviceAdminTestReceiver' setup Device Owner失敗


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)) 。

isAdminTestOnlyLocked會判斷對應的application的ApplicationInfo.FLAG_TEST_ONLY是否為true,這個變量是通過AndroidManifest.xml中的android:testOnly="true"控制的。

添加之后重新編譯,再次執行 success。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM