Fix the adb serial information for acloud list.

The local instance adb serial was changed as like "0.0.0.0:6520".
Original logic to set serial as "127.0.0.1:6520" needs to update.

Bug: 213124619
Test: acloud-dev list -v
Change-Id: I3045b913d3e6034855a2576f03ea68b948d89d03
diff --git a/internal/lib/adb_tools.py b/internal/lib/adb_tools.py
index 4862ba9..29253e1 100644
--- a/internal/lib/adb_tools.py
+++ b/internal/lib/adb_tools.py
@@ -31,6 +31,7 @@
                        r"(model:(?P<model>[\S]+))? ?"
                        r"(device:(?P<device>[\S]+))? ?"
                        r"(transport_id:(?P<transport_id>[\S]+))? ?")
+_RE_SERIAL = r"(?P<ip>.+):(?P<port>.+)"
 _DEVICE_ATTRIBUTES = ["adb_status", "usb", "product", "model", "device", "transport_id"]
 _MAX_RETRIES_ON_WAIT_ADB_GONE = 5
 #KEY_CODE 82 = KEY_MENU
@@ -79,6 +80,13 @@
                            argument is empty, the serial number is set to the
                            network address.
         """
+        if device_serial:
+            match = re.match(_RE_SERIAL, device_serial)
+            if match:
+                self._adb_port = match.group("port")
+                self._device_address = device_serial
+                self._device_serial = device_serial
+                return
         self._device_address = ("127.0.0.1:%s" % self._adb_port if
                                 self._adb_port else "")
         self._device_serial = (device_serial if device_serial else
diff --git a/internal/lib/adb_tools_test.py b/internal/lib/adb_tools_test.py
index 6be6ebf..a3ebf44 100644
--- a/internal/lib/adb_tools_test.py
+++ b/internal/lib/adb_tools_test.py
@@ -98,6 +98,20 @@
         adb_cmd = adb_tools.AdbTools(fake_adb_port)
         self.assertEqual(adb_cmd.device_information, dict_none)
 
+    # pylint: disable=protected-access
+    def testSetDeviceSerial(self):
+        """Test SetDeviceSerial."""
+        self.Patch(subprocess, "check_output", return_value=self.DEVICE_ALIVE)
+        adb_port = "6666"
+        adb_tool = adb_tools.AdbTools(adb_port)
+        expected_result = "127.0.0.1:6666"
+        self.assertEqual(adb_tool._device_address, expected_result)
+
+        serial = "0.0.0.0:6520"
+        adb_tool = adb_tools.AdbTools(device_serial=serial)
+        expected_result = "0.0.0.0:6520"
+        self.assertEqual(adb_tool._device_address, expected_result)
+
     def testGetDeviceSerials(self):
         """Test parsing the output of adb devices."""
         self.Patch(subprocess, "check_output",
diff --git a/list/instance.py b/list/instance.py
index 097ca1c..2fa8bdc 100644
--- a/list/instance.py
+++ b/list/instance.py
@@ -279,8 +279,9 @@
         representation.append("%s webrtc port: %s" % (_INDENT, self._webrtc_port))
 
         if self._adb_port and self._device_information:
-            representation.append("%s adb serial: 127.0.0.1:%s" %
-                                  (_INDENT, self._adb_port))
+            serial_ip = self._ip if self._ip == "0.0.0.0" else "127.0.0.1"
+            representation.append("%s adb serial: %s:%s" %
+                                  (_INDENT, serial_ip, self._adb_port))
             representation.append("%s product: %s" % (
                 _INDENT, self._device_information["product"]))
             representation.append("%s model: %s" % (
@@ -398,7 +399,7 @@
                     {"device_serial": "0.0.0.0:%s" % self._cf_runtime_cfg.adb_port,
                      "instance_name": name,
                      "elapsed_time": None})
-        adb_device = AdbTools(self._cf_runtime_cfg.adb_port)
+        adb_device = AdbTools(device_serial="0.0.0.0:%s" % self._cf_runtime_cfg.adb_port)
         webrtc_port = local_image_local_instance.LocalImageLocalInstance.GetWebrtcSigServerPort(
             self._local_instance_id)
         device_information = None