• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5import os
6import posixpath
7
8from devil import devil_env
9from devil.android import device_errors
10from devil.android.constants import file_system
11
12BIN_DIR = '%s/bin' % file_system.TEST_EXECUTABLE_DIR
13_FRAMEWORK_DIR = '%s/framework' % file_system.TEST_EXECUTABLE_DIR
14
15_COMMANDS = {
16    'unzip': 'org.chromium.android.commands.unzip.Unzip',
17}
18
19_SHELL_COMMAND_FORMAT = ("""#!/system/bin/sh
20base=%s
21export CLASSPATH=$base/framework/chromium_commands.jar
22exec app_process $base/bin %s $@
23""")
24
25
26def 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
32def 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 = devil_env.config.FetchPath('chromium_commands')
39  if not os.path.exists(chromium_commands_jar_path):
40    raise device_errors.CommandFailedError(
41        '%s not found. Please build chromium_commands.' %
42        chromium_commands_jar_path)
43
44  device.RunShellCommand(['mkdir', '-p', BIN_DIR, _FRAMEWORK_DIR],
45                         check_return=True)
46  for command, main_class in _COMMANDS.iteritems():
47    shell_command = _SHELL_COMMAND_FORMAT % (file_system.TEST_EXECUTABLE_DIR,
48                                             main_class)
49    shell_file = '%s/%s' % (BIN_DIR, command)
50    device.WriteFile(shell_file, shell_command)
51    device.RunShellCommand(['chmod', '755', shell_file], check_return=True)
52
53  device.adb.Push(chromium_commands_jar_path,
54                  '%s/chromium_commands.jar' % _FRAMEWORK_DIR)
55