2

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.

ZolaKt
  • 4,683
  • 8
  • 43
  • 66
  • 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 Mar 17 '20 at 16:54
  • This would seem to be a hardware and firmware issue, not an app issue. – CommonsWare Mar 17 '20 at 16:55
  • 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 https://android.stackexchange.com/questions/20021/automatically-power-on-android-when-the-charger-is-connected – ZolaKt Mar 17 '20 at 17:04
  • 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 Mar 17 '20 at 17:07

1 Answers1

2

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.

JensV
  • 3,997
  • 2
  • 19
  • 43
  • Thanks for the answer. I'm just wondering, if there is not a "fully-automated" way to do this, how does KNOX do it? Certainly, it's not by plugging each device into a Raspberry pi, since you don't ship the devices to Samsung when you want to use KNOX. Btw. all the devices that we are using are Samsung tablets, so whatever KNOX is doing, we need the same thing. As long as it's fully automated – ZolaKt Apr 14 '20 at 11:07
  • @ZolaKt Simply said, because it's made by Samsung :). But my kind of educated guess is that Samsung has exposed this functionality in it's own bootloader to KNOX. KNOX is built into the bootloader and android firmware and because Samsung controls the whole system they must have implemented a way for the Android part of KNOX to speak with the bootloader part of KNOX. So in the end, it's because *Samsung* and not *Android/Google in general* modified the system to make it possible. – JensV Apr 14 '20 at 11:11
  • @ZolaKt since you're working with Samsung hardware, you are able to leverage KNOX. As mentioned in the answer, you will probably need to pay for the ProKiosk mode. I'd also investigate this work app for KNOX https://play.google.com/work/apps/details?id=com.samsung.android.knox.kpu You might be able to leverage that app and define everything through an AMA Policy – JensV Apr 14 '20 at 11:15
  • Yeah, that would be by guess as well. I'm hoping that there is a way to make use of that exposed bootloader functionality, without using KNOX. Although, they probably have zero public documentation regarding that, but I'll give it a show anyway. Thanks for the answer. I've awarded you the bounty – ZolaKt Apr 14 '20 at 11:15
  • We are not looking to leverage KNOX, since it's quite expensive, and honestly isn't really rocket science. We are making our own EMM. So far we have everything covered, apart from this feature – ZolaKt Apr 14 '20 at 11:16
  • @ZolaKt I've worked with KNOX before and I don't think making use of the functionality will be easy without using KNOX. KNOX performs a license validation using the system and will not grant any access to it's features if that doesn't pass. But I wish you good luck :) – JensV Apr 14 '20 at 11:17
  • @ZolaKt any update on this? I'm in a similar situation. – theDude Jul 14 '21 at 18:23
  • @theDude No. I gave up on the manual approach, and went with KNOX. It works fine there. Have no idea if it's even possible to do this any other way. They have some firmaware hacks, that aren't exposed in "normal" Android – ZolaKt Jul 15 '21 at 19:16