Fine tune code coverage filters for SystemUI tests.

Bug: 28269038
Change-Id: Iece993a76b39873170c4ae0b2d1cd2dd5445e3c2
diff --git a/packages/SystemUI/tests/ b/packages/SystemUI/tests/
index 188f8bf..d122ccc 100644
--- a/packages/SystemUI/tests/
+++ b/packages/SystemUI/tests/
@@ -58,9 +58,42 @@
 # UI it doesn't own. This is necessary to allow screenshots to be taken
+# Provide jack a list of classes to exclude from code coverage.
+# This is needed because the SystemUITests compile SystemUI source directly, rather than using
+# We want to exclude the test classes from code coverage measurements, but they share the same
+# package as the rest of SystemUI so they can't be easily filtered by package name.
+# Generate a comma separated list of patterns based on the test source files under src/
+# SystemUI classes are in ../src/ so they won't be excluded.
+# Example:
+#   Input files: src/com/android/systemui/ src/com/android/systemui/
+#   Generated exclude list:*,*
+# Filter all src files under src/ to just java files
+local_java_files := $(filter,$(call all-java-files-under, src))
+# Transform java file names into full class names.
+# This only works if the class name matches the file name and the directory structure
+# matches the package.
+local_classes := $(subst /,.,$(patsubst src/,%,$(local_java_files)))
+local_comma := ,
+local_empty :=
+local_space := $(local_empty) $(local_empty)
+# Convert class name list to jacoco exclude list
+# This appends a * to all classes and replace the space separators with commas.
+jacoco_exclude := $(subst $(space),$(comma),$(patsubst %,%*,$(local_classes)))
 include frameworks/base/packages/SettingsLib/
 include $(BUILD_PACKAGE)
+# Reset variables
+local_java_files :=
+local_classes :=
+local_comma :=
+local_space :=
+jacoco_exclude :=