| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Provides an interface to start and stop Android emulator. | 7 """Provides an interface to start and stop Android emulator. |
| 8 | 8 |
| 9 Assumes system environment ANDROID_NDK_ROOT has been set. | 9 Assumes system environment ANDROID_NDK_ROOT has been set. |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 from pylib import cmd_helper | 26 from pylib import cmd_helper |
| 27 from pylib import constants | 27 from pylib import constants |
| 28 from pylib import pexpect | 28 from pylib import pexpect |
| 29 | 29 |
| 30 import errors | 30 import errors |
| 31 import run_command | 31 import run_command |
| 32 | 32 |
| 33 # Android API level | 33 # Android API level |
| 34 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION | 34 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION |
| 35 | 35 |
| 36 # SD card size |
| 37 SDCARD_SIZE = '512M' |
| 36 | 38 |
| 37 class EmulatorLaunchException(Exception): | 39 class EmulatorLaunchException(Exception): |
| 38 """Emulator failed to launch.""" | 40 """Emulator failed to launch.""" |
| 39 pass | 41 pass |
| 40 | 42 |
| 41 def _KillAllEmulators(): | 43 def _KillAllEmulators(): |
| 42 """Kill all running emulators that look like ones we started. | 44 """Kill all running emulators that look like ones we started. |
| 43 | 45 |
| 44 There are odd 'sticky' cases where there can be no emulator process | 46 There are odd 'sticky' cases where there can be no emulator process |
| 45 running but a device slot is taken. A little bot trouble and and | 47 running but a device slot is taken. A little bot trouble and and |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 else: | 197 else: |
| 196 abi_option = 'x86' | 198 abi_option = 'x86' |
| 197 | 199 |
| 198 avd_command = [ | 200 avd_command = [ |
| 199 self.android, | 201 self.android, |
| 200 '--silent', | 202 '--silent', |
| 201 'create', 'avd', | 203 'create', 'avd', |
| 202 '--name', self.avd_name, | 204 '--name', self.avd_name, |
| 203 '--abi', abi_option, | 205 '--abi', abi_option, |
| 204 '--target', API_TARGET, | 206 '--target', API_TARGET, |
| 207 '--sdcard', SDCARD_SIZE, |
| 205 '--force', | 208 '--force', |
| 206 ] | 209 ] |
| 207 avd_cmd_str = ' '.join(avd_command) | 210 avd_cmd_str = ' '.join(avd_command) |
| 208 logging.info('Create AVD command: %s', avd_cmd_str) | 211 logging.info('Create AVD command: %s', avd_cmd_str) |
| 209 avd_process = pexpect.spawn(avd_cmd_str) | 212 avd_process = pexpect.spawn(avd_cmd_str) |
| 210 | 213 |
| 211 # Instead of creating a custom profile, we overwrite config files. | 214 # Instead of creating a custom profile, we overwrite config files. |
| 212 avd_process.expect('Do you wish to create a custom hardware profile') | 215 avd_process.expect('Do you wish to create a custom hardware profile') |
| 213 avd_process.sendline('no\n') | 216 avd_process.sendline('no\n') |
| 214 avd_process.expect('Created AVD \'%s\'' % self.avd_name) | 217 avd_process.expect('Created AVD \'%s\'' % self.avd_name) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 logging.critical('emulator _ShutdownOnSignal') | 362 logging.critical('emulator _ShutdownOnSignal') |
| 360 for sig in self._SIGNALS: | 363 for sig in self._SIGNALS: |
| 361 signal.signal(sig, signal.SIG_DFL) | 364 signal.signal(sig, signal.SIG_DFL) |
| 362 self.Shutdown() | 365 self.Shutdown() |
| 363 raise KeyboardInterrupt # print a stack | 366 raise KeyboardInterrupt # print a stack |
| 364 | 367 |
| 365 def _InstallKillHandler(self): | 368 def _InstallKillHandler(self): |
| 366 """Install a handler to kill the emulator when we exit unexpectedly.""" | 369 """Install a handler to kill the emulator when we exit unexpectedly.""" |
| 367 for sig in self._SIGNALS: | 370 for sig in self._SIGNALS: |
| 368 signal.signal(sig, self._ShutdownOnSignal) | 371 signal.signal(sig, self._ShutdownOnSignal) |
| OLD | NEW |