Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device Owner not working as expected #282

Open
bonswouar opened this issue Dec 1, 2024 · 2 comments
Open

Device Owner not working as expected #282

bonswouar opened this issue Dec 1, 2024 · 2 comments

Comments

@bonswouar
Copy link

bonswouar commented Dec 1, 2024

Maybe I misunderstand Android settings,
but when I go to Settings > Security & privacy > More security & privacy > Device admin apps, I can see that Hail is enabled.
Isn't it the same thing as "Device owner"?

If I run adb shell dpm set-device-owner com.aistral.hail/.receiver.DeviceAdminReceiver I get:

com.aistral.hail/.receiver.DeviceAdminReceiver was already an admin for user 0. No need to set it again

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.
[...]

So it looks like it's already set, although those 2 error messages seem to contradict themselves..
I saw I might be able to reset the device owner with a factory reset, but not sure it will work, and I don't really want to factory reset my phone.
I'd like to avoid rooting the device just for this app if possible?

Thanks!

  • OnePlus 5
  • LineageOS 21 / Android 14
@candroid-man
Copy link

I am also experiencing this issue on a non-rooted Pixel 8 with GrapheneOS. Here is my full terminal output:

candroid_man@fedora~$ adb shell dpm set-device-owner com.aistra.hail/.receiver.DeviceAdminReceiver

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.
	at com.android.server.devicepolicy.DevicePolicyManagerService.enforceCanSetDeviceOwnerLocked(DevicePolicyManagerService.java:11171)
	at com.android.server.devicepolicy.DevicePolicyManagerService.setDeviceOwner(DevicePolicyManagerService.java:9807)
	at com.android.server.devicepolicy.DevicePolicyManagerServiceShellCommand.runSetDeviceOwner(DevicePolicyManagerServiceShellCommand.java:285)
	at com.android.server.devicepolicy.DevicePolicyManagerServiceShellCommand.onCommand(DevicePolicyManagerServiceShellCommand.java:90)
	at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
	at android.os.ShellCommand.exec(ShellCommand.java:38)
	at com.android.server.devicepolicy.DevicePolicyManagerService.onShellCommand(DevicePolicyManagerService.java:11592)
	at android.os.Binder.shellCommand(Binder.java:1140)
	at android.os.Binder.onTransact(Binder.java:957)
	at android.app.admin.IDevicePolicyManager$Stub.onTransact(IDevicePolicyManager.java:6457)
	at android.os.Binder.execTransactInternal(Binder.java:1425)
	at android.os.Binder.execTransact(Binder.java:1359)

@bonswouar
Copy link
Author

bonswouar commented Dec 18, 2024

FYI I found out that Hail instructions are a bit misleading:
Apparently dpm set-device-owner won't work directly on many (most?) phones, as lots of apps have registered Accounts (even if they don't appear in Android Accounts settings), preventing changing the device owner for some reason.


Basically the cleaner solution I've found (inspired by this discussion) was:

  1. Install Shizuku
  2. adb shell sh /sdcard/Android/data/moe.shizuku.privileged.api/start.sh1 to run Shizuku service
  3. Use Hail with Shizuku

The main issue if stopping at this step, is that Shizuku will be disabled at each reboot (and Hail permissions). So frozen apps can't be unfrozen easily and vice versa (not without running the adb command after each reboot2), which isn't ideal imo.

So what I ended up doing after was:

  1. Use aShell or some similar app3 that can list Apps Accounts (command dumpsys account) using Shizuku api
  2. (Temporary) freeze all those apps with Accounts, using "Shizuku - Disable" mode in Hail
  3. Reboot (really needed in my case!)
  4. Then two possible solutions:
    • A. Set the device owner to Hail if you only care about this app
      • adb shell dpm set-device-owner com.aistral.hail/.receiver.DeviceAdminReceiver should work now
    • B. Or use Dhizuku to have permanent root-like permissions4 - for some potential other apps5 - without the need of adb
      • Install Dhizuku
      • adb shell dpm set-device-owner com.rosan.dhizuku/.server.DhizukuDAReceiver
  5. Still using "Shizuku - Disable" mode in Hail, un-freeze the apps from step 5.
  6. Switch to the appropriate mode in Hail (Owner for A. or Dhizuku for B.)

Footnotes

  1. Path can depend on your OS, refer to the app's instructions, for me it was /storage/emulated/0/Android/data/moe.shizuku.privileged.api/start.sh

  2. Apparently Shizuku can also be activated another way, by emulating a fake wireless debugging, but it still requires quite a few steps after reboot

  3. Some are listed here: https://github.com/timschneeb/awesome-shizuku#awesome-shizuku

  4. As far as I understand Dhizuku shares Device Owner permissions, while Shizuku shares adb root permissions

  5. Very few seem compatible for now, but the project is only 1 year old

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants