Index: build/android/pylib/android_commands.py |
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py |
index fcf97a859ed139a3bbeb91c71d7ae0ab7387b0c3..d0e441655518fb627e236e6c050ec1e3d1dc2403 100644 |
--- a/build/android/pylib/android_commands.py |
+++ b/build/android/pylib/android_commands.py |
@@ -150,7 +150,7 @@ def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): |
if file_match: |
filename = os.path.join(current_dir, file_match.group('filename')) |
if filename.startswith(path_dir): |
- filename = filename[len(path_dir)+1:] |
+ filename = filename[len(path_dir) + 1:] |
lastmod = datetime.datetime.strptime( |
file_match.group('date') + ' ' + file_match.group('time')[:5], |
'%Y-%m-%d %H:%M') |
@@ -226,12 +226,16 @@ class AndroidCommands(object): |
True: if output from executing adb root was as expected. |
False: otherwise. |
""" |
- return_value = self._adb.EnableAdbRoot() |
- # EnableAdbRoot inserts a call for wait-for-device only when adb logcat |
- # output matches what is expected. Just to be safe add a call to |
- # wait-for-device. |
- self._adb.SendCommand('wait-for-device') |
- return return_value |
+ if self.GetBuildType() == 'user': |
+ logging.warning("Can't enable root in production builds with type user") |
+ return False |
+ else: |
+ return_value = self._adb.EnableAdbRoot() |
+ # EnableAdbRoot inserts a call for wait-for-device only when adb logcat |
+ # output matches what is expected. Just to be safe add a call to |
+ # wait-for-device. |
+ self._adb.SendCommand('wait-for-device') |
+ return return_value |
def GetDeviceYear(self): |
"""Returns the year information of the date on device.""" |
@@ -328,7 +332,9 @@ class AndroidCommands(object): |
install_cmd = ' '.join(install_cmd) |
logging.info('>>> $' + install_cmd) |
- return self._adb.SendCommand(install_cmd, timeout_time=2*60, retry_count=0) |
+ return self._adb.SendCommand(install_cmd, |
+ timeout_time=2 * 60, |
+ retry_count=0) |
def ManagedInstall(self, apk_path, keep_data=False, package_name=None, |
reboots_on_failure=2): |
@@ -636,14 +642,14 @@ class AndroidCommands(object): |
# They don't match, so remove everything first and then create it. |
if os.path.isdir(local_path): |
- self.RunShellCommand('rm -r %s' % device_path, timeout_time=2*60) |
+ self.RunShellCommand('rm -r %s' % device_path, timeout_time=2 * 60) |
self.RunShellCommand('mkdir -p %s' % device_path) |
# NOTE: We can't use adb_interface.Push() because it hardcodes a timeout of |
# 60 seconds which isn't sufficient for a lot of users of this method. |
push_command = 'push %s %s' % (local_path, device_path) |
logging.info('>>> $' + push_command) |
- output = self._adb.SendCommand(push_command, timeout_time=30*60) |
+ output = self._adb.SendCommand(push_command, timeout_time=30 * 60) |
assert _HasAdbPushSucceeded(output) |
@@ -659,10 +665,38 @@ class AndroidCommands(object): |
f.flush() |
self._adb.Push(f.name, filename) |
+ _TEMP_FILE_BASE = 'temp_file_%d' |
+ _TEMP_SCRIPT_FILE_BASE = 'temp_script_file_%d.sh' |
+ |
+ def _GetDeviceTempFileName(self, base_name): |
+ i = 0 |
+ while self.FileExistsOnDevice( |
+ self.GetExternalStorage() + '/' + base_name % i): |
bulach
2013/01/16 19:11:05
since base_name is required to be a format and thi
aberent
2013/01/17 17:18:06
Will add format, but can't use _TEMP_FILE_BASE(_FM
|
+ i += 1 |
+ return self.GetExternalStorage() + '/' + base_name % i |
+ |
+ def SetProtectedFileContents(self, filename, contents): |
+ """Writes |contents| to the file specified by |filename|. |
bulach
2013/01/16 19:11:05
nit: add a \n (python style requires a one-line do
aberent
2013/01/17 17:18:06
Done.
|
+ This is less efficient than SetFileContents, but will |
+ work for protected files and device files.""" |
+ temp_file = self._GetDeviceTempFileName(AndroidCommands._TEMP_FILE_BASE) |
+ temp_script = self._GetDeviceTempFileName( |
+ AndroidCommands._TEMP_SCRIPT_FILE_BASE) |
+ |
+ # Put the contents in a temporary file |
+ self.SetFileContents(temp_file, contents) |
+ # Create a script to copy the file contents to its final destination |
+ self.SetFileContents(temp_script, 'cat %s > %s' % (temp_file, filename)) |
+ # Run the script as root |
+ self.RunShellCommand('su -c sh %s' % temp_script) |
+ # And remove the temporary files |
+ self.RunShellCommand('rm ' + temp_file) |
+ self.RunShellCommand('rm ' + temp_script) |
+ |
def RemovePushedFiles(self): |
"""Removes all files pushed with PushIfNeeded() from the device.""" |
for p in self._pushed_files: |
- self.RunShellCommand('rm -r %s' % p, timeout_time=2*60) |
+ self.RunShellCommand('rm -r %s' % p, timeout_time=2 * 60) |
def ListPathContents(self, path): |
"""Lists files in all subdirectories of |path|. |