15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#!/bin/bash
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Copyright (c) 2012 The Chromium Authors. All rights reserved.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# found in the LICENSE file.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# If no flags are given, prints the current content shell flags.
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Otherwise, the given flags are used to REPLACE (not modify) the content shell
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# flags. For example:
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#   adb_content_shell_command_line --enable-webgl
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# To remove all content shell flags, pass an empty string for the flags:
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#   adb_content_shell_command_line ""
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CMD_LINE_FILE=/data/local/tmp/content-shell-command-line
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if [ $# -eq 0 ] ; then
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # If nothing specified, print the command line (stripping off "content_shell")
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tempfile=$(tempfile)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  adb pull $CMD_LINE_FILE $tempfile 2>/dev/null
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if [ $? -eq 0 ] ; then
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    rm $tempfile
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    adb shell cat $CMD_LINE_FILE | cut -d " " -f "2-" 2>/dev/null
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  fi
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)elif [ $# -eq 1 ] && [ "$1" = '' ] ; then
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # If given an empty string, delete the command line.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  set -x
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  adb shell rm $CMD_LINE_FILE >/dev/null
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)else
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # Else set it.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  set -x
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  adb shell "echo 'content_shell $*' > $CMD_LINE_FILE"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  # Prevent other apps from modifying flags -- this can create security issues.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  adb shell chmod 0664 $CMD_LINE_FILE
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)fi
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
38