Skip to contentSkip to conversation

android-console: Add console power command

PATCH In review Greg Bellows 2 participants 21 messages Nov 12, 2014 – Nov 13, 2014

lore
Share & tools
lore
#0 lore raw

cover android-console: Add console power command

This patchset includes 3 changes:
- Fixes to the existing Android emulator console.
- Restructure the emulator console redir help output
- Add support for the emulator console power command

Greg Bellows (15):
android-console: Fix goldfish audio misnaming
android-console: Unify available commands output
android-console: Remove extra redir help message
android-console: Consolidate redir help text
android-console: Add console base power command
android-console: Add missing hw_has_battery prop
android-console: Init the battery ID state field
android-console: Add header for battery externs
android-console: Add GF battery prop print func
android-console: Add GF battery property getter
android-console: Add power ac command
android-console: Add power status command
android-console: Add power present command
android-console: Add power health command
android-console: Add power capacity command

 android-commands.h                 |  53 ++++++++
 android-console.c                  | 254 ++++++++++++++++++++++++++++++++-----
 android-console.h                  |   8 ++
 hw/misc/goldfish_battery.c         | 122 ++++++++++++++++--
 include/hw/misc/goldfish_battery.h |  74 +++++++++++
 monitor.c                          |  16 ++-
 6 files changed, 484 insertions(+), 43 deletions(-)
 create mode 100644 include/hw/misc/goldfish_battery.h

--
1.8.3.2

#1 lore raw

PATCH 1/15 android-console: Fix goldfish audio misnaming

Replaced goldfish_audio misnaming to goldfish_battery where appropriate in goldfish_battery.c

---
 hw/misc/goldfish_battery.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/misc/goldfish_battery.c +5 -5
index 03847d6..89fd05d 100644
@@ -121,7 +121,7 @@ static void goldfish_battery_write(void *opaque, hwaddr offset, uint64_t val,
             break;
 
         default:
-            error_report ("goldfish_audio_write: Bad offset " TARGET_FMT_plx,
+            error_report("goldfish_battery_write: Bad offset " TARGET_FMT_plx,
                     offset);
     }
 }
@@ -161,16 +161,16 @@ static void goldfish_battery_class_init(ObjectClass *klass, void *data)
     dc->desc = "goldfish battery";
 }
 
-static const TypeInfo goldfish_audio_info = {
+static const TypeInfo goldfish_battery_info = {
     .name          = TYPE_GOLDFISH_BATTERY,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(struct goldfish_battery_state),
     .class_init    = goldfish_battery_class_init,
 };
 
-static void goldfish_audio_register(void)
+static void goldfish_battery_register(void)
 {
-    type_register_static(&goldfish_audio_info);
+    type_register_static(&goldfish_battery_info);
 }
 
-type_init(goldfish_audio_register);
+type_init(goldfish_battery_register);
Signature · 1 line
1.8.3.2
#2 lore raw

Re: [Qemu-devel] [PATCH v1 01/15] android-console: Fix goldfish audio misnaming

Quoted 2 lines · Greg Bellows

Replaced goldfish_audio misnaming to goldfish_battery where appropriate in goldfish_battery.c

Ahh good 'ole copy pasta bugs ;-)

This will probably be worth squash merging when we clean-up the tree.

Quoted 40 lines
---
 hw/misc/goldfish_battery.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/misc/goldfish_battery.c +5 -5
index 03847d6..89fd05d 100644
@@ -121,7 +121,7 @@ static void goldfish_battery_write(void *opaque, hwaddr offset, uint64_t val,
             break;
 
         default:
-            error_report ("goldfish_audio_write: Bad offset " TARGET_FMT_plx,
+            error_report("goldfish_battery_write: Bad offset " TARGET_FMT_plx,
                     offset);
     }
 }
@@ -161,16 +161,16 @@ static void goldfish_battery_class_init(ObjectClass *klass, void *data)
     dc->desc = "goldfish battery";
 }
 
