First, recap: what is the Android serial number.
In Android ADB protocal, the serial number following the host-serial: is URL-safe string and it could be a host:port string.
if (android::base::ConsumePrefix(&service, "host-serial:")) { // serial number should follow "host:" and could be a host:port string.
Second, LLDB is not able to connect it to Android device when multiple devices are connected to the host.
(lldb) platform select remote-android (lldb) platform connect unix-abstract-connect:///data/local/tmp/debug.sock error: Expected a single connected device, got instead 2 - try setting 'ANDROID_SERIAL'
However setting ANDROID_SERIAL environment variable is not always a viable option.
For instance, VS Code + lldb-server and debugging multiple Android devices at the same time.
The potential solution is to use platform connect URL.
(lldb) platform select remote-android (lldb) platform connect unix-abstract-connect://emulator-5554/data/local/tmp/debug.sock
This works for USB-connected devices and emulators.
But it does not work for TCP/IP-connected devices.
(lldb) platform select remote-android (lldb) platform connect unix-abstract-connect://127.0.0.1:5556/data/local/tmp/debug.sock
The reason is that the current code only uses the hostname part of the URL.
So m_device_id will be 127.0.0.1. But this should be 127.0.0.1:5556
Also localhost should not be skipped when the port number is available. m_device_id should be localhost:5556
(lldb) platform connect unix-abstract-connect://localhost:5556/data/local/tmp/debug.sock
Third, the host could be IPv6, for instance [::1].
(lldb) platform connect unix-abstract-connect://[::1]:5556/data/local/tmp/debug.sock
This is a valid URL and serial number [::1]:5556.
The parsed_url does not look it has the information of IPv6 brackets. Thus, GetDeviceIDFromURL checks the raw URL again for the bracket.
Fourth, when a port number is available in the connect URL, MakeConnectURL function create a new TCP/IP forwarding with the port number. When adb devices shows a device with host:port style serial number, the port in the serial number is already connected or forwarded to the adb server. host-serial:host:port should work.
clang-format not found in user’s local PATH; not linting file.