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

Commit 4f1fc19f authored by Sandeep Bandaru's avatar Sandeep Bandaru Committed by Android (Google) Code Review
Browse files

Merge "Add bundle validations on request/response and state params." into main

parents 94c30ca6 209dcc14
Loading
Loading
Loading
Loading
+44 −15
Original line number Diff line number Diff line
@@ -365,7 +365,6 @@ public final class OnDeviceIntelligenceManager {
     *                           associated params.
     */
    @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)

    public void processRequest(@NonNull Feature feature, @NonNull @InferenceParams Bundle request,
            @RequestType int requestType,
            @Nullable CancellationSignal cancellationSignal,
@@ -430,7 +429,7 @@ public final class OnDeviceIntelligenceManager {
     * @param cancellationSignal          signal to invoke cancellation.
     * @param processingSignal            signal to send custom signals in the
     *                                    remote implementation.
     * @param streamingResponseCallback streaming callback to populate the response content and
     * @param streamingProcessingCallback streaming callback to populate the response content and
     *                                    associated params.
     * @param callbackExecutor            executor to run the callback on.
     */
@@ -528,19 +527,18 @@ public final class OnDeviceIntelligenceManager {

    /**
     * {@link Bundle}s annotated with this type will be validated that they are in-effect read-only
     * when passed to inference service via Binder IPC. Following restrictions apply :
     * when passed via Binder IPC. Following restrictions apply :
     * <ul>
     * <li> No Nested Bundles are allowed.</li>
     * <li> {@link PersistableBundle}s are allowed.</li>
     * <li> Any primitive types or their collections can be added as usual.</li>
     * <li>IBinder objects should *not* be added.</li>
     * <li>Parcelable data which has no active-objects, should be added as
     * {@link Bundle#putByteArray}</li>
     * <li>Parcelables have active-objects, only following types will be allowed</li>
     * <ul>
     *  <li>{@link Bitmap} set as {@link Bitmap#setImmutable()}</li>
     *  <li>{@link android.database.CursorWindow}</li>
     *  <li>{@link android.os.ParcelFileDescriptor} opened in
     *  {@link android.os.ParcelFileDescriptor#MODE_READ_ONLY}</li>
     *  <li>{@link android.os.SharedMemory} set to {@link OsConstants#PROT_READ}</li>
     * </ul>
     * </ul>
     *
@@ -550,9 +548,40 @@ public final class OnDeviceIntelligenceManager {
     * @hide
     */
    @Target({ElementType.PARAMETER, ElementType.FIELD})
    public @interface StateParams {
    }

    /**
     * This is an extension of {@link StateParams} but for purpose of inference few other types are
     * also allowed as read-only, as listed below.
     *
     * <li>{@link Bitmap} set as immutable.</li>
     * <li>{@link android.database.CursorWindow}</li>
     * <li>{@link android.os.SharedMemory} set to {@link OsConstants#PROT_READ}</li>
     * </ul>
     * </ul>
     *
     * In all other scenarios the system-server might throw a
     * {@link android.os.BadParcelableException} if the Bundle validation fails.
     *
     * @hide
     */
    @Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.TYPE_USE})
    public @interface InferenceParams {
    }

    /**
     * This is an extension of {@link StateParams} with the exception that it allows writing
     * {@link Bitmap} as part of the response.
     *
     * In all other scenarios the system-server might throw a
     * {@link android.os.BadParcelableException} if the Bundle validation fails.
     *
     * @hide
     */
    @Target({ElementType.PARAMETER, ElementType.FIELD})
    public @interface ResponseParams {
    }

    @Nullable
    private static AndroidFuture<IBinder> configureRemoteCancellationFuture(
+4 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Bundle;
import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams;
import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.ResponseParams;

import java.util.function.Consumer;

@@ -43,7 +44,7 @@ public interface ProcessingCallback {
     *
     * @param result Response to be passed as a result.
     */
    void onResult(@NonNull @InferenceParams Bundle result);
    void onResult(@NonNull @ResponseParams Bundle result);

    /**
     * Called when the request processing fails. The failure details are indicated by the
@@ -64,8 +65,8 @@ public interface ProcessingCallback {
     *                         expected to be non-null or EMPTY when there is no response.
     */
    default void onDataAugmentRequest(
            @NonNull @InferenceParams Bundle processedContent,
            @NonNull Consumer<Bundle> contentConsumer) {
            @NonNull @ResponseParams Bundle processedContent,
            @NonNull Consumer<@InferenceParams Bundle> contentConsumer) {
        contentConsumer.accept(Bundle.EMPTY);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Bundle;
import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams;
import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.ResponseParams;

/**
 * Streaming variant of {@link ProcessingCallback} to populate response while processing a given
@@ -37,5 +37,5 @@ public interface StreamingProcessingCallback extends ProcessingCallback {
     * Callback that would be invoked when a part of the response i.e. some response is
     * already processed, and needs to be passed onto the caller.
     */
    void onPartialResult(@NonNull @InferenceParams Bundle partialResult);
    void onPartialResult(@NonNull @ResponseParams Bundle partialResult);
}
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ oneway interface IOnDeviceIntelligenceService {
    void getReadOnlyFileDescriptor(in String fileName, in AndroidFuture<ParcelFileDescriptor> future);
    void getReadOnlyFeatureFileDescriptorMap(in Feature feature, in RemoteCallback remoteCallback);
    void requestFeatureDownload(int callerUid, in Feature feature,
                                in AndroidFuture<ICancellationSignal> cancellationSignal,
                                in AndroidFuture cancellationSignal,
                                in IDownloadCallback downloadCallback);
    void registerRemoteServices(in IRemoteProcessingService remoteProcessingService);
    void notifyInferenceServiceConnected();
+5 −5
Original line number Diff line number Diff line
@@ -36,15 +36,15 @@ import android.service.ondeviceintelligence.IProcessingUpdateStatusCallback;
oneway interface IOnDeviceSandboxedInferenceService {
    void registerRemoteStorageService(in IRemoteStorageService storageService);
    void requestTokenInfo(int callerUid, in Feature feature, in Bundle request,
                            in AndroidFuture<ICancellationSignal> cancellationSignal,
                            in AndroidFuture cancellationSignal,
                            in ITokenInfoCallback tokenInfoCallback);
    void processRequest(int callerUid, in Feature feature, in Bundle request, in int requestType,
                        in AndroidFuture<ICancellationSignal> cancellationSignal,
                        in AndroidFuture<IProcessingSignal> processingSignal,
                        in AndroidFuture cancellationSignal,
                        in AndroidFuture processingSignal,
                        in IResponseCallback callback);
    void processRequestStreaming(int callerUid, in Feature feature, in Bundle request, in int requestType,
                                in AndroidFuture<ICancellationSignal> cancellationSignal,
                                in AndroidFuture<IProcessingSignal> processingSignal,
                                in AndroidFuture cancellationSignal,
                                in AndroidFuture processingSignal,
                                in IStreamingResponseCallback callback);
    void updateProcessingState(in Bundle processingState,
                                     in IProcessingUpdateStatusCallback callback);
Loading