OLD | NEW |
| (Empty) |
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. | |
4 | |
5 import os | |
6 import posixpath | |
7 | |
8 from devil.android import device_errors | |
9 from pylib import constants | |
10 | |
11 BIN_DIR = '%s/bin' % constants.TEST_EXECUTABLE_DIR | |
12 _FRAMEWORK_DIR = '%s/framework' % constants.TEST_EXECUTABLE_DIR | |
13 | |
14 _COMMANDS = { | |
15 'unzip': 'org.chromium.android.commands.unzip.Unzip', | |
16 } | |
17 | |
18 _SHELL_COMMAND_FORMAT = ( | |
19 """#!/system/bin/sh | |
20 base=%s | |
21 export CLASSPATH=$base/framework/chromium_commands.jar | |
22 exec app_process $base/bin %s $@ | |
23 """) | |
24 | |
25 | |
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) | |
30 | |
31 | |
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()) | |
37 | |
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) | |
45 | |
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) | |
54 | |
55 device.adb.Push( | |
56 chromium_commands_jar_path, | |
57 '%s/chromium_commands.jar' % _FRAMEWORK_DIR) | |
58 | |
OLD | NEW |