Commit b5cbbae4 authored by Xi Han's avatar Xi Han Committed by Commit Bot

Fix WebAPKs doesn't find Chrome when it is installed.

On Android Q, queryIntentActivities(.. , MATCH_ALL) doesn't return
Chrome even if Chrome is installed. Passing MATCH_DEFAULT_ONLY
instead will fix this issue.

Bug: 851725
Change-Id: Id851ec9fcbea47df5a522a23355ad2b67401544f
Reviewed-on: https://chromium-review.googlesource.com/1222675
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591133}
parent c1dd83c1
...@@ -206,7 +206,7 @@ public class HostBrowserUtilsTest { ...@@ -206,7 +206,7 @@ public class HostBrowserUtilsTest {
private void uninstallBrowser(String packageName) { private void uninstallBrowser(String packageName) {
Intent intent = null; Intent intent = null;
try { try {
intent = Intent.parseUri("http://", Intent.URI_INTENT_SCHEME); intent = WebApkUtils.getQueryInstalledBrowsersIntent();
} catch (Exception e) { } catch (Exception e) {
Assert.fail(); Assert.fail();
return; return;
...@@ -228,7 +228,7 @@ public class HostBrowserUtilsTest { ...@@ -228,7 +228,7 @@ public class HostBrowserUtilsTest {
private void mockInstallBrowsers(String[] browsersToInstall, String defaultBrowser) { private void mockInstallBrowsers(String[] browsersToInstall, String defaultBrowser) {
Intent intent = null; Intent intent = null;
try { try {
intent = Intent.parseUri("http://", Intent.URI_INTENT_SCHEME); intent = WebApkUtils.getQueryInstalledBrowsersIntent();
} catch (Exception e) { } catch (Exception e) {
Assert.fail(); Assert.fail();
return; return;
......
...@@ -197,7 +197,7 @@ public final class MainActivityTest { ...@@ -197,7 +197,7 @@ public final class MainActivityTest {
} }
private void installBrowser(String browserPackageName) { private void installBrowser(String browserPackageName) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://")); Intent intent = WebApkUtils.getQueryInstalledBrowsersIntent();
Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager()) Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager())
.addResolveInfoForIntent(intent, newResolveInfo(browserPackageName)); .addResolveInfoForIntent(intent, newResolveInfo(browserPackageName));
Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager()) Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager())
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# (including AndroidManifest.xml) is updated. This version should be incremented # (including AndroidManifest.xml) is updated. This version should be incremented
# prior to uploading a new ShellAPK to the WebAPK Minting Server. # prior to uploading a new ShellAPK to the WebAPK Minting Server.
# Does not affect Chrome.apk # Does not affect Chrome.apk
template_shell_apk_version = 51 template_shell_apk_version = 52
# The ShellAPK version expected by Chrome. Chrome will try to update the WebAPK # The ShellAPK version expected by Chrome. Chrome will try to update the WebAPK
# if the WebAPK's ShellAPK version is less than |expected_shell_apk_version|. # if the WebAPK's ShellAPK version is less than |expected_shell_apk_version|.
......
...@@ -11,7 +11,6 @@ import android.content.pm.ApplicationInfo; ...@@ -11,7 +11,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import org.chromium.webapk.lib.common.WebApkConstants; import org.chromium.webapk.lib.common.WebApkConstants;
...@@ -182,7 +181,7 @@ public class HostBrowserUtils { ...@@ -182,7 +181,7 @@ public class HostBrowserUtils {
/** Returns the package name of the default browser on the Android device. */ /** Returns the package name of the default browser on the Android device. */
private static String getDefaultBrowserPackageName(PackageManager packageManager) { private static String getDefaultBrowserPackageName(PackageManager packageManager) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://")); Intent browserIntent = WebApkUtils.getQueryInstalledBrowsersIntent();
ResolveInfo resolveInfo = ResolveInfo resolveInfo =
packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY); packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo == null || resolveInfo.activityInfo == null) return null; if (resolveInfo == null || resolveInfo.activityInfo == null) return null;
......
...@@ -90,10 +90,11 @@ public class WebApkUtils { ...@@ -90,10 +90,11 @@ public class WebApkUtils {
/** Returns a list of ResolveInfo for all of the installed browsers. */ /** Returns a list of ResolveInfo for all of the installed browsers. */
public static List<ResolveInfo> getInstalledBrowserResolveInfos(PackageManager packageManager) { public static List<ResolveInfo> getInstalledBrowserResolveInfos(PackageManager packageManager) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://")); Intent browserIntent = getQueryInstalledBrowsersIntent();
// Note: {@link PackageManager#queryIntentActivities()} does not return ResolveInfos for // Note: {@link PackageManager#queryIntentActivities()} does not return ResolveInfos for
// disabled browsers. // disabled browsers.
return packageManager.queryIntentActivities(browserIntent, PackageManager.MATCH_ALL); return packageManager.queryIntentActivities(
browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
} }
/** /**
...@@ -150,4 +151,14 @@ public class WebApkUtils { ...@@ -150,4 +151,14 @@ public class WebApkUtils {
int version = Integer.parseInt(versionName.substring(0, dotIndex)); int version = Integer.parseInt(versionName.substring(0, dotIndex));
return version < MINIMUM_REQUIRED_CHROME_VERSION; return version < MINIMUM_REQUIRED_CHROME_VERSION;
} }
/**
* Returns the Intent to query a list of installed browser apps.
*/
static Intent getQueryInstalledBrowsersIntent() {
return new Intent()
.setAction(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(Uri.parse("http://"));
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment