[Android] Don't use zip pushing if not built or on user builds.

BUG=422995,423026

Review URL: https://codereview.chromium.org/655723003

Cr-Original-Commit-Position: refs/heads/master@{#299663}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 16e91399723076cc0c5cf8a5348efd1952e84198
This commit is contained in:
jbudorick 2014-10-15 01:24:13 -07:00 коммит произвёл Commit bot
Родитель bc94d1fb17
Коммит ac06a5fa64
6 изменённых файлов: 72 добавлений и 17 удалений

Просмотреть файл

@ -766,6 +766,7 @@
'../breakpad/breakpad.gyp:minidump_dump#host',
'../breakpad/breakpad.gyp:minidump_stackwalk#host',
'../build/android/tests/multiple_proguards/multiple_proguards.gyp:multiple_proguards_test_apk',
'../build/android/pylib/device/commands/commands.gyp:chromium_commands',
'../cc/blink/cc_blink_tests.gyp:cc_blink_unittests',
'../cc/cc_tests.gyp:cc_perftests_apk',
'../cc/cc_tests.gyp:cc_unittests',
@ -830,6 +831,7 @@
'target_name': 'android_builder_chromium_webrtc',
'type': 'none',
'dependencies': [
'../build/android/pylib/device/commands/commands.gyp:chromium_commands',
'../content/content_shell_and_tests.gyp:content_browsertests',
'../tools/android/android_tools.gyp:android_tools',
'../tools/android/android_tools.gyp:memconsumer',

Просмотреть файл

@ -22,10 +22,20 @@ exec app_process $base/bin %s $@
def Installed(device):
return all(device.FileExists('%s/%s' % (BIN_DIR, c)) for c in _COMMANDS)
return (all(device.FileExists('%s/%s' % (BIN_DIR, c)) for c in _COMMANDS)
and device.FileExists('%s/chromium_commands.jar' % _FRAMEWORK_DIR))
def InstallCommands(device):
if device.IsUserBuild():
raise Exception('chromium_commands currently requires a userdebug build.')
chromium_commands_jar_path = os.path.join(
constants.GetOutDirectory(), constants.SDK_BUILD_JAVALIB_DIR,
'chromium_commands.dex.jar')
if not os.path.exists(chromium_commands_jar_path):
raise Exception('%s not found. Please build chromium_commands.'
% chromium_commands_jar_path)
device.RunShellCommand(['mkdir', BIN_DIR, _FRAMEWORK_DIR])
for command, main_class in _COMMANDS.iteritems():
shell_command = _SHELL_COMMAND_FORMAT % (
@ -36,8 +46,6 @@ def InstallCommands(device):
['chmod', '755', shell_file], check_return=True)
device.adb.Push(
os.path.join(constants.GetOutDirectory(),
constants.SDK_BUILD_JAVALIB_DIR,
'chromium_commands.dex.jar'),
chromium_commands_jar_path,
'%s/chromium_commands.jar' % _FRAMEWORK_DIR)

Просмотреть файл

@ -8,6 +8,7 @@ Eventually, this will be based on adb_wrapper.
"""
# pylint: disable=W0613
import logging
import multiprocessing
import os
import pipes
@ -83,7 +84,7 @@ class DeviceUtils(object):
self.old_interface = pylib.android_commands.AndroidCommands()
else:
raise ValueError('Unsupported type passed for argument "device"')
self._commands_installed = False
self._commands_installed = None
self._default_timeout = default_timeout
self._default_retries = default_retries
assert(hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR))
@ -144,6 +145,24 @@ class DeviceUtils(object):
raise device_errors.CommandFailedError(
'Could not enable root.', device=str(self))
@decorators.WithTimeoutAndRetriesFromInstance()
def IsUserBuild(self, timeout=None, retries=None):
"""Checks whether or not the device is running a user build.
Args:
timeout: timeout in seconds
retries: number of retries
Returns:
True if the device is running a user build, False otherwise (i.e. if
it's running a userdebug build).
Raises:
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
return self._GetPropImpl('ro.build.type') == 'user'
@decorators.WithTimeoutAndRetriesFromInstance()
def GetExternalStoragePath(self, timeout=None, retries=None):
"""Get the device's path to its SD card.
@ -528,9 +547,12 @@ class DeviceUtils(object):
len(host_device_tuples), dir_file_count, dir_size, False)
zip_duration = self._ApproximateDuration(1, 1, size, True)
if dir_push_duration < push_duration and dir_push_duration < zip_duration:
self._InstallCommands()
if dir_push_duration < push_duration and (
dir_push_duration < zip_duration or not self._commands_installed):
self._PushChangedFilesIndividually(host_device_tuples)
elif push_duration < zip_duration:
elif push_duration < zip_duration or not self._commands_installed:
self._PushChangedFilesIndividually(files)
else:
self._PushChangedFilesZipped(files)
@ -572,6 +594,16 @@ class DeviceUtils(object):
to_push.append((host_abs_path, device_abs_path))
return to_push
def _InstallCommands(self):
if self._commands_installed is None:
try:
if not install_commands.Installed(self):
install_commands.InstallCommands(self)
self._commands_installed = True
except Exception as e:
logging.warning('unzip not available: %s' % str(e))
self._commands_installed = False
@staticmethod
def _ApproximateDuration(adb_calls, file_count, byte_count, is_zipping):
# We approximate the time to push a set of files to a device as:
@ -613,8 +645,6 @@ class DeviceUtils(object):
if not files:
return
self._InstallCommands()
with tempfile.NamedTemporaryFile(suffix='.zip') as zip_file:
zip_proc = multiprocessing.Process(
target=DeviceUtils._CreateDeviceZip,
@ -635,11 +665,6 @@ class DeviceUtils(object):
if self._IsOnlineImpl():
self._RunShellCommandImpl(['rm', zip_on_device])
def _InstallCommands(self):
if not self._commands_installed and not install_commands.Installed(self):
install_commands.InstallCommands(self)
self._commands_installed = True
@staticmethod
def _CreateDeviceZip(zip_path, host_device_tuples):
with zipfile.ZipFile(zip_path, 'w') as zip_file:
@ -831,6 +856,9 @@ class DeviceUtils(object):
Raises:
CommandTimeoutError on timeout.
"""
return self._GetPropImpl(property_name)
def _GetPropImpl(self, property_name):
return self.old_interface.system_properties[property_name]
@decorators.WithTimeoutAndRetriesFromInstance()

Просмотреть файл

@ -288,6 +288,21 @@ class DeviceUtilsEnableRootTest(DeviceUtilsOldImplTest):
self.device.EnableRoot()
class DeviceUtilsIsUserBuildTest(DeviceUtilsOldImplTest):
def testIsUserBuild_yes(self):
with self.assertCalls(
'adb -s 0123456789abcdef shell getprop ro.build.type',
'user\r\n'):
self.assertTrue(self.device.IsUserBuild())
def testIsUserBuild_no(self):
with self.assertCalls(
'adb -s 0123456789abcdef shell getprop ro.build.type',
'userdebug\r\n'):
self.assertFalse(self.device.IsUserBuild())
class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsOldImplTest):
def testGetExternalStoragePath_succeeds(self):
@ -896,12 +911,12 @@ class DeviceUtilsPushChangedFilesIndividuallyTest(DeviceUtilsNewImplTest):
'/test/host/path/file2', '/test/device/path/file2')
@mock.patch('pylib.device.commands.install_commands.Installed', new=None)
@mock.patch('pylib.device.commands.install_commands.InstallCommands', new=None)
class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsHybridImplTest):
def setUp(self):
super(DeviceUtilsPushChangedFilesZippedTest, self).setUp()
self.original_install_commands = self.device._InstallCommands
self.device._InstallCommands = mock.Mock()
def testPushChangedFilesZipped_empty(self):
test_files = []

Просмотреть файл

@ -436,6 +436,7 @@
},
'dependencies': [
'<(DEPTH)/build/android/setup.gyp:get_build_device_configurations',
'<(DEPTH)/build/android/pylib/device/commands/commands.gyp:chromium_commands',
],
'actions': [
{

Просмотреть файл

@ -15,6 +15,7 @@
{
'dependencies': [
'<(DEPTH)/build/android/pylib/device/commands/commands.gyp:chromium_commands',
'<(DEPTH)/tools/android/android_tools.gyp:android_tools',
],
'variables': {