Android: Add presubmit check for StrictMode.
New violations should be white-listed using the try-with-resources
method in StrictModeContext.
Bug: 766228
Change-Id: Ic420189aaa2eb2e3fbb9cbc06250d09e4364e251
Reviewed-on: https://chromium-review.googlesource.com/673846
Reviewed-by: Yaron Friedman <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Commit-Queue: Eric Stevenson <[email protected]>
Cr-Commit-Position: refs/heads/master@{#503913}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index d85a05b..efd126d 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -65,6 +65,25 @@
'cppguide.html#Names_and_Order_of_Includes')
+_BANNED_JAVA_FUNCTIONS = (
+ (
+ 'StrictMode.allowThreadDiskReads()',
+ (
+ 'Prefer using StrictModeContext.allowDiskReads() to using StrictMode '
+ 'directly.',
+ ),
+ False,
+ ),
+ (
+ 'StrictMode.allowThreadDiskWrites()',
+ (
+ 'Prefer using StrictModeContext.allowDiskWrites() to using StrictMode '
+ 'directly.',
+ ),
+ False,
+ ),
+)
+
_BANNED_OBJC_FUNCTIONS = (
(
'addTrackingRect:',
@@ -775,6 +794,12 @@
for message_line in message:
problems.append(' %s' % message_line)
+ file_filter = lambda f: f.LocalPath().endswith(('.java'))
+ for f in input_api.AffectedFiles(file_filter=file_filter):
+ for line_num, line in f.ChangedContents():
+ for func_name, message, error in _BANNED_JAVA_FUNCTIONS:
+ CheckForMatch(f, line_num, line, func_name, message, error)
+
file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
for f in input_api.AffectedFiles(file_filter=file_filter):
for line_num, line in f.ChangedContents():