AnsweredAssumed Answered

AOSP 7 on a batteryless device

Question asked by Tim Gruijters on Jul 23, 2019
Latest reply on Jul 31, 2019 by jimmychan

Hi,

 

I have to disable the BatteryService Java class among several references to battery related objects in order to boot Android. It hangs in an boot-loop otherwise.

How can I make AOSP 7 work on my batteryless device? Do I have to write software or should I disable something?


What I've done so far:
I've written a power stub driver that has the options and return static values.

static enum power_supply_property stub_power_charger_props[] = {
     POWER_SUPPLY_PROP_ONLINE,
};

static enum power_supply_property stub_power_battery_props[] = {
     POWER_SUPPLY_PROP_STATUS,
     POWER_SUPPLY_PROP_PRESENT,
     POWER_SUPPLY_PROP_CAPACITY,
     POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
     POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
     POWER_SUPPLY_PROP_HEALTH,
     POWER_SUPPLY_PROP_CAPACITY_LEVEL,
};

I've tried to add missing battery stuff in the board config:

device/brand/imx6/imx6.mk: libhealthd.default \
device/brand/imx6/imx6.mk: libbatterymonitor \
device/brand/imx6/imx6.mk: libhealthd_internal \
device/brand/imx6/imx6.mk: healthd \
device/brand/imx6/imx6.mk: batterystats \
device/brand/imx6/imx6.mk: batteryproperties \
device/brand/imx6/imx6.mk: batteryservice \
device/brand/imx6/imx6.mk: libbatteryservice

I even changed system/core/healthd/healthd.cpp so it takes special operations:

diff --git a/system/core/healthd/healthd.cpp b/system/core/healthd/healthd.cpp
index 1c144b34d7..fc431860f3 100644
--- a/system/core/healthd/healthd.cpp
+++ b/system/core/healthd/healthd.cpp
@@ -132,6 +132,13 @@ static struct healthd_mode_ops recovery_ops = {
     .battery_update = healthd_mode_nop_battery_update,
};

+static struct healthd_mode_ops touchpoint_ops = {
+    .init = healthd_mode_android_init,
+    .preparetowait = healthd_mode_android_preparetowait,
+    .heartbeat = healthd_mode_nop_heartbeat,
+    .battery_update = healthd_mode_nop_battery_update,
+};
+
static void healthd_mode_nop_init(struct healthd_config* /*config*/) {
}

@@ -366,6 +373,7 @@ int main(int argc, char **argv) {
             }
         }
     }
+    healthd_mode_ops = &touchpoint_ops;

     ret = healthd_init();
     if (ret) {

I know for sure that an object exists in system/core/healthd/BatteryMonitor.cpp because I've logged the address, thus a BatteryProperties object must exist. However, AOSP complains that "batteryLevel" is called on a null object.

01-01 00:00:28.948   511   546 D VoldConnector: RCV <- {200 27 Command succeeded}
01-01 00:00:28.952   511   511 V UserManagerService: Found /data/user_de/0 with serial number 0
01-01 00:00:28.952   511   511 V UserManagerService: Found /data/user/0 with serial number 0
01-01 00:00:28.953   511   511 V UserManagerService: Found /data/system_de/0 with serial number 0
01-01 00:00:28.958   511   511 I ActivityManager: System now ready
01-01 00:00:28.970   511   511 I SystemServer: Making services ready
01-01 00:00:28.970   511   511 I SystemServiceManager: Starting phase 550
01-01 00:00:28.972   511   511 E System  : ******************************************
01-01 00:00:28.973   511   511 E System  : ************ Failure starting system services
01-01 00:00:28.973   511   511 E System  : java.lang.RuntimeException: Failed to boot service com.android.server.BatteryService: onBootPhase threw an exception during phase 550
01-01 00:00:28.973   511   511 E System  :      at com.android.server.SystemServiceManager.startBootPhase(SystemServiceManager.java:145)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.SystemServer$2.run(SystemServer.java:1327)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.am.ActivityManagerService.systemReady(ActivityManagerService.java:13392)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.SystemServer.startOtherServices(SystemServer.java:1323)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.SystemServer.run(SystemServer.java:340)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.SystemServer.main(SystemServer.java:222)
01-01 00:00:28.973   511   511 E System  :      at java.lang.reflect.Method.invoke(Native Method)
01-01 00:00:28.973   511   511 E System  :      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:890)
01-01 00:00:28.973   511   511 E System  :      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:780)
01-01 00:00:28.973   511   511 E System  : Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.os.BatteryProperties.batteryLevel' on a null object reference
01-01 00:00:28.973   511   511 E System  :      at com.android.server.BatteryService.processValuesLocked(BatteryService.java:331)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.BatteryService.updateBatteryWarningLevelLocked(BatteryService.java:237)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.BatteryService.onBootPhase(BatteryService.java:218)
01-01 00:00:28.973   511   511 E System  :      at com.android.server.SystemServiceManager.startBootPhase(SystemServiceManager.java:143)
01-01 00:00:28.973   511   511 E System  :      ... 8 more
01-01 00:00:28.974   511   511 D AndroidRuntime: Shutting down VM
--------- beginning of crash
01-01 00:00:28.974   511   511 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: main
01-01 00:00:28.974   511   511 E AndroidRuntime: java.lang.RuntimeException: Failed to boot service com.android.server.BatteryService: onBootPhase threw an exception during phase 550
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.SystemServiceManager.startBootPhase(SystemServiceManager.java:145)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.SystemServer$2.run(SystemServer.java:1327)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.am.ActivityManagerService.systemReady(ActivityManagerService.java:13392)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.SystemServer.startOtherServices(SystemServer.java:1323)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.SystemServer.run(SystemServer.java:340)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.SystemServer.main(SystemServer.java:222)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:890)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:780)
01-01 00:00:28.974   511   511 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.os.BatteryProperties.batteryLevel' on a null object reference
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.BatteryService.processValuesLocked(BatteryService.java:331)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.BatteryService.updateBatteryWarningLevelLocked(BatteryService.java:237)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.BatteryService.onBootPhase(BatteryService.java:218)
01-01 00:00:28.974   511   511 E AndroidRuntime:        at com.android.server.SystemServiceManager.startBootPhase(SystemServiceManager.java:143)
01-01 00:00:28.974   511   511 E AndroidRuntime:        ... 8 more
01-01 00:00:28.988   511   511 I Process : Sending signal. PID: 511 SIG: 9

 

I would love to know how to solve this. It already has taken me several days of debugging, and I don't know what to do next and I'm on the point of just removing code from the Android SDK in order to continue the boot.

Outcomes