From e1fb96676cd2404c5de091d60828185228ef4c90 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Mon, 31 Aug 2009 14:31:52 -0400 Subject: [PATCH] Do not include ourselves as a candidate for downloading content. If we are attempting to download a file and try to resolve to another activity, it is possible to get BrowserActivity as the best candidate. In that case, we need to fall back to the download manager. If we do not, we end up in a loop trying to download the file and sending ourselves a new intent. BUG: 2062310 --- src/com/android/browser/BrowserActivity.java | 37 +++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index c766c74..3f0569a 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -3172,23 +3172,36 @@ public class BrowserActivity extends Activity // if we're dealing wih A/V content that's not explicitly marked // for download, check if it's streamable. if (contentDisposition == null - || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { + || !contentDisposition.regionMatches( + true, 0, "attachment", 0, 10)) { // query the package manager to see if there's a registered handler // that matches. Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(url), mimetype); - if (getPackageManager().resolveActivity(intent, - PackageManager.MATCH_DEFAULT_ONLY) != null) { - // someone knows how to handle this mime type with this scheme, don't download. - try { - startActivity(intent); - return; - } catch (ActivityNotFoundException ex) { - if (LOGD_ENABLED) { - Log.d(LOGTAG, "activity not found for " + mimetype - + " over " + Uri.parse(url).getScheme(), ex); + ResolveInfo info = getPackageManager().resolveActivity(intent, + PackageManager.MATCH_DEFAULT_ONLY); + if (info != null) { + ComponentName myName = getComponentName(); + // If we resolved to ourselves, we don't want to attempt to + // load the url only to try and download it again. + if (!myName.getPackageName().equals( + info.activityInfo.packageName) + || !myName.getClassName().equals( + info.activityInfo.name)) { + // someone (other than us) knows how to handle this mime + // type with this scheme, don't download. + try { + startActivity(intent); + return; + } catch (ActivityNotFoundException ex) { + if (LOGD_ENABLED) { + Log.d(LOGTAG, "activity not found for " + mimetype + + " over " + Uri.parse(url).getScheme(), + ex); + } + // Best behavior is to fall back to a download in this + // case } - // Best behavior is to fall back to a download in this case } } } -- 2.11.0