From 30eacbbc8e12b98500675024db08bb47db18fdb8 Mon Sep 17 00:00:00 2001 From: "primiano@chromium.org" Date: Tue, 10 Sep 2013 21:36:16 +0000 Subject: [PATCH] Telemetry: fix permission check when setting Android command line. This is to fix a bug introduced by r221426 on the WebView telemetry bot. The issue was related to the fact that ls -l can return no output if the target folder exists but is empty. This change makes the IsProtectedFile logic inside _SetCommandLineFile more reliable, introducing the IsFileWritableOnDevice method in adb commands. BUG=284468 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/23477053 git-svn-id: http://src.chromium.org/svn/trunk/src/build@222349 4ff67af0-8c30-449e-8e8b-ad334ec8d88c --- android/pylib/android_commands.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/android/pylib/android_commands.py b/android/pylib/android_commands.py index 66f7bcf63..d8d3be665 100644 --- a/android/pylib/android_commands.py +++ b/android/pylib/android_commands.py @@ -1466,6 +1466,29 @@ class AndroidCommands(object): return False + def IsFileWritableOnDevice(self, file_name): + """Checks whether the given file (or directory) is writable on the device. + + Args: + file_name: Full path of file/directory to check. + + Returns: + True if writable, False otherwise. + """ + assert '"' not in file_name, 'file_name cannot contain double quotes' + try: + status = self._adb.SendShellCommand( + '\'test -w "%s"; echo $?\'' % (file_name)) + if 'test: not found' not in status: + return int(status) == 0 + raise errors.AbortError('"test" binary not found. OS too old.') + + except ValueError: + if IsDeviceAttached(self._device): + raise errors.DeviceUnresponsiveError('Device may be offline.') + + return False + def TakeScreenshot(self, host_file): """Saves a screenshot image to |host_file| on the host.