Snap for 11149604 from 9dc8c43529b23104501967724f6df75c63cab3d3 to androidx-versionedparcelable-release

Change-Id: I94444477b977b6021032342d34225abb3f495bf1
diff --git a/LICENSE b/LICENSE
index c6ed510..19e3071 100644
--- a/LICENSE
+++ b/LICENSE
@@ -2,13 +2,13 @@
                        Version 2.1, February 1999
 
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
-[This is the first released version of the Lesser GPL.  It also counts
+(This is the first released version of the Lesser GPL.  It also counts
  as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
+ the version number 2.1.)
 
                             Preamble
 
@@ -55,7 +55,7 @@
 that what they have is not the original version, so that the original
 author's reputation will not be affected by problems that might be
 introduced by others.
-
+
   Finally, software patents pose a constant threat to the existence of
 any free program.  We wish to make sure that a company cannot
 effectively restrict the users of a free program by obtaining a
@@ -111,7 +111,7 @@
 "work based on the library" and a "work that uses the library".  The
 former contains code derived from the library, whereas the latter must
 be combined with the library in order to run.
-
+
                   GNU LESSER GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
@@ -146,7 +146,7 @@
 on the Library (independent of the use of the Library in a tool for
 writing it).  Whether that is true depends on what the Library does
 and what the program that uses the Library does.
-  
+
   1. You may copy and distribute verbatim copies of the Library's
 complete source code as you receive it, in any medium, provided that
 you conspicuously and appropriately publish on each copy an
@@ -158,7 +158,7 @@
   You may charge a fee for the physical act of transferring a copy,
 and you may at your option offer warranty protection in exchange for a
 fee.
-
+
   2. You may modify your copy or copies of the Library or any portion
 of it, thus forming a work based on the Library, and copy and
 distribute such modifications or work under the terms of Section 1
@@ -216,7 +216,7 @@
 ordinary GNU General Public License has appeared, then you can specify
 that version instead if you wish.)  Do not make any other change in
 these notices.
-
+
   Once this change is made in a given copy, it is irreversible for
 that copy, so the ordinary GNU General Public License applies to all
 subsequent copies and derivative works made from that copy.
@@ -267,7 +267,7 @@
 distribute the object code for the work under the terms of Section 6.
 Any executables containing that work also fall under Section 6,
 whether or not they are linked directly with the Library itself.
-
+
   6. As an exception to the Sections above, you may also combine or
 link a "work that uses the Library" with the Library to produce a
 work containing portions of the Library, and distribute that work
@@ -329,7 +329,7 @@
 accompany the operating system.  Such a contradiction means you cannot
 use both them and the Library together in an executable that you
 distribute.
-
+
   7. You may place library facilities that are a work based on the
 Library side-by-side in a single library together with other library
 facilities not covered by this License, and distribute such a combined
@@ -370,7 +370,7 @@
 restrictions on the recipients' exercise of the rights granted herein.
 You are not responsible for enforcing compliance by third parties with
 this License.
