Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Unified Diff: chrome/android/java/src/PRESUBMIT.py

Issue 2894643002: [Android] Presubmit check for banned Notification construction (Closed)
Patch Set: remove blank lines for peter Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/PRESUBMIT.py
diff --git a/chrome/android/java/src/PRESUBMIT.py b/chrome/android/java/src/PRESUBMIT.py
new file mode 100644
index 0000000000000000000000000000000000000000..c1f96e30ef6c113bc39deb4ca5190ca39146825a
--- /dev/null
+++ b/chrome/android/java/src/PRESUBMIT.py
@@ -0,0 +1,63 @@
+# Copyright (c) 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Presubmit script for Android Java code.
+
+See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
+for more details about the presubmit API built into depot_tools.
+
+This presubmit checks for the following:
+ - No new calls to Notification.Builder or NotificationCompat.Builder
+ constructors. Callers should use ChromeNotificationBuilder instead.
+"""
+
+import re
+
+NEW_NOTIFICATION_BUILDER_RE = re.compile(
+ r'new\sNotification(Compat)?\.Builder')
+
+def CheckChangeOnUpload(input_api, output_api):
+ return _CommonChecks(input_api, output_api)
+
+
+def CheckChangeOnCommit(input_api, output_api):
+ return _CommonChecks(input_api, output_api)
+
+def _CommonChecks(input_api, output_api):
+ """Checks common to both upload and commit."""
+ result = []
+ result.extend(_CheckNotificationConstructors(input_api, output_api))
+ # Add more checks here
+ return result
+
+def _CheckNotificationConstructors(input_api, output_api):
+ whitelist = [
+ 'chrome/android/java/src/org/chromium/chrome/browser/notifications/'
+ 'NotificationBuilder.java',
+ 'chrome/android/java/src/org/chromium/chrome/browser/notifications/'
+ 'NotificationCompatBuilder.java'
+ ]
+ problems = []
+ for f in input_api.AffectedFiles():
+ if f.LocalPath() in whitelist:
+ continue
+ for line_number, line in f.ChangedContents():
+ if NEW_NOTIFICATION_BUILDER_RE.search(line):
+ problems.append(
+ ' %s:%d\n \t%s' % (f.LocalPath(), line_number, line.strip()))
+ if problems:
+ return [output_api.PresubmitError(
+'''
+Android Notification Construction Check failed:
+ Your new code added one or more calls to the Notification.Builder and/or
+ NotificationCompat.Builder constructors, listed below.
+
+ This is banned, please construct notifications using
+ NotificationBuilderFactory.createChromeNotificationBuilder instead,
+ specifying a channel for use on Android O.
+
+ See https://crbug.com/678670 for more information.
+''',
+ problems)]
+ return []
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698