android-console: Add power status command

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.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>

---

v2 -> v3
- Add missing "OK" messages
diff --git a/android-commands.h b/android-commands.h
index e770fcf..ce3ea59 100644
--- a/android-commands.h
+++ b/android-commands.h
@@ -40,6 +40,13 @@
         .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, },
 };
 
diff --git a/android-console.c b/android-console.c
index 999f84d..34db818 100644
--- a/android-console.c
+++ b/android-console.c
@@ -334,10 +334,49 @@
     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);
+            monitor_printf(mon, "OK\n");
+            return;
+        } else if (strcasecmp(arg, "charging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_CHARGING);
+            monitor_printf(mon, "OK\n");
+            return;
+        } else if (strcasecmp(arg, "discharging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_DISCHARGING);
+            monitor_printf(mon, "OK\n");
+            return;
+        } else if (strcasecmp(arg, "not-charging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_NOT_CHARGING);
+            monitor_printf(mon, "OK\n");
+            return;
+        } else if (strcasecmp(arg, "full") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_FULL);
+            monitor_printf(mon, "OK\n");
+            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[] = {
@@ -355,6 +394,9 @@
         "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)
@@ -370,6 +412,8 @@
             cmd = CMD_POWER_DISPLAY;
         } else if (strstr(helptext, "ac")) {
             cmd = CMD_POWER_AC;
+        } else if (strstr(helptext, "status")) {
+            cmd = CMD_POWER_STATUS;
         }
     }
 
diff --git a/android-console.h b/android-console.h
index 458f44c..184ae69 100644
--- a/android-console.h
+++ b/android-console.h
@@ -30,6 +30,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(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);