-static const TypeInfo goldfish_audio_info = {
+static const TypeInfo goldfish_battery_info = {
     .name          = TYPE_GOLDFISH_BATTERY,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(struct goldfish_battery_state),
     .class_init    = goldfish_battery_class_init,
 };
 
-static void goldfish_audio_register(void)
+static void goldfish_battery_register(void)
 {
-    type_register_static(&goldfish_audio_info);
+    type_register_static(&goldfish_battery_info);
 }
 
-type_init(goldfish_audio_register);
+type_init(goldfish_battery_register);
Signature · 1 line
Alex Bennée
#3 lore raw

PATCH 2/15 android-console: Unify available commands output

In reply to Greg Bellows

Moved the "available commands" print output to the top level help command handler to avoid repitition across all commands with sub-commands. Adjusted the redir command handler to no longer print out available commands. Adjusted "OK" message to be shared by all cases to avoid duplicates.

---
 android-console.c | 20 +++++---------------
 monitor.c         | 16 ++++++++++++----
 2 files changed, 17 insertions(+), 19 deletions(-)
android-console.c +5 -15
index c2e41da..be573b5 100644
@@ -242,8 +242,7 @@ void android_console_redir_remove(Monitor *mon, const QDict *qdict)
 
 static const char *redir_list_help =
     "list current port redirections. "
-    "use 'redir add' and 'redir del' to add and remove them\n"
-    "OK\n";
+    "use 'redir add' and 'redir del' to add and remove them\n";
 
 static const char *redir_add_help =
     "add a new port redirection, arguments must be:\n"
@@ -258,15 +257,13 @@ static const char *redir_add_help =
     "\n"
     "as an example, 'redir  tcp:5000:6000' will allow any packets sent to\n"
     "the host's TCP port 5000 to be routed to TCP port 6000 of the "
-    "emulated device\n"
-    "OK\n";
+    "emulated device\n";
 
 static const char *redir_del_help =
     "remove a port redirecion that was created with 'redir add', "
-    "arguments must be:\n\n"
+    "arguments must be:\n"
     "  redir  del <protocol>:<host-port>\n\n"
-    "see the 'help redir add' for the meaning of <protocol> and <host-port>\n"
-    "OK\n";
+    "see the 'help redir add' for the meaning of <protocol> and <host-port>\n";
 
 void android_console_redir(Monitor *mon, const QDict *qdict)
 {
@@ -291,12 +288,5 @@ void android_console_redir(Monitor *mon, const QDict *qdict)
                    "PORT redirection from the host to the device\n"
                    "as an example, 'redir  tcp:5000:6000' will route "
                    "any packet sent to the host's TCP port 5000\n"
-                   "to TCP port 6000 of the emulated device\n"
-                   "\n"
-                   "available sub-commands:\n"
-                   "    list             list current redirections\n"
-                   "    add              add new redirection\n"
-                   "    del              remove existing redirection\n"
-                   "\n%s\n",
-                   helptext ? "OK" : "KO: missing sub-command");
+                   "to TCP port 6000 of the emulated device\n");
 }
monitor.c +12 -4
index f071878..4222b7a 100644
@@ -943,7 +943,7 @@ static void do_help_cmd(Monitor *mon, const QDict *qdict)
 static void android_console_help(Monitor *mon, const QDict *qdict)
 {
     const char *name = qdict_get_try_str(qdict, "helptext");
-    const mon_cmd_t *cmd;
+    const mon_cmd_t *cmd, *subcmd;
     const mon_cmd_t *cmds = mon->cmd_table;
     char *args[MAX_ARGS];
     int nb_args = 0;
@@ -957,7 +957,7 @@ static void android_console_help(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "    %-15s  %s\n", cmd->name, cmd->help);
         }
         monitor_printf(mon,
-                       "\ntry 'help <command>' for command-specific help\n");
+                       "\ntry 'help <command>' for command-specific help\nOK\n");
         return;
     }
 
@@ -1000,15 +1000,23 @@ static void android_console_help(Monitor *mon, const QDict *qdict)
                 parent_cmd->mhandler.cmd(mon, qdict);
             } else if (cmd->sub_table) {
                 cmd->mhandler.cmd(mon, qdict);
+                monitor_printf(mon, "\navailable sub-commands:\n");
+                for (subcmd = cmd->sub_table; subcmd->name; subcmd++) {
+                    monitor_printf(mon, "    %-15s  %s\n",
+                                    subcmd->name, subcmd->help);
+                }
+                monitor_printf(mon, "\n");
             } else {
-                monitor_printf(mon, "%s\nOK\n", cmd->help);
+                monitor_printf(mon, "%s\n", cmd->help);
             }
-            return;
+            break;
         }
 
         parent_cmd = cmd;
         cmds = cmd->sub_table;
     }
+
+    monitor_printf(mon, "OK\n");
 }
 
 static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH 3/15 android-console: Remove extra redir help message

In reply to Greg Bellows

Removed an extraneous message in the redir command help. The message is not part of the standard Android emulator output.

---
 android-console.c | 2 --
 1 file changed, 2 deletions(-)
android-console.c +0 -2
index be573b5..2de4a0c 100644
@@ -270,8 +270,6 @@ void android_console_redir(Monitor *mon, const QDict *qdict)
     /* This only gets called for bad subcommands and help requests */
     const char *helptext = qdict_get_try_str(qdict, "helptext");
 
