minor recovery changes

- add the --just_exit option to make recovery exit normally without doing anything
- make it possible to build updater extensions in C++
- add the clear_display command so that the updater binary can request
  recovery switch to the NONE background UI

These are all used to support the notion of using OTA as a factory
reflash mechanism.

Change-Id: Ib00d1cbf540feff38f52a61a2cf198915b48488c
diff --git a/edify/expr.c b/edify/expr.c
index 3600075..07a8ceb 100644
--- a/edify/expr.c
+++ b/edify/expr.c
@@ -495,7 +495,7 @@
 
 // Use printf-style arguments to compose an error message to put into
 // *state.  Returns NULL.
-Value* ErrorAbort(State* state, char* format, ...) {
+Value* ErrorAbort(State* state, const char* format, ...) {
     char* buffer = malloc(4096);
     va_list v;
     va_start(v, format);
diff --git a/edify/expr.h b/edify/expr.h
index 8e1c638..0d8ed8f 100644
--- a/edify/expr.h
+++ b/edify/expr.h
@@ -21,6 +21,10 @@
 
 #include "yydefs.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MAX_STRING_LEN 1024
 
 typedef struct Expr Expr;
@@ -152,7 +156,7 @@
 
 // Use printf-style arguments to compose an error message to put into
 // *state.  Returns NULL.
-Value* ErrorAbort(State* state, char* format, ...);
+Value* ErrorAbort(State* state, const char* format, ...) __attribute__((format(printf, 2, 3)));
 
 // Wrap a string into a Value, taking ownership of the string.
 Value* StringValue(char* str);
@@ -160,4 +164,8 @@
 // Free a Value object.
 void FreeValue(Value* v);
 
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+
 #endif  // _EXPRESSION_H
diff --git a/install.cpp b/install.cpp
index 0783433..4d73aa9 100644
--- a/install.cpp
+++ b/install.cpp
@@ -156,6 +156,8 @@
             }
         } else if (strcmp(command, "wipe_cache") == 0) {
             *wipe_cache = 1;
+        } else if (strcmp(command, "clear_display") == 0) {
+            ui->SetBackground(RecoveryUI::NONE);
         } else {
             LOGE("unknown command [%s]\n", command);
         }
diff --git a/recovery.cpp b/recovery.cpp
index 3f95372..2b5c65c 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -51,6 +51,7 @@
   { "wipe_data", no_argument, NULL, 'w' },
   { "wipe_cache", no_argument, NULL, 'c' },
   { "show_text", no_argument, NULL, 't' },
+  { "just_exit", no_argument, NULL, 'x' },
   { NULL, 0, NULL, 0 },
 };
 
@@ -79,6 +80,7 @@
  *   --wipe_data - erase user data (and cache), then reboot
  *   --wipe_cache - wipe cache (but not user data), then reboot
  *   --set_encrypted_filesystem=on|off - enables / diasables encrypted fs
+ *   --just_exit - do nothing; exit and reboot
  *
  * After completing, we remove /cache/recovery/command and reboot.
  * Arguments may also be supplied in the bootloader control block (BCB).
@@ -279,7 +281,7 @@
     chmod(LAST_LOG_FILE, 0640);
     chmod(LAST_INSTALL_FILE, 0644);
 
-    // Reset to mormal system boot so recovery won't cycle indefinitely.
+    // Reset to normal system boot so recovery won't cycle indefinitely.
     struct bootloader_message boot;
     memset(&boot, 0, sizeof(boot));
     set_bootloader_message(&boot);
@@ -783,6 +785,7 @@
     const char *send_intent = NULL;
     const char *update_package = NULL;
     int wipe_data = 0, wipe_cache = 0;
+    bool just_exit = false;
 
     int arg;
     while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
@@ -793,6 +796,7 @@
         case 'w': wipe_data = wipe_cache = 1; break;
         case 'c': wipe_cache = 1; break;
         case 't': ui->ShowText(true); break;
+        case 'x': just_exit = true; break;
         case '?':
             LOGE("Invalid command argument\n");
             continue;
@@ -844,7 +848,7 @@
     } else if (wipe_cache) {
         if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
         if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n");
-    } else {
+    } else if (!just_exit) {
         status = INSTALL_ERROR;  // No command specified
     }