Commit 5ead9a8a authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: improve command_line tool

This improves the adb_command_line tool as follows:

 * For WebView, throw an exception if someone tries to use this on a
   user device (WebView won't respect the flags anyway)
 * For Chrome, log a warning on user devices (Chrome is slightly more
   relaxed, but usually won't respect flags)
 * Minor refactoring to use already-existing helper methods to add some
   flags (no significant change to behavior here though).

R=agrieve@chromium.org

Bug: 918727
Test: Manual (try to write flags on user and userdebug emulators)
Change-Id: I78dc223bd882fc41d47d19bac6b2b2a26a6a53ac
Reviewed-on: https://chromium-review.googlesource.com/c/1458369
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Auto-Submit: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630131}
parent 9712529a
...@@ -6,14 +6,17 @@ ...@@ -6,14 +6,17 @@
"""Utility for reading / writing command-line flag files on device(s).""" """Utility for reading / writing command-line flag files on device(s)."""
import argparse import argparse
import os import logging
import sys import sys
import devil_chromium import devil_chromium # pylint: disable=import-error, unused-import
from devil.android import device_errors
from devil.android import device_utils from devil.android import device_utils
from devil.android import flag_changer from devil.android import flag_changer
from devil.android.tools import script_common
from devil.utils import cmd_helper from devil.utils import cmd_helper
from devil.utils import logging_common
def main(): def main():
...@@ -25,17 +28,17 @@ Empty string: Deletes command-line file. ...@@ -25,17 +28,17 @@ Empty string: Deletes command-line file.
Otherwise: Writes command-line file. Otherwise: Writes command-line file.
''' '''
parser.add_argument('-d', '--device', dest='devices', action='append',
default=[], help='Target device serial (repeatable).')
parser.add_argument('--name', required=True, parser.add_argument('--name', required=True,
help='Name of file where to store flags on the device.') help='Name of file where to store flags on the device.')
parser.add_argument('-e', '--executable', dest='executable', default='chrome', parser.add_argument('-e', '--executable', dest='executable', default='chrome',
help='(deprecated) No longer used.') help='(deprecated) No longer used.')
parser.add_argument('--adb-path', type=os.path.abspath, script_common.AddEnvironmentArguments(parser)
help='Path to the adb binary.') script_common.AddDeviceArguments(parser)
args, remote_args = parser.parse_known_args() logging_common.AddLoggingArguments(parser)
devil_chromium.Initialize(adb_path=args.adb_path) args, remote_args = parser.parse_known_args()
script_common.InitializeEnvironment(args)
logging_common.InitializeLogging(args)
devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices, devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices,
default_retries=0) default_retries=0)
...@@ -52,7 +55,19 @@ Otherwise: Writes command-line file. ...@@ -52,7 +55,19 @@ Otherwise: Writes command-line file.
else: else:
action = 'Wrote command line file. ' action = 'Wrote command line file. '
is_webview = args.name == 'webview-command-line'
def update_flags(device): def update_flags(device):
if device.IsUserBuild() and is_webview:
raise device_errors.CommandFailedError(
'WebView only respects flags on a userdebug or eng device, yours '
'is a user build.', device)
elif device.IsUserBuild():
logging.warning(
'Your device (%s) is a user build; Chrome may or may not pick up '
'your commandline flags. Check your '
'"command_line_on_non_rooted_enabled" preference, or switch '
'devices.', device)
changer = flag_changer.FlagChanger(device, args.name) changer = flag_changer.FlagChanger(device, args.name)
if remote_args is not None: if remote_args is not None:
flags = changer.ReplaceFlags(remote_args) flags = changer.ReplaceFlags(remote_args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment