Update from https://crrev.com/320931
- Add IsFlat() definition to ui/gfx/transform
- Change sky's uses of skia's FilterLevel to FilterQuality
- Update cc_strip_video.patch

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/1013463003
diff --git a/build/android/gyp/javac.py b/build/android/gyp/javac.py
index 3738062..a0fcda8 100755
--- a/build/android/gyp/javac.py
+++ b/build/android/gyp/javac.py
@@ -80,7 +80,8 @@
       '-classpath', ':'.join(classpath),
       '-d', classes_dir]
   if chromium_code:
-    javac_args.extend(['-Xlint:unchecked', '-Xlint:deprecation'])
+    # TODO(aurimas): re-enable '-Xlint:deprecation' checks once they are fixed.
+    javac_args.extend(['-Xlint:unchecked'])
   else:
     # XDignore.symbol.file makes javac compile against rt.jar instead of
     # ct.sym. This means that using a java internal package/class will not
diff --git a/build/android/gyp/package_resources.py b/build/android/gyp/package_resources.py
index 9b6ec68..2251de0 100755
--- a/build/android/gyp/package_resources.py
+++ b/build/android/gyp/package_resources.py
@@ -100,11 +100,11 @@
   multiple targets. If it is multiple targets merged into one, the actual
   resource directories will be contained in the subdirectories 0, 1, 2, ...
   """
-  res_dirs = []
   subdirs = [os.path.join(d, s) for s in os.listdir(d)]
-  subdirs = sorted([s for s in subdirs if os.path.isdir(s)])
-  if subdirs and os.path.basename(subdirs[0]) == '0':
-    res_dirs = subdirs
+  subdirs = [s for s in subdirs if os.path.isdir(s)]
+  is_multi = '0' in [os.path.basename(s) for s in subdirs]
+  if is_multi:
+    res_dirs = sorted(subdirs, key=lambda p : int(os.path.basename(p)))
   else:
     res_dirs = [d]
   package_command = []
diff --git a/build/android/gyp/write_build_config.py b/build/android/gyp/write_build_config.py
index bf887e3..5fc8955 100755
--- a/build/android/gyp/write_build_config.py
+++ b/build/android/gyp/write_build_config.py
@@ -139,6 +139,9 @@
 
   direct_resources_deps = DepsOfType('android_resources', direct_deps_configs)
   all_resources_deps = DepsOfType('android_resources', all_deps_configs)
+  # Resources should be ordered with the highest-level dependency first so that
+  # overrides are done correctly.
+  all_resources_deps.reverse()
 
   # Initialize some common config.
   config = {
diff --git a/build/android/pylib/constants.py b/build/android/pylib/constants.py
index b849a8d..34dbf19 100644
--- a/build/android/pylib/constants.py
+++ b/build/android/pylib/constants.py
@@ -167,9 +167,10 @@
   KITKAT = 19
   KITKAT_WATCH = 20
   LOLLIPOP = 21
+  LOLLIPOP_MR1 = 22
 
-ANDROID_SDK_VERSION = ANDROID_SDK_VERSION_CODES.LOLLIPOP
-ANDROID_SDK_BUILD_TOOLS_VERSION = '21.0.1'
+ANDROID_SDK_VERSION = ANDROID_SDK_VERSION_CODES.LOLLIPOP_MR1
+ANDROID_SDK_BUILD_TOOLS_VERSION = '22.0.0'
 ANDROID_SDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
                                 'third_party/android_tools/sdk')
 ANDROID_SDK_TOOLS = os.path.join(ANDROID_SDK_ROOT,
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py
index b6fd732..292752a 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -13,7 +13,9 @@
 import logging
 import multiprocessing
 import os
+import posixpath
 import re
+import shutil
 import sys
 import tempfile
 import time
@@ -129,6 +131,7 @@
 class DeviceUtils(object):
 
   _MAX_ADB_COMMAND_LENGTH = 512
+  _MAX_ADB_OUTPUT_LENGTH = 32768
   _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')
 
   # Property in /data/local.prop that controls Java assertions.
@@ -937,6 +940,21 @@
       os.makedirs(dirname)
     self.adb.Pull(device_path, host_path)
 
+  def _ReadFileWithPull(self, device_path):
+    try:
+      d = tempfile.mkdtemp()
+      host_temp_path = os.path.join(d, 'tmp_ReadFileWithPull')
+      self.adb.Pull(device_path, host_temp_path)
+      with open(host_temp_path, 'r') as host_temp:
+        return host_temp.read()
+    finally:
+      if os.path.exists(d):
+        shutil.rmtree(d)
+
+  _LS_RE = re.compile(
+      r'(?P<perms>\S+) +(?P<owner>\S+) +(?P<group>\S+) +(?:(?P<size>\d+) +)?'
+      + r'(?P<date>\S+) +(?P<time>\S+) +(?P<name>.+)$')
+
   @decorators.WithTimeoutAndRetriesFromInstance()
   def ReadFile(self, device_path, as_root=False,
                timeout=None, retries=None):
@@ -960,8 +978,29 @@
       CommandTimeoutError on timeout.
       DeviceUnreachableError on missing device.
     """
-    return _JoinLines(self.RunShellCommand(
-        ['cat', device_path], as_root=as_root, check_return=True))
+    # TODO(jbudorick): Implement a generic version of Stat() that handles
+    # as_root=True, then switch this implementation to use that.
+    size = None
+    ls_out = self.RunShellCommand(['ls', '-l', device_path], as_root=as_root,
+                                  check_return=True)
+    for line in ls_out:
+      m = self._LS_RE.match(line)
+      if m and m.group('name') == posixpath.basename(device_path):
+        size = int(m.group('size'))
+        break
+    else:
+      logging.warning('Could not determine size of %s.', device_path)
+
+    if size is None or size <= self._MAX_ADB_OUTPUT_LENGTH:
+      return _JoinLines(self.RunShellCommand(
+          ['cat', device_path], as_root=as_root, check_return=True))
+    elif as_root and self.NeedsSU():
+      with device_temp_file.DeviceTempFile(self.adb) as device_temp:
+        self.RunShellCommand(['cp', device_path, device_temp.name],
+                             as_root=True, check_return=True)
+        return self._ReadFileWithPull(device_temp.name)
+    else:
+      return self._ReadFileWithPull(device_path)
 
   def _WriteFileWithPush(self, device_path, contents):
     with tempfile.NamedTemporaryFile() as host_temp:
diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py
index b7e807e..7c20f0d 100755
--- a/build/android/pylib/device/device_utils_test.py
+++ b/build/android/pylib/device/device_utils_test.py
@@ -1046,31 +1046,100 @@
 
 class DeviceUtilsReadFileTest(DeviceUtilsTest):
 
+  def testReadFileWithPull_success(self):
+    tmp_host_dir = '/tmp/dir/on.host/'
+    tmp_host = MockTempFile('/tmp/dir/on.host/tmp_ReadFileWithPull')
+    tmp_host.file.read.return_value = 'some interesting contents'
+    with self.assertCalls(
+        (mock.call.tempfile.mkdtemp(), tmp_host_dir),
+        (self.call.adb.Pull('/path/to/device/file', mock.ANY)),
+        (mock.call.__builtin__.open(mock.ANY, 'r'), tmp_host),
+        (mock.call.os.path.exists(tmp_host_dir), True),
+        (mock.call.shutil.rmtree(tmp_host_dir), None)):
+      self.assertEquals('some interesting contents',
+                        self.device._ReadFileWithPull('/path/to/device/file'))
+    tmp_host.file.read.assert_called_once_with()
+
+  def testReadFileWithPull_rejected(self):
+    tmp_host_dir = '/tmp/dir/on.host/'
+    with self.assertCalls(
+        (mock.call.tempfile.mkdtemp(), tmp_host_dir),
+        (self.call.adb.Pull('/path/to/device/file', mock.ANY),
+         self.CommandError()),
+        (mock.call.os.path.exists(tmp_host_dir), True),
+        (mock.call.shutil.rmtree(tmp_host_dir), None)):
+      with self.assertRaises(device_errors.CommandFailedError):
+        self.device._ReadFileWithPull('/path/to/device/file')
+
   def testReadFile_exists(self):
-    with self.assertCall(
-        self.call.adb.Shell('cat /read/this/test/file'),
-        'this is a test file\r\n'):
+    with self.assertCalls(
+        (self.call.device.RunShellCommand(
+            ['ls', '-l', '/read/this/test/file'],
+            as_root=False, check_return=True),
+         ['-rw-rw---- root foo 256 1970-01-01 00:00 file']),
+        (self.call.device.RunShellCommand(
+            ['cat', '/read/this/test/file'], as_root=False, check_return=True),
+         ['this is a test file'])):
       self.assertEqual('this is a test file\n',
                        self.device.ReadFile('/read/this/test/file'))
 
   def testReadFile_doesNotExist(self):
     with self.assertCall(
-        self.call.adb.Shell('cat /this/file/does.not.exist'),
-        self.ShellError('/system/bin/sh: cat: /this/file/does.not.exist: '
-                        'No such file or directory')):
-      with self.assertRaises(device_errors.AdbCommandFailedError):
+        self.call.device.RunShellCommand(
+            ['ls', '-l', '/this/file/does.not.exist'],
+            as_root=False, check_return=True),
+        self.CommandError('File does not exist')):
+      with self.assertRaises(device_errors.CommandFailedError):
         self.device.ReadFile('/this/file/does.not.exist')
 
   def testReadFile_withSU(self):
     with self.assertCalls(
-      (self.call.device.NeedsSU(), True),
-      (self.call.adb.Shell("su -c sh -c 'cat /this/file/can.be.read.with.su'"),
-       'this is a test file\nread with su')):
+        (self.call.device.RunShellCommand(
+            ['ls', '-l', '/this/file/can.be.read.with.su'],
+            as_root=True, check_return=True),
+         ['-rw------- root root 256 1970-01-01 00:00 can.be.read.with.su']),
+        (self.call.device.RunShellCommand(
+            ['cat', '/this/file/can.be.read.with.su'],
+            as_root=True, check_return=True),
+         ['this is a test file', 'read with su'])):
       self.assertEqual(
           'this is a test file\nread with su\n',
           self.device.ReadFile('/this/file/can.be.read.with.su',
                                as_root=True))
 
