2
votes

So, as the title describes, I'm looking for a way to boot an Android device when the power charger is connected. We are making dedicated devices, in kiosk mode, and are using the Android Management API to setup everything on the device.

This covers most of our requirements, like preinstalling apps, disabling everything else, hooking it up to Managed Google Play, getting device reports etc... But for this power thing, I can't find any solutions in the docs.

The problem is that the physical power button isn't accessible to the user (don't ask my why :)), and when the battery drains they have to be able to power it up again, without unscrewing the case to get to the physical button.

I know this can be done in different ways, but I can't find anything that would work with Android Management API. I'm looking at this "fastboot" approach, since it seems pretty simple https://source.android.com/devices/bootloader/unlock-trusty#off-mode-charging

Initially, I though I could run this somehow using the devices/issueCommand endpoint https://developers.google.com/android/management/reference/rest/v1/enterprises.devices/issueCommand, but that seems to support only some predefined commands like: LOCK, RESET_PASSWORD and REBOOT.

Maybe I'm just missing something. If someone has another approach in mind, please share.

If it's any help, we also have the Android Management API hooked up to the PubSub API, and a topic there that the pulls the reports of the devices. Theoretically, I could listed to the "power connected" event there, and run some command on the device. But again, the problem is how to run this command on the device remotely.

Maybe a solution would be to make another app that will run as a background process that runs this command. I guess I would need to add it as "receiverActivity" in the policy. But the same problem remains... how to invoke this activity from the Android Management API.

The bottom line is that this needs to be fully automated. Running this command on each device manually is not an option.

Also, worth mentioning, this is an Ionic app. Although it's probably not impossible, we would like to keep this logic outside of the app itself. Ideal solution would be just to run some adb command remotely using the Android Management API.

Or maybe there is a good 3rd party app that does this, and I could install that app in the policy and invoke it somehow.

All suggestions are welcome. Maybe there is a simple solution that I've missed.

UPDATE AFTER COMMENTS: I'm not looking how the actual app can do this. I'm looking for a way to execute some "native" command when the device is initially setup from the Android Management API policy. So it should execute only once. When it sets up everything initially. It should edit some file on the device (or run some command) to enable this feature. Later, it shouldn't care if the device is turned on or not, or what apps are running on it. There are a few different ways how to do this suggested here https://android.stackexchange.com/questions/20021/automatically-power-on-android-when-the-charger-is-connected. I'm looking for a way to trigger one of these commands when the device is setup initially (only once). In other words, this should execute only when the device is enrolled. It shouldn't care about any apps running on the device.

1
You can't do this programatically, the device isn't on to run your program. This would be something the OEM would need to build into the device at a hardware level. You're at completely the wrong level to think about this. - Gabe Sechan
This would seem to be a hardware and firmware issue, not an app issue. - CommonsWare
Thanks for the reply. But I'm not looking for a way how to do it from the app directly. I'm looking for a way to edit some internal file (or something) on the device, when it's first setup by the management api, so it would always behave like this. I'm not quite following why would and OEM need to do this, or through firmware, since there are multiple ways you can get this functionality on any device. e.g. there are a few approaches suggested here android.stackexchange.com/questions/20021/… - ZolaKt
I'm just looking for a way to trigger one of these commands when the management api policy sets up its stuff. It should execute only once, when the device is initially setup. After that it shouldn't care if the device is turned on or not, or what apps are running on it. - ZolaKt

1 Answers

2
votes

So the "free" way to do this is using the fastboot commands. But from the AMA API this is currently not (and most likely ever) possible. This problem will always be hardware specific, since the bootloader is controlling the boot process, and the bootloader is custom made for each device.

There are options for different manufacturers though. Look into OEMConfig apps (which you can get in the Play Store for Work or from the manufacturer themselves).

Samsung has it's KNOX API, and the paid ProKiosk mode supports controlling Power Control.

Regarding the post in your question solving the problem, you will not be able to modify any files in the system since that's restricted to root. This will also never work for Managed Devices.


You could "half-automate" the process by setting up a raspberry pi or some other device with a script that waits for fastboot devices to get connected and executing the command. That way you just visit every device and put it into fastboot and plug in the device and you're off to the next one.


For clarification: adb and fastboot are two entirely different things. Fastboot is running while the device is in it's bootloader. Adb is running while the device has started android. It should technically be not possible to execute fastboot commands while android is started since the bootloader has already exited.