Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d9c4215 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adds a public Contextual Search invocation method." into main

parents afcfbde2 dfcdb093
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -9188,6 +9188,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 {
+2 −2
Original line number Diff line number Diff line
@@ -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<android.app.contextualsearch.CallbackToken> 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
+105 −16
Original line number Diff line number Diff line
@@ -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;
 * <p>
 * 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.
     * <br>
     * <b>Note</b> 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<Integer> 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.
     * <p>
     *     When {@link #startContextualSearch} is called, the system server does the following:
     *     <ul>
@@ -202,9 +267,15 @@ public final class ContextualSearchManager {
     * </p>
     *
     * @param entrypoint the invocation entrypoint
     *
     * @hide
     */
    @RequiresPermission(ACCESS_CONTEXTUAL_SEARCH)
    @SystemApi
    public void startContextualSearch(@Entrypoint int entrypoint) {
        if (!VALID_ENTRYPOINT_VALUES.contains(entrypoint)) {
            throw new IllegalArgumentException("Invalid entrypoint: " + entrypoint);
        }
        if (DEBUG) Log.d(TAG, "startContextualSearch for entrypoint: " + entrypoint);
        try {
            mService.startContextualSearch(entrypoint);
@@ -213,4 +284,22 @@ public final class ContextualSearchManager {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Used to start contextual search from within an app.
     *
     * <p>System apps should use the available System APIs rather than this method.
     *
     * @throws SecurityException if the caller does not have a foreground Activity.
     */
    @FlaggedApi(Flags.FLAG_SELF_INVOCATION)
    public void startContextualSearch() {
        if (DEBUG) Log.d(TAG, "startContextualSearch from app");
        try {
            mService.startContextualSearchForForegroundApp();
        } catch (RemoteException e) {
            if (DEBUG) Log.d(TAG, "Failed to startContextualSearch", e);
            e.rethrowFromSystemServer();
        }
    }
}
+4 −3
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@ import android.app.contextualsearch.IContextualSearchCallback;
/**
 * @hide
 */
oneway interface IContextualSearchManager {
  void startContextualSearch(int entrypoint);
  void getContextualSearchState(in IBinder token, in IContextualSearchCallback callback);
interface IContextualSearchManager {
  void startContextualSearchForForegroundApp();
  oneway void startContextualSearch(int entrypoint);
  oneway void getContextualSearchState(in IBinder token, in IContextualSearchCallback callback);
}
+8 −0
Original line number Diff line number Diff line
@@ -39,3 +39,11 @@ flag {
    description: "Add audio playing status to the contextual search invocation intent."
    bug: "372935419"
}

flag {
  name: "self_invocation"
  namespace: "sysui_integrations"
  description: "Enable apps to self-invoke Contextual Search."
  bug: "368653769"
  is_exported: true
}
Loading