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

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

Merge "Add isContextualSearchAvailable() method and improve documentation." into main

parents 5e6ab733 2ba53334
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9433,6 +9433,7 @@ 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 boolean isContextualSearchAvailable();
    method @FlaggedApi("android.app.contextualsearch.flags.self_invocation") public void startContextualSearch();
  }
+32 −2
Original line number Diff line number Diff line
@@ -253,6 +253,26 @@ public final class ContextualSearchManager {
        mService = IContextualSearchManager.Stub.asInterface(b);
    }

    /**
     * Used to check whether contextual search is available on the device. This method should be
     * called before calling {@link #startContextualSearch()} or adding any UI related to it to
     * ensure that the device is configured to support contextual search.
     *
     * @see #startContextualSearch()
     * @return true if contextual search is available on the device, false otherwise.
     */
    @FlaggedApi(Flags.FLAG_SELF_INVOCATION)
    public boolean isContextualSearchAvailable() {
        if (DEBUG) Log.d(TAG, "isContextualSearchAvailable");
        try {
            return mService.isContextualSearchAvailable();
        } catch (RemoteException e) {
            if (DEBUG) Log.e(TAG, "Failed to determine isContextualSearchAvailable", e);
            e.rethrowFromSystemServer();
        }
        return false;
    }

    /**
     * Used to start contextual search for a given system entrypoint.
     * <p>
@@ -267,6 +287,8 @@ public final class ContextualSearchManager {
     *     </ul>
     * </p>
     *
     * <p>This method will fail silently if Contextual Search is not available on the device.
     *
     * @param entrypoint the invocation entrypoint
     *
     * @hide
@@ -287,10 +309,18 @@ public final class ContextualSearchManager {
    }

    /**
     * Used to start contextual search from within an app.
     * Used to start Contextual Search from within an app. This will send a screenshot to the
     * Contextual Search app designated by the device manufacturer. The user can then select content
     * on the screenshot to get a search result or take an action such as calling a phone number or
     * translating the text.
     *
     * <p>Prior to calling this method or showing any UI related to it, you should verify that
     * Contextual Search is available on the device by using {@link #isContextualSearchAvailable()}.
     * Otherwise, this method will fail silently.
     *
     * <p>System apps should use the available System APIs rather than this method.
     * <p>This method should only be called from an app that has a foreground Activity.
     *
     * @see #isContextualSearchAvailable()
     * @throws SecurityException if the caller does not have a foreground Activity.
     */
    @FlaggedApi(Flags.FLAG_SELF_INVOCATION)
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import android.app.contextualsearch.IContextualSearchCallback;
 * @hide
 */
interface IContextualSearchManager {
  boolean isContextualSearchAvailable();
  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
@@ -20,6 +20,7 @@ import static android.Manifest.permission.ACCESS_CONTEXTUAL_SEARCH;
import static android.app.AppOpsManager.OP_ASSIST_SCREENSHOT;
import static android.app.AppOpsManager.OP_ASSIST_STRUCTURE;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.contextualsearch.ContextualSearchManager.FEATURE_CONTEXTUAL_SEARCH;
import static android.content.Context.CONTEXTUAL_SEARCH_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
@@ -515,6 +516,13 @@ public class ContextualSearchManagerService extends SystemService {
            }
        }

        @Override
        public boolean isContextualSearchAvailable() {
            return mContext.getPackageManager().hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)
                    && getResolvedLaunchIntent(Binder.getCallingUserHandle().getIdentifier())
                            != null;
        }

        @Override
        public void startContextualSearchForForegroundApp() {
            synchronized (this) {