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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 self.popen.poll() | 217 self.popen.poll() |
218 if self.popen.returncode != None: | 218 if self.popen.returncode != None: |
219 raise EmulatorLaunchException('EMULATOR DIED') | 219 raise EmulatorLaunchException('EMULATOR DIED') |
220 if seconds_waited >= self._LAUNCH_TIMEOUT: | 220 if seconds_waited >= self._LAUNCH_TIMEOUT: |
221 raise EmulatorLaunchException('TIMEOUT with wait-for-device') | 221 raise EmulatorLaunchException('TIMEOUT with wait-for-device') |
222 logging.info('Seconds waited on wait-for-device: %d', seconds_waited) | 222 logging.info('Seconds waited on wait-for-device: %d', seconds_waited) |
223 if wait_for_boot: | 223 if wait_for_boot: |
224 # Now that we checked for obvious problems, wait for a boot complete. | 224 # Now that we checked for obvious problems, wait for a boot complete. |
225 # Waiting for the package manager is sometimes problematic. | 225 # Waiting for the package manager is sometimes problematic. |
226 a = android_commands.AndroidCommands(self.device) | 226 a = android_commands.AndroidCommands(self.device) |
227 a.Adb().WaitForSystemBootCompleted(self._WAITFORBOOT_TIMEOUT) | 227 a.WaitForSystemBootCompleted(self._WAITFORBOOT_TIMEOUT) |
228 | 228 |
229 def Shutdown(self): | 229 def Shutdown(self): |
230 """Shuts down the process started by launch.""" | 230 """Shuts down the process started by launch.""" |
231 if self.popen: | 231 if self.popen: |
232 self.popen.poll() | 232 self.popen.poll() |
233 if self.popen.returncode == None: | 233 if self.popen.returncode == None: |
234 self.popen.kill() | 234 self.popen.kill() |
235 self.popen = None | 235 self.popen = None |
236 | 236 |
237 def _ShutdownOnSignal(self, signum, frame): | 237 def _ShutdownOnSignal(self, signum, frame): |
238 logging.critical('emulator _ShutdownOnSignal') | 238 logging.critical('emulator _ShutdownOnSignal') |
239 for sig in self._SIGNALS: | 239 for sig in self._SIGNALS: |
240 signal.signal(sig, signal.SIG_DFL) | 240 signal.signal(sig, signal.SIG_DFL) |
241 self.Shutdown() | 241 self.Shutdown() |
242 raise KeyboardInterrupt # print a stack | 242 raise KeyboardInterrupt # print a stack |
243 | 243 |
244 def _InstallKillHandler(self): | 244 def _InstallKillHandler(self): |
245 """Install a handler to kill the emulator when we exit unexpectedly.""" | 245 """Install a handler to kill the emulator when we exit unexpectedly.""" |
246 for sig in self._SIGNALS: | 246 for sig in self._SIGNALS: |
247 signal.signal(sig, self._ShutdownOnSignal) | 247 signal.signal(sig, self._ShutdownOnSignal) |
248 | 248 |
249 def main(argv): | 249 def main(argv): |
250 Emulator(True).Launch(True) | 250 Emulator(True).Launch(True) |
251 | 251 |
252 | 252 |
253 if __name__ == '__main__': | 253 if __name__ == '__main__': |
254 main(sys.argv) | 254 main(sys.argv) |
OLD | NEW |