| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides an interface to start and stop Android emulator. | 5 """Provides an interface to start and stop Android emulator. |
| 6 | 6 |
| 7 Emulator: The class provides the methods to launch/shutdown the emulator with | 7 Emulator: The class provides the methods to launch/shutdown the emulator with |
| 8 the android virtual device named 'avd_armeabi' . | 8 the android virtual device named 'avd_armeabi' . |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 sdcard_size=sdcard_size, storage_size=storage_size, | 183 sdcard_size=sdcard_size, storage_size=storage_size, |
| 184 headless=headless) | 184 headless=headless) |
| 185 emulator.CreateAVD(api_level) | 185 emulator.CreateAVD(api_level) |
| 186 emulator.Launch(kill_all_emulators=(n == 0 and kill_and_launch)) | 186 emulator.Launch(kill_all_emulators=(n == 0 and kill_and_launch)) |
| 187 t.Stop() | 187 t.Stop() |
| 188 emulators.append(emulator) | 188 emulators.append(emulator) |
| 189 # Wait for all emulators to boot completed. | 189 # Wait for all emulators to boot completed. |
| 190 if wait_for_boot: | 190 if wait_for_boot: |
| 191 for emulator in emulators: | 191 for emulator in emulators: |
| 192 emulator.ConfirmLaunch(True) | 192 emulator.ConfirmLaunch(True) |
| 193 logging.info('All emulators are fully booted') |
| 193 return emulators | 194 return emulators |
| 194 | 195 |
| 195 | 196 |
| 196 def LaunchEmulator(avd_name, abi, kill_and_launch=True, enable_kvm=False, | 197 def LaunchEmulator(avd_name, abi, kill_and_launch=True, enable_kvm=False, |
| 197 sdcard_size=DEFAULT_SDCARD_SIZE, | 198 sdcard_size=DEFAULT_SDCARD_SIZE, |
| 198 storage_size=DEFAULT_STORAGE_SIZE, headless=False): | 199 storage_size=DEFAULT_STORAGE_SIZE, headless=False): |
| 199 """Launch an existing emulator with name avd_name. | 200 """Launch an existing emulator with name avd_name. |
| 200 | 201 |
| 201 Args: | 202 Args: |
| 202 avd_name: name of existing emulator | 203 avd_name: name of existing emulator |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 raise EmulatorLaunchException('EMULATOR DIED') | 456 raise EmulatorLaunchException('EMULATOR DIED') |
| 456 | 457 |
| 457 if seconds_waited >= self._LAUNCH_TIMEOUT: | 458 if seconds_waited >= self._LAUNCH_TIMEOUT: |
| 458 raise EmulatorLaunchException('TIMEOUT with wait-for-device') | 459 raise EmulatorLaunchException('TIMEOUT with wait-for-device') |
| 459 | 460 |
| 460 logging.info('Seconds waited on wait-for-device: %d', seconds_waited) | 461 logging.info('Seconds waited on wait-for-device: %d', seconds_waited) |
| 461 if wait_for_boot: | 462 if wait_for_boot: |
| 462 # Now that we checked for obvious problems, wait for a boot complete. | 463 # Now that we checked for obvious problems, wait for a boot complete. |
| 463 # Waiting for the package manager is sometimes problematic. | 464 # Waiting for the package manager is sometimes problematic. |
| 464 device.WaitUntilFullyBooted(timeout=self._WAITFORBOOT_TIMEOUT) | 465 device.WaitUntilFullyBooted(timeout=self._WAITFORBOOT_TIMEOUT) |
| 466 logging.info('%s is now fully booted', self.avd_name) |
| 465 | 467 |
| 466 def Shutdown(self): | 468 def Shutdown(self): |
| 467 """Shuts down the process started by launch.""" | 469 """Shuts down the process started by launch.""" |
| 468 self._DeleteAVD() | 470 self._DeleteAVD() |
| 469 if self.popen: | 471 if self.popen: |
| 470 self.popen.poll() | 472 self.popen.poll() |
| 471 if self.popen.returncode == None: | 473 if self.popen.returncode == None: |
| 472 self.popen.kill() | 474 self.popen.kill() |
| 473 self.popen = None | 475 self.popen = None |
| 474 | 476 |
| 475 def _ShutdownOnSignal(self, _signum, _frame): | 477 def _ShutdownOnSignal(self, _signum, _frame): |
| 476 logging.critical('emulator _ShutdownOnSignal') | 478 logging.critical('emulator _ShutdownOnSignal') |
| 477 for sig in self._SIGNALS: | 479 for sig in self._SIGNALS: |
| 478 signal.signal(sig, signal.SIG_DFL) | 480 signal.signal(sig, signal.SIG_DFL) |
| 479 self.Shutdown() | 481 self.Shutdown() |
| 480 raise KeyboardInterrupt # print a stack | 482 raise KeyboardInterrupt # print a stack |
| 481 | 483 |
| 482 def _InstallKillHandler(self): | 484 def _InstallKillHandler(self): |
| 483 """Install a handler to kill the emulator when we exit unexpectedly.""" | 485 """Install a handler to kill the emulator when we exit unexpectedly.""" |
| 484 for sig in self._SIGNALS: | 486 for sig in self._SIGNALS: |
| 485 signal.signal(sig, self._ShutdownOnSignal) | 487 signal.signal(sig, self._ShutdownOnSignal) |
| OLD | NEW |