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

9

30

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.

Ignoble answered 24/5, 2017 at 10:24 Comment(0)
I
39

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.

Ignoble answered 26/5, 2017 at 5:26 Comment(2)
It should be noted that on modern (S6+ ?) Samsung phones removing all accounts and attempting this still does not work. The only way is to remove all accounts AND then factory reset.Doing
@NickBetcher In my case I removed all the account from settings->accounts but still getting error that several accounts are logged in. I uninstall every app but nothing helps. at last reseting the phone fixed it .but that is not solution in my case can you please let me know what are these hidden accounts how I can get know about those?Georgetta
T
6

This post gives a really good overview on the dpm command: http://florent-dupont.blogspot.fr/2015/01/android-shell-command-dpm-device-policy.html

Near the end of the post, this update was added: "Device owner can only be set on an unprovisioned device, unless it was initiated by “adb”, in which case we allow it if no account is associated with the device” says the source code. So, make sure you don’t have any account (like Gmail) associated to your current user set before using the dpm command"

I recommend installing and setting your app as a device owner using dpm after performing a factory reset, going through Google Wizard without setting up any accounts, enable developer mode from settings, and finally enable "USB debugging"... If that's a viable option for you...

Tantivy answered 24/5, 2017 at 17:11 Comment(0)
S
2

I did similar as @user2572085 and after deleting all accounts there was still a account remaining which could be found with adb shell dumpsys account, I tried to uninstall the corresponding app but that did not help. In the end it turned out that an older version of the app used accounts but the newer one did not, so uninstalling the current version of the app did not remove the accounts. I then installed an older version of the app, as a result the account appeared again in the settings and I could remove it from there. After that I could run adb shell dpm set-device-owner

Sealer answered 18/10, 2022 at 11:9 Comment(0)
R
1

I had the same problem with emulator. Then from Android studio's AVD manager, I right clicked on the device-> wipe data.

Rigney answered 6/12, 2019 at 13:35 Comment(0)
B
1

I know this is a post from 4 years ago but I was having the same problem and I didn't want to do a factory data reset so I clicked on that and then you will get a confirmation screen showing everything that you have installed and the accounts that are still logged in, even though they don't show up under accounts & backup.

You can then proceed to erease those apps and you're set!

*In my case the apps still logged in were reddit and zoho invoice

Brownout answered 3/1, 2021 at 20:12 Comment(2)
Can you elaborate on "that" which you clicked?Mroz
In my case I removed all the account from settings->accounts but still getting error that several accounts are logged in. I uninstall every app but nothing helps. at last reseting the phone fixed it .but that is not solution in my case can you please let me know what are these hidden accounts how I can get know about thoseGeorgetta
Y
0

Follow instructions below to solve the problem:

  1. Remove all accounts in the settings->Accounts
  2. Use the command: adb shell dumpsys account (It will list all the accounts remains but not lists before, uninstall all the apps)
  3. Try again
Yearning answered 9/10, 2021 at 6:4 Comment(1)
In my case I removed all the account from settings->accounts but still getting error that several accounts are logged in. I uninstall every app but nothing helps. at last reseting the phone fixed it .but that is not solution in my case can you please let me know what are these hidden accounts how I can get know about thoseGeorgetta
T
0

In my case, after a hard reset, the device still showed me an exception:

Exception occurred while executing 'set-device-owner':
java.lang.IllegalStateException: Not allowed to set the device owner because there are already some accounts on the device.

The cause was the SIM card inside... Put it off and restart, it should work.

Traditional answered 2/3, 2023 at 17:52 Comment(0)
S
0

Check whether multi-user is enabled on the device, or the multi-application function is used to delete other users.

# pm list users

# pm remove-user 999
Sammy answered 4/3 at 9:37 Comment(0)
S
0

For me I deleted all accounts via Settings > Accounts.

However, I still couldn't do this. The problem was Threema and Telegram kept invisibly recreating the accounts immediately. I didn't have adb or PC access to do a dumpsys so that wasn't an option for me.

After rebooting I saw back in Settings > Accounts. That Threema and Telegram had made their account again. Clearing full storage for those apps and uninstalling them finally worked.

So in short, delete everything you can from the settings, then reboot and then check it again again to see if any apps still have account data left. I also pulled my SIM card and that might have helped too.

I finally got device admin for Owndroid after this.

Shirley answered 22/7 at 18:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.