From 325e7ba955f2bb4f26f48c646eb0a9cee16ee418 Mon Sep 17 00:00:00 2001 From: Bob Clary Date: Fri, 7 Aug 2020 18:35:26 +0000 Subject: [PATCH] Bug 1522661 - [mozdevice 4.0.1] adb should use ANDROID_SERIAL environment variable if device not otherwise specified. r=gbrown Differential Revision: https://phabricator.services.mozilla.com/D86401 --- testing/mozbase/mozdevice/mozdevice/adb.py | 13 ++++++++++--- testing/mozbase/mozdevice/setup.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/testing/mozbase/mozdevice/mozdevice/adb.py b/testing/mozbase/mozdevice/mozdevice/adb.py index 19b7626bbed6..4fcba120c3c3 100644 --- a/testing/mozbase/mozdevice/mozdevice/adb.py +++ b/testing/mozbase/mozdevice/mozdevice/adb.py @@ -236,7 +236,8 @@ class ADBCommand(object): executed. :param str device_serial: The device's serial number if the adb command is to be executed against - a specific device. + a specific device. If it is not specified, ANDROID_SERIAL + from the environment will be used if it is set. :param int timeout: The maximum time in seconds for any spawned adb process to complete before throwing an ADBTimeoutError. This timeout is per adb call. The @@ -263,6 +264,7 @@ class ADBCommand(object): the stdout temporary file. """ args = [self._adb_path] + device_serial = device_serial or os.environ.get('ANDROID_SERIAL') if self._adb_host: args.extend(['-H', self._adb_host]) if self._adb_port: @@ -298,7 +300,8 @@ class ADBCommand(object): executed. :param str device_serial: The device's serial number if the adb command is to be executed against - a specific device. + a specific device. If it is not specified, ANDROID_SERIAL + from the environment will be used if it is set. :param int timeout: The maximum time in seconds for any spawned adb process to complete before throwing an ADBTimeoutError. @@ -561,6 +564,7 @@ def ADBDeviceFactory(device=None, :exc:`ADBTimeoutError` """ + device = device or os.environ.get('ANDROID_SERIAL') if device is not None and device in ADBDEVICES: # We have already created an ADBDevice for this device, just re-use it. adbdevice = ADBDEVICES[device] @@ -617,7 +621,9 @@ class ADBDevice(ADBCommand): be used to identify the device, otherwise the value of the usb key, prefixed with "usb:" is used. If None is passed and there is exactly one device attached to the host, that device - is used. If there is more than one device attached, ValueError + is used. If None is passed and ANDROID_SERIAL is set in the environment, + that device is used. If there is more than one device attached and + device is None and ANDROID_SERIAL is not set in the environment, ValueError is raised. If no device is attached the constructor will block until a device is attached or the timeout is reached. :param str adb_host: host of the adb server to connect to. @@ -958,6 +964,7 @@ class ADBDevice(ADBCommand): raise ADBError('Failed to complete boot in time') def _get_device_serial(self, device): + device = device or os.environ.get('ANDROID_SERIAL') if device is None: devices = ADBHost(adb=self._adb_path, adb_host=self._adb_host, adb_port=self._adb_port).devices() diff --git a/testing/mozbase/mozdevice/setup.py b/testing/mozbase/mozdevice/setup.py index 70a00814ce58..46273ee7429f 100644 --- a/testing/mozbase/mozdevice/setup.py +++ b/testing/mozbase/mozdevice/setup.py @@ -8,7 +8,7 @@ from __future__ import absolute_import from setuptools import setup PACKAGE_NAME = 'mozdevice' -PACKAGE_VERSION = '4.0.0' +PACKAGE_VERSION = '4.0.1' deps = ['mozlog >= 6.0']