You had offline-charging right all along Tom, just needed a slight change in the order I believe. Seems your test for last_kmsg does work, but the tails were not applied appropriately.
Note- I have included root/sbin/ftmpower and system/bin/battery_charging binaries from the stock OV system dump in the build I tested this on via device_thunderc.mk. I haven't tried without them yet, so I don't know if they have any impact. They were not added in as part of this commit, will test without them tomorrow (too tired now).
In init.c, there was already a
battchg_pause variable being used, but it was never flagged properly I assume due to the OS and kernel not communicating the reboot command. We can use the last_kmsg test to set that variable appropriately, and then it adds the boot-pause queue-tail at the right moment. No need to add warm/cold tails, or write new drivers for the kernel.
Code:
/system/core/init.c
@@ -740,9 +740,9 @@ int main(int argc, char **argv)
/* If /proc/last_kmsg exists the phone has been rebooted, if not
it's a cold boot */
if (access("/proc/last_kmsg", R_OK) == 0) {
- action_for_each_trigger("boot-warm", action_add_queue_tail);
+ battchg_pause = 0;
} else {
- action_for_each_trigger("boot-cold", action_add_queue_tail);
+ battchg_pause = 1;
}
In init.thunderc.rc I removed the exec of bootlogo in early-boot and added it at the top in boot-pause (diffs were over two commits, sorry, hope this makes sense):
Code:
# Charging while powered off
# *from powered off state, plug in charger
# *from os power down with charger plugged in
on boot-pause
exec sbin/chargerlogo
# This does the initial RLE animation for the vendor logo.
# Taken verbatim from the stock init.rc.
service bootlogo /sbin/bootlogo
user root
group root
oneshot
# Boot normally into os
# *if rebooted via any method
# *via power button when powered off and no charger
# *via long press on power button while offline charging
on early-boot
start bootlogo
With these changes, the following behaviour occurs (crashes tested by oc to 864):
With charger plugged in:
Reboot from recovery - boots fully
Reboot from os - boots fully
Power off - boots to chargerlogo
Crash - boots fully
Without charger:
Reboot from recovery - boots fully
Reboot from os - boots fully
Power off - powers off
Crash - boots fully
Powered off > No charger > Press power button - boots fully
Powered off > Plug in charger - boots to to chargerlogo
Offline-charging > Long press power button - boots fully
I believe this is the behaviour we have been looking for. Now users can have offline-charging, and I can charge my phone overnight without worrying about some random crash rebooting it into offline-charging mode and making me miss alarms and phone calls!
Thanks again Tom!