2

I am having an issue with trying to set the device owner on my android device. If I install the app onto the physical device from within android studio by hitting the play button, I am able to add and remove device owner with adb shell dpm set-device-owner package/.receiver without any issues. I can do this from within android studio or via cmd.

When I install the app from using the apk and manually installed or using adb outside of android studio, I can no longer set the device owner. I always get the error Not allowed to set the device owner because there are already some accounts on the device

This is what makes no sense, as there are no accounts on the device. I can go back into android studio, install the app over the top of it and run the adb command again and it works just fine without doing anything else.

I am lost here because there error seems incorrect, but I have no idea why installing from the apk outside of android studio is not working.

Edit: Some notes

  • I am not testing with an emulator. When I say installing from android studio, I mean installing directly to the phone, not an emulator
  • I have the manifest pointing to the xml with properly defined
  • The app works fine when installing from android studio and setting device owner, I am getting all the expected permissions
  • When I install from the output apk, I am no longer able to set device owner (previous was cleared, even tried on a fresh recovery of the phone. Accounts settings is empty with no accounts listed)
JeremyK
  • 1,075
  • 1
  • 22
  • 45
  • Added a bounty because I have not had any help on this. I do not believe the error I am getting is accurate. There are NO accounts on the phone, I get the same thing if fresh factory reset. And if I re-install the app as debug direct from android studio, it works. It only fails when manually installing the APK. Is this a signing issue? – JeremyK Feb 14 '22 at 18:44
  • 1
    Did you checkout this comment? Might be helpful. https://stackoverflow.com/a/44164769/9715339 – Mayur Gajra Feb 15 '22 at 13:57
  • Yes I have seen that post thank you. It is not an account issue, as this has been tested after a factory reset with the same issue. And if I switch to installing via android studio it will work even when it didnt from the apk without making any changes to device. – JeremyK Feb 15 '22 at 14:42
  • One thing that has come to light is that setting TestOnly to true for whatever reason will allow the apk to install and then be set as device owner. That is obviously not ideal as no one should be leaving an app in test only, but at least starts us down a path – JeremyK Feb 15 '22 at 14:44
  • Just FYI: https://source.android.com/compatibility/12/android-12-cdd#391_device_provisioning Although you should check the CDD for your supported Android OS versions. – Morrison Chang Feb 16 '22 at 14:12

2 Answers2

2

"Not allowed to set the device owner because there are already some accounts on the device" means any account listed in Settings > Passwords & accounts. This may include things like:

  • Google
  • Gmail
  • Outlook
  • Signal
  • Google Duo
  • Password auto-fill services (Bitwarden, Lastpass, etc.)

You must remove all of these from the Settings > Passwords & accounts page before you can set the device/profile owner.


Update: You can check for what specific condition is occurring by looking at adb logcat -b system. See hasIncompatibleAccountsOrNonAdbNoLock() within DevicePolicyManagerService for a hint at what logs to look for.


Alternative Answer

If there is something special about the OEM/device you are using (perhaps Sonim does not allow non-testOnly DPM apps to be installed), you could try to install your DPM app the "real" way, which is via the factory reset welcome screen.

You can do this via NFC or Qr code enrollment.

BLuFeNiX
  • 2,496
  • 2
  • 20
  • 40
  • @JeremyK Tagging you specifically to take a look at the update, above. – BLuFeNiX Feb 18 '22 at 03:27
  • 1
    We have finally discovered the issue. We were unaware that a SIM card adds a system level account that is not visible to the phone's settings. After removing the SIM card, we were finally able to get the device owner set. When setting testOnly to true, it ignored this issue which android studio does by default launching from there – JeremyK Feb 18 '22 at 10:51
  • 1
    @JeremyK that's very interesting! Thanks for sharing that detail. – BLuFeNiX Feb 19 '22 at 01:19
2

We have finally arrived at the cause of this issue. When running an app from android studio, it gets the testOnly flag set to true, doing so allows for certain things to be allowed that normally would not pass. So up until testing from outside of android studio, we just had no idea there was a problem.

This issue: The SIM card adds an account under com.android.sim package that does not show itself in the accounts settings. So to us the phone appeared to have no accounts because this was hidden.

After removing the SIM card, we were finally able to set device owner.

Thank you to everyone who gave suggestions.

JeremyK
  • 1,075
  • 1
  • 22
  • 45