-    monitor_printf(mon, "help text %s\n", helptext ? helptext : "(null)");
-
     if (helptext) {
         if (strstr(helptext, "add")) {
             monitor_printf(mon, "%s", redir_add_help);
Signature · 1 line
1.8.3.2
#5 lore raw

PATCH 4/15 android-console: Consolidate redir help text

In reply to Greg Bellows

Consolidated the Android emulator console help text for the redir command to make the hndler functions more readable. This establishes the pattern to be used for each command added in the future.

---
 android-console.c | 50 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 20 deletions(-)
android-console.c +30 -20
index 2de4a0c..0be5949 100644
@@ -240,11 +240,24 @@ void android_console_redir_remove(Monitor *mon, const QDict *qdict)
 }
 #endif
 
-static const char *redir_list_help =
-    "list current port redirections. "
-    "use 'redir add' and 'redir del' to add and remove them\n";
-
-static const char *redir_add_help =
+enum {
+    CMD_REDIR,
+    CMD_REDIR_LIST,
+    CMD_REDIR_ADD,
+    CMD_REDIR_DEL,
+};
+
+static const char *redir_help[] = {
+    /* CMD_REDIR */
+    "allows you to add, list and remove UDP and/or PORT redirection "
+    "from the host to the device\n"
+    "as an example, 'redir  tcp:5000:6000' will route any packet sent "
+    "to the host's TCP port 5000\n"
+    "to TCP port 6000 of the emulated device",
+    /* CMD_REDIR_LIST */
+    "list current port redirections. use 'redir add' and 'redir del' to add "
+    "and remove them",
+    /* CMD_REDIR_ADD */
     "add a new port redirection, arguments must be:\n"
     "\n"
     "  redir add <protocol>:<host-port>:<guest-port>\n"
@@ -257,34 +270,31 @@ static const char *redir_add_help =
     "\n"
     "as an example, 'redir  tcp:5000:6000' will allow any packets sent to\n"
     "the host's TCP port 5000 to be routed to TCP port 6000 of the "
-    "emulated device\n";
-
-static const char *redir_del_help =
+    "emulated device",
+    /* CMD_REDIR_DEL */
     "remove a port redirecion that was created with 'redir add', "
     "arguments must be:\n"
     "  redir  del <protocol>:<host-port>\n\n"
-    "see the 'help redir add' for the meaning of <protocol> and <host-port>\n";
+    "see the 'help redir add' for the meaning of <protocol> and <host-port>",
+};
 
 void android_console_redir(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_REDIR;
+
     if (helptext) {
         if (strstr(helptext, "add")) {
-            monitor_printf(mon, "%s", redir_add_help);
-            return;
+            cmd = CMD_REDIR_ADD;
         } else if (strstr(helptext, "del")) {
-            monitor_printf(mon, "%s", redir_del_help);
-            return;
+            cmd = CMD_REDIR_DEL;
         } else if (strstr(helptext, "list")) {
-            monitor_printf(mon, "%s", redir_list_help);
-            return;
+            cmd = CMD_REDIR_LIST;
         }
     }
-    monitor_printf(mon, "allows you to add, list and remove and/or "
-                   "PORT redirection from the host to the device\n"
-                   "as an example, 'redir  tcp:5000:6000' will route "
-                   "any packet sent to the host's TCP port 5000\n"
-                   "to TCP port 6000 of the emulated device\n");
+    monitor_printf(mon, "%s\n", redir_help[cmd]);
 }
+
Signature · 1 line
1.8.3.2
#6 lore raw

PATCH 5/15 android-console: Add console base power command

In reply to Greg Bellows

Added the base Android emulator console power command and infrastructure for adding sub-commands.

---
 android-commands.h | 11 +++++++++++
 android-console.c  | 16 ++++++++++++++++
 android-console.h  |  2 ++
 3 files changed, 29 insertions(+)
android-commands.h +11 -0
index 1bfd15d..29c8769 100644
@@ -25,6 +25,10 @@ static mon_cmd_t android_redir_cmds[] = {
     { NULL, NULL, },
 };
 
+static mon_cmd_t android_power_cmds[] = {
+    { NULL, NULL, },
+};
+
 static mon_cmd_t android_cmds[] = {
     {
         .name = "help|h|?",
@@ -55,5 +59,12 @@ static mon_cmd_t android_cmds[] = {
         .mhandler.cmd = android_console_redir,
         .sub_table = android_redir_cmds,
     },
+    {   .name = "power",
+        .args_type = "item:s?",
+        .params = "",
+        .help = "power related commands",
+        .mhandler.cmd = android_console_power,
+        .sub_table = android_power_cmds,
+    },
     { NULL, NULL, },
 };
android-console.c +16 -0
index 0be5949..c08c607 100644
@@ -298,3 +298,19 @@ void android_console_redir(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "%s\n", redir_help[cmd]);
 }
 
+enum {
+    CMD_POWER,
+};
+
+static const char *power_help[] = {
+        /* CMD_POWER */
+        "allows to change battery and AC power status",
+};
+
+void android_console_power(Monitor *mon, const QDict *qdict)
+{
+    /* Default to the first entry which is the parent help message */
+    int cmd = CMD_POWER;
+
+    monitor_printf(mon, "%s\n", power_help[cmd]);
+}
android-console.h +2 -0
index 2786b64..ba936be 100644
@@ -28,6 +28,8 @@ 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(Monitor *mon, const QDict *qdict);
+
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
 
 #endif
Signature · 1 line
1.8.3.2
#7 lore raw

PATCH 6/15 android-console: Add missing hw_has_battery prop

In reply to Greg Bellows

Added the missing hw_has_battery property to the Goldfish batter state. This property indicates whether the device has a battery and controls whether some power commands are available.

In the Android emulator this property is acquired from the AVD for the device. For now, this is wired as always enabled.

---
 hw/misc/goldfish_battery.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/misc/goldfish_battery.c +7 -0
index 89fd05d..a0bc379 100644
@@ -52,6 +52,7 @@ struct goldfish_battery_state {
     uint32_t health;
     uint32_t present;
     uint32_t capacity;
+    uint32_t hw_has_battery;;
 };
 
 /* update this each time you update the battery_state struct */
@@ -70,6 +71,7 @@ static const VMStateDescription goldfish_battery_vmsd = {
         VMSTATE_UINT32(health, struct goldfish_battery_state),
         VMSTATE_UINT32(present, struct goldfish_battery_state),
         VMSTATE_UINT32(capacity, struct goldfish_battery_state),
+        VMSTATE_UINT32(hw_has_battery, struct goldfish_battery_state),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -146,6 +148,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
 
     // default values for the battery
     s->ac_online = 1;
+    /* TODO: The Android Emulator gets this attribute from the AVD
+     *       hw-config-defs.h.  For now we hard-code the value to match the
+     *       other values.
+     */
+    s->hw_has_battery = 1;
     s->status = POWER_SUPPLY_STATUS_CHARGING;
     s->health = POWER_SUPPLY_HEALTH_GOOD;
     s->present = 1;     // battery is present
Signature · 1 line
1.8.3.2
#8 lore raw

Re: [Qemu-devel] [PATCH v1 06/15] android-console: Add missing hw_has_battery prop

Quoted 17 lines · Greg Bellows

Added the missing hw_has_battery property to the Goldfish batter state. This property indicates whether the device has a battery and controls whether some power commands are available.

In the Android emulator this property is acquired from the AVD for the device. For now, this is wired as always enabled.

---
 hw/misc/goldfish_battery.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/misc/goldfish_battery.c +0 -0
index 89fd05d..a0bc379 100644

hw/misc/goldfish_battery.c struct goldfish_battery_state { · line 55

Quoted 4 lines
hw/misc/goldfish_battery.c +1 -0
@@ -52,6 +52,7 @@ struct goldfish_battery_state {
     uint32_t health;
     uint32_t present;
     uint32_t capacity;
+    uint32_t hw_has_battery;;

Double semi-colon

Quoted 23 lines
hw/misc/goldfish_battery.c +6 -0
 };
 
 /* update this each time you update the battery_state struct */
@@ -70,6 +71,7 @@ static const VMStateDescription goldfish_battery_vmsd = {
         VMSTATE_UINT32(health, struct goldfish_battery_state),
         VMSTATE_UINT32(present, struct goldfish_battery_state),
         VMSTATE_UINT32(capacity, struct goldfish_battery_state),
+        VMSTATE_UINT32(hw_has_battery, struct goldfish_battery_state),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -146,6 +148,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
 
     // default values for the battery
     s->ac_online = 1;
+    /* TODO: The Android Emulator gets this attribute from the AVD
+     *       hw-config-defs.h.  For now we hard-code the value to match the
+     *       other values.
+     */
+    s->hw_has_battery = 1;
     s->status = POWER_SUPPLY_STATUS_CHARGING;
     s->health = POWER_SUPPLY_HEALTH_GOOD;
     s->present = 1;     // battery is present
Signature · 1 line
Alex Bennée
#9 lore raw

PATCH 7/15 android-console: Init the battery ID state field

In reply to Greg Bellows

Adds initialization of the battery ID field so that it is discoverable by name (ID) when needed by power commands.

---
 hw/misc/goldfish_battery.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/misc/goldfish_battery.c +5 -0
index a0bc379..11a2561 100644
@@ -141,6 +141,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
     SysBusDevice *sbdev = SYS_BUS_DEVICE(dev);
     struct goldfish_battery_state *s = GOLDFISH_BATTERY(dev);
 
+    /* Initialize the device ID so the battery can be looked up during monitor
+     * commands.
+     */
+    dev->id = strdup("goldfish_battery");
+
     memory_region_init_io(&s->iomem, OBJECT(s), &goldfish_battery_iomem_ops, s,
             "goldfish_battery", 0x1000);
     sysbus_init_mmio(sbdev, &s->iomem);
Signature · 1 line
1.8.3.2
#10 lore raw

Re: [Qemu-devel] [PATCH v1 07/15] android-console: Init the battery ID state field

Quoted 13 lines · Greg Bellows

Adds initialization of the battery ID field so that it is discoverable by name (ID) when needed by power commands.

---
 hw/misc/goldfish_battery.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/misc/goldfish_battery.c +0 -0
index a0bc379..11a2561 100644

hw/misc/goldfish_battery.c static void goldfish_battery_realize(DeviceState *dev, Error **errp) · line 148

Quoted 8 lines
hw/misc/goldfish_battery.c +5 -0
@@ -141,6 +141,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
     SysBusDevice *sbdev = SYS_BUS_DEVICE(dev);
     struct goldfish_battery_state *s = GOLDFISH_BATTERY(dev);
 
+    /* Initialize the device ID so the battery can be looked up during monitor
+     * commands.
+     */
+    dev->id = strdup("goldfish_battery");
+

We should probably use g_strdup() here.

Quoted 3 lines
hw/misc/goldfish_battery.c +0 -0
     memory_region_init_io(&s->iomem, OBJECT(s), &goldfish_battery_iomem_ops, s,
             "goldfish_battery", 0x1000);
     sysbus_init_mmio(sbdev, &s->iomem);
Signature · 1 line
Alex Bennée
#11 lore raw

PATCH 8/15 android-console: Add header for battery externs

In reply to Greg Bellows

Added goldfish_battery.h to share power and battery constants and externs between the Goldfish battery code and the Android console code.

---
 hw/misc/goldfish_battery.c         |  4 +--
 include/hw/misc/goldfish_battery.h | 71 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 include/hw/misc/goldfish_battery.h
hw/misc/goldfish_battery.c +1 -3
index 11a2561..c956eb2 100644
@@ -12,6 +12,7 @@
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "qemu/error-report.h"
+#include "hw/misc/goldfish_battery.h"
 
 enum {
 	/* status register */
@@ -30,9 +31,6 @@ enum {
 	BATTERY_INT_MASK        = BATTERY_STATUS_CHANGED | AC_STATUS_CHANGED,
 };
 
-const uint32_t POWER_SUPPLY_STATUS_CHARGING = 1;
-const uint32_t POWER_SUPPLY_HEALTH_GOOD = 1;
-
 #define TYPE_GOLDFISH_BATTERY "goldfish_battery"
 #define GOLDFISH_BATTERY(obj) OBJECT_CHECK(struct goldfish_battery_state, (obj), TYPE_GOLDFISH_BATTERY)
 
include/hw/misc/goldfish_battery.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#12 lore raw

PATCH 9/15 android-console: Add GF battery prop print func

In reply to Greg Bellows

Add a function for printing out the Goldfish battery properties to the android console.

---
 hw/misc/goldfish_battery.c         | 54 ++++++++++++++++++++++++++++++++++++++
 include/hw/misc/goldfish_battery.h |  2 ++
 2 files changed, 56 insertions(+)
hw/misc/goldfish_battery.c +54 -0
index c956eb2..c7c9d98 100644
@@ -12,6 +12,7 @@
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "qemu/error-report.h"
+#include "monitor/monitor.h"
 #include "hw/misc/goldfish_battery.h"
 
 enum {
@@ -74,6 +75,59 @@ static const VMStateDescription goldfish_battery_vmsd = {
     }
 };
 
+void goldfish_battery_display(Monitor *mon)
+{
+    DeviceState *dev = qdev_find_recursive(sysbus_get_default(),
+                                           TYPE_GOLDFISH_BATTERY);
+    struct goldfish_battery_state *s = GOLDFISH_BATTERY(dev);
+    const char *value;
+
+    monitor_printf(mon, "AC: %s\n", (s->ac_online) ? "online" : "offline");
+
+    switch (s->status) {
+    case POWER_SUPPLY_STATUS_CHARGING:
+        value = "Charging";
+        break;
+    case POWER_SUPPLY_STATUS_DISCHARGING:
+        value = "Discharging";
+        break;
+    case POWER_SUPPLY_STATUS_NOT_CHARGING:
+        value = "Not charging";
+        break;
+    case POWER_SUPPLY_STATUS_FULL:
+        value = "Full";
+        break;
+    default:
+        value = "Unknown";
+    }
+    monitor_printf(mon, "status: %s\n", value);
+
+    switch (s->health) {
+    case POWER_SUPPLY_HEALTH_GOOD:
+        value = "Good";
+        break;
+    case POWER_SUPPLY_HEALTH_OVERHEAT:
+        value = "Overhead";
+        break;
+    case POWER_SUPPLY_HEALTH_DEAD:
+        value = "Dead";
+        break;
+    case POWER_SUPPLY_HEALTH_OVERVOLTAGE:
+        value = "Overvoltage";
+        break;
+    case POWER_SUPPLY_HEALTH_UNSPEC_FAILURE:
+        value = "Unspecified failure";
+        break;
+    default:
+        value = "Unknown";
+    }
+    monitor_printf(mon, "health: %s\n", value);
+
+    monitor_printf(mon, "present: %s\n", (s->present) ? "true" : "false");
+
+    monitor_printf(mon, "capacity: %d\n", s->capacity);
+}
+
 static uint64_t goldfish_battery_read(void *opaque, hwaddr offset, unsigned size)
 {
     uint64_t ret;
include/hw/misc/goldfish_battery.h +2 -0
index 85a9f2f..f497538 100644
@@ -68,4 +68,6 @@ enum power_supply_property {
     POWER_SUPPLY_PROP_MANUFACTURER,
 };
 
+extern void goldfish_battery_display(Monitor *mon);
+
 #endif /* _HW_GOLDFISH_BATTERY_H */

--
1.8.3.2

#13 lore raw

PATCH 10/15 android-console: Add GF battery property getter

In reply to Greg Bellows

Add a function for acquiring each of the goldfish battery properties.

---
 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(+)
android-commands.h +7 -0
index 29c8769..8bf856d 100644
@@ -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, },
 };
 
android-console.c +20 -0
index c08c607..faaeeaf 100644
@@ -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]);
 }
android-console.h +1 -0
index ba936be..44ff11b 100644
@@ -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, ...);
hw/misc/goldfish_battery.c +42 -0

