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

Commit f13c0744 authored by Felix Oghina's avatar Felix Oghina Committed by Android (Google) Code Review
Browse files

Merge "[contextualsearch] address API feedback" into main

parents e533d851 e8446f61
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2186,7 +2186,7 @@ package android.app.contextualsearch {
    field @NonNull public static final android.os.Parcelable.Creator<android.app.contextualsearch.CallbackToken> CREATOR;
  }
  @FlaggedApi("android.app.contextualsearch.flags.enable_service") public class ContextualSearchManager {
  @FlaggedApi("android.app.contextualsearch.flags.enable_service") 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
+13 −2
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public final class CallbackToken implements Parcelable {
    private static final String TAG = CallbackToken.class.getSimpleName();
    private final IBinder mToken;

    private final Object mLock = new Object();
    private boolean mTokenUsed = false;

    public CallbackToken() {
@@ -75,10 +76,14 @@ public final class CallbackToken implements Parcelable {
    public void getContextualSearchState(@NonNull @CallbackExecutor Executor executor,
            @NonNull OutcomeReceiver<ContextualSearchState, Throwable> callback) {
        if (DEBUG) Log.d(TAG, "getContextualSearchState for token:" + mToken);
        if (mTokenUsed) {
        boolean tokenUsed;
        synchronized (mLock) {
            tokenUsed = markUsedLocked();
        }
        if (tokenUsed) {
            callback.onError(new IllegalAccessException("Token already used."));
            return;
        }
        mTokenUsed = true;
        try {
            // Get the service from the system server.
            IBinder b = ServiceManager.getService(Context.CONTEXTUAL_SEARCH_SERVICE);
@@ -96,6 +101,12 @@ public final class CallbackToken implements Parcelable {
        }
    }

    private boolean markUsedLocked() {
        boolean oldValue = mTokenUsed;
        mTokenUsed = true;
        return oldValue;
    }

    /**
     * Return the token necessary for validating the caller of {@link #getContextualSearchState}.
     *
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import java.lang.annotation.RetentionPolicy;
 */
@SystemApi
@FlaggedApi(Flags.FLAG_ENABLE_SERVICE)
public class ContextualSearchManager {
public final class ContextualSearchManager {

    /**
     * Key to get the entrypoint from the extras of the activity launched by contextual search.