| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
| 6 | 6 |
| 7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
| 8 """ | 8 """ |
| 9 # pylint: disable-all | 9 # pylint: disable-all |
| 10 | 10 |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 'SD card not ready after %s seconds' % timeout_time) | 649 'SD card not ready after %s seconds' % timeout_time) |
| 650 | 650 |
| 651 def _CheckCommandIsValid(self, command): | 651 def _CheckCommandIsValid(self, command): |
| 652 """Raises a ValueError if the command is not valid.""" | 652 """Raises a ValueError if the command is not valid.""" |
| 653 | 653 |
| 654 # A dict of commands the user should not run directly and a mapping to the | 654 # A dict of commands the user should not run directly and a mapping to the |
| 655 # API they should use instead. | 655 # API they should use instead. |
| 656 preferred_apis = { | 656 preferred_apis = { |
| 657 'getprop': 'system_properties[<PROPERTY>]', | 657 'getprop': 'system_properties[<PROPERTY>]', |
| 658 'setprop': 'system_properties[<PROPERTY>]', | 658 'setprop': 'system_properties[<PROPERTY>]', |
| 659 'su': 'RunShellCommandWithSU()', | |
| 660 } | 659 } |
| 661 | 660 |
| 662 # A dict of commands to methods that may call them. | 661 # A dict of commands to methods that may call them. |
| 663 whitelisted_callers = { | 662 whitelisted_callers = { |
| 664 'su': 'RunShellCommandWithSU', | |
| 665 'getprop': 'ProvisionDevices', | 663 'getprop': 'ProvisionDevices', |
| 666 } | 664 } |
| 667 | 665 |
| 668 base_command = shlex.split(command)[0].strip(';') | 666 base_command = shlex.split(command)[0].strip(';') |
| 669 if (base_command in preferred_apis and | 667 if (base_command in preferred_apis and |
| 670 (base_command not in whitelisted_callers or | 668 (base_command not in whitelisted_callers or |
| 671 whitelisted_callers[base_command] not in [ | 669 whitelisted_callers[base_command] not in [ |
| 672 f[3] for f in inspect.stack()])): | 670 f[3] for f in inspect.stack()])): |
| 673 error_msg = ('%s should not be run directly. Instead use: %s' % | 671 error_msg = ('%s should not be run directly. Instead use: %s' % |
| 674 (base_command, preferred_apis[base_command])) | 672 (base_command, preferred_apis[base_command])) |
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 """ | 1983 """ |
| 1986 def __init__(self, output): | 1984 def __init__(self, output): |
| 1987 self._output = output | 1985 self._output = output |
| 1988 | 1986 |
| 1989 def write(self, data): | 1987 def write(self, data): |
| 1990 data = data.replace('\r\r\n', '\n') | 1988 data = data.replace('\r\r\n', '\n') |
| 1991 self._output.write(data) | 1989 self._output.write(data) |
| 1992 | 1990 |
| 1993 def flush(self): | 1991 def flush(self): |
| 1994 self._output.flush() | 1992 self._output.flush() |
| OLD | NEW |