48 lines not on this page · raw message

include/hw/misc/goldfish_battery.h +1 -0
index f497538..2d02a38 100644
@@ -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 */
Signature · 1 line
1.8.3.2
#14 lore raw

PATCH 11/15 android-console: Add power ac command

In reply to Greg Bellows

Add the Android emulator console "power ac" along with the associated help messages. The "ac" command allows the power supply state of the device to be manipulated.

---
 android-commands.h |  7 +++++++
 android-console.c  | 23 +++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 31 insertions(+)
android-commands.h +7 -0
index 8bf856d..674e259 100644
@@ -33,6 +33,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "display battery and charger state",
         .mhandler.cmd = android_console_power_display,
     },
+    {
+        .name = "ac",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set AC charging state",
+        .mhandler.cmd = android_console_power_ac,
+    },
     { NULL, NULL, },
 };
 
android-console.c +23 -0
index faaeeaf..dbcc993 100644
@@ -306,9 +306,28 @@ void android_console_power_display(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "OK\n");
 }
 
+void android_console_power_ac(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+    if (arg) {
+        if (strcasecmp(arg, "on") == 0) {
+            goldfish_battery_set_prop(1, POWER_SUPPLY_PROP_ONLINE, 1);
+            return;
+        }
+        if (strcasecmp(arg, "off") == 0) {
+            goldfish_battery_set_prop(1, POWER_SUPPLY_PROP_ONLINE, 0);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"ac on\" or \"ac off\"\n");
+}
+
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
+    CMD_POWER_AC,
 };
 
 static const char *power_help[] = {
@@ -316,6 +335,8 @@ static const char *power_help[] = {
         "allows to change battery and AC power status",
         /* CMD_POWER_DISPLAY */
         "display battery and charger state",
+        /* CMD_POWER_AC */
+        "'ac on|off' allows you to set the AC charging state to on or off",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -329,6 +350,8 @@ void android_console_power(Monitor *mon, const QDict *qdict)
     if (helptext) {
         if (strstr(helptext, "display")) {
             cmd = CMD_POWER_DISPLAY;
+        } else if (strstr(helptext, "ac")) {
+            cmd = CMD_POWER_AC;
         }
     }
 
android-console.h +1 -0
index 44ff11b..458f44c 100644
@@ -29,6 +29,7 @@ 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_ac(Monitor *mon, const QDict *qdict);
 void android_console_power(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
Signature · 1 line
1.8.3.2
#15 lore raw

PATCH 12/15 android-console: Add power status command

In reply to Greg Bellows

Add the Android emulator console "power status" command and associated help messages. The "status" command allows the battery status of the device to be manipulated.

---
 android-commands.h |  7 +++++++
 android-console.c  | 39 +++++++++++++++++++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 47 insertions(+)
android-commands.h +7 -0
index 674e259..53f89b1 100644
@@ -40,6 +40,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "set AC charging state",
         .mhandler.cmd = android_console_power_ac,
     },
+    {
+        .name = "status",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set battery status",
+        .mhandler.cmd = android_console_power_status,
+    },
     { NULL, NULL, },
 };
 
android-console.c +39 -0
index dbcc993..04a1971 100644
@@ -324,10 +324,44 @@ void android_console_power_ac(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "KO: Usage: \"ac on\" or \"ac off\"\n");
 }
 
