Snap for 6224475 from 5a76063e9931e17a8462fe7a59283e7066cace0a to rvc-release

Change-Id: I9c74e484cc172245fd959fb1c1ed3c2b6d1737f0
diff --git a/create/avd_spec.py b/create/avd_spec.py
index 76340fd..b34ad03 100644
--- a/create/avd_spec.py
+++ b/create/avd_spec.py
@@ -90,7 +90,7 @@
 
 
 # pylint: disable=too-many-public-methods
-class AVDSpec(object):
+class AVDSpec:
     """Class to store data on the type of AVD to create."""
 
     def __init__(self, args):
@@ -675,6 +675,14 @@
         return self._autoconnect is not False
 
     @property
+    def connect_adb(self):
+        """Auto-connect to adb.
+
+        Return: Boolean, whether autoconnect is enabled.
+        """
+        return self._autoconnect is not False
+
+    @property
     def connect_vnc(self):
         """Launch vnc.
 
diff --git a/create/avd_spec_test.py b/create/avd_spec_test.py
index 2fef629..22c1db5 100644
--- a/create/avd_spec_test.py
+++ b/create/avd_spec_test.py
@@ -370,24 +370,28 @@
         self.args.autoconnect = False
         self.AvdSpec._ProcessMiscArgs(self.args)
         self.assertEqual(self.AvdSpec.autoconnect, False)
+        self.assertEqual(self.AvdSpec.connect_adb, False)
         self.assertEqual(self.AvdSpec.connect_vnc, False)
         self.assertEqual(self.AvdSpec.connect_webrtc, False)
 
         self.args.autoconnect = constants.INS_KEY_VNC
         self.AvdSpec._ProcessMiscArgs(self.args)
         self.assertEqual(self.AvdSpec.autoconnect, True)
+        self.assertEqual(self.AvdSpec.connect_adb, True)
         self.assertEqual(self.AvdSpec.connect_vnc, True)
         self.assertEqual(self.AvdSpec.connect_webrtc, False)
 
         self.args.autoconnect = constants.INS_KEY_ADB
         self.AvdSpec._ProcessMiscArgs(self.args)
         self.assertEqual(self.AvdSpec.autoconnect, True)
+        self.assertEqual(self.AvdSpec.connect_adb, True)
         self.assertEqual(self.AvdSpec.connect_vnc, False)
         self.assertEqual(self.AvdSpec.connect_webrtc, False)
 
         self.args.autoconnect = constants.INS_KEY_WEBRTC
         self.AvdSpec._ProcessMiscArgs(self.args)
         self.assertEqual(self.AvdSpec.autoconnect, True)
+        self.assertEqual(self.AvdSpec.connect_adb, True)
         self.assertEqual(self.AvdSpec.connect_vnc, False)
         self.assertEqual(self.AvdSpec.connect_webrtc, True)
 
diff --git a/create/local_image_local_instance.py b/create/local_image_local_instance.py
index 43bb168..0ee5ee8 100644
--- a/create/local_image_local_instance.py
+++ b/create/local_image_local_instance.py
@@ -54,8 +54,8 @@
 logger = logging.getLogger(__name__)
 
 _CMD_LAUNCH_CVD_ARGS = (" -daemon -cpus %s -x_res %s -y_res %s -dpi %s "
-                        "-memory_mb %s -system_image_dir %s "
-                        "-instance_dir %s")
+                        "-memory_mb %s -run_adb_connector=%s "
+                        "-system_image_dir %s -instance_dir %s")
 _CMD_LAUNCH_CVD_DISK_ARGS = (" -blank_data_image_mb %s "
                              "-data_policy always_create")
 _CONFIRM_RELAUNCH = ("\nCuttlefish AVD[id:%d] is already running. \n"
@@ -98,6 +98,7 @@
                                        constants.CMD_LAUNCH_CVD)
         cmd = self.PrepareLaunchCVDCmd(launch_cvd_path,
                                        avd_spec.hw_property,
+                                       avd_spec.connect_adb,
                                        local_image_path,
                                        avd_spec.local_instance_id)
 
@@ -170,8 +171,8 @@
                 self._FindCvdHostBinaries(avd_spec.local_tool_dirs))
 
     @staticmethod
-    def PrepareLaunchCVDCmd(launch_cvd_path, hw_property, system_image_dir,
-                            local_instance_id):
+    def PrepareLaunchCVDCmd(launch_cvd_path, hw_property, connect_adb,
+                            system_image_dir, local_instance_id):
         """Prepare launch_cvd command.
 
         Create the launch_cvd commands with all the required args and add
@@ -181,6 +182,7 @@
             launch_cvd_path: String of launch_cvd path.
             hw_property: dict object of hw property.
             system_image_dir: String of local images path.
+            connect_adb: Boolean flag that enables adb_connector.
             local_instance_id: Integer of instance id.
 
         Returns:
