summaryrefslogtreecommitdiffstats
path: root/build/android
diff options
context:
space:
mode:
authoragrieve <agrieve@chromium.org>2015-06-01 13:52:43 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-01 20:53:18 +0000
commitc481d6771df7cfd731ab174b561388fca8596ce1 (patch)
tree6ebae63d3b98d795c1791b60e1fcb757e645fe8b /build/android
parentf6177a015283f56441b72fe08eabacce3a950f7d (diff)
downloadchromium_src-c481d6771df7cfd731ab174b561388fca8596ce1.zip
chromium_src-c481d6771df7cfd731ab174b561388fca8596ce1.tar.gz
chromium_src-c481d6771df7cfd731ab174b561388fca8596ce1.tar.bz2
Fix adb_chrome_public_command_line for Android M & refactor into a helper .sh
BUG=493878 Review URL: https://codereview.chromium.org/1165753002 Cr-Commit-Position: refs/heads/master@{#332263}
Diffstat (limited to 'build/android')
-rwxr-xr-xbuild/android/adb_android_webview_command_line23
-rwxr-xr-xbuild/android/adb_chrome_public_command_line24
-rwxr-xr-xbuild/android/adb_chrome_shell_command_line23
-rwxr-xr-xbuild/android/adb_command_line_functions.sh40
-rwxr-xr-xbuild/android/adb_content_shell_command_line23
5 files changed, 52 insertions, 81 deletions
diff --git a/build/android/adb_android_webview_command_line b/build/android/adb_android_webview_command_line
index 947cfb1..791e270 100755
--- a/build/android/adb_android_webview_command_line
+++ b/build/android/adb_android_webview_command_line
@@ -13,25 +13,8 @@
# 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
-
-if [ $# -eq 0 ] ; then
- # If nothing specified, print the command line (stripping off "content_shell")
- tempfile=$(tempfile)
- adb pull $CMD_LINE_FILE $tempfile 2>/dev/null
- if [ $? -eq 0 ] ; then
- rm $tempfile
- adb shell cat $CMD_LINE_FILE | cut -d " " -f "2-" 2>/dev/null
- fi
-elif [ $# -eq 1 ] && [ "$1" = '' ] ; then
- # If given an empty string, delete the command line.
- set -x
- adb shell rm $CMD_LINE_FILE >/dev/null
-else
- # Else set it.
- set -x
- adb shell "echo 'android_webview $*' > $CMD_LINE_FILE"
- # Prevent other apps from modifying flags -- this can create security issues.
- adb shell chmod 0664 $CMD_LINE_FILE
-fi
+REQUIRES_SU=0
+set_command_line "$@"
diff --git a/build/android/adb_chrome_public_command_line b/build/android/adb_chrome_public_command_line
index efbd6ff..9bf91c6 100755
--- a/build/android/adb_chrome_public_command_line
+++ b/build/android/adb_chrome_public_command_line
@@ -13,25 +13,7 @@
# 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
-
-if [ $# -eq 0 ] ; then
- # If nothing specified, print the command line (stripping off "chrome")
- tempfile=$(tempfile)
- adb pull $CMD_LINE_FILE $tempfile 2>/dev/null
- if [ $? -eq 0 ] ; then
- rm $tempfile
- adb shell cat $CMD_LINE_FILE | cut -d " " -f "2-" 2>/dev/null
- fi
-elif [ $# -eq 1 ] && [ "$1" = '' ] ; then
- # If given an empty string, delete the command line.
- set -x
- adb shell su -c rm $CMD_LINE_FILE >/dev/null
-else
- # Else set it.
- set -x
- adb shell "echo 'chrome $*' | su -c dd of=$CMD_LINE_FILE"
- # Prevent other apps from modifying flags -- this can create security issues.
- adb shell su -c chmod 0664 $CMD_LINE_FILE
-fi
-
+REQUIRES_SU=1
+set_command_line "$@"
diff --git a/build/android/adb_chrome_shell_command_line b/build/android/adb_chrome_shell_command_line
index 1e2bd38..750f906 100755
--- a/build/android/adb_chrome_shell_command_line
+++ b/build/android/adb_chrome_shell_command_line
@@ -13,25 +13,8 @@
# To remove all chrome shell flags, pass an empty string for the flags:
# adb_chrome_shell_command_line ""
+. $(dirname $0)/adb_command_line_functions.sh
CMD_LINE_FILE=/data/local/tmp/chrome-shell-command-line
-
-if [ $# -eq 0 ] ; then
- # If nothing specified, print the command line (stripping off "chrome_shell")
- tempfile=$(tempfile)
- adb pull $CMD_LINE_FILE $tempfile 2>/dev/null
- if [ $? -eq 0 ] ; then
- rm $tempfile
- adb shell cat $CMD_LINE_FILE | cut -d " " -f "2-" 2>/dev/null
- fi
-elif [ $# -eq 1 ] && [ "$1" = '' ] ; then
- # If given an empty string, delete the command line.
- set -x
- adb shell rm $CMD_LINE_FILE >/dev/null
-else
- # Else set it.
- set -x
- adb shell "echo 'chrome_shell $*' > $CMD_LINE_FILE"
- # Prevent other apps from modifying flags -- this can create security issues.
- adb shell chmod 0664 $CMD_LINE_FILE
-fi
+REQUIRES_SU=0
+set_command_line "$@"
diff --git a/build/android/adb_command_line_functions.sh b/build/android/adb_command_line_functions.sh
new file mode 100755
index 0000000..8a77009
--- /dev/null
+++ b/build/android/adb_command_line_functions.sh
@@ -0,0 +1,40 @@
+#!/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 f3c1d4f..2ac7ece 100755
--- a/build/android/adb_content_shell_command_line
+++ b/build/android/adb_content_shell_command_line
@@ -13,25 +13,8 @@
# 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
-
-if [ $# -eq 0 ] ; then
- # If nothing specified, print the command line (stripping off "content_shell")
- tempfile=$(tempfile)
- adb pull $CMD_LINE_FILE $tempfile 2>/dev/null
- if [ $? -eq 0 ] ; then
- rm $tempfile
- adb shell cat $CMD_LINE_FILE | cut -d " " -f "2-" 2>/dev/null
- fi
-elif [ $# -eq 1 ] && [ "$1" = '' ] ; then
- # If given an empty string, delete the command line.
- set -x
- adb shell rm $CMD_LINE_FILE >/dev/null
-else
- # Else set it.
- set -x
- adb shell "echo 'content_shell $*' > $CMD_LINE_FILE"
- # Prevent other apps from modifying flags -- this can create security issues.
- adb shell chmod 0664 $CMD_LINE_FILE
-fi
+REQUIRES_SU=0
+set_command_line "$@"