2

I need to update my application silently (as described here).

So I need to make my app a device owner in phone SAMSUNG S6. I use dpm command through adb shell command, so I provision my device (remove all account from Settings->Accounts), enable developer mode, enable debugging, install my app as usual (install it with Android Studio for example) and then run command:

adb shell dpm set-device-owner <PACKAGE-NAME>/.DeviceAdminComponent

But I get a next error:

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:1701)
        at android.os.Parcel.readException(Parcel.java:1646)
        at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:6123)
        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:51)
        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:301)

It's a very strange. If I run this command:

adb shell dpm set-profile-owner <PACKAGE-NAME>/.DeviceAdminComponent

It works me fine.

Can somebody help me in this issue? Maybe it happens due to KNOX of SAMSUNG? (I see through Device Administrators - My Knox Policy Admin, that I can't disable).

Rougher
  • 834
  • 5
  • 19
  • 46

2 Answers2

1

You will ALWAYS be able to run the set-device-owner command without a factory reset. Here are the things to look out for that I currently am aware of and will try to keep this updated as I run into new scenarios.

  • First, go to Settings > Users & Accounts and remove all the accounts that you can find there.
  • Remove all sim cards. Some devices won't set owner with sim inserted.
  • If you have a OnePlus device with a OnePlus account you may need to run this command to remove it. pm uninstall --user 0 com.oneplus.account
  • Make sure all guest accounts are removed, run pm list users and if you get a result similar to below Users: UerInfo{0:Owner:*} running UserInfo{20:Guest:*} you can remove the guest account with this command pm remove-user 20 replace number 20 with whatever number you find in UserInfo{this_number:Guest} the Owner account can stay.

Finally, after every account has been removed, restart the device and run your set-device-owner command again and you should be successful. If not leave a comment and I'll see what I can do.

edgar_wideman
  • 315
  • 4
  • 16
-1

To set a device owner app on the phone requires a factory reset, then you can use adb command.

greywolf82
  • 21,813
  • 18
  • 54
  • 108
  • I search for a way to do it without a factory reset. For example, here: https://stackoverflow.com/questions/21183328/how-to-make-my-app-a-device-owner in accepted answer is written: "Also notice that this tool is working only if no account is set for the user (make sure no account is set in Settings > Accounts) before its use." – Rougher Oct 22 '19 at 03:36
  • in my experience it only works sometimes, with factory reset works always. – greywolf82 Oct 22 '19 at 04:56
  • It is always possible. Have done this on a ton of different devices and never had one that just wouldn't work. There is always a hidden account or user that prevents it to work. You just have to dig deep and find it. – edgar_wideman Jan 27 '23 at 04:25