Add the Android emulator console "power health" command and associated help messages. The "health" command allows the battery health of the device to be manipulated.
Signed-off-by: Greg Bellows <greg.bell...@linaro.org> --- android-commands.h | 7 +++++++ android-console.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ android-console.h | 1 + 3 files changed, 55 insertions(+) diff --git a/android-commands.h b/android-commands.h index 3adef55..bb3f783 100644 --- a/android-commands.h +++ b/android-commands.h @@ -54,6 +54,13 @@ static mon_cmd_t android_power_cmds[] = { .help = "set battery present state", .mhandler.cmd = android_console_power_present, }, + { + .name = "health", + .args_type = "arg:s?", + .params = "", + .help = "set battery health state", + .mhandler.cmd = android_console_power_health, + }, { NULL, NULL, }, }; diff --git a/android-console.c b/android-console.c index b08519d..0a4fc1d 100644 --- a/android-console.c +++ b/android-console.c @@ -374,12 +374,54 @@ void android_console_power_present(Monitor *mon, const QDict *qdict) monitor_printf(mon, "KO: Usage: \"present true\" or \"present false\"\n"); } +void android_console_power_health(Monitor *mon, const QDict *qdict) +{ + const char *arg = qdict_get_try_str(qdict, "arg"); + + if (arg) { + if (strcasecmp(arg, "unknown") == 0) { + goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_HEALTH_UNKNOWN); + return; + } + if (strcasecmp(arg, "good") == 0) { + goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_HEALTH_GOOD); + return; + } + if (strcasecmp(arg, "overheat") == 0) { + goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_HEALTH_OVERHEAT); + return; + } + if (strcasecmp(arg, "dead") == 0) { + goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_HEALTH_DEAD); + return; + } + if (strcasecmp(arg, "overvoltage") == 0) { + goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_HEALTH_OVERVOLTAGE); + return; + } + if (strcasecmp(arg, "failure") == 0) { + goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_HEALTH_UNSPEC_FAILURE); + return; + } + } + + monitor_printf(mon, "KO: Usage: \"health unknown|good|overheat|" + "dead|overvoltage|failure\"\n"); +} + enum { CMD_POWER, CMD_POWER_DISPLAY, CMD_POWER_AC, CMD_POWER_STATUS, CMD_POWER_PRESENT, + CMD_POWER_HEALTH, }; static const char *power_help[] = { @@ -395,6 +437,9 @@ static const char *power_help[] = { /* CMD_POWER_PRESENT */ "'present true|false' allows you to set battery present state to true " "or false", + /* CMD_POWER_HEALTH */ + "'health unknown|good|overheat|dead|overvoltage|failure' allows you " + "to set battery health state", }; void android_console_power(Monitor *mon, const QDict *qdict) @@ -414,6 +459,8 @@ void android_console_power(Monitor *mon, const QDict *qdict) cmd = CMD_POWER_STATUS; } else if (strstr(helptext, "present")) { cmd = CMD_POWER_PRESENT; + } else if (strstr(helptext, "health")) { + cmd = CMD_POWER_HEALTH; } } diff --git a/android-console.h b/android-console.h index c7c7c86..aea671f 100644 --- a/android-console.h +++ b/android-console.h @@ -32,6 +32,7 @@ void android_console_power_display(Monitor *mon, const QDict *qdict); void android_console_power_ac(Monitor *mon, const QDict *qdict); void android_console_power_status(Monitor *mon, const QDict *qdict); void android_console_power_present(Monitor *mon, const QDict *qdict); +void android_console_power_health(Monitor *mon, const QDict *qdict); void android_console_power(Monitor *mon, const QDict *qdict); void android_monitor_print_error(Monitor *mon, const char *fmt, ...); -- 1.8.3.2