+void android_console_power_status(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_STATUS,
+                                      POWER_SUPPLY_STATUS_UNKNOWN);
+            return;
+        } else if (strcasecmp(arg, "charging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_CHARGING);
+            return;
+        } else if (strcasecmp(arg, "discharging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_DISCHARGING);
+            return;
+        } else if (strcasecmp(arg, "not-charging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_NOT_CHARGING);
+            return;
+        } else if (strcasecmp(arg, "full") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_FULL);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"status unknown|charging|"
+                   "discharging|not-charging|full\"\n");
+}
+
+
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
     CMD_POWER_AC,
+    CMD_POWER_STATUS,
 };
 
 static const char *power_help[] = {
@@ -337,6 +371,9 @@ static const char *power_help[] = {
         "display battery and charger state",
         /* CMD_POWER_AC */
         "'ac on|off' allows you to set the AC charging state to on or off",
+        /* CMD_POWER_STATUS */
+        "'status unknown|charging|discharging|not-charging|full' allows you "
+        "to set battery status",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -352,6 +389,8 @@ void android_console_power(Monitor *mon, const QDict *qdict)
             cmd = CMD_POWER_DISPLAY;
         } else if (strstr(helptext, "ac")) {
             cmd = CMD_POWER_AC;
+        } else if (strstr(helptext, "status")) {
+            cmd = CMD_POWER_STATUS;
         }
     }
 
