Commit d789260d authored by Haiyang Pan's avatar Haiyang Pan Committed by Commit Bot

android: add the ability to enable window display on the emulator

This would help local development with emulator

Bug: 922145
Change-Id: Ie107381b80e3c0acae1145cf4078a327e38ffa3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849434Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Haiyang Pan <hypan@google.com>
Cr-Commit-Position: refs/heads/master@{#704885}
parent 9e88892a
......@@ -428,7 +428,7 @@ class _AvdInstance(object):
def __str__(self):
return '%s|%s' % (self._avd_name, (self._emulator_serial or id(self)))
def Start(self, read_only=True, snapshot_save=False):
def Start(self, read_only=True, snapshot_save=False, window=False):
"""Starts the emulator running an instance of the given AVD."""
with tempfile_ext.TemporaryFileName() as socket_path, (contextlib.closing(
socket.socket(socket.AF_UNIX))) as sock:
......@@ -439,7 +439,6 @@ class _AvdInstance(object):
self._avd_name,
'-report-console',
'unix:%s' % socket_path,
'-no-window',
]
if read_only:
emulator_cmd.append('-read-only')
......@@ -448,6 +447,13 @@ class _AvdInstance(object):
emulator_env = {}
if self._emulator_home:
emulator_env['ANDROID_EMULATOR_HOME'] = self._emulator_home
if window:
if 'DISPLAY' in os.environ:
emulator_env['DISPLAY'] = os.environ.get('DISPLAY')
else:
raise AvdException('Emulator failed to start: DISPLAY not defined')
else:
emulator_cmd.append('-no-window')
sock.listen(1)
logging.info('Starting emulator.')
......
......@@ -23,6 +23,7 @@ class LocalEmulatorEnvironment(local_device_environment.LocalDeviceEnvironment):
elif args.emulator_count >= _MAX_ANDROID_EMULATORS:
logging.warning('--emulator-count capped at 16.')
self._emulator_count = min(_MAX_ANDROID_EMULATORS, args.emulator_count)
self._emulator_window = args.emulator_window
self._emulator_instances = []
self._device_serials = []
......@@ -36,7 +37,7 @@ class LocalEmulatorEnvironment(local_device_environment.LocalDeviceEnvironment):
def start_emulator_instance(e):
try:
e.Start()
e.Start(window=self._emulator_window)
return e
except avd.AvdException:
logging.exception('Failed to start emulator instance.')
......
......@@ -320,6 +320,11 @@ def AddEmulatorOptions(parser):
type=int,
default=1,
help='Number of emulators to use.')
parser.add_argument(
'--emulator-window',
action='store_true',
default=False,
help='Enable graphical window display on the emulator.')
def AddGTestOptions(parser):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment