Merge "Remove unnecessary calls in UI <-> Core protocols."
diff --git a/android/core-ui-protocol.c b/android/core-ui-protocol.c
index 58517d4..ff7f3d5 100644
--- a/android/core-ui-protocol.c
+++ b/android/core-ui-protocol.c
@@ -24,7 +24,6 @@
 #if !defined(CONFIG_STANDALONE_CORE)
 /* in android/qemulator.c */
 extern void  android_emulator_set_window_scale( double, int );
-extern void  android_emulator_set_base_port(int  port);
 #endif
 
 void
@@ -35,11 +34,3 @@
 #endif
 }
 
-void
-android_ui_set_base_port(int  port)
-{
-#if !defined(CONFIG_STANDALONE_CORE)
-    android_emulator_set_base_port(port);
-#endif
-}
-
diff --git a/android/core-ui-protocol.h b/android/core-ui-protocol.h
index 5ffe3d5..5fc2372 100644
--- a/android/core-ui-protocol.h
+++ b/android/core-ui-protocol.h
@@ -24,7 +24,4 @@
 /* Changes the scale of the emulator window at runtime. */
 void android_ui_set_window_scale(double scale, int is_dpi);
 
-/* Change the console port in the UI window */
-void android_ui_set_base_port(int  port);
-
 #endif  // QEMU_ANDROID_CORE_UI_PROTOCOL_H
diff --git a/android/main-ui.c b/android/main-ui.c
index 4d8560c..79dbea6 100644
--- a/android/main-ui.c
+++ b/android/main-ui.c
@@ -109,6 +109,9 @@
 /* -ui-settings parameters received from the core on UI attachment. */
 char* core_ui_settings = "";
 
+/* Emulator's core port. */
+int android_base_port = 0;
+
 /***********************************************************************/
 /***********************************************************************/
 /*****                                                             *****/
@@ -951,7 +954,11 @@
         return -1;
     }
 
+    // Save core's port, and set the title.
+    android_base_port = sock_address_get_port(&console_socket);
     emulator = qemulator_get();
+    qemulator_set_title(emulator);
+
     fb_client = clientfb_create(&console_socket, "-raw",
                                 qemulator_get_first_framebuffer(emulator));
     if (fb_client == NULL) {
diff --git a/android/qemu-setup.c b/android/qemu-setup.c
index 6c3785c..f0157cd 100644
--- a/android/qemu-setup.c
+++ b/android/qemu-setup.c
@@ -331,9 +331,8 @@
 
     android_modem_init( base_port );
 
-    /* Save base port and call back to UI so it can properly set up its window title. */
+    /* Save base port. */
     android_base_port = base_port;
-    android_ui_set_base_port(base_port);
 
    /* send a simple message to the ADB host server to tell it we just started.
     * it should be listening on port 5037. if we can't reach it, don't bother
diff --git a/android/qemulator.c b/android/qemulator.c
index 35e7cc8..054c5a6 100644
--- a/android/qemulator.c
+++ b/android/qemulator.c
@@ -258,7 +258,7 @@
     }
 
     p = bufprint(p, end, "%d:%s",
-                 android_core_get_base_port(),
+                 android_base_port,
                  avdInfo_getName( android_avdInfo ));
 
     skin_window_set_title( emulator->window, temp );
diff --git a/android/ui-core-protocol.c b/android/ui-core-protocol.c
index 8877c0b..08591c0 100644
--- a/android/ui-core-protocol.c
+++ b/android/ui-core-protocol.c
@@ -51,16 +51,6 @@
 #endif  // CONFIG_STANDALONE_UI
 }
 
-int
-android_core_get_base_port(void)
-{
-#if !defined(CONFIG_STANDALONE_UI)
-    return android_base_port;
-#else
-    return 5554;
-#endif  // CONFIG_STANDALONE_UI
-}
-
 void
 android_core_sensors_set_coarse_orientation( AndroidCoarseOrientation  orient )
 {
diff --git a/android/ui-core-protocol.h b/android/ui-core-protocol.h
index 6930e62..3cb239d 100644
--- a/android/ui-core-protocol.h
+++ b/android/ui-core-protocol.h
@@ -39,9 +39,6 @@
 void android_core_set_brightness_change_callback(AndroidHwLightBrightnessCallback callback,
                                                  void* opaque);
 
-/* Returns base port assigned for the emulated system. */
-int android_core_get_base_port(void);
-
 /* change the coarse orientation value */
 void  android_core_sensors_set_coarse_orientation( AndroidCoarseOrientation  orient );
 
diff --git a/vl-android.c b/vl-android.c
index af17c33..60c3a01 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -199,6 +199,11 @@
 unsigned long   android_verbose;
 #endif  // CONFIG_STANDALONE_CORE
 
+#if !defined(CONFIG_STANDALONE_CORE)
+/* in android/qemulator.c */
+extern void  android_emulator_set_base_port(int  port);
+#endif
+
 #if defined(CONFIG_SKINS) && !defined(CONFIG_STANDALONE_CORE)
 #undef main
 #define main qemu_main
@@ -5302,6 +5307,12 @@
     /* call android-specific setup function */
     android_emulation_setup();
 
+#if !defined(CONFIG_STANDALONE_CORE)
+    // For the standalone emulator (UI+core in one executable) we need to
+    // set the window title here.
+    android_emulator_set_base_port(android_base_port);
+#endif
+
     if (loadvm)
         do_loadvm(cur_mon, loadvm);