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): ...@@ -428,7 +428,7 @@ class _AvdInstance(object):
def __str__(self): def __str__(self):
return '%s|%s' % (self._avd_name, (self._emulator_serial or id(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.""" """Starts the emulator running an instance of the given AVD."""
with tempfile_ext.TemporaryFileName() as socket_path, (contextlib.closing( with tempfile_ext.TemporaryFileName() as socket_path, (contextlib.closing(
socket.socket(socket.AF_UNIX))) as sock: socket.socket(socket.AF_UNIX))) as sock:
...@@ -439,7 +439,6 @@ class _AvdInstance(object): ...@@ -439,7 +439,6 @@ class _AvdInstance(object):
self._avd_name, self._avd_name,
'-report-console', '-report-console',
'unix:%s' % socket_path, 'unix:%s' % socket_path,
'-no-window',
] ]
if read_only: if read_only:
emulator_cmd.append('-read-only') emulator_cmd.append('-read-only')
...@@ -448,6 +447,13 @@ class _AvdInstance(object): ...@@ -448,6 +447,13 @@ class _AvdInstance(object):
emulator_env = {} emulator_env = {}
if self._emulator_home: if self._emulator_home:
emulator_env['ANDROID_EMULATOR_HOME'] = 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) sock.listen(1)
logging.info('Starting emulator.') logging.info('Starting emulator.')
......
...@@ -23,6 +23,7 @@ class LocalEmulatorEnvironment(local_device_environment.LocalDeviceEnvironment): ...@@ -23,6 +23,7 @@ class LocalEmulatorEnvironment(local_device_environment.LocalDeviceEnvironment):
elif args.emulator_count >= _MAX_ANDROID_EMULATORS: elif args.emulator_count >= _MAX_ANDROID_EMULATORS:
logging.warning('--emulator-count capped at 16.') logging.warning('--emulator-count capped at 16.')
self._emulator_count = min(_MAX_ANDROID_EMULATORS, args.emulator_count) self._emulator_count = min(_MAX_ANDROID_EMULATORS, args.emulator_count)
self._emulator_window = args.emulator_window
self._emulator_instances = [] self._emulator_instances = []
self._device_serials = [] self._device_serials = []
...@@ -36,7 +37,7 @@ class LocalEmulatorEnvironment(local_device_environment.LocalDeviceEnvironment): ...@@ -36,7 +37,7 @@ class LocalEmulatorEnvironment(local_device_environment.LocalDeviceEnvironment):
def start_emulator_instance(e): def start_emulator_instance(e):
try: try:
e.Start() e.Start(window=self._emulator_window)
return e return e
except avd.AvdException: except avd.AvdException:
logging.exception('Failed to start emulator instance.') logging.exception('Failed to start emulator instance.')
......
...@@ -320,6 +320,11 @@ def AddEmulatorOptions(parser): ...@@ -320,6 +320,11 @@ def AddEmulatorOptions(parser):
type=int, type=int,
default=1, default=1,
help='Number of emulators to use.') 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): 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