Prevent activity selection dialog spam
Only show the activity selection dialog if there is a non-browser
intent handler for the intent. For example, if you click on a
google maps link, we want to show the dialog so the user can
jump to the native app
Change-Id: I0671e9782c34a32623087861b0cc313c0c5405c8
diff --git a/src/com/android/browser/UrlHandler.java b/src/com/android/browser/UrlHandler.java
index f1d1c4c..686ed7b 100644
--- a/src/com/android/browser/UrlHandler.java
+++ b/src/com/android/browser/UrlHandler.java
@@ -19,15 +19,18 @@
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
-import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import java.net.URISyntaxException;
+import java.util.List;
/**
*
@@ -153,6 +156,9 @@
// security (only access to BROWSABLE activities).
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setComponent(null);
+ if (!isSpecializedHandlerAvailable(intent)) {
+ return false;
+ }
try {
if (mActivity.startActivityIfNeeded(intent, -1)) {
// before leaving BrowserActivity, close the empty child tab.
@@ -170,6 +176,33 @@
return false;
}
+ /**
+ * Search for intent handlers that are specific to this URL
+ * aka, specialized apps like google maps or youtube
+ */
+ private boolean isSpecializedHandlerAvailable(Intent intent) {
+ PackageManager pm = mActivity.getPackageManager();
+ List<ResolveInfo> handlers = pm.queryIntentActivities(intent,
+ PackageManager.GET_RESOLVED_FILTER);
+ if (handlers == null || handlers.size() == 0) {
+ return false;
+ }
+ for (ResolveInfo resolveInfo : handlers) {
+ IntentFilter filter = resolveInfo.filter;
+ if (filter == null) {
+ // No intent filter matches this intent?
+ // Error on the side of staying in the browser, ignore
+ continue;
+ }
+ if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) {
+ // Generic handler, skip
+ continue;
+ }
+ return true;
+ }
+ return false;
+ }
+
// In case a physical keyboard is attached, handle clicks with the menu key
// depressed by opening in a new tab
boolean handleMenuClick(Tab tab, String url) {