Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: build/android/emulator.py

Issue 10695170: init AndroidCommand after the device online to root it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix according to bulach's comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 os.unlink(full_name) 189 os.unlink(full_name)
190 190
191 def ConfirmLaunch(self, wait_for_boot=False): 191 def ConfirmLaunch(self, wait_for_boot=False):
192 """Confirm the emulator launched properly. 192 """Confirm the emulator launched properly.
193 193
194 Loop on a wait-for-device with a very small timeout. On each 194 Loop on a wait-for-device with a very small timeout. On each
195 timeout, check the emulator process is still alive. 195 timeout, check the emulator process is still alive.
196 After confirming a wait-for-device can be successful, make sure 196 After confirming a wait-for-device can be successful, make sure
197 it returns the right answer. 197 it returns the right answer.
198 """ 198 """
199 a = android_commands.AndroidCommands(self.device)
200 seconds_waited = 0 199 seconds_waited = 0
201 number_of_waits = 2 # Make sure we can wfd twice 200 number_of_waits = 2 # Make sure we can wfd twice
202 adb_cmd = "adb -s %s %s" % (self.device, 'wait-for-device') 201 adb_cmd = "adb -s %s %s" % (self.device, 'wait-for-device')
203 while seconds_waited < self._LAUNCH_TIMEOUT: 202 while seconds_waited < self._LAUNCH_TIMEOUT:
204 try: 203 try:
205 run_command.RunCommand(adb_cmd, 204 run_command.RunCommand(adb_cmd,
206 timeout_time=self._WAITFORDEVICE_TIMEOUT, 205 timeout_time=self._WAITFORDEVICE_TIMEOUT,
207 retry_count=1) 206 retry_count=1)
208 number_of_waits -= 1 207 number_of_waits -= 1
209 if not number_of_waits: 208 if not number_of_waits:
210 break 209 break
211 except errors.WaitForResponseTimedOutError as e: 210 except errors.WaitForResponseTimedOutError as e:
212 seconds_waited += self._WAITFORDEVICE_TIMEOUT 211 seconds_waited += self._WAITFORDEVICE_TIMEOUT
213 adb_cmd = "adb -s %s %s" % (self.device, 'kill-server') 212 adb_cmd = "adb -s %s %s" % (self.device, 'kill-server')
214 run_command.RunCommand(adb_cmd) 213 run_command.RunCommand(adb_cmd)
215 self.popen.poll() 214 self.popen.poll()
216 if self.popen.returncode != None: 215 if self.popen.returncode != None:
217 raise EmulatorLaunchException('EMULATOR DIED') 216 raise EmulatorLaunchException('EMULATOR DIED')
218 if seconds_waited >= self._LAUNCH_TIMEOUT: 217 if seconds_waited >= self._LAUNCH_TIMEOUT:
219 raise EmulatorLaunchException('TIMEOUT with wait-for-device') 218 raise EmulatorLaunchException('TIMEOUT with wait-for-device')
220 logging.info('Seconds waited on wait-for-device: %d', seconds_waited) 219 logging.info('Seconds waited on wait-for-device: %d', seconds_waited)
221 if wait_for_boot: 220 if wait_for_boot:
222 # Now that we checked for obvious problems, wait for a boot complete. 221 # Now that we checked for obvious problems, wait for a boot complete.
223 # Waiting for the package manager is sometimes problematic. 222 # Waiting for the package manager is sometimes problematic.
224 a.Adb().SetTargetSerial(self.device) 223 a = android_commands.AndroidCommands(self.device)
225 a.Adb().WaitForSystemBootCompleted(self._WAITFORBOOT_TIMEOUT) 224 a.Adb().WaitForSystemBootCompleted(self._WAITFORBOOT_TIMEOUT)
226 225
227 def Shutdown(self): 226 def Shutdown(self):
228 """Shuts down the process started by launch.""" 227 """Shuts down the process started by launch."""
229 if self.popen: 228 if self.popen:
230 self.popen.poll() 229 self.popen.poll()
231 if self.popen.returncode == None: 230 if self.popen.returncode == None:
232 self.popen.kill() 231 self.popen.kill()
233 self.popen = None 232 self.popen = None
234 233
235 def _ShutdownOnSignal(self, signum, frame): 234 def _ShutdownOnSignal(self, signum, frame):
236 logging.critical('emulator _ShutdownOnSignal') 235 logging.critical('emulator _ShutdownOnSignal')
237 for sig in self._SIGNALS: 236 for sig in self._SIGNALS:
238 signal.signal(sig, signal.SIG_DFL) 237 signal.signal(sig, signal.SIG_DFL)
239 self.Shutdown() 238 self.Shutdown()
240 raise KeyboardInterrupt # print a stack 239 raise KeyboardInterrupt # print a stack
241 240
242 def _InstallKillHandler(self): 241 def _InstallKillHandler(self):
243 """Install a handler to kill the emulator when we exit unexpectedly.""" 242 """Install a handler to kill the emulator when we exit unexpectedly."""
244 for sig in self._SIGNALS: 243 for sig in self._SIGNALS:
245 signal.signal(sig, self._ShutdownOnSignal) 244 signal.signal(sig, self._ShutdownOnSignal)
246 245
247 def main(argv): 246 def main(argv):
248 Emulator(True).Launch(True) 247 Emulator(True).Launch(True)
249 248
250 249
251 if __name__ == '__main__': 250 if __name__ == '__main__':
252 main(sys.argv) 251 main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698