From dfcdb093c7452d24cbb334503927f76707bbe780 Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Fri, 31 Jan 2025 12:45:58 -0800 Subject: Adds a public Contextual Search invocation method. - Adds the new startContextualSearch() method. - Makes ContextualSearchManager non-hidden to expose that method. - The above clas and method are behind FLAG_SELF_INVOCATION. - This method requires the caller to have a foreground activity. - A corresponding startContextualSearchForForegroundApp() method is added to the service, which is is non-oneway to propagate SecurityException for background calls. Demo with SupportApp: https://drive.google.com/file/d/1Il-jWGosepboB9462yjn_vGA8hzDXaR2/view?usp=drive_link&resourcekey=0-dvuGjbwlML7UOST3IjJuDw Bug: 368653769 Test: Build and flash, invoke with SupportApp Flag: android.app.contextualsearch.flags.self_invocation Change-Id: I296ce39cb6349e41dc39a20820e5e445860e5c8a --- core/api/current.txt | 8 ++ core/api/system-current.txt | 4 +- .../contextualsearch/ContextualSearchManager.java | 121 ++++++++++++++++++--- .../contextualsearch/IContextualSearchManager.aidl | 7 +- .../android/app/contextualsearch/flags.aconfig | 8 ++ core/res/AndroidManifest.xml | 10 +- .../ContextualSearchManagerService.java | 77 ++++++++++--- 7 files changed, 191 insertions(+), 44 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index dd606774b770..666d0aa3954a 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -9187,6 +9187,14 @@ package android.app.blob { } +package android.app.contextualsearch { + + @FlaggedApi("android.app.contextualsearch.flags.self_invocation") public final class ContextualSearchManager { + method @FlaggedApi("android.app.contextualsearch.flags.self_invocation") public void startContextualSearch(); + } + +} + package android.app.jank { @FlaggedApi("android.app.jank.detailed_app_jank_metrics_api") public final class AppJankStats { diff --git a/core/api/system-current.txt b/core/api/system-current.txt index ab824119d643..354c16b889d8 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -7,7 +7,7 @@ package android { field public static final String ACCESS_BROADCAST_RADIO = "android.permission.ACCESS_BROADCAST_RADIO"; field public static final String ACCESS_BROADCAST_RESPONSE_STATS = "android.permission.ACCESS_BROADCAST_RESPONSE_STATS"; field public static final String ACCESS_CACHE_FILESYSTEM = "android.permission.ACCESS_CACHE_FILESYSTEM"; - field @FlaggedApi("android.app.contextualsearch.flags.enable_service") public static final String ACCESS_CONTEXTUAL_SEARCH = "android.permission.ACCESS_CONTEXTUAL_SEARCH"; + field public static final String ACCESS_CONTEXTUAL_SEARCH = "android.permission.ACCESS_CONTEXTUAL_SEARCH"; field public static final String ACCESS_CONTEXT_HUB = "android.permission.ACCESS_CONTEXT_HUB"; field public static final String ACCESS_DRM_CERTIFICATES = "android.permission.ACCESS_DRM_CERTIFICATES"; field @FlaggedApi("android.permission.flags.fine_power_monitor_permission") public static final String ACCESS_FINE_POWER_MONITORS = "android.permission.ACCESS_FINE_POWER_MONITORS"; @@ -2231,7 +2231,7 @@ package android.app.contextualsearch { field @NonNull public static final android.os.Parcelable.Creator CREATOR; } - public final class ContextualSearchManager { + @FlaggedApi("android.app.contextualsearch.flags.self_invocation") public final class ContextualSearchManager { method @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXTUAL_SEARCH) public void startContextualSearch(int); field public static final String ACTION_LAUNCH_CONTEXTUAL_SEARCH = "android.app.contextualsearch.action.LAUNCH_CONTEXTUAL_SEARCH"; field public static final int ENTRYPOINT_LONG_PRESS_HOME = 2; // 0x2 diff --git a/core/java/android/app/contextualsearch/ContextualSearchManager.java b/core/java/android/app/contextualsearch/ContextualSearchManager.java index 2ce431dcb32d..4e5fa6bac951 100644 --- a/core/java/android/app/contextualsearch/ContextualSearchManager.java +++ b/core/java/android/app/contextualsearch/ContextualSearchManager.java @@ -32,6 +32,9 @@ import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; /** * {@link ContextualSearchManager} is a system service to facilitate contextual search experience on @@ -39,10 +42,8 @@ import java.lang.annotation.RetentionPolicy; *