@@ -189,7 +191,8 @@
         instance_dir = instance.GetLocalInstanceRuntimeDir(local_instance_id)
         launch_cvd_w_args = launch_cvd_path + _CMD_LAUNCH_CVD_ARGS % (
             hw_property["cpu"], hw_property["x_res"], hw_property["y_res"],
-            hw_property["dpi"], hw_property["memory"], system_image_dir,
+            hw_property["dpi"], hw_property["memory"],
+            ("true" if connect_adb else "false"), system_image_dir,
             instance_dir)
         if constants.HW_ALIAS_DISK in hw_property:
             launch_cvd_w_args = (launch_cvd_w_args + _CMD_LAUNCH_CVD_DISK_ARGS %
diff --git a/create/local_image_local_instance_test.py b/create/local_image_local_instance_test.py
index e520470..d1a0acc 100644
--- a/create/local_image_local_instance_test.py
+++ b/create/local_image_local_instance_test.py
@@ -35,12 +35,12 @@
 
     LAUNCH_CVD_CMD_WITH_DISK = """sg group1 <<EOF
 sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -blank_data_image_mb fake -data_policy always_create
+launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -blank_data_image_mb fake -data_policy always_create
 EOF"""
 
     LAUNCH_CVD_CMD_NO_DISK = """sg group1 <<EOF
 sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -system_image_dir fake_image_dir -instance_dir fake_cvd_dir
+launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir
 EOF"""
 
     _EXPECTED_DEVICES_IN_REPORT = [
@@ -77,7 +77,7 @@
         """Test the report returned by _CreateAVD."""
         mock_utils.IsSupportedPlatform.return_value = True
         mock_get_image.return_value = ("/image/path", "/host/bin/path")
-        mock_avd_spec = mock.Mock(autoconnect=False, unlock_screen=False)
+        mock_avd_spec = mock.Mock(connect_adb=False, unlock_screen=False)
         self.Patch(instance, "GetLocalInstanceName",
                    return_value="local-instance-1")
         local_ins = mock.MagicMock(
@@ -145,7 +145,7 @@
         constants.LIST_CF_USER_GROUPS = ["group1", "group2"]
 
         launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
-            constants.CMD_LAUNCH_CVD, hw_property, "fake_image_dir",
+            constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
             "fake_cvd_dir")
         self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_WITH_DISK)
 
@@ -153,7 +153,7 @@
         hw_property = {"cpu": "fake", "x_res": "fake", "y_res": "fake",
                        "dpi":"fake", "memory": "fake"}
         launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
-            constants.CMD_LAUNCH_CVD, hw_property, "fake_image_dir",
+            constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
             "fake_cvd_dir")
         self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_NO_DISK)
 
diff --git a/internal/lib/utils.py b/internal/lib/utils.py
index f248f54..a60c6c3 100755
--- a/internal/lib/utils.py
+++ b/internal/lib/utils.py
@@ -918,14 +918,22 @@
     Args:
         report: Report object, that stores and generates report.
     """
+    PrintColorString("(This is an experimental project for webrtc, and since "
+                     "the certificate is self-signed, Chrome will mark it as "
+                     "an insecure website. keep going.)",
+                     TextColors.WARNING)
+
     for device in report.data.get("devices", []):
         if device.get("ip"):
-            PrintColorString("(This is an experimental project for webrtc, and "
-                             "since the certificate is self-signed, Chrome will "
-                             "mark it as an insecure website. keep going.)",
-                             TextColors.WARNING)
-            webbrowser.open_new_tab("%s%s:%s" % (
-                _WEBRTC_URL, device.get("ip"), _WEBRTC_PORT))
+            webrtc_link = "%s%s:%s" % (_WEBRTC_URL, device.get("ip"),
+                                       _WEBRTC_PORT)
+            if os.environ.get(_ENV_DISPLAY, None):
+                webbrowser.open_new_tab(webrtc_link)
+            else:
+                PrintColorString("Remote terminal can't support launch webbrowser.",
+                                 TextColors.FAIL)
+                PrintColorString("Open %s to remotely control AVD on the "
+                                 "browser." % webrtc_link)
         else:
             PrintColorString("Auto-launch devices webrtc in browser failed!",
                              TextColors.FAIL)
diff --git a/list/instance.py b/list/instance.py
index 8e4d69a..fb98960 100644
--- a/list/instance.py
+++ b/list/instance.py
@@ -330,7 +330,7 @@
         # cuttlefish_config.json so far.
         name = GetLocalInstanceName(self._local_instance_id)
         fullname = (_FULL_NAME_STRING %
-                    {"device_serial": "127.0.0.1:%d" % self._cf_runtime_cfg.adb_port,
+                    {"device_serial": "127.0.0.1:%s" % self._cf_runtime_cfg.adb_port,
                      "instance_name": name,
                      "elapsed_time": None})
         adb_device = AdbTools(self._cf_runtime_cfg.adb_port)