OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 | 6 |
| 7 from devil.android import device_errors |
7 from pylib import constants | 8 from pylib import constants |
8 | 9 |
9 BIN_DIR = '%s/bin' % constants.TEST_EXECUTABLE_DIR | 10 BIN_DIR = '%s/bin' % constants.TEST_EXECUTABLE_DIR |
10 _FRAMEWORK_DIR = '%s/framework' % constants.TEST_EXECUTABLE_DIR | 11 _FRAMEWORK_DIR = '%s/framework' % constants.TEST_EXECUTABLE_DIR |
11 | 12 |
12 _COMMANDS = { | 13 _COMMANDS = { |
13 'unzip': 'org.chromium.android.commands.unzip.Unzip', | 14 'unzip': 'org.chromium.android.commands.unzip.Unzip', |
14 } | 15 } |
15 | 16 |
16 _SHELL_COMMAND_FORMAT = ( | 17 _SHELL_COMMAND_FORMAT = ( |
17 """#!/system/bin/sh | 18 """#!/system/bin/sh |
18 base=%s | 19 base=%s |
19 export CLASSPATH=$base/framework/chromium_commands.jar | 20 export CLASSPATH=$base/framework/chromium_commands.jar |
20 exec app_process $base/bin %s $@ | 21 exec app_process $base/bin %s $@ |
21 """) | 22 """) |
22 | 23 |
23 | 24 |
24 def Installed(device): | 25 def Installed(device): |
25 return (all(device.FileExists('%s/%s' % (BIN_DIR, c)) for c in _COMMANDS) | 26 return (all(device.FileExists('%s/%s' % (BIN_DIR, c)) for c in _COMMANDS) |
26 and device.FileExists('%s/chromium_commands.jar' % _FRAMEWORK_DIR)) | 27 and device.FileExists('%s/chromium_commands.jar' % _FRAMEWORK_DIR)) |
27 | 28 |
28 def InstallCommands(device): | 29 def InstallCommands(device): |
29 if device.IsUserBuild(): | 30 if device.IsUserBuild(): |
30 raise Exception('chromium_commands currently requires a userdebug build.') | 31 raise device_errors.CommandFailedError( |
| 32 'chromium_commands currently requires a userdebug build.', |
| 33 device_serial=device.GetDeviceSerial()) |
31 | 34 |
32 chromium_commands_jar_path = os.path.join( | 35 chromium_commands_jar_path = os.path.join( |
33 constants.GetOutDirectory(), constants.SDK_BUILD_JAVALIB_DIR, | 36 constants.GetOutDirectory(), constants.SDK_BUILD_JAVALIB_DIR, |
34 'chromium_commands.dex.jar') | 37 'chromium_commands.dex.jar') |
35 if not os.path.exists(chromium_commands_jar_path): | 38 if not os.path.exists(chromium_commands_jar_path): |
36 raise Exception('%s not found. Please build chromium_commands.' | 39 raise device_errors.CommandFailedError( |
37 % chromium_commands_jar_path) | 40 '%s not found. Please build chromium_commands.' |
| 41 % chromium_commands_jar_path) |
38 | 42 |
39 device.RunShellCommand(['mkdir', BIN_DIR, _FRAMEWORK_DIR]) | 43 device.RunShellCommand(['mkdir', BIN_DIR, _FRAMEWORK_DIR]) |
40 for command, main_class in _COMMANDS.iteritems(): | 44 for command, main_class in _COMMANDS.iteritems(): |
41 shell_command = _SHELL_COMMAND_FORMAT % ( | 45 shell_command = _SHELL_COMMAND_FORMAT % ( |
42 constants.TEST_EXECUTABLE_DIR, main_class) | 46 constants.TEST_EXECUTABLE_DIR, main_class) |
43 shell_file = '%s/%s' % (BIN_DIR, command) | 47 shell_file = '%s/%s' % (BIN_DIR, command) |
44 device.WriteFile(shell_file, shell_command) | 48 device.WriteFile(shell_file, shell_command) |
45 device.RunShellCommand( | 49 device.RunShellCommand( |
46 ['chmod', '755', shell_file], check_return=True) | 50 ['chmod', '755', shell_file], check_return=True) |
47 | 51 |
48 device.adb.Push( | 52 device.adb.Push( |
49 chromium_commands_jar_path, | 53 chromium_commands_jar_path, |
50 '%s/chromium_commands.jar' % _FRAMEWORK_DIR) | 54 '%s/chromium_commands.jar' % _FRAMEWORK_DIR) |
51 | 55 |
OLD | NEW |