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

Commit 70694b00 authored by Satakshi Rana's avatar Satakshi Rana Committed by Android (Google) Code Review
Browse files

Merge "Allow passing the bitmap to ContentSuggestionsService via the extras Bundle"

parents 645256e6 c45d86fc
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -45,6 +45,17 @@ import java.util.concurrent.Executor;
 */
@SystemApi
public final class ContentSuggestionsManager {
    /**
     * Key into the extras Bundle passed to {@link #provideContextImage(int, Bundle)}.
     * This can be used to provide the bitmap to
     * {@link android.service.contentsuggestions.ContentSuggestionsService}.
     * The value must be a {@link android.graphics.Bitmap} with the
     * config {@link android.graphics.Bitmap.Config.HARDWARE}.
     *
     * @hide
     */
    public static final String EXTRA_BITMAP = "android.contentsuggestions.extra.BITMAP";

    private static final String TAG = ContentSuggestionsManager.class.getSimpleName();

    /**
@@ -70,7 +81,7 @@ public final class ContentSuggestionsManager {
     * system content suggestions service.
     *
     * @param taskId of the task to snapshot.
     * @param imageContextRequestExtras sent with with request to provide implementation specific
     * @param imageContextRequestExtras sent with request to provide implementation specific
     *                                  extra information.
     */
    public void provideContextImage(
+10 −5
Original line number Diff line number Diff line
@@ -66,6 +66,10 @@ public abstract class ContentSuggestionsService extends Service {
                int colorSpaceId, Bundle imageContextRequestExtras) {

            Bitmap wrappedBuffer = null;
            if (imageContextRequestExtras.containsKey(ContentSuggestionsManager.EXTRA_BITMAP)) {
                wrappedBuffer = imageContextRequestExtras.getParcelable(
                        ContentSuggestionsManager.EXTRA_BITMAP);
            } else {
                if (contextImage != null) {
                    ColorSpace colorSpace = null;
                    if (colorSpaceId >= 0 && colorSpaceId < ColorSpace.Named.values().length) {
@@ -73,6 +77,7 @@ public abstract class ContentSuggestionsService extends Service {
                    }
                    wrappedBuffer = Bitmap.wrapHardwareBuffer(contextImage, colorSpace);
                }
            }

            mHandler.sendMessage(
                    obtainMessage(ContentSuggestionsService::onProcessContextImage,
+12 −7
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AppGlobals;
import android.app.contentsuggestions.ClassificationsRequest;
import android.app.contentsuggestions.ContentSuggestionsManager;
import android.app.contentsuggestions.IClassificationsCallback;
import android.app.contentsuggestions.ISelectionsCallback;
import android.app.contentsuggestions.SelectionsRequest;
@@ -97,10 +98,13 @@ public final class ContentSuggestionsPerUserService extends
    void provideContextImageLocked(int taskId, @NonNull Bundle imageContextRequestExtras) {
        RemoteContentSuggestionsService service = ensureRemoteServiceLocked();
        if (service != null) {
            ActivityManager.TaskSnapshot snapshot =
                    mActivityTaskManagerInternal.getTaskSnapshotNoRestore(taskId, false);
            GraphicBuffer snapshotBuffer = null;
            int colorSpaceId = 0;

            // Skip taking TaskSnapshot when bitmap is provided.
            if (!imageContextRequestExtras.containsKey(ContentSuggestionsManager.EXTRA_BITMAP)) {
                ActivityManager.TaskSnapshot snapshot =
                        mActivityTaskManagerInternal.getTaskSnapshotNoRestore(taskId, false);
                if (snapshot != null) {
                    snapshotBuffer = snapshot.getSnapshot();
                    ColorSpace colorSpace = snapshot.getColorSpace();
@@ -108,6 +112,7 @@ public final class ContentSuggestionsPerUserService extends
                        colorSpaceId = colorSpace.getId();
                    }
                }
            }

            service.provideContextImage(taskId, snapshotBuffer, colorSpaceId,
                    imageContextRequestExtras);