android-console.h +1 -0
index 458f44c..184ae69 100644
@@ -30,6 +30,7 @@ void android_console_redir_del(Monitor *mon, const QDict *qdict);
 
 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(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
Signature · 1 line
1.8.3.2
#16 lore raw

PATCH 13/15 android-console: Add power present command

In reply to Greg Bellows

Add the Android emulator console "power present" command and associated help messages. The "present" command allows the battery presence in the device to be manipulated.

---
 android-commands.h |  7 +++++++
 android-console.c  | 23 +++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 31 insertions(+)
android-commands.h +7 -0
index 53f89b1..3adef55 100644
@@ -47,6 +47,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "set battery status",
         .mhandler.cmd = android_console_power_status,
     },
+    {
+        .name = "present",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set battery present state",
+        .mhandler.cmd = android_console_power_present,
+    },
     { NULL, NULL, },
 };
 
android-console.c +23 -0
index 04a1971..b08519d 100644
@@ -356,12 +356,30 @@ void android_console_power_status(Monitor *mon, const QDict *qdict)
                    "discharging|not-charging|full\"\n");
 }
 
+void android_console_power_present(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+    if (arg) {
+        if (strcasecmp(arg, "true") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_PRESENT, 1);
+            return;
+        }
+        if (strcasecmp(arg, "false") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_PRESENT, 0);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"present true\" or \"present false\"\n");
+}
 
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
     CMD_POWER_AC,
     CMD_POWER_STATUS,
