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

Commit 9f22c535 authored by Perumaal Shanmugam's avatar Perumaal Shanmugam Committed by Android (Google) Code Review
Browse files

Merge "Change provideContextImage() API to accept Bitmap"

parents ad1c710e 3c78cc58
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1174,6 +1174,7 @@ package android.app.contentsuggestions {
    method public void classifyContentSelections(@NonNull android.app.contentsuggestions.ClassificationsRequest, @NonNull java.util.concurrent.Executor, @NonNull android.app.contentsuggestions.ContentSuggestionsManager.ClassificationsCallback);
    method public boolean isEnabled();
    method public void notifyInteraction(@NonNull String, @NonNull android.os.Bundle);
    method public void provideContextImage(@NonNull android.graphics.Bitmap, @NonNull android.os.Bundle);
    method public void provideContextImage(int, @NonNull android.os.Bundle);
    method public void suggestContentSelections(@NonNull android.app.contentsuggestions.SelectionsRequest, @NonNull java.util.concurrent.Executor, @NonNull android.app.contentsuggestions.ContentSuggestionsManager.SelectionsCallback);
  }
+23 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.UserIdInt;
import android.graphics.Bitmap;
import android.os.Binder;
import android.os.Bundle;
import android.os.RemoteException;
@@ -76,6 +77,28 @@ public final class ContentSuggestionsManager {
        mUser = userId;
    }

    /**
     * Hints to the system that a new context image using the provided bitmap should be sent to
     * the system content suggestions service.
     *
     * @param bitmap the new context image
     * @param imageContextRequestExtras sent with request to provide implementation specific
     *                                  extra information.
     */
    public void provideContextImage(
            @NonNull Bitmap bitmap, @NonNull Bundle imageContextRequestExtras) {
        if (mService == null) {
            Log.e(TAG, "provideContextImage called, but no ContentSuggestionsManager configured");
            return;
        }

        try {
            mService.provideContextBitmap(mUser, bitmap, imageContextRequestExtras);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Hints to the system that a new context image for the provided task should be sent to the
     * system content suggestions service.
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.contentsuggestions.IClassificationsCallback;
import android.app.contentsuggestions.ISelectionsCallback;
import android.app.contentsuggestions.ClassificationsRequest;
import android.app.contentsuggestions.SelectionsRequest;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.UserHandle;
import com.android.internal.os.IResultReceiver;
@@ -30,6 +31,10 @@ oneway interface IContentSuggestionsManager {
            int userId,
            int taskId,
            in Bundle imageContextRequestExtras);
    void provideContextBitmap(
            int userId,
            in Bitmap bitmap,
            in Bundle imageContextRequestExtras);
    void suggestContentSelections(
            int userId,
            in SelectionsRequest request,
+32 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.app.contentsuggestions.IContentSuggestionsManager;
import android.app.contentsuggestions.ISelectionsCallback;
import android.app.contentsuggestions.SelectionsRequest;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Binder;
import android.os.Bundle;
import android.os.RemoteException;
@@ -61,6 +62,10 @@ public class ContentSuggestionsManagerService extends
    private static final boolean VERBOSE = false; // TODO: make dynamic

    private static final int MAX_TEMP_SERVICE_DURATION_MS = 1_000 * 60 * 2; // 2 minutes
    /**
     * Key into the extras Bundle passed to {@link #provideContextImage(int, Bundle)}.
     */
    private static final String EXTRA_BITMAP = "android.contentsuggestions.extra.BITMAP";

    private ActivityTaskManagerInternal mActivityTaskManagerInternal;

@@ -110,6 +115,33 @@ public class ContentSuggestionsManagerService extends
    }

    private class ContentSuggestionsManagerStub extends IContentSuggestionsManager.Stub {
        @Override
        public void provideContextBitmap(
                int userId,
                @NonNull Bitmap bitmap,
                @NonNull Bundle imageContextRequestExtras) {
            if (bitmap == null) {
                throw new IllegalArgumentException("Expected non-null bitmap");
            }
            if (imageContextRequestExtras == null) {
                throw new IllegalArgumentException("Expected non-null imageContextRequestExtras");
            }
            enforceCaller(UserHandle.getCallingUserId(), "provideContextBitmap");

            synchronized (mLock) {
                final ContentSuggestionsPerUserService service = getServiceForUserLocked(userId);
                if (service != null) {
                    // TODO(b/147324195): Temporarily pass bitmap until we change the service API.
                    imageContextRequestExtras.putParcelable(EXTRA_BITMAP, bitmap);
                    service.provideContextImageLocked(/* taskId = */ -1, imageContextRequestExtras);
                } else {
                    if (VERBOSE) {
                        Slog.v(TAG, "provideContextImageLocked: no service for " + userId);
                    }
                }
            }
        }

        @Override
        public void provideContextImage(
                int userId,