From 7bd98d251947a0adbb42cbfb35abaca6c8f6543c Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Wed, 20 Feb 2019 11:23:15 -0800 Subject: [PATCH] Use MATCH_ALL to query available browsers. Browser intent resolution has been special for a long time, and we need to pass MATCH_ALL to get all the candidates, then do manual filtering later. Bug: 116216651 Test: manual Change-Id: I5e9b7b907005f73b7c54c3253c872d85ef7c4863 --- .../defaultapps/DefaultBrowserPreferenceController.java | 9 ++++++--- .../DefaultBrowserPreferenceControllerTest.java | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java index 24b4dcd501e..6cd72f70db8 100644 --- a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java +++ b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java @@ -45,7 +45,8 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont static final Intent BROWSE_PROBE = new Intent() .setAction(Intent.ACTION_VIEW) .addCategory(Intent.CATEGORY_BROWSABLE) - .setData(Uri.parse("http:")); + .setData(Uri.parse("http:")) + .addFlags(Intent.FLAG_IGNORE_EPHEMERAL); public DefaultBrowserPreferenceController(Context context) { super(context); @@ -112,11 +113,13 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont final List candidates = new ArrayList<>(); // Resolve that intent and check that the handleAllWebDataURI boolean is set final List list = packageManager.queryIntentActivitiesAsUser( - BROWSE_PROBE, 0 /* flags */, userId); + BROWSE_PROBE, PackageManager.MATCH_ALL, userId); if (list != null) { final Set addedPackages = new ArraySet<>(); for (ResolveInfo info : list) { - if (info.activityInfo == null || !info.handleAllWebDataURI) { + if (!info.handleAllWebDataURI || info.activityInfo == null + || !info.activityInfo.enabled + || !info.activityInfo.applicationInfo.enabled) { continue; } final String packageName = info.activityInfo.packageName; diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java index 03b3867848d..1aa9f9d2c7a 100644 --- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java @@ -181,11 +181,11 @@ public class DefaultBrowserPreferenceControllerTest { } @Test - public void getCandidates_shouldQueryActivityWithFlagsEquals0() { + public void getCandidates_shouldQueryActivityWithMatchAll() { DefaultBrowserPreferenceController.getCandidates(mPackageManager, 0 /* userId */); verify(mPackageManager).queryIntentActivitiesAsUser( - any(Intent.class), eq(0) /* flags */, eq(0) /* userId */); + any(Intent.class), eq(PackageManager.MATCH_ALL), eq(0) /* userId */); } @Test @@ -221,6 +221,7 @@ public class DefaultBrowserPreferenceControllerTest { info.handleAllWebDataURI = true; info.activityInfo = new ActivityInfo(); info.activityInfo.packageName = packageName; + info.activityInfo.applicationInfo = createApplicationInfo(packageName); return info; }