Not allowed to set the device owner because there are already several users on the device

Ankit Shubham picture Ankit Shubham · May 24, 2017 · Viewed 17.6k times · Source

I was following this tutorial to set the app as device owner. In that tutorial, there is a section 'Using adb to set the device owner'. The tutorial here says that after installing the Kiosk Mode Demo App, run the following command:

adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver

This gave me the error:

adb server is out of date.  killing...
* daemon started successfully *
java.lang.IllegalStateException: Not allowed to set the device owner because there are already several users on the device
    at android.os.Parcel.readException(Parcel.java:1629)
    at android.os.Parcel.readException(Parcel.java:1574)
    at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:5146)
    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:257)

I followed this SO link and the answer of Diego Plascencia Lara helped me to get rid of

adb server is out of date.  killing...
* daemon started successfully *

But still the following error is occurring after running the adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver command:

java.lang.IllegalStateException: Not allowed to set the device owner because there are already several users on the device
    at android.os.Parcel.readException(Parcel.java:1629)
    at android.os.Parcel.readException(Parcel.java:1574)
    at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:5146)
    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:257)

Why is this error happening and how can I remove this? I had earlier tried to set different apps as device owner but I think I did not manage to pull them off entirely and there were always some errors while completing the entire procedure of getting the app running on the device.

Answer

Ankit Shubham picture Ankit Shubham · May 26, 2017

There is a way out of this problem without Factory-resetting the device. Just remove all the accounts from your device (In Settings->Accounts). You may want to sync the data before doing this so that later, you can restore them. After removing all the accounts, connect your phone to the computer and run the command:

adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver

If you get a message like this:

Success: Device owner set to package ComponentInfo{org.bluetooth.bledemo/org.bluetooth.bledemo.AdminReceiver}
Active admin set to component {org.bluetooth.bledemo/org.bluetooth.bledemo.AdminReceiver}

consider yourself successful. Now you can add back all the accounts that you removed earlier.

Another way : As pointed out by Steve Miskovetz in the answer, factory reset is one of the ways to set the app as device owner if previously, your phone had accounts (e.g. Gmail accounts). But in recent versions of Android and/or some phones,after doing a factory reset, they do not allow to move forward unless you have set a google account. So, in order to solve this, go ahead and register your google account and when your phone is back to normal operable state, delete that account by going in Settings -> Accounts. Now all you need is to enable developer mode and then USB debugging. After that connect your phone to the computer and run the command adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver.