Loading core/java/android/app/ondeviceintelligence/OnDeviceIntelligenceManager.java +38 −8 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.content.ComponentName; import android.content.Context; import android.graphics.Bitmap; import android.os.Binder; import android.os.Bundle; import android.os.CancellationSignal; Loading @@ -36,6 +37,7 @@ import android.os.OutcomeReceiver; import android.os.PersistableBundle; import android.os.RemoteCallback; import android.os.RemoteException; import android.system.OsConstants; import androidx.annotation.IntDef; Loading Loading @@ -313,7 +315,7 @@ public final class OnDeviceIntelligenceManager { * @param callbackExecutor executor to run the callback on. */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void requestTokenInfo(@NonNull Feature feature, @NonNull Bundle request, public void requestTokenInfo(@NonNull Feature feature, @NonNull @InferenceParams Bundle request, @Nullable CancellationSignal cancellationSignal, @NonNull @CallbackExecutor Executor callbackExecutor, @NonNull OutcomeReceiver<TokenInfo, Loading Loading @@ -369,7 +371,7 @@ public final class OnDeviceIntelligenceManager { */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequest(@NonNull Feature feature, @NonNull Bundle request, public void processRequest(@NonNull Feature feature, @NonNull @InferenceParams Bundle request, @RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -378,7 +380,7 @@ public final class OnDeviceIntelligenceManager { try { IResponseCallback callback = new IResponseCallback.Stub() { @Override public void onSuccess(Bundle result) { public void onSuccess(@InferenceParams Bundle result) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute(() -> processingCallback.onResult(result)); }); Loading @@ -394,7 +396,8 @@ public final class OnDeviceIntelligenceManager { } @Override public void onDataAugmentRequest(Bundle request, RemoteCallback contentCallback) { public void onDataAugmentRequest(@NonNull @InferenceParams Bundle request, @NonNull RemoteCallback contentCallback) { Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( () -> processingCallback.onDataAugmentRequest(request, result -> { Bundle bundle = new Bundle(); Loading Loading @@ -447,7 +450,7 @@ public final class OnDeviceIntelligenceManager { * @param callbackExecutor executor to run the callback on. */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequestStreaming(@NonNull Feature feature, @NonNull Bundle request, public void processRequestStreaming(@NonNull Feature feature, @NonNull @InferenceParams Bundle request, @RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -456,7 +459,7 @@ public final class OnDeviceIntelligenceManager { try { IStreamingResponseCallback callback = new IStreamingResponseCallback.Stub() { @Override public void onNewContent(Bundle result) { public void onNewContent(@InferenceParams Bundle result) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute( () -> streamingProcessingCallback.onPartialResult(result)); Loading @@ -464,7 +467,7 @@ public final class OnDeviceIntelligenceManager { } @Override public void onSuccess(Bundle result) { public void onSuccess(@InferenceParams Bundle result) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute( () -> streamingProcessingCallback.onResult(result)); Loading @@ -484,7 +487,7 @@ public final class OnDeviceIntelligenceManager { @Override public void onDataAugmentRequest(@NonNull Bundle content, public void onDataAugmentRequest(@NonNull @InferenceParams Bundle content, @NonNull RemoteCallback contentCallback) { Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( () -> streamingProcessingCallback.onDataAugmentRequest(content, Loading Loading @@ -545,4 +548,31 @@ public final class OnDeviceIntelligenceManager { @Retention(RetentionPolicy.SOURCE) public @interface RequestType { } /** * {@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 : * <ul> * <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> * * 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 InferenceParams { } } core/java/android/app/ondeviceintelligence/ProcessingCallback.java +4 −2 Original line number Diff line number Diff line Loading @@ -22,6 +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 java.util.function.Consumer; Loading @@ -42,7 +43,7 @@ public interface ProcessingCallback { * * @param result Response to be passed as a result. */ void onResult(@NonNull Bundle result); void onResult(@NonNull @InferenceParams Bundle result); /** * Called when the request processing fails. The failure details are indicated by the Loading @@ -62,7 +63,8 @@ public interface ProcessingCallback { * service for further processing a request. Bundle passed in here is * expected to be non-null or EMPTY when there is no response. */ default void onDataAugmentRequest(@NonNull Bundle processedContent, default void onDataAugmentRequest( @NonNull @InferenceParams Bundle processedContent, @NonNull Consumer<Bundle> contentConsumer) { contentConsumer.accept(Bundle.EMPTY); } Loading core/java/android/app/ondeviceintelligence/StreamingProcessingCallback.java +2 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.SystemApi; import android.os.Bundle; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams; /** * Streaming variant of {@link ProcessingCallback} to populate response while processing a given Loading @@ -36,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 Bundle partialResult); void onPartialResult(@NonNull @InferenceParams Bundle partialResult); } core/java/android/service/ondeviceintelligence/OnDeviceIntelligenceService.java +2 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.app.ondeviceintelligence.IFeatureDetailsCallback; import android.app.ondeviceintelligence.IListFeaturesCallback; import android.app.ondeviceintelligence.OnDeviceIntelligenceException; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams; import android.content.Intent; import android.os.Binder; import android.os.Bundle; Loading Loading @@ -227,7 +228,7 @@ public abstract class OnDeviceIntelligenceService extends Service { * @param callbackExecutor executor to the run status callback on. * @param statusReceiver receiver to get status of the update state operation. */ public final void updateProcessingState(@NonNull Bundle processingState, public final void updateProcessingState(@NonNull @InferenceParams Bundle processingState, @NonNull @CallbackExecutor Executor callbackExecutor, @NonNull OutcomeReceiver<PersistableBundle, OnDeviceIntelligenceException> statusReceiver) { Objects.requireNonNull(callbackExecutor); Loading core/java/android/service/ondeviceintelligence/OnDeviceSandboxedInferenceService.java +5 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.IStreamingResponseCallback; import android.app.ondeviceintelligence.ITokenInfoCallback; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams; import android.app.ondeviceintelligence.ProcessingSignal; import android.app.ondeviceintelligence.ProcessingCallback; import android.app.ondeviceintelligence.StreamingProcessingCallback; Loading Loading @@ -197,7 +198,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { @NonNull public abstract void onTokenInfoRequest( int callerUid, @NonNull Feature feature, @NonNull Bundle request, @NonNull @InferenceParams Bundle request, @Nullable CancellationSignal cancellationSignal, @NonNull OutcomeReceiver<TokenInfo, OnDeviceIntelligenceException> callback); Loading @@ -223,7 +224,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { @NonNull public abstract void onProcessRequestStreaming( int callerUid, @NonNull Feature feature, @NonNull Bundle request, @NonNull @InferenceParams Bundle request, @OnDeviceIntelligenceManager.RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -249,7 +250,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { @NonNull public abstract void onProcessRequest( int callerUid, @NonNull Feature feature, @NonNull Bundle request, @NonNull @InferenceParams Bundle request, @OnDeviceIntelligenceManager.RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -265,7 +266,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { * @param callback callback to populate the update status and if there are params * associated with the status. */ public abstract void onUpdateProcessingState(@NonNull Bundle processingState, public abstract void onUpdateProcessingState(@NonNull @InferenceParams Bundle processingState, @NonNull OutcomeReceiver<PersistableBundle, OnDeviceIntelligenceException> callback); Loading Loading
core/java/android/app/ondeviceintelligence/OnDeviceIntelligenceManager.java +38 −8 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.content.ComponentName; import android.content.Context; import android.graphics.Bitmap; import android.os.Binder; import android.os.Bundle; import android.os.CancellationSignal; Loading @@ -36,6 +37,7 @@ import android.os.OutcomeReceiver; import android.os.PersistableBundle; import android.os.RemoteCallback; import android.os.RemoteException; import android.system.OsConstants; import androidx.annotation.IntDef; Loading Loading @@ -313,7 +315,7 @@ public final class OnDeviceIntelligenceManager { * @param callbackExecutor executor to run the callback on. */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void requestTokenInfo(@NonNull Feature feature, @NonNull Bundle request, public void requestTokenInfo(@NonNull Feature feature, @NonNull @InferenceParams Bundle request, @Nullable CancellationSignal cancellationSignal, @NonNull @CallbackExecutor Executor callbackExecutor, @NonNull OutcomeReceiver<TokenInfo, Loading Loading @@ -369,7 +371,7 @@ public final class OnDeviceIntelligenceManager { */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequest(@NonNull Feature feature, @NonNull Bundle request, public void processRequest(@NonNull Feature feature, @NonNull @InferenceParams Bundle request, @RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -378,7 +380,7 @@ public final class OnDeviceIntelligenceManager { try { IResponseCallback callback = new IResponseCallback.Stub() { @Override public void onSuccess(Bundle result) { public void onSuccess(@InferenceParams Bundle result) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute(() -> processingCallback.onResult(result)); }); Loading @@ -394,7 +396,8 @@ public final class OnDeviceIntelligenceManager { } @Override public void onDataAugmentRequest(Bundle request, RemoteCallback contentCallback) { public void onDataAugmentRequest(@NonNull @InferenceParams Bundle request, @NonNull RemoteCallback contentCallback) { Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( () -> processingCallback.onDataAugmentRequest(request, result -> { Bundle bundle = new Bundle(); Loading Loading @@ -447,7 +450,7 @@ public final class OnDeviceIntelligenceManager { * @param callbackExecutor executor to run the callback on. */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequestStreaming(@NonNull Feature feature, @NonNull Bundle request, public void processRequestStreaming(@NonNull Feature feature, @NonNull @InferenceParams Bundle request, @RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -456,7 +459,7 @@ public final class OnDeviceIntelligenceManager { try { IStreamingResponseCallback callback = new IStreamingResponseCallback.Stub() { @Override public void onNewContent(Bundle result) { public void onNewContent(@InferenceParams Bundle result) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute( () -> streamingProcessingCallback.onPartialResult(result)); Loading @@ -464,7 +467,7 @@ public final class OnDeviceIntelligenceManager { } @Override public void onSuccess(Bundle result) { public void onSuccess(@InferenceParams Bundle result) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute( () -> streamingProcessingCallback.onResult(result)); Loading @@ -484,7 +487,7 @@ public final class OnDeviceIntelligenceManager { @Override public void onDataAugmentRequest(@NonNull Bundle content, public void onDataAugmentRequest(@NonNull @InferenceParams Bundle content, @NonNull RemoteCallback contentCallback) { Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( () -> streamingProcessingCallback.onDataAugmentRequest(content, Loading Loading @@ -545,4 +548,31 @@ public final class OnDeviceIntelligenceManager { @Retention(RetentionPolicy.SOURCE) public @interface RequestType { } /** * {@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 : * <ul> * <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> * * 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 InferenceParams { } }
core/java/android/app/ondeviceintelligence/ProcessingCallback.java +4 −2 Original line number Diff line number Diff line Loading @@ -22,6 +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 java.util.function.Consumer; Loading @@ -42,7 +43,7 @@ public interface ProcessingCallback { * * @param result Response to be passed as a result. */ void onResult(@NonNull Bundle result); void onResult(@NonNull @InferenceParams Bundle result); /** * Called when the request processing fails. The failure details are indicated by the Loading @@ -62,7 +63,8 @@ public interface ProcessingCallback { * service for further processing a request. Bundle passed in here is * expected to be non-null or EMPTY when there is no response. */ default void onDataAugmentRequest(@NonNull Bundle processedContent, default void onDataAugmentRequest( @NonNull @InferenceParams Bundle processedContent, @NonNull Consumer<Bundle> contentConsumer) { contentConsumer.accept(Bundle.EMPTY); } Loading
core/java/android/app/ondeviceintelligence/StreamingProcessingCallback.java +2 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.SystemApi; import android.os.Bundle; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams; /** * Streaming variant of {@link ProcessingCallback} to populate response while processing a given Loading @@ -36,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 Bundle partialResult); void onPartialResult(@NonNull @InferenceParams Bundle partialResult); }
core/java/android/service/ondeviceintelligence/OnDeviceIntelligenceService.java +2 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.app.ondeviceintelligence.IFeatureDetailsCallback; import android.app.ondeviceintelligence.IListFeaturesCallback; import android.app.ondeviceintelligence.OnDeviceIntelligenceException; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams; import android.content.Intent; import android.os.Binder; import android.os.Bundle; Loading Loading @@ -227,7 +228,7 @@ public abstract class OnDeviceIntelligenceService extends Service { * @param callbackExecutor executor to the run status callback on. * @param statusReceiver receiver to get status of the update state operation. */ public final void updateProcessingState(@NonNull Bundle processingState, public final void updateProcessingState(@NonNull @InferenceParams Bundle processingState, @NonNull @CallbackExecutor Executor callbackExecutor, @NonNull OutcomeReceiver<PersistableBundle, OnDeviceIntelligenceException> statusReceiver) { Objects.requireNonNull(callbackExecutor); Loading
core/java/android/service/ondeviceintelligence/OnDeviceSandboxedInferenceService.java +5 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.IStreamingResponseCallback; import android.app.ondeviceintelligence.ITokenInfoCallback; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams; import android.app.ondeviceintelligence.ProcessingSignal; import android.app.ondeviceintelligence.ProcessingCallback; import android.app.ondeviceintelligence.StreamingProcessingCallback; Loading Loading @@ -197,7 +198,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { @NonNull public abstract void onTokenInfoRequest( int callerUid, @NonNull Feature feature, @NonNull Bundle request, @NonNull @InferenceParams Bundle request, @Nullable CancellationSignal cancellationSignal, @NonNull OutcomeReceiver<TokenInfo, OnDeviceIntelligenceException> callback); Loading @@ -223,7 +224,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { @NonNull public abstract void onProcessRequestStreaming( int callerUid, @NonNull Feature feature, @NonNull Bundle request, @NonNull @InferenceParams Bundle request, @OnDeviceIntelligenceManager.RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -249,7 +250,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { @NonNull public abstract void onProcessRequest( int callerUid, @NonNull Feature feature, @NonNull Bundle request, @NonNull @InferenceParams Bundle request, @OnDeviceIntelligenceManager.RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, Loading @@ -265,7 +266,7 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { * @param callback callback to populate the update status and if there are params * associated with the status. */ public abstract void onUpdateProcessingState(@NonNull Bundle processingState, public abstract void onUpdateProcessingState(@NonNull @InferenceParams Bundle processingState, @NonNull OutcomeReceiver<PersistableBundle, OnDeviceIntelligenceException> callback); Loading