From 0c7c5d59f8002500330b1571f9e5221d4316492f Mon Sep 17 00:00:00 2001 From: shafik Date: Wed, 27 Feb 2019 12:13:25 +0000 Subject: [PATCH] Display browsable layout for http/s scheme intents Displays Settings button instead of always button for all intents that have http or https scheme, as opposed to only intents that have BROWSABLE as category. This fixes an inconsistent and confusing behaviour that users were experiencing, as sometimes they saw the Always button and sometime the Settings button. Fixes: 126499502 Test: open a mail.google.com from Facebook Messenger - used to display Always button and now displays Settings button Test: use shell command to send https intent without BROWSABLE category - used to display Always button and now displays Settings button Change-Id: I1084fd716ba8e584c2b17d8fe1500dbc641cab46 --- .../com/android/internal/app/ResolverActivity.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 0919911303916..353bae6a1b12c 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -194,7 +194,7 @@ public class ResolverActivity extends Activity { com.android.internal.R.string.whichHomeApplicationNamed, com.android.internal.R.string.whichHomeApplicationLabel); - // SpR.id.buttonecial titles for BROWSABLE components + // titles for layout that deals with http(s) intents public static final int BROWSABLE_TITLE_RES = com.android.internal.R.string.whichGiveAccessToApplication; public static final int BROWSABLE_NAMED_TITLE_RES = @@ -302,7 +302,7 @@ public class ResolverActivity extends Activity { mUseLayoutForBrowsables = getTargetIntent() == null ? false - : getTargetIntent().hasCategory(Intent.CATEGORY_BROWSABLE); + : isHttpSchemeAndViewAction(getTargetIntent()); // We don't want to support Always Use if browsable layout is being used, // as to mitigate Intent Capturing vulnerability @@ -473,8 +473,8 @@ public class ResolverActivity extends Activity { final boolean named = mAdapter.getFilteredPosition() >= 0; if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) { return getString(defaultTitleRes); - } else if (intent.hasCategory(Intent.CATEGORY_BROWSABLE)) { - // If the Intent is BROWSABLE then we need to warn the user that + } else if (isHttpSchemeAndViewAction(intent)) { + // If the Intent's scheme is http(s) then we need to warn the user that // they're giving access for the activity to open URLs from this specific host return named ? getString(ActionTitle.BROWSABLE_NAMED_TITLE_RES, intent.getData().getHost(), @@ -583,6 +583,12 @@ public class ResolverActivity extends Activity { resetButtonBar(); } + private boolean isHttpSchemeAndViewAction(Intent intent) { + return (IntentFilter.SCHEME_HTTP.equals(intent.getScheme()) + || IntentFilter.SCHEME_HTTPS.equals(intent.getScheme())) + && Intent.ACTION_VIEW.equals(intent.getAction()); + } + private boolean hasManagedProfile() { UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); if (userManager == null) {