OLD | NEW |
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 Loading... |
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 Loading... |
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) |
| 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 """ |
| 647 if not self.cache.external_storage_path: |
| 648 return False |
631 start = time.time() | 649 start = time.time() |
632 while True: | 650 while True: |
633 if (time.time() - start) > timeout: | 651 if (time.time() - start) > timeout: |
634 return False | 652 break |
635 if self.Stat(self.cache.external_storage_path)[0] != None: | 653 if self.Stat(self.cache.external_storage_path)[0] != None: |
636 return True | 654 return True |
637 time.sleep(0.1) | 655 time.sleep(0.1) |
| 656 _LOG.warning('%s.WaitForDevice() failed', self.port_path) |
638 return False | 657 return False |
639 | 658 |
640 def WaitUntilFullyBooted(self, timeout=300): | 659 def WaitUntilFullyBooted(self, timeout=300): |
641 """Waits for the device to be fully started up with network connectivity. | 660 """Waits for the device to be fully started up with network connectivity. |
642 | 661 |
643 Arguments: | 662 Arguments: |
644 - timeout: minimum amount of time to wait for for the device to come up | 663 - 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. | 664 online. It may extend to up to lock_timeout_ms more. |
646 """ | 665 """ |
647 # Wait for the device to respond at all and optionally have lower uptime. | 666 # Wait for the device to respond at all and optionally have lower uptime. |
648 start = time.time() | 667 start = time.time() |
649 if not self.WaitForDevice(timeout): | 668 if not self.WaitForDevice(timeout): |
650 return False | 669 return False |
651 | 670 |
652 # Wait for the internal sys.boot_completed bit to be set. This is the place | 671 # Wait for the internal sys.boot_completed bit to be set. This is the place |
653 # where most time is spent. | 672 # where most time is spent. |
654 while True: | 673 while True: |
655 if (time.time() - start) > timeout: | 674 if (time.time() - start) > timeout: |
| 675 _LOG.warning( |
| 676 '%s.WaitUntilFullyBooted() didn\'t get init.svc.bootanim in time: ' |
| 677 '%r', |
| 678 self.port_path, self.GetProp('init.svc.bootanim')) |
656 return False | 679 return False |
657 if self.GetProp('sys.boot_completed') == '1': | 680 # sys.boot_completed can't be relyed on. It fires too early or worse can |
| 681 # be completely missing on some kernels (e.g. Manta). |
| 682 if self.GetProp('init.svc.bootanim') == 'stopped': |
658 break | 683 break |
659 time.sleep(0.1) | 684 time.sleep(0.1) |
660 | 685 |
661 # Wait for one network to be up and running. | 686 # Wait for one network to be up and running. |
662 while not self.GetIPs(): | 687 while not self.GetIPs(): |
663 if (time.time() - start) > timeout: | 688 if (time.time() - start) > timeout: |
| 689 _LOG.warning( |
| 690 '%s.WaitUntilFullyBooted() didn\'t get an IP in time', |
| 691 self.port_path) |
664 return False | 692 return False |
665 time.sleep(0.1) | 693 time.sleep(0.1) |
666 return True | 694 return True |
667 | 695 |
668 def PushKeys(self): | 696 def PushKeys(self): |
669 """Pushes all the keys on the file system to the device. | 697 """Pushes all the keys on the file system to the device. |
670 | 698 |
671 This is necessary when the device just got wiped but still has | 699 This is necessary when the device just got wiped but still has |
672 authorization, as soon as it reboots it'd lose the authorization. | 700 authorization, as soon as it reboots it'd lose the authorization. |
673 | 701 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 return out | 786 return out |
759 | 787 |
760 @classmethod | 788 @classmethod |
761 def _Connect(cls, constructor, **kwargs): | 789 def _Connect(cls, constructor, **kwargs): |
762 """Called by either ConnectDevice or Connect.""" | 790 """Called by either ConnectDevice or Connect.""" |
763 if not kwargs.get('rsa_keys'): | 791 if not kwargs.get('rsa_keys'): |
764 with _ADB_KEYS_LOCK: | 792 with _ADB_KEYS_LOCK: |
765 kwargs['rsa_keys'] = _ADB_KEYS[:] | 793 kwargs['rsa_keys'] = _ADB_KEYS[:] |
766 device = constructor(**kwargs) | 794 device = constructor(**kwargs) |
767 return HighDevice(device, _InitCache(device)) | 795 return HighDevice(device, _InitCache(device)) |
OLD | NEW |