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

Side by Side Diff: adb/contrib/adb_commands_safe.py

Issue 2177573003: Add option to send reboot command and not wait for device. (Closed) Base URL: https://github.com/luci/python-adb.git@master
Patch Set: Created 4 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
OLDNEW
1 # Copyright 2015 Google Inc. All rights reserved. 1 # Copyright 2015 Google Inc. All rights reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 try: 320 try:
321 self._adb_cmd.Push(cStringIO.StringIO(content), dest, mtime) 321 self._adb_cmd.Push(cStringIO.StringIO(content), dest, mtime)
322 return True 322 return True
323 except usb_exceptions.AdbCommandFailureException: 323 except usb_exceptions.AdbCommandFailureException:
324 break 324 break
325 except self._ERRORS as e: 325 except self._ERRORS as e:
326 if not self._Reset('(%s, %s): %s', dest, content, e): 326 if not self._Reset('(%s, %s): %s', dest, content, e):
327 break 327 break
328 return False 328 return False
329 329
330 def Reboot(self): 330 def Reboot(self, wait=True):
331 """Reboots the device. Waits for it to be rebooted but not fully 331 """Reboots the device. Waits for it to be rebooted but not fully
332 operational. 332 operational.
333 333
334 This causes the USB device to disapear momentarily and get a new port_path. 334 This causes the USB device to disapear momentarily and get a new port_path.
335 If the phone just booted up, this function will cause the caller to sleep. 335 If the phone just booted up, this function will cause the caller to sleep.
336 336
337 The caller will likely want to call self.Root() to switch adbd to root 337 The caller will likely want to call self.Root() to switch adbd to root
338 context if desired. 338 context if desired.
339 339
340 Returns True on success. 340 Returns True on success.
341 """ 341 """
342 if self._adb_cmd: 342 if self._adb_cmd:
343 if not wait:
344 return self._Reboot()
345
343 # Get previous uptime to ensure the phone actually rebooted. 346 # Get previous uptime to ensure the phone actually rebooted.
344 previous_uptime = self.GetUptime() 347 previous_uptime = self.GetUptime()
345 if not previous_uptime: 348 if not previous_uptime:
346 return False 349 return False
347 if previous_uptime <= 30.: 350 if previous_uptime <= 30.:
348 # Wait for uptime to be high enough. Otherwise we can't know if the 351 # Wait for uptime to be high enough. Otherwise we can't know if the
349 # device rebooted or not. 352 # device rebooted or not.
350 time.sleep(31. - previous_uptime) 353 time.sleep(31. - previous_uptime)
351 previous_uptime = self.GetUptime() 354 previous_uptime = self.GetUptime()
352 if not previous_uptime: 355 if not previous_uptime:
(...skipping 27 matching lines...) Expand all
380 # TODO(maruel): Wait for the remount operation to be completed. 383 # TODO(maruel): Wait for the remount operation to be completed.
381 _LOG.info('%s.Remount(): %s', self.port_path, out) 384 _LOG.info('%s.Remount(): %s', self.port_path, out)
382 return True 385 return True
383 except usb_exceptions.AdbCommandFailureException: 386 except usb_exceptions.AdbCommandFailureException:
384 break 387 break
385 except self._ERRORS as e: 388 except self._ERRORS as e:
386 if not self._Reset('(): %s', e): 389 if not self._Reset('(): %s', e):
387 break 390 break
388 return False 391 return False
389 392
393 def ResetHandle(self, new_endpoint=None):
M-A Ruel 2016/07/23 00:58:44 Please add a docstring.
bpastene 2016/07/23 01:17:39 Done.
394 if self._adb_cmd:
395 self._adb_cmd.Close()
396 self._adb_cmd = None
397 if new_endpoint:
398 self._serial = None
399 self._handle.Reset(new_endpoint=new_endpoint)
400 return self._Connect(False)
401
390 def Shell(self, cmd, timeout_ms=None): 402 def Shell(self, cmd, timeout_ms=None):
391 """Runs a command on an Android device while swallowing exceptions. 403 """Runs a command on an Android device while swallowing exceptions.
392 404
393 Traps all kinds of USB errors so callers do not have to handle this. 405 Traps all kinds of USB errors so callers do not have to handle this.
394 406
395 Returns: 407 Returns:
396 tuple(stdout, exit_code) 408 tuple(stdout, exit_code)
397 - stdout is as unicode if it ran, None if an USB error occurred. 409 - stdout is as unicode if it ran, None if an USB error occurred.
398 - exit_code is set if ran. 410 - exit_code is set if ran.
399 """ 411 """
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 self.Close() 862 self.Close()
851 if not self._WaitUntilFound(use_serial=use_serial, timeout=timeout): 863 if not self._WaitUntilFound(use_serial=use_serial, timeout=timeout):
852 return False 864 return False
853 if not self._OpenHandle(): 865 if not self._OpenHandle():
854 return False 866 return False
855 return self._Connect(use_serial=use_serial) 867 return self._Connect(use_serial=use_serial)
856 868
857 def __repr__(self): 869 def __repr__(self):
858 return '<Device %s %s>' % ( 870 return '<Device %s %s>' % (
859 self.port_path, self.serial if self.is_valid else '(broken)') 871 self.port_path, self.serial if self.is_valid else '(broken)')
OLDNEW
« adb/common.py ('K') | « adb/common.py ('k') | adb/contrib/high.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698