Mark `utils.get_available_host_port` deprecated (#907)
Getting host port then applying it is inherently unreliable.
Letting the OS handle it is better.
diff --git a/mobly/utils.py b/mobly/utils.py
index 4d5dfc6..02125ed 100644
--- a/mobly/utils.py
+++ b/mobly/utils.py
@@ -596,6 +596,8 @@
def get_available_host_port():
"""Gets a host port number available for adb forward.
+ DEPRECATED: This method is unreliable. Pass `tcp:0` to adb forward instead.
+
Returns:
An integer representing a port number on the host available for adb
forward.
@@ -603,6 +605,11 @@
Raises:
Error: when no port is found after MAX_PORT_ALLOCATION_RETRY times.
"""
+ logging.warning(
+ 'The method mobly.utils.get_available_host_port is deprecated because it '
+ 'is unreliable. Pass "tcp:0" to adb forward instead.'
+ )
+
# Only import adb module if needed.
from mobly.controllers.android_device_lib import adb