@@ -26,6 +26,13 @@ static mon_cmd_t android_redir_cmds[] = {
};
static mon_cmd_t android_power_cmds[] = {
+ {
+ .name = "display",
+ .args_type = "",
+ .params = "",
+ .help = "display battery and charger state",
+ .mhandler.cmd = android_console_power_display,
+ },
{ NULL, NULL, },
};
@@ -21,6 +21,7 @@
#include "net/slirp.h"
#include "slirp/libslirp.h"
#include "qmp-commands.h"
+#include "hw/misc/goldfish_battery.h"
typedef struct {
int is_udp;
@@ -298,19 +299,38 @@ void android_console_redir(Monitor *mon, const QDict *qdict)
monitor_printf(mon, "%s\n", redir_help[cmd]);
}
+void android_console_power_display(Monitor *mon, const QDict *qdict)
+{
+ goldfish_battery_display(mon);
+
+ monitor_printf(mon, "OK\n");
+}
+
enum {
CMD_POWER,
+ CMD_POWER_DISPLAY,
};
static const char *power_help[] = {
/* CMD_POWER */
"allows to change battery and AC power status",
+ /* CMD_POWER_DISPLAY */
+ "display battery and charger state",
};
void android_console_power(Monitor *mon, const QDict *qdict)
{
+ /* This only gets called for bad subcommands and help requests */
+ const char *helptext = qdict_get_try_str(qdict, "helptext");
+
/* Default to the first entry which is the parent help message */
int cmd = CMD_POWER;
+ if (helptext) {
+ if (strstr(helptext, "display")) {
+ cmd = CMD_POWER_DISPLAY;
+ }
+ }
+
monitor_printf(mon, "%s\n", power_help[cmd]);
}
@@ -28,6 +28,7 @@ void android_console_redir_list(Monitor *mon, const QDict *qdict);
void android_console_redir_add(Monitor *mon, const QDict *qdict);
void android_console_redir_del(Monitor *mon, const QDict *qdict);
+void android_console_power_display(Monitor *mon, const QDict *qdict);
void android_console_power(Monitor *mon, const QDict *qdict);
void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
@@ -128,6 +128,48 @@ void goldfish_battery_display(Monitor *mon)
monitor_printf(mon, "capacity: %d\n", s->capacity);
}
+void goldfish_battery_set_prop(int ac, int property, int value)
+{
+ DeviceState *dev = qdev_find_recursive(sysbus_get_default(),
+ TYPE_GOLDFISH_BATTERY);
+ struct goldfish_battery_state *battery_state = GOLDFISH_BATTERY(dev);
+ int new_status = (ac ? AC_STATUS_CHANGED : BATTERY_STATUS_CHANGED);
+
+ if (!battery_state || !battery_state->hw_has_battery) {
+ return;
+ }
+
+ if (ac) {
+ switch (property) {
+ case POWER_SUPPLY_PROP_ONLINE:
+ battery_state->ac_online = value;
+ break;
+ }
+ } else {
+ switch (property) {
+ case POWER_SUPPLY_PROP_STATUS:
+ battery_state->status = value;
+ break;
+ case POWER_SUPPLY_PROP_HEALTH:
+ battery_state->health = value;
+ break;
+ case POWER_SUPPLY_PROP_PRESENT:
+ battery_state->present = value;
+ break;
+ case POWER_SUPPLY_PROP_CAPACITY:
+ battery_state->capacity = value;
+ break;
+ }
+ }
+
+ if (new_status != battery_state->int_status) {
+ battery_state->int_status |= new_status;
+ qemu_set_irq(battery_state->irq,
+ (battery_state->int_status &
+ battery_state->int_enable));
+ }
+}
+
static uint64_t goldfish_battery_read(void *opaque, hwaddr offset, unsigned size)
{
uint64_t ret;
@@ -69,5 +69,6 @@ enum power_supply_property {
};
extern void goldfish_battery_display(Monitor *mon);
+void goldfish_battery_set_prop(int ac, int property, int value);
#endif /* _HW_GOLDFISH_BATTERY_H */
Add a function for acquiring each of the goldfish battery properties. Signed-off-by: Greg Bellows <greg.bellows@linaro.org> --- android-commands.h | 7 +++++++ android-console.c | 20 ++++++++++++++++++ android-console.h | 1 + hw/misc/goldfish_battery.c | 42 ++++++++++++++++++++++++++++++++++++++ include/hw/misc/goldfish_battery.h | 1 + 5 files changed, 71 insertions(+)