[Android Q&A, Help & Troubleshooting] Jiketsu:
Hi thanks for reading :)

I have a rooted Android TV Box [CSA96] running Marshmallow. When first plugged in to AC power, the only indicator of this is a red LED. There is no battery so no charging screen or any output (HDMI). The power button must be pushed in order for Android to boot up. The LED turns blue when the power button is pushed.

My goal is to force the device to automatically turn on when plugged into AC power, removing the requirement of pushing the power button.

From what I've learned so far, the button isn't necessarily a physical barrier -- while plugged in, Android is in a Low Powered State and can listen for an event saying the power button has been pushed. I want to try to invoke the event manually by editing init.rc ... but I am not certain if init.rc is even available at this time, or what other parts of the Android environment are available before the power button is pushed (if any). I'd like to gain an understanding of this so that I am not stumbling in the dark.

Before I continue, I'd like to mention here that I am a developer and am comfortable bricking the device (I've done it several times already, and recovered no problem). I am also using Android Image Kitchen for persistent modification of the system.

Another thing I'd like to say too is, I am well aware of the fastboot oem off-mode-charge 0 command. Unfortunately I have not been able to get fastboot working with this device. The drivers are definitely working as I can flash this device, and even access its bootloader. However for the life of me fastboot devices never shows anything. If someone knows a trick to get it working on the CSA96, that would be great as I'd love to actually try this command for a simple solution :)

Okay. So I'll get into why I am thinking the key to this is through the init.rc ...

The / dir has several init files, but the ones that seem to be relative to what I am doing are init.rc and init.rockchip.rc and maybe init.debug-charging.rc. I'll paste some of the contents of each ...

[init.rc]

# Healthd can trigger a full boot from charger mode by signaling this
# property when the power button is held.
on property:sys.boot_from_charger_mode=1
class_stop charger
trigger late-init

on charger
class_start charger

init.rockchip.rc

service charger /charger
class charger
seclabel u:r:healthd:s0

on property:ro.boot.charger.emmc=1
mount ext4 /dev/block/platform/emmc/by-name/system /system wait ro noatime nodiratime
start console
mount ext4 /dev/block/platform/emmc/by-name/metadata /metadata wait noatime nodiratime nosuid nodev noauto_da_alloc,discard
start charger

on property:ro.boot.charger.emmc=0
insmod /rk30xxnand_ko.ko
mount ext4 mtd@system /system wait ro noatime nodiratime noauto_da_alloc
start console
mount ext4 mtd@metadata /metadata wait noatime nodiratime nosuid nodev noauto_da_alloc
start charger

on charger
setprop ro.boot.charger.emmc 0
export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
export LD_LIBRARY_PATH /vendor/lib:/system/lib
setprop sys.usb.config adb

So in the init.rockchip.rc file, a service named charger invokes a binary called charger, located at /charger ... I found the source code for this program here: https://gitlab.com/pbeeler/system_core/commit/e4b7b294f37d9b64d6b7c1931e2c9bfb1a500d68

Here is a snippet that I find interesting (Line 830)..

if (code == KEY_POWER) {
if (key->down) {
int64_t reboot_timeout = key->timestamp + POWER_ON_KEY_TIME;
if (now >= reboot_timeout) {
LOGI("[%lld] rebooting\n", now);
android_reboot(ANDROID_RB_RESTART, 0, 0);
/* We do not currently support booting from charger mode on
all devices. Check the property and continue booting or reboot
accordingly. */
if (property_get_bool("ro.enable_boot_charger_mode", false)) {
LOGI("[%lld] booting from charger mode\n", now);
property_set("sys.boot_from_charger_mode", "1");
} else {
LOGI("[%lld] rebooting\n", now);
android_reboot(ANDROID_RB_RESTART, 0, 0);
}.....

So while I don't entirely understand the order of operation, it seems that when the device is plugged in, the charger service is run (executing the /charger binary) .. this binary detects the power button key, and if pressed, sets the sys.boot_from_charger_mode property to 1. Then the on property event inside the init.rc file is triggered, and then i assume late-init is what boots up the device.

So it appears that the contents of init.rc are available at some capacity, before Android has booted up. But I've tried a few adjustments to these files with no results. One thing I've tried is adding setprop sys.boot_from_charger_mode 1 to init.rockchip.rc's on charger event, or at the top of init.rc and other places.

I've also tried changing /charger to /system/bin/reboot

I've also tried putting trigger late-init under init.rockchip.rc's on charger event too.

When I make these changes and try them on the device, I do check the files to verify the changes had stayed.. and they do.

So now I cannot help but wonder that perhaps I am on the wrong track and that maybe these files aren't actually available before the power button is pushed. Some insight would be greatly appreciated.

Thank you.