Simplify UI-only sources.

Get rid of console-ui.c, qemu-timer-ui.c and modify vl-android-ui.c
to use a generic Looper object instead of a crummy event loop.

We still need to implement qemu_set_fd_handler for two sources under
android/protocol/ but this will be cleaned up later.

Change-Id: Icd0762675ca2f54e720a9cec40f96caea500b52f
diff --git a/android/framebuffer.c b/android/framebuffer.c
index 53c6a48..b9b968e 100644
--- a/android/framebuffer.c
+++ b/android/framebuffer.c
@@ -281,6 +281,15 @@
 }
 
 void
+qframebuffer_pulse( void )
+{
+    int  nn;
+    for (nn = 0; nn < framebuffer_fifo_count; nn++) {
+        qframebuffer_poll(framebuffer_fifo[nn]);
+    }
+}
+
+void
 qframebuffer_invalidate_all( void )
 {
     int  nn;
diff --git a/android/framebuffer.h b/android/framebuffer.h
index 9d1f626..faf2f41 100644
--- a/android/framebuffer.h
+++ b/android/framebuffer.h
@@ -172,6 +172,10 @@
 extern void
 qframebuffer_rotate( QFrameBuffer*  qfbuff, int  rotation );
 
+/* this function is used to poll a framebuffer's client for input
+ * events. Should be called either explicitely, or through qframebuffer_pulse()
+ * periodically.
+ */
 extern void
 qframebuffer_poll( QFrameBuffer* qfbuff );
 
@@ -188,6 +192,11 @@
 extern void
 qframebuffer_check_updates( void );
 
+/* call this function periodically to force a poll on all franebuffers
+ */
+extern void
+qframebuffer_pulse( void );
+
 /* this is called by the emulator. for each registered framebuffer, call
  * its producer's Invalidate method, if any
  */
diff --git a/android/looper-generic.c b/android/looper-generic.c
index 6ec0db4..d75fbff 100644
--- a/android/looper-generic.c
+++ b/android/looper-generic.c
@@ -289,7 +289,7 @@
         pnode = &node->activeNext;
     }
     tt->activeNext = *pnode;
-    *pnode         = tt->activeNext;
+    *pnode         = tt;
 }
 
 static void
diff --git a/android/main-common.c b/android/main-common.c
index 23ba5b9..bcae501 100644
--- a/android/main-common.c
+++ b/android/main-common.c
@@ -315,7 +315,9 @@
     }
 
     snprintf(buf, sizeof buf, "width=%d,height=%d", width, height);
+#if !defined(CONFIG_STANDALONE_UI) && !defined(CONFIG_STANDALONE_CORE)
     android_display_init(ds, qframebuffer_fifo_get());
+#endif
 }
 
 /* list of skin aliases */
diff --git a/android/main-ui.c b/android/main-ui.c
index 9981b76..daf71cb 100644
--- a/android/main-ui.c
+++ b/android/main-ui.c
@@ -1507,16 +1507,5 @@
         }
     }
 
-    // Connect to the core's framebuffer service
-    if (implFb_create(attachUiImpl_get_console_socket(), "-raw",
-                      qemulator_get_first_framebuffer(qemulator_get()))) {
-        return -1;
-    }
-
-    // Attach the recepient of UI commands.
-    if (uiCmdImpl_create(attachUiImpl_get_console_socket())) {
-        return -1;
-    }
-
     return qemu_main(n, args);
 }
diff --git a/android/protocol/ui-commands-impl.c b/android/protocol/ui-commands-impl.c
index f265514..2ca4194 100644
--- a/android/protocol/ui-commands-impl.c
+++ b/android/protocol/ui-commands-impl.c
@@ -124,7 +124,7 @@
         status = read(uicmd->sock, uicmd->reader_buffer + uicmd->reader_offset,
                       uicmd->reader_bytes - uicmd->reader_offset);
         if (status == 0) {
-            /* Disconnection, meaning that the core process got termonated. */
+            /* Disconnection, meaning that the core process got terminated. */
             fprintf(stderr, "core-ui-control service got disconnected\n");
             uiCmdImpl_destroy();
             return;
@@ -201,7 +201,7 @@
         return -1;
     }
 
-    // Initialze UI command reader.
+    // Initialize UI command reader.
     _uiCmdImpl.sock = core_connection_get_socket(_uiCmdImpl.core_connection);
     if (qemu_set_fd_handler(_uiCmdImpl.sock, _uiCmdImpl_io_read, NULL,
                             &_uiCmdImpl)) {
diff --git a/android/qemulator.c b/android/qemulator.c
index 36a9ec8..c90a674 100644
--- a/android/qemulator.c
+++ b/android/qemulator.c
@@ -97,8 +97,10 @@
 {
     QEmulator*  emulator = _emulator;
 
-    if (emulator->window)
-        skin_window_update_display( emulator->window, x, y, w, h );
+    if (!emulator->window) {
+        qemulator_setup( emulator );
+    }
+    skin_window_update_display( emulator->window, x, y, w, h );
 }
 
 static void