Put native apps above browser in resolver activity.

Add a special case for situations where we have some activities
that are matching a URI host/path, so that these are ordered
above others.  This only happens when dealing with http or https
intents, for ordering native apps above the browser.

Change-Id: I21f3361229bc7a1ebefda66373d31b6b1fd19973
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java
index 376db6e..2db466a 100644
--- a/core/java/com/android/internal/app/ResolverActivity.java
+++ b/core/java/com/android/internal/app/ResolverActivity.java
@@ -840,7 +840,7 @@
                 }
                 if (N > 1) {
                     Comparator<ResolveInfo> rComparator =
-                            new ResolverComparator(ResolverActivity.this);
+                            new ResolverComparator(ResolverActivity.this, mIntent);
                     Collections.sort(currentResolveList, rComparator);
                 }
                 // First put the initial items at the top.
@@ -1093,11 +1093,20 @@
         }
     }
 
+    static final boolean isSpecificUriMatch(int match) {
+        match = match&IntentFilter.MATCH_CATEGORY_MASK;
+        return match >= IntentFilter.MATCH_CATEGORY_HOST
+                && match <= IntentFilter.MATCH_CATEGORY_PATH;
+    }
+
     class ResolverComparator implements Comparator<ResolveInfo> {
         private final Collator mCollator;
+        private final boolean mHttp;
 
-        public ResolverComparator(Context context) {
+        public ResolverComparator(Context context, Intent intent) {
             mCollator = Collator.getInstance(context.getResources().getConfiguration().locale);
+            String scheme = intent.getScheme();
+            mHttp = "http".equals(scheme) || "https".equals(scheme);
         }
 
         @Override
@@ -1107,6 +1116,17 @@
                 return 1;
             }
 
+            if (mHttp) {
+                // Special case: we want filters that match URI paths/schemes to be
+                // ordered before others.  This is for the case when opening URIs,
+                // to make native apps go above browsers.
+                final boolean lhsSpecific = isSpecificUriMatch(lhs.match);
+                final boolean rhsSpecific = isSpecificUriMatch(rhs.match);
+                if (lhsSpecific != rhsSpecific) {
+                    return lhsSpecific ? -1 : 1;
+                }
+            }
+
             if (mStats != null) {
                 final long timeDiff =
                         getPackageTimeSpent(rhs.activityInfo.packageName) -