Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 936
Ankit Shubham Avatar asked May 24 '17 10:05

Ankit Shubham


People also ask

What is app device owner?

A Device Owner is an application that runs as a device administrator on your Android 5.0+ device. The Device Owner app can use the programming methods in the DevicePolicyManager class to take control of the configuration, security and other applications on the device. A device can have only one Device Owner.


1 Answers

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.

like image 137
Ankit Shubham Avatar answered Sep 19 '22 08:09

Ankit Shubham