1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
8 from devil
.android
import device_errors
9 from pylib
import constants
11 BIN_DIR
= '%s/bin' % constants
.TEST_EXECUTABLE_DIR
12 _FRAMEWORK_DIR
= '%s/framework' % constants
.TEST_EXECUTABLE_DIR
15 'unzip': 'org.chromium.android.commands.unzip.Unzip',
18 _SHELL_COMMAND_FORMAT
= (
21 export CLASSPATH=$base/framework/chromium_commands.jar
22 exec app_process $base/bin %s $@
26 def Installed(device
):
27 paths
= [posixpath
.join(BIN_DIR
, c
) for c
in _COMMANDS
]
28 paths
.append(posixpath
.join(_FRAMEWORK_DIR
, 'chromium_commands.jar'))
29 return device
.PathExists(paths
)
32 def InstallCommands(device
):
33 if device
.IsUserBuild():
34 raise device_errors
.CommandFailedError(
35 'chromium_commands currently requires a userdebug build.',
36 device_serial
=device
.adb
.GetDeviceSerial())
38 chromium_commands_jar_path
= os
.path
.join(
39 constants
.GetOutDirectory(), constants
.SDK_BUILD_JAVALIB_DIR
,
40 'chromium_commands.dex.jar')
41 if not os
.path
.exists(chromium_commands_jar_path
):
42 raise device_errors
.CommandFailedError(
43 '%s not found. Please build chromium_commands.'
44 % chromium_commands_jar_path
)
46 device
.RunShellCommand(['mkdir', BIN_DIR
, _FRAMEWORK_DIR
])
47 for command
, main_class
in _COMMANDS
.iteritems():
48 shell_command
= _SHELL_COMMAND_FORMAT
% (
49 constants
.TEST_EXECUTABLE_DIR
, main_class
)
50 shell_file
= '%s/%s' % (BIN_DIR
, command
)
51 device
.WriteFile(shell_file
, shell_command
)
52 device
.RunShellCommand(
53 ['chmod', '755', shell_file
], check_return
=True)
56 chromium_commands_jar_path
,
57 '%s/chromium_commands.jar' % _FRAMEWORK_DIR
)