+  def testReadFile_withPull(self):
+    contents = 'a' * 123456
+    with self.assertCalls(
+        (self.call.device.RunShellCommand(
+            ['ls', '-l', '/read/this/big/test/file'],
+            as_root=False, check_return=True),
+         ['-rw-rw---- root foo 123456 1970-01-01 00:00 file']),
+        (self.call.device._ReadFileWithPull('/read/this/big/test/file'),
+         contents)):
+      self.assertEqual(
+          contents, self.device.ReadFile('/read/this/big/test/file'))
+
+  def testReadFile_withPullAndSU(self):
+    contents = 'b' * 123456
+    with self.assertCalls(
+        (self.call.device.RunShellCommand(
+            ['ls', '-l', '/this/big/file/can.be.read.with.su'],
+            as_root=True, check_return=True),
+         ['-rw------- root root 123456 1970-01-01 00:00 can.be.read.with.su']),
+        (self.call.device.NeedsSU(), True),
+        (mock.call.pylib.utils.device_temp_file.DeviceTempFile(self.adb),
+         MockTempFile('/sdcard/tmp/on.device')),
+        self.call.device.RunShellCommand(
+            ['cp', '/this/big/file/can.be.read.with.su',
+             '/sdcard/tmp/on.device'],
+            as_root=True, check_return=True),
+        (self.call.device._ReadFileWithPull('/sdcard/tmp/on.device'),
+         contents)):
+      self.assertEqual(
+          contents,
+          self.device.ReadFile('/this/big/file/can.be.read.with.su',
+                               as_root=True))
+
 
 class DeviceUtilsWriteFileTest(DeviceUtilsTest):
 
diff --git a/build/android/tombstones.py b/build/android/tombstones.py
index 7449a73..9b8a8b2 100755
--- a/build/android/tombstones.py
+++ b/build/android/tombstones.py
@@ -18,9 +18,12 @@
 import optparse
 
 from pylib import android_commands
+from pylib.device import device_errors
 from pylib.device import device_utils
 
 
+_TZ_UTC = {'TZ': 'UTC'}
+
 def _ListTombstones(device):
   """List the tombstone files on the device.
 
@@ -30,7 +33,9 @@
   Yields:
     Tuples of (tombstone filename, date time of file on device).
   """
-  lines = device.RunShellCommand('TZ=UTC su -c ls -a -l /data/tombstones')
+  lines = device.RunShellCommand(
+      ['ls', '-a', '-l', '/data/tombstones'],
+      as_root=True, check_return=True, env=_TZ_UTC, timeout=60)
   for line in lines:
     if 'tombstone' in line and not 'No such file or directory' in line:
       details = line.split()
@@ -48,7 +53,8 @@
   Returns:
     A datetime instance.
   """
-  device_now_string = device.RunShellCommand('TZ=UTC date')
+  device_now_string = device.RunShellCommand(
+      ['date'], check_return=True, env=_TZ_UTC)
   return datetime.datetime.strptime(
       device_now_string[0], '%a %b %d %H:%M:%S %Z %Y')
 
@@ -75,7 +81,8 @@
     tombstone_file: the tombstone to delete.
   """
   return device.RunShellCommand(
-      'rm /data/tombstones/' + tombstone_file, as_root=True)
+      ['rm', '/data/tombstones/' + tombstone_file],
+      as_root=True, check_return=True)
 
 
 def _DeviceAbiToArch(device_abi):
@@ -172,14 +179,21 @@
   tombstones = all_tombstones if options.all_tombstones else [all_tombstones[0]]
 
   device_now = _GetDeviceDateTime(device)
-  for tombstone_file, tombstone_time in tombstones:
-    ret += [{'serial': str(device),
-             'device_abi': device.product_cpu_abi,
-             'device_now': device_now,
-             'time': tombstone_time,
-             'file': tombstone_file,
-             'stack': options.stack,
-             'data': _GetTombstoneData(device, tombstone_file)}]
+  try:
+    for tombstone_file, tombstone_time in tombstones:
+      ret += [{'serial': str(device),
+               'device_abi': device.product_cpu_abi,
+               'device_now': device_now,
+               'time': tombstone_time,
+               'file': tombstone_file,
+               'stack': options.stack,
+               'data': _GetTombstoneData(device, tombstone_file)}]
+  except device_errors.CommandFailedError:
+    for line in device.RunShellCommand(
+        ['ls', '-a', '-l', '/data/tombstones'],
+        as_root=True, check_return=True, env=_TZ_UTC, timeout=60):
+      print '%s: %s' % (str(device), line)
+    raise
 
   # Erase all the tombstones if desired.
   if options.wipe_tombstones: