diff options
author | agrieve <agrieve@chromium.org> | 2015-11-24 07:23:18 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-24 15:24:20 +0000 |
commit | d7c8cc052f46bc38cb7eb5fafda396b8c2e3cd0c (patch) | |
tree | a3e7a1991cdb246e29f090213133537135a81464 | |
parent | 122f84f37a2ff865c3e76ff99280b24da8f2a2f9 (diff) | |
download | chromium_src-d7c8cc052f46bc38cb7eb5fafda396b8c2e3cd0c.zip chromium_src-d7c8cc052f46bc38cb7eb5fafda396b8c2e3cd0c.tar.gz chromium_src-d7c8cc052f46bc38cb7eb5fafda396b8c2e3cd0c.tar.bz2 |
Refactor adb_*_command_line helpers bash->python
* Now targets all devices by default rather than failing
* Allows --device flag to target a specific device
BUG=
Review URL: https://codereview.chromium.org/1469143002
Cr-Commit-Position: refs/heads/master@{#361343}
-rwxr-xr-x | build/android/adb_android_webview_command_line | 7 | ||||
-rwxr-xr-x | build/android/adb_blimp_command_line | 6 | ||||
-rwxr-xr-x | build/android/adb_chrome_public_command_line | 6 | ||||
-rwxr-xr-x | build/android/adb_command_line.py | 83 | ||||
-rwxr-xr-x | build/android/adb_command_line_functions.sh | 40 | ||||
-rwxr-xr-x | build/android/adb_content_shell_command_line | 7 | ||||
-rwxr-xr-x | build/android/adb_system_webview_command_line | 7 |
7 files changed, 93 insertions, 63 deletions
diff --git a/build/android/adb_android_webview_command_line b/build/android/adb_android_webview_command_line index 791e270..9075918 100755 --- a/build/android/adb_android_webview_command_line +++ b/build/android/adb_android_webview_command_line @@ -13,8 +13,5 @@ # To remove all content shell flags, pass an empty string for the flags: # adb_android_webview_command_line "" -. $(dirname $0)/adb_command_line_functions.sh -CMD_LINE_FILE=/data/local/tmp/android-webview-command-line -REQUIRES_SU=0 -set_command_line "$@" - +exec $(dirname $0)/adb_command_line.py --device-path \ + /data/local/tmp/android-webview-command-line "$@" diff --git a/build/android/adb_blimp_command_line b/build/android/adb_blimp_command_line index 2050ead..1ff3769 100755 --- a/build/android/adb_blimp_command_line +++ b/build/android/adb_blimp_command_line @@ -13,7 +13,5 @@ # To remove all Blimp flags, pass an empty string for the flags: # adb_blimp_command_line "" -. $(dirname $0)/adb_command_line_functions.sh -CMD_LINE_FILE=/data/local/blimp-command-line -REQUIRES_SU=1 -set_command_line "$@" +exec $(dirname $0)/adb_command_line.py --device-path \ + /data/local/blimp-command-line "$@" diff --git a/build/android/adb_chrome_public_command_line b/build/android/adb_chrome_public_command_line index 9bf91c6..ac379e8 100755 --- a/build/android/adb_chrome_public_command_line +++ b/build/android/adb_chrome_public_command_line @@ -13,7 +13,5 @@ # To remove all Chrome flags, pass an empty string for the flags: # adb_chrome_public_command_line "" -. $(dirname $0)/adb_command_line_functions.sh -CMD_LINE_FILE=/data/local/chrome-command-line -REQUIRES_SU=1 -set_command_line "$@" +exec $(dirname $0)/adb_command_line.py --device-path \ + /data/local/chrome-command-line "$@" diff --git a/build/android/adb_command_line.py b/build/android/adb_command_line.py new file mode 100755 index 0000000..fa3a82b --- /dev/null +++ b/build/android/adb_command_line.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Utility for reading / writing command-line flag files on device(s).""" + +import argparse +import sys + +from devil.android import device_utils +from devil.android import device_errors +from devil.utils import cmd_helper + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.usage = '''%(prog)s --device-path PATH [--device SERIAL] [flags...] + +No flags: Prints existing command-line file. +Empty string: Deletes command-line file. +Otherwise: Writes command-line file. + +''' + parser.add_argument('-d', '--device', dest='device', + help='Target device for apk to install on.') + parser.add_argument('--device-path', required=True, + help='Remote path to flags file.') + args, remote_args = parser.parse_known_args() + + as_root = not args.device_path.startswith('/data/local/tmp/') + + if args.device: + devices = [device_utils.DeviceUtils(args.device, default_retries=0)] + else: + devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0) + if not devices: + raise device_errors.NoDevicesError() + + all_devices = device_utils.DeviceUtils.parallel(devices) + + def print_args(): + def read_flags(device): + try: + return device.ReadFile(args.device_path, as_root=as_root) + except device_errors.AdbCommandFailedError: + return '\n' # File might not exist. + + descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None) + flags = all_devices.pMap(read_flags).pGet(None) + for d, desc, flags in zip(devices, descriptions, flags): + print ' %s (%s): %s' % (d, desc, flags), + + # No args == print flags. + if not remote_args: + print 'Existing flags (in %s):' % args.device_path + print_args() + return 0 + + # Empty string arg == delete flags file. + if len(remote_args) == 1 and not remote_args[0]: + def delete_flags(device): + device.RunShellCommand(['rm', '-f', args.device_path], as_root=as_root) + all_devices.pMap(delete_flags).pGet(None) + print 'Deleted %s' % args.device_path + return 0 + + # Set flags. + quoted_args = ' '.join(cmd_helper.SingleQuote(x) for x in remote_args) + flags_str = 'chrome %s' % quoted_args + + def write_flags(device): + device.WriteFile(args.device_path, flags_str, as_root=as_root) + device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root) + + all_devices.pMap(write_flags).pGet(None) + print 'Wrote flags to %s' % args.device_path + print_args() + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/build/android/adb_command_line_functions.sh b/build/android/adb_command_line_functions.sh deleted file mode 100755 index 7ea98b0..0000000 --- a/build/android/adb_command_line_functions.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Variables must be set before calling: -# CMD_LINE_FILE - Path on device to flags file. -# REQUIRES_SU - Set to 1 if path requires root. -function set_command_line() { - SU_CMD="" - if [[ "$REQUIRES_SU" = 1 ]]; then - # Older androids accept "su -c", while newer use "su uid". - SDK_LEVEL=$(adb shell getprop ro.build.version.sdk | tr -d '\r') - # E.g. if no device connected. - if [[ -z "$SDK_LEVEL" ]]; then - exit 1 - fi - SU_CMD="su -c" - if (( $SDK_LEVEL >= 21 )); then - SU_CMD="su 0" - fi - fi - - if [ $# -eq 0 ] ; then - # If nothing specified, print the command line (stripping off "chrome ") - adb shell "cat $CMD_LINE_FILE 2>/dev/null" | cut -d ' ' -s -f2- - elif [ $# -eq 1 ] && [ "$1" = '' ] ; then - # If given an empty string, delete the command line. - set -x - adb shell $SU_CMD rm $CMD_LINE_FILE >/dev/null - else - # Else set it. - set -x - adb shell "echo 'chrome $*' | $SU_CMD dd of=$CMD_LINE_FILE" - # Prevent other apps from modifying flags (this can create security issues). - adb shell $SU_CMD chmod 0664 $CMD_LINE_FILE - fi -} - diff --git a/build/android/adb_content_shell_command_line b/build/android/adb_content_shell_command_line index 2ac7ece..02ef802 100755 --- a/build/android/adb_content_shell_command_line +++ b/build/android/adb_content_shell_command_line @@ -13,8 +13,5 @@ # To remove all content shell flags, pass an empty string for the flags: # adb_content_shell_command_line "" -. $(dirname $0)/adb_command_line_functions.sh -CMD_LINE_FILE=/data/local/tmp/content-shell-command-line -REQUIRES_SU=0 -set_command_line "$@" - +exec $(dirname $0)/adb_command_line.py --device-path \ + /data/local/tmp/content-shell-command-line "$@" diff --git a/build/android/adb_system_webview_command_line b/build/android/adb_system_webview_command_line index a0658ea..376b0b3 100755 --- a/build/android/adb_system_webview_command_line +++ b/build/android/adb_system_webview_command_line @@ -13,8 +13,5 @@ # To remove all content shell flags, pass an empty string for the flags: # adb_android_webview_command_line "" -. $(dirname $0)/adb_command_line_functions.sh -CMD_LINE_FILE=/data/local/tmp/webview-command-line -REQUIRES_SU=0 -set_command_line "$@" - +exec $(dirname $0)/adb_command_line.py --device-path \ + /data/local/tmp/webview-command-line "$@" |