Update isBrowserPresent to understand stubs

Since supporting ACTION_VIEW with the default flags is required, devices
without a built-in browser will include an intent filter with negative
priority to stop ActivityNotFoundException being thrown when eg. web
views fire an intent.

Bug: 158095408
Test: atest MatchFlagTests
Change-Id: I454a1b78306b54f8f8a0557d8eb3f8f18647d6a7
diff --git a/tests/tests/match_flags/src/android/matchflags/cts/MatchFlagTests.java b/tests/tests/match_flags/src/android/matchflags/cts/MatchFlagTests.java
index 74024df..77a00f8 100644
--- a/tests/tests/match_flags/src/android/matchflags/cts/MatchFlagTests.java
+++ b/tests/tests/match_flags/src/android/matchflags/cts/MatchFlagTests.java
@@ -52,7 +52,7 @@
                 .addCategory(Intent.CATEGORY_BROWSABLE)
                 .setData(Uri.parse(ONLY_BROWSER_URI));
 
-        if (isBrowserPresent()) {
+        if (isBrowserPresent(true)) {
             startActivity(onlyBrowserIntent);
         } else {
             try {
@@ -110,7 +110,7 @@
                 .addFlags(Intent.FLAG_ACTIVITY_REQUIRE_NON_BROWSER)
                 .addFlags(Intent.FLAG_ACTIVITY_REQUIRE_DEFAULT);
 
-        if (isBrowserPresent()) {
+        if (isBrowserPresent(false)) {
             // with non-browser, we'd expect the resolver
             // with require default, we'll get activity not found
             try {
@@ -126,12 +126,14 @@
         }
     }
 
-    private static boolean isBrowserPresent() {
+    private static boolean isBrowserPresent(boolean includeFallback) {
         return InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager()
                 .queryIntentActivities(new Intent(Intent.ACTION_VIEW).addCategory(
                         Intent.CATEGORY_BROWSABLE).setData(Uri.parse(ONLY_BROWSER_URI)),
                         0 /* flags */)
-                .stream().anyMatch(resolveInfo -> resolveInfo.handleAllWebDataURI);
+                .stream().anyMatch(resolveInfo ->
+                        resolveInfo.handleAllWebDataURI
+                        && (includeFallback || resolveInfo.priority >= 0));
     }
 
     private static void startActivity(Intent onlyBrowserIntent) {