[RESTRICT AUTOMERGE]: Give tests more control of crash parser behavior

Added a config object instead of a multitude of arguments.

Bug: 142482078
Test: cts-tradefed run compatibility-common-util-tests
Test: cts-tradefed run cts -m CtsSecurityTestCases -t android.security.cts.StagefrightTest
Change-Id: I6ae9881e2590592110790d61d31fccc888774b9b
diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java
index 1496f7b..9015f61 100644
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -87,12 +87,12 @@
 
     @SecurityTest
     public void testStagefright_cve_2017_0643() throws Exception {
-        doStagefrightTest(R.raw.cve_2017_0643, false);
+        doStagefrightTest(R.raw.cve_2017_0643, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
     public void testStagefright_cve_2017_0728() throws Exception {
-        doStagefrightTest(R.raw.cve_2017_0728, false);
+        doStagefrightTest(R.raw.cve_2017_0728, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -135,7 +135,7 @@
     }
 
     public void testStagefright_bug_35763994() throws Exception {
-        doStagefrightTest(R.raw.bug_35763994, false);
+        doStagefrightTest(R.raw.bug_35763994, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -145,7 +145,7 @@
 
     @SecurityTest
     public void testStagefright_cve_2016_2507() throws Exception {
-        doStagefrightTest(R.raw.cve_2016_2507, false);
+        doStagefrightTest(R.raw.cve_2016_2507, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -235,13 +235,14 @@
 
     @SecurityTest
     public void testStagefright_cve_2016_2429_b_27211885() throws Exception {
-        doStagefrightTest(R.raw.cve_2016_2429_b_27211885, false);
+        doStagefrightTest(R.raw.cve_2016_2429_b_27211885,
+                new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
     public void testStagefright_bug_34031018() throws Exception {
-        doStagefrightTest(R.raw.bug_34031018_32bit, false);
-        doStagefrightTest(R.raw.bug_34031018_64bit, false);
+        doStagefrightTest(R.raw.bug_34031018_32bit, new CrashUtils.Config().checkMinAddress(false));
+        doStagefrightTest(R.raw.bug_34031018_64bit, new CrashUtils.Config().checkMinAddress(false));
     }
 
     /***********************************************************
@@ -261,7 +262,8 @@
 
     @SecurityTest
     public void testStagefright_cve_2017_0852_b_62815506() throws Exception {
-        doStagefrightTest(R.raw.cve_2017_0852_b_62815506, false);
+        doStagefrightTest(R.raw.cve_2017_0852_b_62815506,
+                new CrashUtils.Config().checkMinAddress(false));
     }
 
     /***********************************************************
@@ -296,12 +298,12 @@
 
     @SecurityTest
     public void testStagefright_cve_2017_0600() throws Exception {
-        doStagefrightTest(R.raw.cve_2017_0600, false);
+        doStagefrightTest(R.raw.cve_2017_0600, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
     public void testStagefright_cve_2017_0599() throws Exception {
-        doStagefrightTest(R.raw.cve_2017_0599, false);
+        doStagefrightTest(R.raw.cve_2017_0599, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -311,7 +313,7 @@
 
     @SecurityTest
     public void testStagefright_cve_2016_6712() throws Exception {
-        doStagefrightTest(R.raw.cve_2016_6712, false);
+        doStagefrightTest(R.raw.cve_2016_6712, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -321,12 +323,12 @@
 
     @SecurityTest
     public void testStagefright_bug_33818508() throws Exception {
-        doStagefrightTest(R.raw.bug_33818508, false);
+        doStagefrightTest(R.raw.bug_33818508, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
     public void testStagefright_bug_32873375() throws Exception {
-        doStagefrightTest(R.raw.bug_32873375, false);
+        doStagefrightTest(R.raw.bug_32873375, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -351,7 +353,7 @@
 
     @SecurityTest
     public void testStagefright_bug_32322258() throws Exception {
-        doStagefrightTest(R.raw.bug_32322258, false);
+        doStagefrightTest(R.raw.bug_32322258, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -366,7 +368,8 @@
 
     @SecurityTest
     public void testStagefright_cve_2015_3862_b_22954006() throws Exception {
-        doStagefrightTest(R.raw.cve_2015_3862_b_22954006, false);
+        doStagefrightTest(R.raw.cve_2015_3862_b_22954006,
+                new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -420,12 +423,13 @@
 
     @SecurityTest
     public void testStagefright_cve_2016_3755() throws Exception {
-        doStagefrightTest(R.raw.cve_2016_3755, false);
+        doStagefrightTest(R.raw.cve_2016_3755, new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
     public void testStagefright_cve_2016_3878_b_29493002() throws Exception {
-        doStagefrightTest(R.raw.cve_2016_3878_b_29493002, false);
+        doStagefrightTest(R.raw.cve_2016_3878_b_29493002,
+                new CrashUtils.Config().checkMinAddress(false));
     }
 
     @SecurityTest
@@ -435,11 +439,11 @@
 
     @SecurityTest
     public void testStagefright_bug_27855419_CVE_2016_2463() throws Exception {
-        doStagefrightTest(R.raw.bug_27855419, false);
+        doStagefrightTest(R.raw.bug_27855419, new CrashUtils.Config().checkMinAddress(false));
     }
 
     public void testStagefright_bug_19779574() throws Exception {
-        doStagefrightTest(R.raw.bug_19779574, false);
+        doStagefrightTest(R.raw.bug_19779574, new CrashUtils.Config().checkMinAddress(false));
     }
 
     /***********************************************************
@@ -449,7 +453,7 @@
 
     @SecurityTest
     public void testStagefright_bug_35467107() throws Exception {
-        doStagefrightTest(R.raw.bug_35467107, false);
+        doStagefrightTest(R.raw.bug_35467107, new CrashUtils.Config().checkMinAddress(false));
     }
 
     /***********************************************************
@@ -468,36 +472,37 @@
     }
 
     private void doStagefrightTest(final int rid) throws Exception {
-        doStagefrightTest(rid, true); // check addresss by default
+        doStagefrightTest(rid, null);
     }
 
-    private void doStagefrightTest(final int rid, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaPlayer(rid, checkMinCrashAddress);
-        doStagefrightTestMediaCodec(rid, checkMinCrashAddress);
-        doStagefrightTestMediaMetadataRetriever(rid, checkMinCrashAddress);
+    private void doStagefrightTest(final int rid, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaPlayer(rid, config);
+        doStagefrightTestMediaCodec(rid, config);
+        doStagefrightTestMediaMetadataRetriever(rid, config);
 
         Context context = getInstrumentation().getContext();
         Resources resources =  context.getResources();
         CtsTestServer server = new CtsTestServer(context);
         String rname = resources.getResourceEntryName(rid);
         String url = server.getAssetUrl("raw/" + rname);
-        doStagefrightTestMediaPlayer(url, checkMinCrashAddress);
-        doStagefrightTestMediaCodec(url, checkMinCrashAddress);
-        doStagefrightTestMediaMetadataRetriever(url, checkMinCrashAddress);
+
+        doStagefrightTestMediaPlayer(url, config);
+        doStagefrightTestMediaCodec(url, config);
+        doStagefrightTestMediaMetadataRetriever(url, config);
         server.shutdown();
     }
 
     private void doStagefrightTest(final int rid, int timeout) throws Exception {
-        doStagefrightTest(rid, true, timeout); // check crash address by default
+        doStagefrightTest(rid, null, timeout);
     }
 
     private void doStagefrightTest(
-            final int rid, boolean checkMinCrashAddress, int timeout) throws Exception {
+            final int rid, CrashUtils.Config config, int timeout) throws Exception {
         runWithTimeout(new Runnable() {
             @Override
             public void run() {
                 try {
-                  doStagefrightTest(rid, checkMinCrashAddress);
+                  doStagefrightTest(rid, config);
                 } catch (Exception e) {
                   fail(e.toString());
                 }
@@ -506,12 +511,12 @@
     }
 
     private void doStagefrightTestANR(final int rid) throws Exception {
-        doStagefrightTestANR(rid, true); // check crash address by default
+        doStagefrightTestANR(rid, null);
     }
 
     private void doStagefrightTestANR(
-            final int rid, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaPlayerANR(rid, null);
+            final int rid, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaPlayerANR(rid, null, config);
     }
 
     private Surface getDummySurface() {
@@ -571,7 +576,7 @@
         MediaPlayer.OnPreparedListener,
         MediaPlayer.OnCompletionListener {
 
-        boolean checkMinAddress = true;
+        CrashUtils.Config config;
 
         private final Pattern[] validProcessPatterns = {
             Pattern.compile("adsprpcd"),
@@ -593,10 +598,16 @@
         };
 
         MediaPlayerCrashListener() {
+            this(null);
         }
 
-        MediaPlayerCrashListener(boolean checkMinAddress) {
-            this.checkMinAddress = checkMinAddress;
+        MediaPlayerCrashListener(CrashUtils.Config config) {
+            if (config == null) {
+                config = new CrashUtils.Config();
+            }
+            // if a different process is needed for a test, it should be added to the main list.
+            config.setProcessPatterns(validProcessPatterns);
+            this.config = config;
         }
 
         @Override
@@ -644,8 +655,7 @@
                 if (crashes == null) {
                     Log.e(TAG, "Crash results not found for test " + getName());
                     return what;
-                } else if (CrashUtils.securityCrashDetected(
-                        crashes, checkMinAddress, validProcessPatterns)) {
+                } else if (CrashUtils.securityCrashDetected(crashes, config)) {
                     return what;
                 } else {
                     Log.i(TAG, "Crash ignored due to no security crash found for test " +
@@ -693,21 +703,21 @@
     }
 
     private void doStagefrightTestMediaPlayer(final int rid) throws Exception {
-        doStagefrightTestMediaPlayer(rid, true); // check crash address by default
+        doStagefrightTestMediaPlayer(rid, null, null);
     }
 
     private void doStagefrightTestMediaPlayer(
-            final int rid, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaPlayer(rid, null, checkMinCrashAddress);
+            final int rid, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaPlayer(rid, null, config);
     }
 
     private void doStagefrightTestMediaPlayer(final String url) throws Exception {
-        doStagefrightTestMediaPlayer(url, true); // check crash address by default
+        doStagefrightTestMediaPlayer(url, null);
     }
 
     private void doStagefrightTestMediaPlayer(
-            final String url, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaPlayer(-1, url, checkMinCrashAddress);
+            final String url, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaPlayer(-1, url, config);
     }
 
     private void closeQuietly(AutoCloseable closeable) {
@@ -722,17 +732,17 @@
     }
 
     private void doStagefrightTestMediaPlayer(final int rid, final String uri) throws Exception {
-        doStagefrightTestMediaPlayer(rid, uri, true); // check crash address by default
+        doStagefrightTestMediaPlayer(rid, uri, null);
     }
 
     private void doStagefrightTestMediaPlayer(final int rid, final String uri,
-            boolean checkMinCrashAddress) throws Exception {
+            CrashUtils.Config config) throws Exception {
 
         String name = uri != null ? uri :
             getInstrumentation().getContext().getResources().getResourceEntryName(rid);
         Log.i(TAG, "start mediaplayer test for: " + name);
 
-        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(checkMinCrashAddress);
+        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
 
         LooperThread t = new LooperThread(new Runnable() {
             @Override
@@ -777,31 +787,31 @@
     }
 
     private void doStagefrightTestMediaCodec(final int rid) throws Exception {
-        doStagefrightTestMediaCodec(rid, true); // check crash address by default
+        doStagefrightTestMediaCodec(rid, null, null);
     }
 
     private void doStagefrightTestMediaCodec(
-            final int rid, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaCodec(rid, null, checkMinCrashAddress);
+            final int rid, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaCodec(rid, null, config);
     }
 
     private void doStagefrightTestMediaCodec(final String url) throws Exception {
-        doStagefrightTestMediaCodec(url, true); // check crash address by default
+        doStagefrightTestMediaCodec(url, null);
     }
 
     private void doStagefrightTestMediaCodec(
-            final String url, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaCodec(-1, url, checkMinCrashAddress);
+            final String url, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaCodec(-1, url, config);
     }
 
     private void doStagefrightTestMediaCodec(final int rid, final String url) throws Exception {
-        doStagefrightTestMediaCodec(rid, url, true); // check crash address by default
+        doStagefrightTestMediaCodec(rid, url, null);
     }
 
     private void doStagefrightTestMediaCodec(
-            final int rid, final String url, boolean checkMinCrashAddress) throws Exception {
+            final int rid, final String url, CrashUtils.Config config) throws Exception {
 
-        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(checkMinCrashAddress);
+        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
 
         LooperThread thr = new LooperThread(new Runnable() {
             @Override
@@ -957,31 +967,31 @@
     }
 
     private void doStagefrightTestMediaMetadataRetriever(final int rid) throws Exception {
-        doStagefrightTestMediaMetadataRetriever(rid, true); // check crash address by default
+        doStagefrightTestMediaMetadataRetriever(rid, null, null);
     }
     private void doStagefrightTestMediaMetadataRetriever(
-            final int rid, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaMetadataRetriever(rid, null, checkMinCrashAddress);
+            final int rid, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaMetadataRetriever(rid, null, config);
     }
 
     private void doStagefrightTestMediaMetadataRetriever(final String url) throws Exception {
-        doStagefrightTestMediaMetadataRetriever(url, true); // check crash address by default
+        doStagefrightTestMediaMetadataRetriever(url, null);
     }
 
     private void doStagefrightTestMediaMetadataRetriever(
-            final String url, boolean checkMinCrashAddress) throws Exception {
-        doStagefrightTestMediaMetadataRetriever(-1, url, checkMinCrashAddress);
+            final String url, CrashUtils.Config config) throws Exception {
+        doStagefrightTestMediaMetadataRetriever(-1, url, config);
     }
 
     private void doStagefrightTestMediaMetadataRetriever(
             final int rid, final String url) throws Exception {
-        doStagefrightTestMediaMetadataRetriever(rid, url, true); // check crash address by default
+        doStagefrightTestMediaMetadataRetriever(rid, url, null);
     }
 
     private void doStagefrightTestMediaMetadataRetriever(
-            final int rid, final String url, boolean checkMinCrashAddress) throws Exception {
+            final int rid, final String url, CrashUtils.Config config) throws Exception {
 
-        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(checkMinCrashAddress);
+        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
 
         LooperThread thr = new LooperThread(new Runnable() {
             @Override
@@ -1054,11 +1064,13 @@
     }
 
     public void testBug36816007() throws Exception {
-        doStagefrightTestRawBlob(R.raw.bug_36816007, "video/avc", 320, 240, false);
+        doStagefrightTestRawBlob(R.raw.bug_36816007, "video/avc", 320, 240,
+                new CrashUtils.Config().checkMinAddress(false));
     }
 
     public void testBug36895511() throws Exception {
-        doStagefrightTestRawBlob(R.raw.bug_36895511, "video/hevc", 320, 240, false);
+        doStagefrightTestRawBlob(R.raw.bug_36895511, "video/hevc", 320, 240,
+                new CrashUtils.Config().checkMinAddress(false));
     }
 
     public void testBug64836894() throws Exception {
@@ -1082,7 +1094,8 @@
 
     @SecurityTest
     public void testBug_70897394() throws Exception {
-        doStagefrightTestRawBlob(R.raw.bug_70897394_avc, "video/avc", 320, 240);
+        doStagefrightTestRawBlob(R.raw.bug_70897394_avc, "video/avc", 320, 240,
+                new CrashUtils.Config().checkMinAddress(false));
     }
 
     private void runWithTimeout(Runnable runner, int timeout) {
@@ -1109,14 +1122,13 @@
 
     private void doStagefrightTestRawBlob(
             int rid, String mime, int initWidth, int initHeight) throws Exception {
-        // check crash address by default
-        doStagefrightTestRawBlob(rid, mime, initWidth, initHeight, true);
+        doStagefrightTestRawBlob(rid, mime, initWidth, initHeight, new CrashUtils.Config());
     }
 
     private void doStagefrightTestRawBlob(int rid, String mime, int initWidth, int initHeight,
-            boolean checkMinCrashAddress) throws Exception {
+            CrashUtils.Config config) throws Exception {
 
-        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(checkMinCrashAddress);
+        final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
         final Context context = getInstrumentation().getContext();
         final Resources resources =  context.getResources();
 
@@ -1229,16 +1241,16 @@
     }
 
     private void doStagefrightTestMediaPlayerANR(final int rid, final String uri) throws Exception {
-        doStagefrightTestMediaPlayerANR(rid, uri, true); // check crash address by default
+        doStagefrightTestMediaPlayerANR(rid, uri, null);
     }
 
     private void doStagefrightTestMediaPlayerANR(final int rid, final String uri,
-            boolean checkMinCrashAddress) throws Exception {
+            CrashUtils.Config config) throws Exception {
         String name = uri != null ? uri :
             getInstrumentation().getContext().getResources().getResourceEntryName(rid);
         Log.i(TAG, "start mediaplayerANR test for: " + name);
 
-        final MediaPlayerCrashListener mpl = new MediaPlayerCrashListener(checkMinCrashAddress);
+        final MediaPlayerCrashListener mpl = new MediaPlayerCrashListener(config);
 
         LooperThread t = new LooperThread(new Runnable() {
             @Override