* This class lets a caller start contextual search by calling {@link #startContextualSearch} * method. - * - * @hide */ -@SystemApi +@FlaggedApi(Flags.FLAG_SELF_INVOCATION) public final class ContextualSearchManager { /** @@ -50,7 +51,9 @@ public final class ContextualSearchManager { * Only supposed to be used with ACTION_LAUNCH_CONTEXTUAL_SEARCH. * * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH + * @hide */ + @SystemApi public static final String EXTRA_ENTRYPOINT = "android.app.contextualsearch.extra.ENTRYPOINT"; @@ -60,7 +63,9 @@ public final class ContextualSearchManager { * Only supposed to be used with ACTION_LAUNCH_CONTEXTUAL_SEARCH. * * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH + * @hide */ + @SystemApi public static final String EXTRA_FLAG_SECURE_FOUND = "android.app.contextualsearch.extra.FLAG_SECURE_FOUND"; @@ -69,7 +74,9 @@ public final class ContextualSearchManager { * Only supposed to be used with ACTION_LAUNCH_CONTEXTUAL_SEARCH. * * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH + * @hide */ + @SystemApi public static final String EXTRA_SCREENSHOT = "android.app.contextualsearch.extra.SCREENSHOT"; @@ -79,7 +86,9 @@ public final class ContextualSearchManager { * Only supposed to be used with ACTION_LAUNCH_CONTEXTUAL_SEARCH. * * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH + * @hide */ + @SystemApi public static final String EXTRA_IS_MANAGED_PROFILE_VISIBLE = "android.app.contextualsearch.extra.IS_MANAGED_PROFILE_VISIBLE"; @@ -89,7 +98,9 @@ public final class ContextualSearchManager { * Only supposed to be used with ACTION_LAUNCH_CONTEXTUAL_SEARCH. * * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH + * @hide */ + @SystemApi public static final String EXTRA_VISIBLE_PACKAGE_NAMES = "android.app.contextualsearch.extra.VISIBLE_PACKAGE_NAMES"; @@ -98,10 +109,9 @@ public final class ContextualSearchManager { * {@link SystemClock#uptimeMillis()}. * Only supposed to be used with ACTION_LAUNCH_CONTEXTUAL_SEARCH. * - * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH - * * TODO: un-hide in W * + * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH * @hide */ public static final String EXTRA_INVOCATION_TIME_MS = @@ -113,7 +123,9 @@ public final class ContextualSearchManager { * Only supposed to be used with ACTION_LAUNCH_CONTEXTUAL_SEARCH. * * @see #ACTION_LAUNCH_CONTEXTUAL_SEARCH + * @hide */ + @SystemApi public static final String EXTRA_TOKEN = "android.app.contextualsearch.extra.TOKEN"; /** @@ -132,7 +144,10 @@ public final class ContextualSearchManager { * experience must add this intent filter action to the activity it wants to be launched. *
* Note This activity must not be exported. + * + * @hide */ + @SystemApi public static final String ACTION_LAUNCH_CONTEXTUAL_SEARCH = "android.app.contextualsearch.action.LAUNCH_CONTEXTUAL_SEARCH"; @@ -144,23 +159,63 @@ public final class ContextualSearchManager { public static final String FEATURE_CONTEXTUAL_SEARCH = "com.google.android.feature.CONTEXTUAL_SEARCH"; - /** Entrypoint to be used when a user long presses on the nav handle. */ + /** + * Entrypoint to be used when a user long presses on the nav handle. + * + * @hide + */ + @SystemApi public static final int ENTRYPOINT_LONG_PRESS_NAV_HANDLE = 1; - /** Entrypoint to be used when a user long presses on the home button. */ + + /** Entrypoint to be used when a user long presses on the home button. + * + * @hide + */ + @SystemApi public static final int ENTRYPOINT_LONG_PRESS_HOME = 2; - /** Entrypoint to be used when a user long presses on the overview button. */ + + /** Entrypoint to be used when a user long presses on the overview button. + * + * @hide + */ + @SystemApi public static final int ENTRYPOINT_LONG_PRESS_OVERVIEW = 3; - /** Entrypoint to be used when a user presses the action button in overview. */ + + /** + * Entrypoint to be used when a user presses the action button in overview. + * + * @hide + */ + @SystemApi public static final int ENTRYPOINT_OVERVIEW_ACTION = 4; - /** Entrypoint to be used when a user presses the context menu button in overview. */ + + /** + * Entrypoint to be used when a user presses the context menu button in overview. + * + * @hide + */ + @SystemApi public static final int ENTRYPOINT_OVERVIEW_MENU = 5; - /** Entrypoint to be used by system actions like TalkBack, Accessibility etc. */ + + /** + * Entrypoint to be used by system actions like TalkBack, Accessibility etc. + * + * @hide + */ + @SystemApi public static final int ENTRYPOINT_SYSTEM_ACTION = 9; - /** Entrypoint to be used when a user long presses on the meta key. */ + + /** + * Entrypoint to be used when a user long presses on the meta key. + * + * @hide + */ + @SystemApi public static final int ENTRYPOINT_LONG_PRESS_META = 10; + /** * The {@link Entrypoint} annotation is used to standardize the entrypoints supported by - * {@link #startContextualSearch} method. + * {@link #startContextualSearch(int entrypoint)} method. * * @hide */ @@ -174,8 +229,18 @@ public final class ContextualSearchManager { ENTRYPOINT_LONG_PRESS_META }) @Retention(RetentionPolicy.SOURCE) - public @interface Entrypoint { - } + public @interface Entrypoint {} + + private static final Set VALID_ENTRYPOINT_VALUES = new HashSet<>(Arrays.asList( + ENTRYPOINT_LONG_PRESS_NAV_HANDLE, + ENTRYPOINT_LONG_PRESS_HOME, + ENTRYPOINT_LONG_PRESS_OVERVIEW, + ENTRYPOINT_OVERVIEW_ACTION, + ENTRYPOINT_OVERVIEW_MENU, + ENTRYPOINT_SYSTEM_ACTION, + ENTRYPOINT_LONG_PRESS_META + )); + private static final String TAG = ContextualSearchManager.class.getSimpleName(); private static final boolean DEBUG = false; @@ -189,7 +254,7 @@ public final class ContextualSearchManager { } /** - * Used to start contextual search. + * Used to start contextual search for a given system entrypoint. *

* When {@link #startContextualSearch} is called, the system server does the following: *