-
+
   11. If, as a consequence of a court judgment or allegation of patent
 infringement or for any other reason (not limited to patent issues),
 conditions are imposed on you (whether by court order, agreement or
@@ -422,7 +422,7 @@
 the Free Software Foundation.  If the Library does not specify a
 license version number, you may choose any version ever published by
 the Free Software Foundation.
-
+
   14. If you wish to incorporate parts of the Library into other free
 programs whose distribution conditions are incompatible with these,
 write to the author to ask for permission.  For software which is
@@ -456,7 +456,7 @@
 DAMAGES.
 
                      END OF TERMS AND CONDITIONS
-
+
            How to Apply These Terms to Your New Libraries
 
   If you develop a new library, and you want it to be of the greatest
@@ -470,8 +470,8 @@
 convey the exclusion of warranty; and each file should have at least the
 "copyright" line and a pointer to where the full notice is found.
 
-    <one line to give the library's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
+    {description}
+    Copyright (C) {year} {fullname}
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -485,7 +485,8 @@
 
     You should have received a copy of the GNU Lesser General Public
     License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
 
 Also add information on how to contact you by electronic and paper mail.
 
@@ -494,9 +495,10 @@
 necessary.  Here is a sample; alter the names:
 
   Yoyodyne, Inc., hereby disclaims all copyright interest in the
-  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+  library `Frob' (a library for tweaking knobs) written by James Random
+  Hacker.
 
-  <signature of Ty Coon>, 1 April 1990
+  {signature of Ty Coon}, 1 April 1990
   Ty Coon, President of Vice
 
 That's all there is to it!
diff --git a/README b/README
deleted file mode 100644
index d147f8b..0000000
--- a/README
+++ /dev/null
@@ -1,28 +0,0 @@
-Description:
-Checkstyle is used by developers to validate Java code style before running repo upload.
-
-It can be invoked in two ways.
-1. To check style of entire specific files:
-checkstyle.py -f FILE [FILE ...]
-2. To check style of the lines modified in the latest commit:
-checkstyle.py
-
-Projects used:
-* Name: Checkstyle
-  Description: Checkstyle is a development tool to help programmers write Java code that
-               adheres to a coding standard.
-  URL: http://checkstyle.sourceforge.net/
-  Version: 7.4-SNAPSHOT
-  License: LGPL 2.1
-  License File: LICENSE
-  Source git repo: https://android.googlesource.com/platform/external/checkstyle
-
-* Name: Git-Lint
-  Description: Git-lint is a tool to run lint checks on only files changed in
-               the latest commit.
-  URL: https://github.com/sk-/git-lint/
-  Version: 0.0.8
-  License: Apache 2.0
-  License File: gitlint/LICENSE
-  Local Modifications:
-  - Downloaded gitlint/git.py and git/utils.py files individually.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c8d5db2
--- /dev/null
+++ b/README.md
@@ -0,0 +1,66 @@
+# Checkstyle
+
+Checkstyle is used by developers to validate Java code style and formatting,
+and can be run as part of the pre-upload hooks.
+
+[TOC]
+
+## Running it
+
+It can be invoked in two ways.
+1.  To check style of entire specific files:
+    `checkstyle.py -f FILE [FILE ...]`
+2.  To check style of the lines modified in the latest commit:
+    `checkstyle.py`
+
+
+## Projects used
+
+### Checkstyle
+
+A development tool to help programmers write Java code that adheres to a
+coding standard.
+
+*   URL: https://checkstyle.sourceforge.io
+*   Version: 10.12.3
+*   License: LGPL 2.1
+*   License File: LICENSE
+*   Source repo: https://github.com/checkstyle/checkstyle
+
+### Git-Lint
+
+Git-lint is a tool to run lint checks on only files changed in the latest
+commit.
+
+*   URL: https://github.com/sk-/git-lint/
+*   Version: 0.0.8
+*   License: Apache 2.0
+*   License File: gitlint/LICENSE
+*   Local Modifications:
+    *   Downloaded gitlint/git.py and git/utils.py files individually.
+
+## Pre-upload linting
+
+To run checkstyle as part of the pre-upload hooks, add the following line to
+your `PREUPLOAD.cfg`:
+```
+checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
+```
+
+Note that checkstyle does not always agree with clang-format, and so it's best
+to only have one enabled for Java.
+
+### Disabling Clang Format for Java
+
+In `.clang-format` add the following to disable format checking and correcting
+for Java:
+```
+---
+Language: Java
+DisableFormat: true
+SortIncludes: false
+---
+```
+In some versions of clang-format, `DisableFormat` doesn't stop the sorting of
+includes. So to fully disable clang-format from doing anything for Java files,
+both options are needed.
diff --git a/checkstyle.jar b/checkstyle.jar
index 747b3e3..8a9e2d1 100644
--- a/checkstyle.jar
+++ b/checkstyle.jar
Binary files differ
diff --git a/checkstyle.py b/checkstyle.py
index a73c7da..c32943d 100755
--- a/checkstyle.py
+++ b/checkstyle.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
 #
 # Copyright 2015, The Android Open Source Project
@@ -18,6 +18,8 @@
 
 """Script that is used by developers to run style checks on Java files."""
 
+from __future__ import print_function
+
 import argparse
 import errno
 import os
@@ -62,7 +64,8 @@
                 'com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck']
 SKIPPED_RULES_FOR_TEST_FILES = ['com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck',
                                 'com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck']
-SUBPATH_FOR_TEST_FILES = ['/tests/', '/test/', '/androidTest/', '/perftests/']
+SUBPATH_FOR_TEST_FILES = ['/tests/', '/test/', '/androidTest/', '/perftests/', '/gts-tests/',
+                          '/hostsidetests/', '/jvmTest/', '/robotests/']
 SUBPATH_FOR_TEST_DATA_FILES = _FindFoldersContaining(git.repository_root(),
                                                      'IGNORE_CHECKSTYLE')
 ERROR_UNCOMMITTED = 'You need to commit all modified files before running Checkstyle\n'
@@ -81,7 +84,7 @@
     A tuple of errors and warnings.
   """
   print('Running Checkstyle on inputted files')
-  java_files = map(os.path.abspath, java_files)
+  java_files = list(map(os.path.abspath, java_files))
   stdout = _ExecuteCheckstyle(java_files, classpath, config_xml)
   (errors, warnings) = _ParseAndFilterOutput(stdout)
   _PrintErrorsAndWarnings(errors, warnings)
@@ -117,14 +120,14 @@
   print('Running Checkstyle on %s commit' % commit)
   commit_modified_files = _GetModifiedFiles(commit, explicit_commit)
   commit_modified_files = _FilterFiles(commit_modified_files, file_whitelist)
-  if not commit_modified_files.keys():
+  if not list(commit_modified_files.keys()):
     print('No Java files to check')
     return [], []
 
   (tmp_dir, tmp_file_map) = _GetTempFilesForCommit(
-      commit_modified_files.keys(), commit)
+      list(commit_modified_files.keys()), commit)
 
-  java_files = tmp_file_map.keys()
+  java_files = list(tmp_file_map.keys())
   stdout = _ExecuteCheckstyle(java_files, classpath, config_xml)
 
   # Remove all the temporary files.
@@ -152,13 +155,10 @@
 
 def _PrintErrorsAndWarnings(errors, warnings):
   """Prints given errors and warnings."""
-  system_encoding = sys.getdefaultencoding()
-  if (system_encoding == 'ascii'):
-    system_encoding = 'UTF-8'
   if errors:
-    print('ERRORS:\n' + '\n'.join(map(lambda x: x.encode(system_encoding), errors)))
+    print('ERRORS:\n' + '\n'.join(errors))
   if warnings:
-    print('WARNINGS:\n' + '\n'.join(map(lambda x: x.encode(system_encoding), warnings)))
+    print('WARNINGS:\n' + '\n'.join(warnings))
 
 
 def _ExecuteCheckstyle(java_files, classpath, config_xml):
@@ -177,14 +177,20 @@
   checkstyle_env['JAVA_CMD'] = 'java'
 
   try:
-    check = subprocess.Popen(['java', '-cp', classpath,
+    check = subprocess.Popen(['java',
+                              '-Dcheckstyle.enableExternalDtdLoad=true',
+                              '-cp', classpath,
                               'com.puppycrawl.tools.checkstyle.Main', '-c',
                               config_xml, '-f', 'xml'] + java_files,
-                             stdout=subprocess.PIPE, env=checkstyle_env)
+                             stdout=subprocess.PIPE, env=checkstyle_env,
+                             universal_newlines=True)
     stdout, _ = check.communicate()
+    stdout_lines = stdout.splitlines()
     # A work-around for Checkstyle printing error count to stdio.
-    if '</checkstyle>' in stdout.splitlines()[-2]:
-      stdout = '\n'.join(stdout.splitlines()[:-1])
+    if len(stdout_lines) < 2:
+      stdout = stdout_lines[0]
+    elif len(stdout_lines) >= 2 and '</checkstyle>' in stdout_lines[-2]:
+      stdout = '\n'.join(stdout_lines[:-1])
     return stdout
   except OSError as e:
     if e.errno == errno.ENOENT:
@@ -314,7 +320,7 @@
     if not os.path.exists(os.path.dirname(tmp_file_name)):
       os.makedirs(os.path.dirname(tmp_file_name))
 
-    tmp_file = open(tmp_file_name, 'w')
+    tmp_file = open(tmp_file_name, 'wb')
     tmp_file.write(content)
     tmp_file.close()
     tmp_file_names[tmp_file_name] = file_name
diff --git a/default-javadoc-checks.xml b/default-javadoc-checks.xml
index b17f2c6..113f119 100644
--- a/default-javadoc-checks.xml
+++ b/default-javadoc-checks.xml
@@ -23,10 +23,15 @@
 </module>
 <module name="JavadocMethod">
   <property name="severity" value="error"/>
+  <property name="tokens" value="METHOD_DEF"/>
+  <property name="validateThrows" value="false"/>
+  <property name="allowMissingParamTags" value="true"/>
+  <property name="allowMissingReturnTag" value="true"/>
+</module>
+<module name="MissingJavadocMethod">
   <property name="scope" value="public"/>
   <property name="tokens" value="METHOD_DEF"/>
-  <property name="allowMissingParamTags" value="true"/>
   <property name="allowMissingPropertyJavadoc" value="true"/>
-  <property name="allowMissingReturnTag" value="true"/>
-  <property name="allowMissingThrowsTags" value="true"/>
+  <property name="allowedAnnotations" value="Override,Test,Before,After,Parameterized.Parameters"/>
+  <property name="ignoreMethodNamesRegex" value="^test.*$"/>
 </module>
diff --git a/default-module-checks.xml b/default-module-checks.xml
index 920a4ec..d82143d 100644
--- a/default-module-checks.xml
+++ b/default-module-checks.xml
@@ -19,6 +19,11 @@
 <module name="FileTabCharacter">
   <property name="severity" value="error"/>
 </module>
+<module name="LineLength">
+  <property name="severity" value="error"/>
+  <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://|^ *\*? \{@link .*$"/>
+  <property name="max" value="100"/>
+</module>
 <module name="NewlineAtEndOfFile">
   <property name="severity" value="error"/>
 </module>
diff --git a/default-treewalker-checks.xml b/default-treewalker-checks.xml
index 7e09891..62f40c0 100644
--- a/default-treewalker-checks.xml
+++ b/default-treewalker-checks.xml
@@ -81,11 +81,6 @@
   <property name="format" value="^m|s|((([ms][a-z0-9])|([a-ln-rt-z]))[a-zA-Z0-9]*)$"/>
   <message key="name.invalidPattern" value="Local variables should be camel-cased (e.g. int minWidth = 4)."/>
 </module>
-<module name="LineLength">
-  <property name="severity" value="error"/>
-  <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
-  <property name="max" value="100"/>
-</module>
 <module name="LeftCurly">
   <property name="severity" value="error"/>
 </module>
@@ -117,6 +112,7 @@
   <property name="severity" value="error"/>
   <property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, TYPE_EXTENSION_AND" />
   <property name="allowEmptyConstructors" value="true"/>
+  <property name="allowEmptyLambdas" value="true"/>
   <property name="allowEmptyMethods" value="true"/>
 </module>
 <module name="WhitespaceAfter">
@@ -158,10 +154,12 @@
 <module name="ImportOrder">
   <property name="severity" value="error"/>
   <message key="import.ordering" value="Wrong order for {0} import. Use Ctrl+Shift+O (Eclipse) or Ctrl+Alt+O (Intellij) to sort imports. https://source.android.com/setup/code-style#order-import-statements"/>
-  <property name="groups" value="android, androidx, com.android, dalvik, com, gov, junit, libcore, net, org, java, javax"/>
+  <property name="groups" value="android, androidx, com.android, dalvik, com, dagger, gov, io, junit, junitparams, libcore, net, kotlin, org, perfetto, java, javax"/>
   <property name="ordered" value="true"/>
   <property name="option" value="top"/>
   <property name="separated" value="true"/>
+  <property name="separatedStaticGroups" value="true"/>
+  <property name="staticGroups" value="android, androidx, com.android, dalvik, com, dagger, gov, io, junit, junitparams, libcore, net, kotlin, org, perfetto, java, javax"/>
 </module>
 <module name="Indentation">
   <property name="severity" value="error"/>
@@ -210,7 +208,6 @@
 <module name="OuterTypeFilename">
   <property name="severity" value="error"/>
 </module>
-<module name="FileContentsHolder"/>
 <module name="SuppressionCommentFilter">
   <property name="offCommentFormat" value="CHECKSTYLE:OFF IndentationCheck"/>
   <property name="onCommentFormat" value="CHECKSTYLE:ON IndentationCheck"/>
@@ -219,4 +216,4 @@
 <module name="SuppressionCommentFilter">
   <property name="offCommentFormat" value="CHECKSTYLE:OFF Generated code"/>
   <property name="onCommentFormat" value="CHECKSTYLE:ON Generated code"/>
-</module>
\ No newline at end of file
+</module>
diff --git a/gitlint/git.py b/gitlint/git.py
index 9d796f6..7a03705 100644
--- a/gitlint/git.py
+++ b/gitlint/git.py
@@ -126,7 +126,7 @@
 
     # Split as bytes, as the output may have some non unicode characters.
     blame_lines = subprocess.check_output(
-        ['git', 'blame', commit, '--porcelain', '--', filename]).split(
+        ['git', 'blame', (commit + b'^!'), '--porcelain', '--', filename]).split(
             os.linesep.encode('utf-8'))
     modified_line_numbers = utils.filter_lines(
         blame_lines,
diff --git a/tests.py b/tests.py
index 7c9c7e4..0e7dd1f 100755
--- a/tests.py
+++ b/tests.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
 #
 # Copyright 2015, The Android Open Source Project