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 ++++ .../src/org/chromium/chrome/browser/IntentHandler.java | 1 + .../chrome/browser/LaunchIntentDispatcher.java | 2 +- 4 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 db72fb7356e29..575050c5c0d06 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. + # DOWNSTREAM + + + # DOWNSTREAM diff --git a/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java index 3647020cb02d8..da7ad2c4a09ac 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java @@ -768,6 +768,7 @@ public class IntentHandler { 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); } 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 aa44a679bee3c..e75c14b279c33 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java @@ -211,7 +211,7 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega 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 {