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

Side by Side Diff: appengine/third_party/python-adb/adb/high.py

Issue 1424923006: Small fixes as found in staging. (Closed) Base URL: git@github.com:luci/luci-py.git@4_more_functionality
Patch Set: . Created 5 years, 1 month 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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 # First query the current state and only try to switch if it's different. 425 # First query the current state and only try to switch if it's different.
426 prev = self.PullContent(path) 426 prev = self.PullContent(path)
427 if prev: 427 if prev:
428 prev = prev.strip() 428 prev = prev.strip()
429 if prev == governor: 429 if prev == governor:
430 return True 430 return True
431 if prev not in self.cache.available_governors: 431 if prev not in self.cache.available_governors:
432 _LOG.warning( 432 _LOG.warning(
433 '%s.SetCPUScalingGovernor(): Read invalid scaling_governor: %s', 433 '%s.SetCPUScalingGovernor(): Read invalid scaling_governor: %s',
434 self.port_path, prev) 434 self.port_path, prev)
435 else:
436 _LOG.warning(
437 '%s.SetCPUScalingGovernor(): Failed to read %s', self.port_path, path)
435 438
436 # This works on Nexus 10 but not on Nexus 5. Need to investigate more. In 439 # This works on Nexus 10 but not on Nexus 5. Need to investigate more. In
437 # the meantime, simply try one after the other. 440 # the meantime, simply try one after the other.
438 if not self.PushContent(governor + '\n', path): 441 if not self.PushContent(governor + '\n', path):
442 _LOG.info(
443 '%s.SetCPUScalingGovernor(): Failed to push %s in %s',
444 self.port_path, governor, path)
439 # Fallback via shell. 445 # Fallback via shell.
440 _, exit_code = self.Shell('echo "%s" > %s' % (governor, path)) 446 _, exit_code = self.Shell('echo "%s" > %s' % (governor, path))
441 if exit_code != 0: 447 if exit_code != 0:
442 _LOG.warning( 448 _LOG.warning(
443 '%s.SetCPUScalingGovernor(): Writing %s failed; was %s', 449 '%s.SetCPUScalingGovernor(): Writing %s failed; was %s',
444 self.port_path, governor, prev) 450 self.port_path, governor, prev)
445 return False 451 return False
446 # Get it back to confirm. 452 # Get it back to confirm.
447 newval = self.PullContent(path) 453 newval = self.PullContent(path)
448 if not (newval or '').strip() == governor: 454 if not (newval or '').strip() == governor:
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 return None 607 return None
602 return [l.split(':', 1)[1] for l in out.strip().splitlines()] 608 return [l.split(':', 1)[1] for l in out.strip().splitlines()]
603 609
604 def InstallAPK(self, destdir, apk): 610 def InstallAPK(self, destdir, apk):
605 """Installs apk to destdir directory.""" 611 """Installs apk to destdir directory."""
606 # TODO(maruel): Test. 612 # TODO(maruel): Test.
607 # '/data/local/tmp/' 613 # '/data/local/tmp/'
608 dest = posixpath.join(destdir, os.path.basename(apk)) 614 dest = posixpath.join(destdir, os.path.basename(apk))
609 if not self.Push(apk, dest): 615 if not self.Push(apk, dest):
610 return False 616 return False
611 return self.Shell('pm install -r %s' % pipes.quote(dest))[1] is 0 617 cmd = 'pm install -r %s' % pipes.quote(dest)
618 out, exit_code = self.Shell(cmd)
619 if not exit_code:
620 return True
621 _LOG.info('%s: %s', cmd, out)
ghost stip (do not use) 2015/11/03 18:50:47 might be cool to abstract this into a helper funct
M-A Ruel 2015/11/04 18:39:10 Yes thinking about that but will leave out for now
622 return False
612 623
613 def UninstallAPK(self, package): 624 def UninstallAPK(self, package):
614 """Uninstalls the package.""" 625 """Uninstalls the package."""
615 return self.Shell('pm uninstall %s' % pipes.quote(package))[1] is 0 626 cmd = 'pm uninstall %s' % pipes.quote(package)
627 out, exit_code = self.Shell(cmd)
628 if not exit_code:
629 return True
630 _LOG.info('%s: %s', cmd, out)
631 return False
616 632
617 def GetApplicationPath(self, package): 633 def GetApplicationPath(self, package):
618 # TODO(maruel): Test. 634 # TODO(maruel): Test.
619 out, _ = self.Shell('pm path %s' % pipes.quote(package)) 635 out, _ = self.Shell('pm path %s' % pipes.quote(package))
620 return out.strip().split(':', 1)[1] if out else out 636 return out.strip().split(':', 1)[1] if out else out
621 637
622 def WaitForDevice(self, timeout=180): 638 def WaitForDevice(self, timeout=180):
623 """Waits for the device to be responsive. 639 """Waits for the device to be responsive.
624 640
625 In practice, waits for the device to have its external storage to be 641 In practice, waits for the device to have its external storage to be
626 mounted. 642 mounted.
627 643
628 Returns: 644 Returns:
629 - uptime as float in second or None. 645 - uptime as float in second or None.
630 """ 646 """
631 start = time.time() 647 start = time.time()
632 while True: 648 while True:
633 if (time.time() - start) > timeout: 649 if (time.time() - start) > timeout:
634 return False 650 break
635 if self.Stat(self.cache.external_storage_path)[0] != None: 651 if self.Stat(self.cache.external_storage_path)[0] != None:
636 return True 652 return True
637 time.sleep(0.1) 653 time.sleep(0.1)
654 _LOG.warning('%s.WaitForDevice() failed', self.port_path)
638 return False 655 return False
639 656
640 def WaitUntilFullyBooted(self, timeout=300): 657 def WaitUntilFullyBooted(self, timeout=300):
641 """Waits for the device to be fully started up with network connectivity. 658 """Waits for the device to be fully started up with network connectivity.
642 659
643 Arguments: 660 Arguments:
644 - timeout: minimum amount of time to wait for for the device to come up 661 - timeout: minimum amount of time to wait for for the device to come up
645 online. It may extend to up to lock_timeout_ms more. 662 online. It may extend to up to lock_timeout_ms more.
646 """ 663 """
647 # Wait for the device to respond at all and optionally have lower uptime. 664 # Wait for the device to respond at all and optionally have lower uptime.
648 start = time.time() 665 start = time.time()
649 if not self.WaitForDevice(timeout): 666 if not self.WaitForDevice(timeout):
650 return False 667 return False
651 668
652 # Wait for the internal sys.boot_completed bit to be set. This is the place 669 # Wait for the internal sys.boot_completed bit to be set. This is the place
653 # where most time is spent. 670 # where most time is spent.
654 while True: 671 while True:
655 if (time.time() - start) > timeout: 672 if (time.time() - start) > timeout:
673 _LOG.warning(
674 '%s.WaitUntilFullyBooted() didn\'t get sys.boot_completed in time',
675 self.port_path)
656 return False 676 return False
657 if self.GetProp('sys.boot_completed') == '1': 677 if self.GetProp('sys.boot_completed') == '1':
658 break 678 break
659 time.sleep(0.1) 679 time.sleep(0.1)
660 680
661 # Wait for one network to be up and running. 681 # Wait for one network to be up and running.
662 while not self.GetIPs(): 682 while not self.GetIPs():
663 if (time.time() - start) > timeout: 683 if (time.time() - start) > timeout:
684 _LOG.warning(
685 '%s.WaitUntilFullyBooted() didn\'t get an IP in time',
686 self.port_path)
664 return False 687 return False
665 time.sleep(0.1) 688 time.sleep(0.1)
666 return True 689 return True
667 690
668 def PushKeys(self): 691 def PushKeys(self):
669 """Pushes all the keys on the file system to the device. 692 """Pushes all the keys on the file system to the device.
670 693
671 This is necessary when the device just got wiped but still has 694 This is necessary when the device just got wiped but still has
672 authorization, as soon as it reboots it'd lose the authorization. 695 authorization, as soon as it reboots it'd lose the authorization.
673 696
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 return out 781 return out
759 782
760 @classmethod 783 @classmethod
761 def _Connect(cls, constructor, **kwargs): 784 def _Connect(cls, constructor, **kwargs):
762 """Called by either ConnectDevice or Connect.""" 785 """Called by either ConnectDevice or Connect."""
763 if not kwargs.get('rsa_keys'): 786 if not kwargs.get('rsa_keys'):
764 with _ADB_KEYS_LOCK: 787 with _ADB_KEYS_LOCK:
765 kwargs['rsa_keys'] = _ADB_KEYS[:] 788 kwargs['rsa_keys'] = _ADB_KEYS[:]
766 device = constructor(**kwargs) 789 device = constructor(**kwargs)
767 return HighDevice(device, _InitCache(device)) 790 return HighDevice(device, _InitCache(device))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698