From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: fgei Date: Wed, 28 Sep 2022 05:37:00 +0200 Subject: [PATCH] Handle web search action in browser --- .../src/org/chromium/base/PackageManagerUtils.java | 10 ++++++++++ chrome/android/java/AndroidManifest.xml | 4 ++++ .../chrome/browser/LaunchIntentDispatcher.java | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/base/android/java/src/org/chromium/base/PackageManagerUtils.java b/base/android/java/src/org/chromium/base/PackageManagerUtils.java index 2d1661ee534f6..2c983646ab42b 100644 --- a/base/android/java/src/org/chromium/base/PackageManagerUtils.java +++ b/base/android/java/src/org/chromium/base/PackageManagerUtils.java @@ -85,6 +85,16 @@ public class PackageManagerUtils { return canResolveActivity(intent, 0); } + public static boolean canOnlyOthersResolveActivity(Intent intent, int flags) { + for (ResolveInfo ri: queryIntentActivities(intent, flags)) { + if (ContextUtils.getApplicationContext() + .getPackageName().equals(ri.activityInfo.packageName)) { + return false; + } + } + return true; + } + /** * @return Intent to query a list of installed home launchers. */ diff --git a/chrome/android/java/AndroidManifest.xml b/chrome/android/java/AndroidManifest.xml index fba6543bde641..31feb44011a56 100644 --- a/chrome/android/java/AndroidManifest.xml +++ b/chrome/android/java/AndroidManifest.xml @@ -345,6 +345,10 @@ by a child template that "extends" this file. + + + + diff --git a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java index f06f00dcfbe3d..dc43814b49142 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java @@ -202,6 +202,7 @@ public class LaunchIntentDispatcher { String query = null; final String action = intent.getAction(); if (Intent.ACTION_SEARCH.equals(action) + || Intent.ACTION_WEB_SEARCH.equals(action) || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) { query = IntentUtils.safeGetStringExtra(intent, SearchManager.QUERY); } @@ -215,7 +216,7 @@ public class LaunchIntentDispatcher { searchIntent.putExtra(SearchManager.QUERY, query); try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { - if (PackageManagerUtils.canResolveActivity( + if (PackageManagerUtils.canOnlyOthersResolveActivity( searchIntent, PackageManager.GET_RESOLVED_FILTER)) { mActivity.startActivity(searchIntent); } else {