+    CMD_POWER_PRESENT,
 };
 
 static const char *power_help[] = {
@@ -374,6 +392,9 @@ static const char *power_help[] = {
         /* CMD_POWER_STATUS */
         "'status unknown|charging|discharging|not-charging|full' allows you "
         "to set battery status",
+        /* CMD_POWER_PRESENT */
+        "'present true|false' allows you to set battery present state to true "
+        "or false",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -391,6 +412,8 @@ void android_console_power(Monitor *mon, const QDict *qdict)
             cmd = CMD_POWER_AC;
         } else if (strstr(helptext, "status")) {
             cmd = CMD_POWER_STATUS;
+        } else if (strstr(helptext, "present")) {
+            cmd = CMD_POWER_PRESENT;
         }
     }
 
android-console.h +1 -0
index 184ae69..c7c7c86 100644
@@ -31,6 +31,7 @@ void android_console_redir_del(Monitor *mon, const QDict *qdict);
 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(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
Signature · 1 line
1.8.3.2
#17 lore raw

PATCH 14/15 android-console: Add power health command

In reply to Greg Bellows

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.

---
 android-commands.h |  7 +++++++
 android-console.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 55 insertions(+)
android-commands.h +7 -0
index 3adef55..bb3f783 100644
@@ -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, },
 };
 
android-console.c +47 -0

71 lines not on this page · raw message

android-console.h +1 -0
index c7c7c86..aea671f 100644
@@ -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, ...);
Signature · 1 line
1.8.3.2
#18 lore raw

PATCH 15/15 android-console: Add power capacity command

In reply to Greg Bellows

Add the Android emulator console "power capacity" command along associated help messages. The "capacity" command allows the battery capacity of the device to be manipulated.

---
 android-commands.h |  7 +++++++
 android-console.c  | 26 ++++++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 34 insertions(+)
android-commands.h +7 -0
index bb3f783..62b181b 100644
@@ -61,6 +61,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "set battery health state",
         .mhandler.cmd = android_console_power_health,
     },
+    {
+        .name = "capacity",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set battery capacity state",
+        .mhandler.cmd = android_console_power_capacity,
+    },
     { NULL, NULL, },
 };
 
android-console.c +26 -0
index 0a4fc1d..e24a87c 100644
@@ -415,6 +415,23 @@ void android_console_power_health(Monitor *mon, const QDict *qdict)
                    "dead|overvoltage|failure\"\n");
 }
 
+void android_console_power_capacity(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+   if (arg) {
+        int capacity;
+
+        if (sscanf(arg, "%d", &capacity) == 1 &&
+            capacity >= 0 && capacity <= 100) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_CAPACITY, capacity);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"capacity <percentage>\"\n");
+ }
+
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
@@ -422,6 +439,7 @@ enum {
     CMD_POWER_STATUS,
     CMD_POWER_PRESENT,
     CMD_POWER_HEALTH,
+    CMD_POWER_CAPACITY,
 };
 
 static const char *power_help[] = {
@@ -440,6 +458,9 @@ static const char *power_help[] = {
         /* CMD_POWER_HEALTH */
         "'health unknown|good|overheat|dead|overvoltage|failure' allows you "
         "to set battery health state",
+        /* CMD_POWER_CAPACITY */
+        "'capacity <percentage>' allows you to set battery capacity to a "
+        "value 0 - 100",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -450,9 +471,14 @@ void android_console_power(Monitor *mon, const QDict *qdict)
     /* Default to the first entry which is the parent help message */
     int cmd = CMD_POWER;
 
+    /* In the below command name parsing, "capacity" has to precede "ac"
+     * otherwise we will hit on "ac" first.
+     */
     if (helptext) {
         if (strstr(helptext, "display")) {
             cmd = CMD_POWER_DISPLAY;
+        } else if (strstr(helptext, "capacity")) {
+            cmd = CMD_POWER_CAPACITY;
         } else if (strstr(helptext, "ac")) {
             cmd = CMD_POWER_AC;
         } else if (strstr(helptext, "status")) {
android-console.h +1 -0
index aea671f..8801600 100644
@@ -33,6 +33,7 @@ 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_capacity(Monitor *mon, const QDict *qdict);
 void android_console_power(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
Signature · 1 line
1.8.3.2
#19 lore raw

Re: [Qemu-devel] [PATCH v1 15/15] android-console: Add power capacity command

Quoted 11 lines · Greg Bellows

Add the Android emulator console "power capacity" command along associated help messages. The "capacity" command allows the battery capacity of the device to be manipulated.

---
 android-commands.h |  7 +++++++
 android-console.c  | 26 ++++++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 34 insertions(+)

<snip>

android-console.c void android_console_power_health(Monitor *mon, const QDict *qdict) · line 429

Quoted 13 lines
android-console.c +12 -0
+void android_console_power_capacity(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+   if (arg) {
+        int capacity;
+
+        if (sscanf(arg, "%d", &capacity) == 1 &&
+            capacity >= 0 && capacity <= 100) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_CAPACITY, capacity);
+            return;
+        }

Has the formatting of const/if (arg) gone off there?

Signature · 1 line
Alex Bennée
#20 lore raw
In reply to Greg Bellows

Please disregard this patch review as it went to a broader audience than intended.

If there is interest in this work then please let me know and I will be happy to point you to a Linaro git repository that can be monitored for future updates.

Regards,

Greg

Quoted 36 lines · Greg Bellows

This patchset includes 3 changes:
- Fixes to the existing Android emulator console.
- Restructure the emulator console redir help output
- Add support for the emulator console power command

Greg Bellows (15):
android-console: Fix goldfish audio misnaming
android-console: Unify available commands output
android-console: Remove extra redir help message
android-console: Consolidate redir help text
android-console: Add console base power command
android-console: Add missing hw_has_battery prop
android-console: Init the battery ID state field
android-console: Add header for battery externs
android-console: Add GF battery prop print func
android-console: Add GF battery property getter
android-console: Add power ac command
android-console: Add power status command
android-console: Add power present command
android-console: Add power health command
android-console: Add power capacity command

 android-commands.h                 |  53 ++++++++
 android-console.c                  | 254
++++++++++++++++++++++++++++++++-----
 android-console.h                  |   8 ++
 hw/misc/goldfish_battery.c         | 122 ++++++++++++++++--
 include/hw/misc/goldfish_battery.h |  74 +++++++++++
 monitor.c                          |  16 ++-
 6 files changed, 484 insertions(+), 43 deletions(-)
 create mode 100644 include/hw/misc/goldfish_battery.h

--
1.8.3.2