skip to Main Content

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)

2

Answers


  1. Chosen as BEST ANSWER

    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.


  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search