diff options
| author | 2024-03-06 21:55:38 +0000 | |
|---|---|---|
| committer | 2024-03-06 21:55:38 +0000 | |
| commit | 9405f9f8e8e538affcef84e1cc1305076bf797d1 (patch) | |
| tree | a9c468672b2a9bffa8914f30ec60006ee3b962bf | |
| parent | eb19e4c69b3fe3e1b038977450378c60d4979c18 (diff) | |
| parent | 46571064a934143eb55620656f656ee0be7daad8 (diff) | |
Merge "Addressing previous todo comments and feedback" into main
24 files changed, 607 insertions, 400 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index adc7ef1990a5..ee69ce159fa8 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -70,7 +70,7 @@ package android { field public static final String BIND_NETWORK_RECOMMENDATION_SERVICE = "android.permission.BIND_NETWORK_RECOMMENDATION_SERVICE"; field public static final String BIND_NOTIFICATION_ASSISTANT_SERVICE = "android.permission.BIND_NOTIFICATION_ASSISTANT_SERVICE"; field @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public static final String BIND_ON_DEVICE_INTELLIGENCE_SERVICE = "android.permission.BIND_ON_DEVICE_INTELLIGENCE_SERVICE"; - field @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public static final String BIND_ON_DEVICE_TRUSTED_SERVICE = "android.permission.BIND_ON_DEVICE_TRUSTED_SERVICE"; + field @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public static final String BIND_ON_DEVICE_SANDBOXED_INFERENCE_SERVICE = "android.permission.BIND_ON_DEVICE_SANDBOXED_INFERENCE_SERVICE"; field public static final String BIND_PHONE_ACCOUNT_SUGGESTION_SERVICE = "android.permission.BIND_PHONE_ACCOUNT_SUGGESTION_SERVICE"; field public static final String BIND_PRINT_RECOMMENDATION_SERVICE = "android.permission.BIND_PRINT_RECOMMENDATION_SERVICE"; field public static final String BIND_REMOTE_LOCKSCREEN_VALIDATION_SERVICE = "android.permission.BIND_REMOTE_LOCKSCREEN_VALIDATION_SERVICE"; @@ -2223,10 +2223,9 @@ package android.app.ondeviceintelligence { } public static final class Feature.Builder { - ctor public Feature.Builder(int, int, int, @NonNull android.os.PersistableBundle); + ctor public Feature.Builder(int); method @NonNull public android.app.ondeviceintelligence.Feature build(); method @NonNull public android.app.ondeviceintelligence.Feature.Builder setFeatureParams(@NonNull android.os.PersistableBundle); - method @NonNull public android.app.ondeviceintelligence.Feature.Builder setId(int); method @NonNull public android.app.ondeviceintelligence.Feature.Builder setModelName(@NonNull String); method @NonNull public android.app.ondeviceintelligence.Feature.Builder setName(@NonNull String); method @NonNull public android.app.ondeviceintelligence.Feature.Builder setType(int); @@ -2238,7 +2237,7 @@ package android.app.ondeviceintelligence { ctor public FeatureDetails(@android.app.ondeviceintelligence.FeatureDetails.Status int); method public int describeContents(); method @NonNull public android.os.PersistableBundle getFeatureDetailParams(); - method @android.app.ondeviceintelligence.FeatureDetails.Status public int getStatus(); + method @android.app.ondeviceintelligence.FeatureDetails.Status public int getFeatureStatus(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.app.ondeviceintelligence.FeatureDetails> CREATOR; field public static final int FEATURE_STATUS_AVAILABLE = 3; // 0x3 @@ -2251,27 +2250,16 @@ package android.app.ondeviceintelligence { @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE_USE, java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.PARAMETER, java.lang.annotation.ElementType.FIELD}) public static @interface FeatureDetails.Status { } - @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public final class FilePart implements android.os.Parcelable { - ctor public FilePart(@NonNull String, @NonNull android.os.PersistableBundle, @NonNull String) throws java.io.FileNotFoundException; - ctor public FilePart(@NonNull String, @NonNull android.os.PersistableBundle, @NonNull java.io.FileInputStream) throws java.io.IOException; - method public int describeContents(); - method @NonNull public java.io.FileInputStream getFileInputStream(); - method @NonNull public String getFilePartKey(); - method @NonNull public android.os.PersistableBundle getFilePartParams(); - method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator<android.app.ondeviceintelligence.FilePart> CREATOR; - } - @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public class OnDeviceIntelligenceManager { method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void getFeature(int, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.Feature,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void getFeatureDetails(@NonNull android.app.ondeviceintelligence.Feature, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.FeatureDetails,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); + method @Nullable @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public String getRemoteServicePackageName(); method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void getVersion(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.LongConsumer); method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void listFeatures(@NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.util.List<android.app.ondeviceintelligence.Feature>,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); - method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequest(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.Content,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException>); - method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequestStreaming(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull java.util.concurrent.Executor, @NonNull android.app.ondeviceintelligence.StreamingResponseReceiver<android.app.ondeviceintelligence.Content,android.app.ondeviceintelligence.Content,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException>); + method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequest(@NonNull android.app.ondeviceintelligence.Feature, @Nullable android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull java.util.concurrent.Executor, @NonNull android.app.ondeviceintelligence.ProcessingOutcomeReceiver); + method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void processRequestStreaming(@NonNull android.app.ondeviceintelligence.Feature, @Nullable android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull java.util.concurrent.Executor, @NonNull android.app.ondeviceintelligence.StreamedProcessingOutcomeReceiver); method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void requestFeatureDownload(@NonNull android.app.ondeviceintelligence.Feature, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.app.ondeviceintelligence.DownloadCallback); - method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void requestTokenCount(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Long,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); - field public static final String API_VERSION_BUNDLE_KEY = "ApiVersionBundleKey"; + method @RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) public void requestTokenInfo(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.TokenInfo,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); field public static final int REQUEST_TYPE_EMBEDDINGS = 2; // 0x2 field public static final int REQUEST_TYPE_INFERENCE = 0; // 0x0 field public static final int REQUEST_TYPE_PREPARE = 1; // 0x1 @@ -2305,6 +2293,10 @@ package android.app.ondeviceintelligence { field public static final int PROCESSING_ERROR_UNKNOWN = 1; // 0x1 } + @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public interface ProcessingOutcomeReceiver extends android.os.OutcomeReceiver<android.app.ondeviceintelligence.Content,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> { + method public default void onDataAugmentRequest(@NonNull android.app.ondeviceintelligence.Content, @NonNull java.util.function.Consumer<android.app.ondeviceintelligence.Content>); + } + @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public final class ProcessingSignal { ctor public ProcessingSignal(); method public void sendSignal(@NonNull android.os.PersistableBundle); @@ -2315,8 +2307,18 @@ package android.app.ondeviceintelligence { method public void onSignalReceived(@NonNull android.os.PersistableBundle); } - @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public interface StreamingResponseReceiver<R, T, E extends java.lang.Throwable> extends android.os.OutcomeReceiver<R,E> { - method public void onNewContent(@NonNull T); + @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public interface StreamedProcessingOutcomeReceiver extends android.app.ondeviceintelligence.ProcessingOutcomeReceiver { + method public void onNewContent(@NonNull android.app.ondeviceintelligence.Content); + } + + @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public final class TokenInfo implements android.os.Parcelable { + ctor public TokenInfo(long, @NonNull android.os.PersistableBundle); + ctor public TokenInfo(long); + method public int describeContents(); + method public long getCount(); + method @NonNull public android.os.PersistableBundle getInfoParams(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator<android.app.ondeviceintelligence.TokenInfo> CREATOR; } } @@ -12963,12 +12965,14 @@ package android.service.ondeviceintelligence { @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public abstract class OnDeviceIntelligenceService extends android.app.Service { ctor public OnDeviceIntelligenceService(); method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent); - method public abstract void onDownloadFeature(@NonNull android.app.ondeviceintelligence.Feature, @Nullable android.os.CancellationSignal, @NonNull android.app.ondeviceintelligence.DownloadCallback); - method public abstract void onGetFeature(int, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.Feature,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); - method public abstract void onGetFeatureDetails(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.FeatureDetails,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); + method public abstract void onDownloadFeature(int, @NonNull android.app.ondeviceintelligence.Feature, @Nullable android.os.CancellationSignal, @NonNull android.app.ondeviceintelligence.DownloadCallback); + method public abstract void onGetFeature(int, int, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.Feature,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); + method public abstract void onGetFeatureDetails(int, @NonNull android.app.ondeviceintelligence.Feature, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.FeatureDetails,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); method public abstract void onGetReadOnlyFeatureFileDescriptorMap(@NonNull android.app.ondeviceintelligence.Feature, @NonNull java.util.function.Consumer<java.util.Map<java.lang.String,android.os.ParcelFileDescriptor>>); method public abstract void onGetVersion(@NonNull java.util.function.LongConsumer); - method public abstract void onListFeatures(@NonNull android.os.OutcomeReceiver<java.util.List<android.app.ondeviceintelligence.Feature>,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); + method public abstract void onInferenceServiceConnected(); + method public abstract void onInferenceServiceDisconnected(); + method public abstract void onListFeatures(int, @NonNull android.os.OutcomeReceiver<java.util.List<android.app.ondeviceintelligence.Feature>,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException>); method public final void updateProcessingState(@NonNull android.os.Bundle, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.os.PersistableBundle,android.service.ondeviceintelligence.OnDeviceIntelligenceService.OnDeviceUpdateProcessingException>); field public static final String SERVICE_INTERFACE = "android.service.ondeviceintelligence.OnDeviceIntelligenceService"; } @@ -12985,17 +12989,18 @@ package android.service.ondeviceintelligence { field public static final int PROCESSING_UPDATE_STATUS_CONNECTION_FAILED = 1; // 0x1 } - @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public abstract class OnDeviceTrustedInferenceService extends android.app.Service { - ctor public OnDeviceTrustedInferenceService(); + @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") public abstract class OnDeviceSandboxedInferenceService extends android.app.Service { + ctor public OnDeviceSandboxedInferenceService(); method public final void fetchFeatureFileInputStreamMap(@NonNull android.app.ondeviceintelligence.Feature, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.util.Map<java.lang.String,java.io.FileInputStream>>); + method @NonNull public java.util.concurrent.Executor getCallbackExecutor(); method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent); - method @NonNull public abstract void onCountTokens(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, @Nullable android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<java.lang.Long,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException>); - method @NonNull public abstract void onProcessRequest(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.Content,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException>); - method @NonNull public abstract void onProcessRequestStreaming(@NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull android.app.ondeviceintelligence.StreamingResponseReceiver<android.app.ondeviceintelligence.Content,android.app.ondeviceintelligence.Content,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException>); + method @NonNull public abstract void onProcessRequest(int, @NonNull android.app.ondeviceintelligence.Feature, @Nullable android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull android.app.ondeviceintelligence.ProcessingOutcomeReceiver); + method @NonNull public abstract void onProcessRequestStreaming(int, @NonNull android.app.ondeviceintelligence.Feature, @Nullable android.app.ondeviceintelligence.Content, int, @Nullable android.os.CancellationSignal, @Nullable android.app.ondeviceintelligence.ProcessingSignal, @NonNull android.app.ondeviceintelligence.StreamedProcessingOutcomeReceiver); + method @NonNull public abstract void onTokenInfoRequest(int, @NonNull android.app.ondeviceintelligence.Feature, @NonNull android.app.ondeviceintelligence.Content, @Nullable android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.app.ondeviceintelligence.TokenInfo,android.app.ondeviceintelligence.OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException>); method public abstract void onUpdateProcessingState(@NonNull android.os.Bundle, @NonNull android.os.OutcomeReceiver<android.os.PersistableBundle,android.service.ondeviceintelligence.OnDeviceIntelligenceService.OnDeviceUpdateProcessingException>); method public final java.io.FileInputStream openFileInput(@NonNull String) throws java.io.FileNotFoundException; method public final void openFileInputAsync(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.io.FileInputStream>) throws java.io.FileNotFoundException; - field public static final String SERVICE_INTERFACE = "android.service.ondeviceintelligence.OnDeviceTrustedInferenceService"; + field public static final String SERVICE_INTERFACE = "android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService"; } } diff --git a/core/api/system-lint-baseline.txt b/core/api/system-lint-baseline.txt index 1923641e2d4e..1e72a061d35a 100644 --- a/core/api/system-lint-baseline.txt +++ b/core/api/system-lint-baseline.txt @@ -511,9 +511,9 @@ GenericException: android.service.autofill.augmented.FillWindow#finalize(): InvalidNullabilityOverride: android.service.ondeviceintelligence.OnDeviceIntelligenceService#onBind(android.content.Intent) parameter #0: Invalid nullability on parameter `intent` in method `onBind`. Parameters of overrides cannot be NonNull if the super parameter is unannotated. -InvalidNullabilityOverride: android.service.ondeviceintelligence.OnDeviceTrustedInferenceService#onBind(android.content.Intent) parameter #0: +InvalidNullabilityOverride: android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService#onBind(android.content.Intent) parameter #0: Invalid nullability on parameter `intent` in method `onBind`. Parameters of overrides cannot be NonNull if the super parameter is unannotated. -InvalidNullabilityOverride: android.service.ondeviceintelligence.OnDeviceTrustedInferenceService#openFileInput(String) parameter #0: +InvalidNullabilityOverride: android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService#openFileInput(String) parameter #0: Invalid nullability on parameter `filename` in method `openFileInput`. Parameters of overrides cannot be NonNull if the super parameter is unannotated. InvalidNullabilityOverride: android.service.textclassifier.TextClassifierService#onUnbind(android.content.Intent) parameter #0: Invalid nullability on parameter `intent` in method `onUnbind`. Parameters of overrides cannot be NonNull if the super parameter is unannotated. @@ -571,7 +571,7 @@ MissingNullability: android.service.contentcapture.ContentCaptureService#dump(ja Missing nullability on parameter `args` in method `dump` MissingNullability: android.service.notification.NotificationAssistantService#attachBaseContext(android.content.Context) parameter #0: Missing nullability on parameter `base` in method `attachBaseContext` -MissingNullability: android.service.ondeviceintelligence.OnDeviceTrustedInferenceService#openFileInput(String): +MissingNullability: android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService#openFileInput(String): Missing nullability on method `openFileInput` return MissingNullability: android.telephony.NetworkService#onUnbind(android.content.Intent) parameter #0: Missing nullability on parameter `intent` in method `onUnbind` diff --git a/core/java/android/app/ondeviceintelligence/Feature.java b/core/java/android/app/ondeviceintelligence/Feature.java index 510735461553..4a38c9224a3d 100644 --- a/core/java/android/app/ondeviceintelligence/Feature.java +++ b/core/java/android/app/ondeviceintelligence/Feature.java @@ -199,24 +199,13 @@ public final class Feature implements Parcelable { private long mBuilderFieldsSet = 0L; - public Builder( - int id, - int type, - int variant, - @NonNull PersistableBundle featureParams) { + /** + * Provides a builder instance to create a feature for given id. + * @param id the unique identifier for the feature. + */ + public Builder(int id) { mId = id; - mType = type; - mVariant = variant; - mFeatureParams = featureParams; - com.android.internal.util.AnnotationValidations.validate( - NonNull.class, null, mFeatureParams); - } - - public @NonNull Builder setId(int value) { - checkNotUsed(); - mBuilderFieldsSet |= 0x1; - mId = value; - return this; + mFeatureParams = new PersistableBundle(); } public @NonNull Builder setName(@NonNull String value) { diff --git a/core/java/android/app/ondeviceintelligence/FeatureDetails.java b/core/java/android/app/ondeviceintelligence/FeatureDetails.java index 92f351362f70..f3cbd2621694 100644 --- a/core/java/android/app/ondeviceintelligence/FeatureDetails.java +++ b/core/java/android/app/ondeviceintelligence/FeatureDetails.java @@ -41,7 +41,7 @@ import java.text.MessageFormat; @FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) public final class FeatureDetails implements Parcelable { @Status - private final int mStatus; + private final int mFeatureStatus; @NonNull private final PersistableBundle mFeatureDetailParams; @@ -73,21 +73,21 @@ public final class FeatureDetails implements Parcelable { } public FeatureDetails( - @Status int status, + @Status int featureStatus, @NonNull PersistableBundle featureDetailParams) { - this.mStatus = status; + this.mFeatureStatus = featureStatus; com.android.internal.util.AnnotationValidations.validate( - Status.class, null, mStatus); + Status.class, null, mFeatureStatus); this.mFeatureDetailParams = featureDetailParams; com.android.internal.util.AnnotationValidations.validate( NonNull.class, null, mFeatureDetailParams); } public FeatureDetails( - @Status int status) { - this.mStatus = status; + @Status int featureStatus) { + this.mFeatureStatus = featureStatus; com.android.internal.util.AnnotationValidations.validate( - Status.class, null, mStatus); + Status.class, null, mFeatureStatus); this.mFeatureDetailParams = new PersistableBundle(); } @@ -95,8 +95,8 @@ public final class FeatureDetails implements Parcelable { /** * Returns an integer value associated with the feature status. */ - public @Status int getStatus() { - return mStatus; + public @Status int getFeatureStatus() { + return mFeatureStatus; } @@ -111,7 +111,7 @@ public final class FeatureDetails implements Parcelable { public String toString() { return MessageFormat.format("FeatureDetails '{' status = {0}, " + "persistableBundle = {1} '}'", - mStatus, + mFeatureStatus, mFeatureDetailParams); } @@ -121,21 +121,21 @@ public final class FeatureDetails implements Parcelable { if (o == null || getClass() != o.getClass()) return false; @SuppressWarnings("unchecked") FeatureDetails that = (FeatureDetails) o; - return mStatus == that.mStatus + return mFeatureStatus == that.mFeatureStatus && java.util.Objects.equals(mFeatureDetailParams, that.mFeatureDetailParams); } @Override public int hashCode() { int _hash = 1; - _hash = 31 * _hash + mStatus; + _hash = 31 * _hash + mFeatureStatus; _hash = 31 * _hash + java.util.Objects.hashCode(mFeatureDetailParams); return _hash; } @Override public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { - dest.writeInt(mStatus); + dest.writeInt(mFeatureStatus); dest.writeTypedObject(mFeatureDetailParams, flags); } @@ -151,9 +151,9 @@ public final class FeatureDetails implements Parcelable { PersistableBundle persistableBundle = (PersistableBundle) in.readTypedObject( PersistableBundle.CREATOR); - this.mStatus = status; + this.mFeatureStatus = status; com.android.internal.util.AnnotationValidations.validate( - Status.class, null, mStatus); + Status.class, null, mFeatureStatus); this.mFeatureDetailParams = persistableBundle; com.android.internal.util.AnnotationValidations.validate( NonNull.class, null, mFeatureDetailParams); diff --git a/core/java/android/app/ondeviceintelligence/FilePart.java b/core/java/android/app/ondeviceintelligence/FilePart.java deleted file mode 100644 index e9fb5f2cb440..000000000000 --- a/core/java/android/app/ondeviceintelligence/FilePart.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.app.ondeviceintelligence; - -import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE; - -import android.annotation.FlaggedApi; -import android.annotation.SystemApi; -import android.os.Parcel; -import android.os.ParcelFileDescriptor; -import android.os.Parcelable; -import android.os.PersistableBundle; - -import android.annotation.NonNull; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Objects; - -/** - * Represents file data with an associated file descriptor sent to and received from remote - * processing. The interface ensures that the underlying file-descriptor is always opened in - * read-only mode. - * - * @hide - */ -@FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) -@SystemApi -public final class FilePart implements Parcelable { - private final String mPartKey; - private final PersistableBundle mPartParams; - private final ParcelFileDescriptor mParcelFileDescriptor; - - private FilePart(@NonNull String partKey, @NonNull PersistableBundle partParams, - @NonNull ParcelFileDescriptor parcelFileDescriptor) { - Objects.requireNonNull(partKey); - Objects.requireNonNull(partParams); - this.mPartKey = partKey; - this.mPartParams = partParams; - this.mParcelFileDescriptor = Objects.requireNonNull(parcelFileDescriptor); - } - - /** - * Create a file part using a filePath and any additional params. - */ - public FilePart(@NonNull String partKey, @NonNull PersistableBundle partParams, - @NonNull String filePath) - throws FileNotFoundException { - this(partKey, partParams, Objects.requireNonNull(ParcelFileDescriptor.open( - new File(Objects.requireNonNull(filePath)), ParcelFileDescriptor.MODE_READ_ONLY))); - } - - /** - * Create a file part using a file input stream and any additional params. - * It is the caller's responsibility to close the stream. It is safe to do so as soon as this - * call returns. - */ - public FilePart(@NonNull String partKey, @NonNull PersistableBundle partParams, - @NonNull FileInputStream fileInputStream) - throws IOException { - this(partKey, partParams, ParcelFileDescriptor.dup(fileInputStream.getFD())); - } - - /** - * Returns a FileInputStream for the associated File. - * Caller must close the associated stream when done reading from it. - * - * @return the FileInputStream associated with the FilePart. - */ - @NonNull - public FileInputStream getFileInputStream() { - return new FileInputStream(mParcelFileDescriptor.getFileDescriptor()); - } - - /** - * Returns the unique key associated with the part. Each Part key added to a content object - * should be ensured to be unique. - */ - @NonNull - public String getFilePartKey() { - return mPartKey; - } - - /** - * Returns the params associated with Part. - */ - @NonNull - public PersistableBundle getFilePartParams() { - return mPartParams; - } - - - @Override - public int describeContents() { - return CONTENTS_FILE_DESCRIPTOR; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeString8(getFilePartKey()); - dest.writePersistableBundle(getFilePartParams()); - mParcelFileDescriptor.writeToParcel(dest, flags - | Parcelable.PARCELABLE_WRITE_RETURN_VALUE); // This flag ensures that the sender's - // copy of the Pfd is closed as soon as the Binder call succeeds. - } - - @NonNull - public static final Creator<FilePart> CREATOR = new Creator<>() { - @Override - public FilePart createFromParcel(Parcel in) { - return new FilePart(in.readString(), in.readTypedObject(PersistableBundle.CREATOR), - in.readParcelable( - getClass().getClassLoader(), ParcelFileDescriptor.class)); - } - - @Override - public FilePart[] newArray(int size) { - return new FilePart[size]; - } - }; -} diff --git a/core/java/android/app/ondeviceintelligence/IOnDeviceIntelligenceManager.aidl b/core/java/android/app/ondeviceintelligence/IOnDeviceIntelligenceManager.aidl index b925f4863de2..360a8094723c 100644 --- a/core/java/android/app/ondeviceintelligence/IOnDeviceIntelligenceManager.aidl +++ b/core/java/android/app/ondeviceintelligence/IOnDeviceIntelligenceManager.aidl @@ -31,7 +31,7 @@ import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.IStreamingResponseCallback; import android.app.ondeviceintelligence.IProcessingSignal; - import android.app.ondeviceintelligence.ITokenCountCallback; + import android.app.ondeviceintelligence.ITokenInfoCallback; /** @@ -56,8 +56,8 @@ void requestFeatureDownload(in Feature feature, ICancellationSignal signal, in IDownloadCallback callback) = 5; @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)") - void requestTokenCount(in Feature feature, in Content request, in ICancellationSignal signal, - in ITokenCountCallback tokenCountcallback) = 6; + void requestTokenInfo(in Feature feature, in Content request, in ICancellationSignal signal, + in ITokenInfoCallback tokenInfocallback) = 6; @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)") void processRequest(in Feature feature, in Content request, int requestType, in ICancellationSignal cancellationSignal, in IProcessingSignal signal, diff --git a/core/java/android/app/ondeviceintelligence/IResponseCallback.aidl b/core/java/android/app/ondeviceintelligence/IResponseCallback.aidl index 9848e1ddda5a..0adf305f2920 100644 --- a/core/java/android/app/ondeviceintelligence/IResponseCallback.aidl +++ b/core/java/android/app/ondeviceintelligence/IResponseCallback.aidl @@ -3,6 +3,7 @@ package android.app.ondeviceintelligence; import android.app.ondeviceintelligence.Content; import android.app.ondeviceintelligence.IProcessingSignal; import android.os.PersistableBundle; +import android.os.RemoteCallback; /** * Interface for a IResponseCallback for receiving response from on-device intelligence service. @@ -12,4 +13,5 @@ import android.os.PersistableBundle; interface IResponseCallback { void onSuccess(in Content result) = 1; void onFailure(int errorCode, in String errorMessage, in PersistableBundle errorParams) = 2; + void onDataAugmentRequest(in Content content, in RemoteCallback contentCallback) = 3; } diff --git a/core/java/android/app/ondeviceintelligence/IStreamingResponseCallback.aidl b/core/java/android/app/ondeviceintelligence/IStreamingResponseCallback.aidl index a6805749fa04..132e53e1ae2e 100644 --- a/core/java/android/app/ondeviceintelligence/IStreamingResponseCallback.aidl +++ b/core/java/android/app/ondeviceintelligence/IStreamingResponseCallback.aidl @@ -4,6 +4,7 @@ import android.app.ondeviceintelligence.Content; import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.IProcessingSignal; import android.os.PersistableBundle; +import android.os.RemoteCallback; /** @@ -15,4 +16,5 @@ interface IStreamingResponseCallback { void onNewContent(in Content result) = 1; void onSuccess(in Content result) = 2; void onFailure(int errorCode, in String errorMessage, in PersistableBundle errorParams) = 3; + void onDataAugmentRequest(in Content content, in RemoteCallback contentCallback) = 4; } diff --git a/core/java/android/app/ondeviceintelligence/ITokenCountCallback.aidl b/core/java/android/app/ondeviceintelligence/ITokenCountCallback.aidl deleted file mode 100644 index b724e03fbca4..000000000000 --- a/core/java/android/app/ondeviceintelligence/ITokenCountCallback.aidl +++ /dev/null @@ -1,13 +0,0 @@ -package android.app.ondeviceintelligence; - -import android.os.PersistableBundle; - -/** - * Interface for receiving the token count of a request for a given features. - * - * @hide - */ -interface ITokenCountCallback { - void onSuccess(long tokenCount) = 1; - void onFailure(int errorCode, in String errorMessage, in PersistableBundle errorParams) = 2; -} diff --git a/core/java/android/app/ondeviceintelligence/ITokenInfoCallback.aidl b/core/java/android/app/ondeviceintelligence/ITokenInfoCallback.aidl new file mode 100644 index 000000000000..9219a89128df --- /dev/null +++ b/core/java/android/app/ondeviceintelligence/ITokenInfoCallback.aidl @@ -0,0 +1,14 @@ +package android.app.ondeviceintelligence; + +import android.os.PersistableBundle; +import android.app.ondeviceintelligence.TokenInfo; + +/** + * Interface for receiving the token info of a request for a given feature. + * + * @hide + */ +interface ITokenInfoCallback { + void onSuccess(in TokenInfo tokenInfo) = 1; + void onFailure(int errorCode, in String errorMessage, in PersistableBundle errorParams) = 2; +} diff --git a/core/java/android/app/ondeviceintelligence/OnDeviceIntelligenceManager.java b/core/java/android/app/ondeviceintelligence/OnDeviceIntelligenceManager.java index 4d8e0d55e355..d195c4d52c22 100644 --- a/core/java/android/app/ondeviceintelligence/OnDeviceIntelligenceManager.java +++ b/core/java/android/app/ondeviceintelligence/OnDeviceIntelligenceManager.java @@ -26,8 +26,10 @@ import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.annotation.SystemService; +import android.content.ComponentName; import android.content.Context; import android.os.Binder; +import android.os.Bundle; import android.os.CancellationSignal; import android.os.ICancellationSignal; import android.os.OutcomeReceiver; @@ -37,6 +39,8 @@ import android.os.RemoteException; import androidx.annotation.IntDef; +import com.android.internal.R; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -60,7 +64,16 @@ import java.util.function.LongConsumer; @SystemService(Context.ON_DEVICE_INTELLIGENCE_SERVICE) @FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) public class OnDeviceIntelligenceManager { + /** + * @hide + */ public static final String API_VERSION_BUNDLE_KEY = "ApiVersionBundleKey"; + + /** + * @hide + */ + public static final String AUGMENT_REQUEST_CONTENT_BUNDLE_KEY = + "AugmentRequestContentBundleKey"; private final Context mContext; private final IOnDeviceIntelligenceManager mService; @@ -82,8 +95,6 @@ public class OnDeviceIntelligenceManager { public void getVersion( @NonNull @CallbackExecutor Executor callbackExecutor, @NonNull LongConsumer versionConsumer) { - // TODO explore modifying this method into getServicePackageDetails and return both - // version and package name of the remote service implementing this. try { RemoteCallback callback = new RemoteCallback(result -> { if (result == null) { @@ -100,6 +111,23 @@ public class OnDeviceIntelligenceManager { } } + + /** + * Get package name configured for providing the remote implementation for this system service. + */ + @Nullable + @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) + public String getRemoteServicePackageName() { + String serviceConfigValue = mContext.getResources().getString( + R.string.config_defaultOnDeviceSandboxedInferenceService); + ComponentName componentName = ComponentName.unflattenFromString(serviceConfigValue); + if (componentName != null) { + return componentName.getPackageName(); + } + + return null; + } + /** * Asynchronously get feature for a given id. * @@ -273,29 +301,29 @@ public class OnDeviceIntelligenceManager { } /** - * The methods computes the token-count for a given request payload using the provided Feature - * details. + * The methods computes the token related information for a given request payload using the + * provided {@link Feature}. * * @param feature feature associated with the request. * @param request request that contains the content data and associated params. - * @param outcomeReceiver callback to populate the token count or exception in case of + * @param outcomeReceiver callback to populate the token info or exception in case of * failure. * @param cancellationSignal signal to invoke cancellation on the operation in the remote * implementation. * @param callbackExecutor executor to run the callback on. */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) - public void requestTokenCount(@NonNull Feature feature, @NonNull Content request, + public void requestTokenInfo(@NonNull Feature feature, @NonNull Content request, @Nullable CancellationSignal cancellationSignal, @NonNull @CallbackExecutor Executor callbackExecutor, - @NonNull OutcomeReceiver<Long, + @NonNull OutcomeReceiver<TokenInfo, OnDeviceIntelligenceManagerException> outcomeReceiver) { try { - ITokenCountCallback callback = new ITokenCountCallback.Stub() { + ITokenInfoCallback callback = new ITokenInfoCallback.Stub() { @Override - public void onSuccess(long tokenCount) { + public void onSuccess(TokenInfo tokenInfo) { Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( - () -> outcomeReceiver.onResult(tokenCount))); + () -> outcomeReceiver.onResult(tokenInfo))); } @Override @@ -314,7 +342,7 @@ public class OnDeviceIntelligenceManager { cancellationSignal.setRemote(transport); } - mService.requestTokenCount(feature, request, transport, callback); + mService.requestTokenInfo(feature, request, transport, callback); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -328,33 +356,31 @@ public class OnDeviceIntelligenceManager { * was a * failure. * - * @param feature feature associated with the request. - * @param request request that contains the Content data and - * associated params. - * @param requestType type of request being sent for processing the content. - * @param responseOutcomeReceiver callback to populate the response content and - * associated - * params. - * @param processingSignal signal to invoke custom actions in the - * remote implementation. - * @param cancellationSignal signal to invoke cancellation or - * @param callbackExecutor executor to run the callback on. + * @param feature feature associated with the request. + * @param request request that contains the Content data and + * associated params. + * @param requestType type of request being sent for processing the content. + * @param cancellationSignal signal to invoke cancellation. + * @param processingSignal signal to send custom signals in the + * remote implementation. + * @param callbackExecutor executor to run the callback on. + * @param responseCallback callback to populate the response content and + * associated params. */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) - public void processRequest(@NonNull Feature feature, @NonNull Content request, + public void processRequest(@NonNull Feature feature, @Nullable Content request, @RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, @NonNull @CallbackExecutor Executor callbackExecutor, - @NonNull OutcomeReceiver<Content, - OnDeviceIntelligenceManagerProcessingException> responseOutcomeReceiver) { + @NonNull ProcessingOutcomeReceiver responseCallback) { try { IResponseCallback callback = new IResponseCallback.Stub() { @Override public void onSuccess(Content result) { Binder.withCleanCallingIdentity(() -> { - callbackExecutor.execute(() -> responseOutcomeReceiver.onResult(result)); + callbackExecutor.execute(() -> responseCallback.onResult(result)); }); } @@ -362,12 +388,24 @@ public class OnDeviceIntelligenceManager { public void onFailure(int errorCode, String errorMessage, PersistableBundle errorParams) { Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( - () -> responseOutcomeReceiver.onError( + () -> responseCallback.onError( new OnDeviceIntelligenceManagerProcessingException( errorCode, errorMessage, errorParams)))); } + + @Override + public void onDataAugmentRequest(@NonNull Content content, + @NonNull RemoteCallback contentCallback) { + Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( + () -> responseCallback.onDataAugmentRequest(content, result -> { + Bundle bundle = new Bundle(); + bundle.putParcelable(AUGMENT_REQUEST_CONTENT_BUNDLE_KEY, result); + callbackExecutor.execute(() -> contentCallback.sendResult(bundle)); + }))); + } }; + IProcessingSignal transport = null; if (processingSignal != null) { transport = ProcessingSignal.createTransport(); @@ -389,46 +427,48 @@ public class OnDeviceIntelligenceManager { } /** - * Variation of {@link #processRequest} that asynchronously processes a request in a streaming + * Variation of {@link #processRequest} that asynchronously processes a request in a + * streaming * fashion, where new content is pushed to caller in chunks via the - * {@link StreamingResponseReceiver#onNewContent}. After the streaming is complete, - * the service should call {@link StreamingResponseReceiver#onResult} and can optionally - * populate the complete {@link Response}'s Content as part of the callback when the final - * {@link Response} contains an enhanced aggregation of the Contents already streamed. + * {@link StreamedProcessingOutcomeReceiver#onNewContent}. After the streaming is complete, + * the service should call {@link StreamedProcessingOutcomeReceiver#onResult} and can optionally + * populate the complete the full response {@link Content} as part of the callback in cases + * when the final response contains an enhanced aggregation of the Contents already + * streamed. * * @param feature feature associated with the request. * @param request request that contains the Content data and associated * params. * @param requestType type of request being sent for processing the content. - * @param processingSignal signal to invoke other custom actions in the + * @param cancellationSignal signal to invoke cancellation. + * @param processingSignal signal to send custom signals in the * remote implementation. - * @param cancellationSignal signal to invoke cancellation - * @param streamingResponseReceiver streaming callback to populate the response content and + * @param streamingResponseCallback streaming callback to populate the response content and * associated params. * @param callbackExecutor executor to run the callback on. */ @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE) - public void processRequestStreaming(@NonNull Feature feature, @NonNull Content request, + public void processRequestStreaming(@NonNull Feature feature, @Nullable Content request, @RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, @NonNull @CallbackExecutor Executor callbackExecutor, - @NonNull StreamingResponseReceiver<Content, Content, - OnDeviceIntelligenceManagerProcessingException> streamingResponseReceiver) { + @NonNull StreamedProcessingOutcomeReceiver streamingResponseCallback) { try { IStreamingResponseCallback callback = new IStreamingResponseCallback.Stub() { @Override public void onNewContent(Content result) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute( - () -> streamingResponseReceiver.onNewContent(result)); + () -> streamingResponseCallback.onNewContent(result)); }); } @Override public void onSuccess(Content result) { Binder.withCleanCallingIdentity(() -> { - callbackExecutor.execute(() -> streamingResponseReceiver.onResult(result)); + callbackExecutor.execute( + () -> streamingResponseCallback.onResult(result)); }); } @@ -437,11 +477,26 @@ public class OnDeviceIntelligenceManager { PersistableBundle errorParams) { Binder.withCleanCallingIdentity(() -> { callbackExecutor.execute( - () -> streamingResponseReceiver.onError( + () -> streamingResponseCallback.onError( new OnDeviceIntelligenceManagerProcessingException( errorCode, errorMessage, errorParams))); }); } + + + @Override + public void onDataAugmentRequest(@NonNull Content content, + @NonNull RemoteCallback contentCallback) { + Binder.withCleanCallingIdentity(() -> callbackExecutor.execute( + () -> streamingResponseCallback.onDataAugmentRequest(content, + contentResponse -> { + Bundle bundle = new Bundle(); + bundle.putParcelable(AUGMENT_REQUEST_CONTENT_BUNDLE_KEY, + contentResponse); + callbackExecutor.execute( + () -> contentCallback.sendResult(bundle)); + }))); + } }; IProcessingSignal transport = null; @@ -468,7 +523,8 @@ public class OnDeviceIntelligenceManager { public static final int REQUEST_TYPE_INFERENCE = 0; /** - * Prepares the remote implementation environment for e.g.loading inference runtime etc.which + * Prepares the remote implementation environment for e.g.loading inference runtime etc + * .which * are time consuming beforehand to remove overhead and allow quick processing of requests * thereof. */ @@ -485,7 +541,8 @@ public class OnDeviceIntelligenceManager { REQUEST_TYPE_PREPARE, REQUEST_TYPE_EMBEDDINGS }, open = true) - @Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) + @Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.PARAMETER, + ElementType.FIELD}) @Retention(RetentionPolicy.SOURCE) public @interface RequestType { } @@ -501,17 +558,32 @@ public class OnDeviceIntelligenceManager { */ public static final int ON_DEVICE_INTELLIGENCE_SERVICE_UNAVAILABLE = 1000; + /** + * Error code to be used for on device intelligence manager failures. + * + * @hide + */ + @IntDef( + value = { + ON_DEVICE_INTELLIGENCE_SERVICE_UNAVAILABLE + }, open = true) + @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) + @interface OnDeviceIntelligenceManagerErrorCode { + } + private final int mErrorCode; private final PersistableBundle errorParams; - public OnDeviceIntelligenceManagerException(int errorCode, @NonNull String errorMessage, + public OnDeviceIntelligenceManagerException( + @OnDeviceIntelligenceManagerErrorCode int errorCode, @NonNull String errorMessage, @NonNull PersistableBundle errorParams) { super(errorMessage); this.mErrorCode = errorCode; this.errorParams = errorParams; } - public OnDeviceIntelligenceManagerException(int errorCode, + public OnDeviceIntelligenceManagerException( + @OnDeviceIntelligenceManagerErrorCode int errorCode, @NonNull PersistableBundle errorParams) { this.mErrorCode = errorCode; this.errorParams = errorParams; @@ -573,11 +645,15 @@ public class OnDeviceIntelligenceManager { /** Inference suspended so that higher-priority inference can run. */ public static final int PROCESSING_ERROR_SUSPENDED = 13; - /** Underlying processing encountered an internal error, like a violated precondition. */ + /** + * Underlying processing encountered an internal error, like a violated precondition + * . + */ public static final int PROCESSING_ERROR_INTERNAL = 14; /** - * The processing was not able to be passed on to the remote implementation, as the service + * The processing was not able to be passed on to the remote implementation, as the + * service * was unavailable. */ public static final int PROCESSING_ERROR_SERVICE_UNAVAILABLE = 15; diff --git a/core/java/android/app/ondeviceintelligence/ProcessingOutcomeReceiver.java b/core/java/android/app/ondeviceintelligence/ProcessingOutcomeReceiver.java new file mode 100644 index 000000000000..b0b6e1948cf0 --- /dev/null +++ b/core/java/android/app/ondeviceintelligence/ProcessingOutcomeReceiver.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.app.ondeviceintelligence; + +import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE; + +import android.annotation.FlaggedApi; +import android.annotation.NonNull; +import android.annotation.SystemApi; +import android.os.OutcomeReceiver; + +import java.util.function.Consumer; + +/** + * Response Callback to populate the processed response or any error that occurred during the + * request processing. This callback also provides a method to request additional data to be + * augmented to the request-processing, using the partial {@link Content} that was already + * processed in the remote implementation. + * + * @hide + */ +@SystemApi +@FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) +public interface ProcessingOutcomeReceiver extends + OutcomeReceiver<Content, + OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> { + /** + * Callback to be invoked in cases where the remote service needs to perform retrieval or + * transformation operations based on a partially processed request, in order to augment the + * final response, by using the additional context sent via this callback. + * + * @param content The content payload that should be used to augment ongoing request. + * @param contentConsumer The augmentation data that should be sent to remote + * service for further processing a request. + */ + default void onDataAugmentRequest(@NonNull Content content, + @NonNull Consumer<Content> contentConsumer) { + contentConsumer.accept(null); + } +} diff --git a/core/java/android/app/ondeviceintelligence/StreamingResponseReceiver.java b/core/java/android/app/ondeviceintelligence/StreamedProcessingOutcomeReceiver.java index ebcf61c8c0c2..ac2b0329496c 100644 --- a/core/java/android/app/ondeviceintelligence/StreamingResponseReceiver.java +++ b/core/java/android/app/ondeviceintelligence/StreamedProcessingOutcomeReceiver.java @@ -21,23 +21,19 @@ import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.SystemApi; -import android.os.OutcomeReceiver; /** * Streaming variant of outcome receiver to populate response while processing a given request, - * possibly in - * chunks to provide a async processing behaviour to the caller. + * possibly in chunks to provide a async processing behaviour to the caller. * * @hide */ @SystemApi @FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) -public interface StreamingResponseReceiver<R, T, E extends Throwable> extends - OutcomeReceiver<R, E> { +public interface StreamedProcessingOutcomeReceiver extends ProcessingOutcomeReceiver { /** - * Callback to be invoked when a part of the response i.e. some {@link Content} is already - * processed and - * needs to be passed onto the caller. + * Callback that would be invoked when a part of the response i.e. some {@link Content} is + * already processed and needs to be passed onto the caller. */ - void onNewContent(@NonNull T content); + void onNewContent(@NonNull Content content); } diff --git a/core/java/android/app/ondeviceintelligence/TokenInfo.aidl b/core/java/android/app/ondeviceintelligence/TokenInfo.aidl new file mode 100644 index 000000000000..2c19c1eb246c --- /dev/null +++ b/core/java/android/app/ondeviceintelligence/TokenInfo.aidl @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.app.ondeviceintelligence; + +/** + * @hide + */ +parcelable TokenInfo; diff --git a/core/java/android/app/ondeviceintelligence/TokenInfo.java b/core/java/android/app/ondeviceintelligence/TokenInfo.java new file mode 100644 index 000000000000..035cc4b365b5 --- /dev/null +++ b/core/java/android/app/ondeviceintelligence/TokenInfo.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.app.ondeviceintelligence; + +import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE; + +import android.annotation.FlaggedApi; +import android.annotation.NonNull; +import android.annotation.SystemApi; +import android.os.Parcel; +import android.os.Parcelable; +import android.os.PersistableBundle; + +/** + * This class is used to provide a token count response for the + * {@link OnDeviceIntelligenceManager#requestTokenInfo} outcome receiver. + * + * @hide + */ +@SystemApi +@FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) +public final class TokenInfo implements Parcelable { + private final long mCount; + private final PersistableBundle mInfoParams; + + /** + * Construct a token count using the count value and associated params. + */ + public TokenInfo(long count, @NonNull PersistableBundle persistableBundle) { + this.mCount = count; + mInfoParams = persistableBundle; + } + + /** + * Construct a token count using the count value. + */ + public TokenInfo(long count) { + this.mCount = count; + this.mInfoParams = new PersistableBundle(); + } + + /** + * Returns the token count associated with a request payload. + */ + public long getCount() { + return mCount; + } + + /** + * Returns the params representing token info. + */ + @NonNull + public PersistableBundle getInfoParams() { + return mInfoParams; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeLong(mCount); + dest.writePersistableBundle(mInfoParams); + } + + public static final @NonNull Parcelable.Creator<TokenInfo> CREATOR + = new Parcelable.Creator<>() { + @Override + public TokenInfo[] newArray(int size) { + return new TokenInfo[size]; + } + + @Override + public TokenInfo createFromParcel(@NonNull Parcel in) { + return new TokenInfo(in.readLong(), in.readPersistableBundle()); + } + }; +} diff --git a/core/java/android/service/ondeviceintelligence/IOnDeviceIntelligenceService.aidl b/core/java/android/service/ondeviceintelligence/IOnDeviceIntelligenceService.aidl index e44c69c4df28..6dbff7185f6f 100644 --- a/core/java/android/service/ondeviceintelligence/IOnDeviceIntelligenceService.aidl +++ b/core/java/android/service/ondeviceintelligence/IOnDeviceIntelligenceService.aidl @@ -36,11 +36,13 @@ import android.service.ondeviceintelligence.IRemoteProcessingService; */ oneway interface IOnDeviceIntelligenceService { void getVersion(in RemoteCallback remoteCallback); - void getFeature(in int featureId, in IFeatureCallback featureCallback); - void listFeatures(in IListFeaturesCallback listFeaturesCallback); - void getFeatureDetails(in Feature feature, in IFeatureDetailsCallback featureDetailsCallback); + void getFeature(int callerUid, int featureId, in IFeatureCallback featureCallback); + void listFeatures(int callerUid, in IListFeaturesCallback listFeaturesCallback); + void getFeatureDetails(int callerUid, in Feature feature, in IFeatureDetailsCallback featureDetailsCallback); void getReadOnlyFileDescriptor(in String fileName, in AndroidFuture<ParcelFileDescriptor> future); void getReadOnlyFeatureFileDescriptorMap(in Feature feature, in RemoteCallback remoteCallback); - void requestFeatureDownload(in Feature feature, in ICancellationSignal cancellationSignal, in IDownloadCallback downloadCallback); + void requestFeatureDownload(int callerUid, in Feature feature, in ICancellationSignal cancellationSignal, in IDownloadCallback downloadCallback); void registerRemoteServices(in IRemoteProcessingService remoteProcessingService); + void notifyInferenceServiceConnected(); + void notifyInferenceServiceDisconnected(); }
\ No newline at end of file diff --git a/core/java/android/service/ondeviceintelligence/IOnDeviceTrustedInferenceService.aidl b/core/java/android/service/ondeviceintelligence/IOnDeviceSandboxedInferenceService.aidl index e3fda04e6592..73257ed7680a 100644 --- a/core/java/android/service/ondeviceintelligence/IOnDeviceTrustedInferenceService.aidl +++ b/core/java/android/service/ondeviceintelligence/IOnDeviceSandboxedInferenceService.aidl @@ -18,7 +18,7 @@ package android.service.ondeviceintelligence; import android.app.ondeviceintelligence.IStreamingResponseCallback; import android.app.ondeviceintelligence.IResponseCallback; -import android.app.ondeviceintelligence.ITokenCountCallback; +import android.app.ondeviceintelligence.ITokenInfoCallback; import android.app.ondeviceintelligence.IProcessingSignal; import android.app.ondeviceintelligence.Content; import android.app.ondeviceintelligence.Feature; @@ -29,18 +29,18 @@ import android.service.ondeviceintelligence.IRemoteStorageService; import android.service.ondeviceintelligence.IProcessingUpdateStatusCallback; /** - * Interface for a concrete implementation to provide on device trusted inference. + * Interface for a concrete implementation to provide on-device sandboxed inference. * * @hide */ -oneway interface IOnDeviceTrustedInferenceService { +oneway interface IOnDeviceSandboxedInferenceService { void registerRemoteStorageService(in IRemoteStorageService storageService); - void requestTokenCount(in Feature feature, in Content request, in ICancellationSignal cancellationSignal, - in ITokenCountCallback tokenCountCallback); - void processRequest(in Feature feature, in Content request, in int requestType, + void requestTokenInfo(int callerUid, in Feature feature, in Content request, in ICancellationSignal cancellationSignal, + in ITokenInfoCallback tokenInfoCallback); + void processRequest(int callerUid, in Feature feature, in Content request, in int requestType, in ICancellationSignal cancellationSignal, in IProcessingSignal processingSignal, in IResponseCallback callback); - void processRequestStreaming(in Feature feature, in Content request, in int requestType, + void processRequestStreaming(int callerUid, in Feature feature, in Content request, in int requestType, in ICancellationSignal cancellationSignal, in IProcessingSignal processingSignal, in IStreamingResponseCallback callback); void updateProcessingState(in Bundle processingState, diff --git a/core/java/android/service/ondeviceintelligence/OnDeviceIntelligenceService.java b/core/java/android/service/ondeviceintelligence/OnDeviceIntelligenceService.java index 46ba25d40bec..fce3689bb8b3 100644 --- a/core/java/android/service/ondeviceintelligence/OnDeviceIntelligenceService.java +++ b/core/java/android/service/ondeviceintelligence/OnDeviceIntelligenceService.java @@ -65,7 +65,7 @@ import java.util.function.LongConsumer; /** * Abstract base class for performing setup for on-device inference and providing file access to - * the isolated counter part {@link OnDeviceTrustedInferenceService}. + * the isolated counter part {@link OnDeviceSandboxedInferenceService}. * * <p> A service that provides configuration and model files relevant to performing inference on * device. The system's default OnDeviceIntelligenceService implementation is configured in @@ -110,6 +110,8 @@ public abstract class OnDeviceIntelligenceService extends Service { @Override public final IBinder onBind(@NonNull Intent intent) { if (SERVICE_INTERFACE.equals(intent.getAction())) { + // TODO(326052028) : Move the remote method calls to an app handler from the binder + // thread. return new IOnDeviceIntelligenceService.Stub() { /** {@inheritDoc} */ @Override @@ -123,38 +125,40 @@ public abstract class OnDeviceIntelligenceService extends Service { } @Override - public void listFeatures(IListFeaturesCallback listFeaturesCallback) { + public void listFeatures(int callerUid, + IListFeaturesCallback listFeaturesCallback) { Objects.requireNonNull(listFeaturesCallback); - OnDeviceIntelligenceService.this.onListFeatures( + OnDeviceIntelligenceService.this.onListFeatures(callerUid, wrapListFeaturesCallback(listFeaturesCallback)); } @Override - public void getFeature(int id, IFeatureCallback featureCallback) { + public void getFeature(int callerUid, int id, IFeatureCallback featureCallback) { Objects.requireNonNull(featureCallback); - OnDeviceIntelligenceService.this.onGetFeature(id, - wrapFeatureCallback(featureCallback)); + OnDeviceIntelligenceService.this.onGetFeature(callerUid, + id, wrapFeatureCallback(featureCallback)); } @Override - public void getFeatureDetails(Feature feature, + public void getFeatureDetails(int callerUid, Feature feature, IFeatureDetailsCallback featureDetailsCallback) { Objects.requireNonNull(feature); Objects.requireNonNull(featureDetailsCallback); - OnDeviceIntelligenceService.this.onGetFeatureDetails(feature, - wrapFeatureDetailsCallback(featureDetailsCallback)); + OnDeviceIntelligenceService.this.onGetFeatureDetails(callerUid, + feature, wrapFeatureDetailsCallback(featureDetailsCallback)); } @Override - public void requestFeatureDownload(Feature feature, + public void requestFeatureDownload(int callerUid, Feature feature, ICancellationSignal cancellationSignal, IDownloadCallback downloadCallback) { Objects.requireNonNull(feature); Objects.requireNonNull(downloadCallback); - OnDeviceIntelligenceService.this.onDownloadFeature(feature, + OnDeviceIntelligenceService.this.onDownloadFeature(callerUid, + feature, CancellationSignal.fromTransport(cancellationSignal), wrapDownloadCallback(downloadCallback)); } @@ -188,12 +192,38 @@ public abstract class OnDeviceIntelligenceService extends Service { IRemoteProcessingService remoteProcessingService) { mRemoteProcessingService = remoteProcessingService; } + + @Override + public void notifyInferenceServiceConnected() { + OnDeviceIntelligenceService.this.onInferenceServiceConnected(); + } + + @Override + public void notifyInferenceServiceDisconnected() { + OnDeviceIntelligenceService.this.onInferenceServiceDisconnected(); + } }; } Slog.w(TAG, "Incorrect service interface, returning null."); return null; } + + /** + * Invoked when a new instance of the remote inference service is created. + * This method should be used as a signal to perform any initialization operations, for e.g. by + * invoking the {@link #updateProcessingState} method to initialize the remote processing + * service. + */ + public abstract void onInferenceServiceConnected(); + + + /** + * Invoked when an instance of the remote inference service is disconnected. + */ + public abstract void onInferenceServiceDisconnected(); + + /** * Invoked by the {@link OnDeviceIntelligenceService} inorder to send updates to the inference * service if there is a state change to be performed. @@ -391,6 +421,7 @@ public abstract class OnDeviceIntelligenceService extends Service { * Request download for feature that is requested and listen to download progress updates. If * the download completes successfully, success callback should be populated. * + * @param callerUid UID of the caller that initiated this call chain. * @param feature the feature for which files need to be downlaoded. * process. * @param cancellationSignal signal to attach a listener to, and receive cancellation signals @@ -398,7 +429,7 @@ public abstract class OnDeviceIntelligenceService extends Service { * @param downloadCallback callback to populate download updates for clients to listen on.. */ public abstract void onDownloadFeature( - @NonNull Feature feature, + int callerUid, @NonNull Feature feature, @Nullable CancellationSignal cancellationSignal, @NonNull DownloadCallback downloadCallback); @@ -407,20 +438,22 @@ public abstract class OnDeviceIntelligenceService extends Service { * implementation use the {@link Feature#getFeatureParams()} as a hint to communicate what * details the client is looking for. * - * @param feature the feature for which status needs to be known. - * @param featureStatusCallback callback to populate the resulting feature status. + * @param callerUid UID of the caller that initiated this call chain. + * @param feature the feature for which status needs to be known. + * @param featureDetailsCallback callback to populate the resulting feature status. */ - public abstract void onGetFeatureDetails(@NonNull Feature feature, + public abstract void onGetFeatureDetails(int callerUid, @NonNull Feature feature, @NonNull OutcomeReceiver<FeatureDetails, - OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException> featureStatusCallback); + OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException> featureDetailsCallback); /** * Get feature using the provided identifier to the remote implementation. * + * @param callerUid UID of the caller that initiated this call chain. * @param featureCallback callback to populate the features list. */ - public abstract void onGetFeature(int featureId, + public abstract void onGetFeature(int callerUid, int featureId, @NonNull OutcomeReceiver<Feature, OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException> featureCallback); @@ -428,9 +461,10 @@ public abstract class OnDeviceIntelligenceService extends Service { * List all features which are available in the remote implementation. The implementation might * choose to provide only a certain list of features based on the caller. * + * @param callerUid UID of the caller that initiated this call chain. * @param listFeaturesCallback callback to populate the features list. */ - public abstract void onListFeatures(@NonNull OutcomeReceiver<List<Feature>, + public abstract void onListFeatures(int callerUid, @NonNull OutcomeReceiver<List<Feature>, OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException> listFeaturesCallback); /** diff --git a/core/java/android/service/ondeviceintelligence/OnDeviceTrustedInferenceService.java b/core/java/android/service/ondeviceintelligence/OnDeviceSandboxedInferenceService.java index 86001975cc09..7f7f9c28c60e 100644 --- a/core/java/android/service/ondeviceintelligence/OnDeviceTrustedInferenceService.java +++ b/core/java/android/service/ondeviceintelligence/OnDeviceSandboxedInferenceService.java @@ -16,6 +16,7 @@ package android.service.ondeviceintelligence; +import static android.app.ondeviceintelligence.OnDeviceIntelligenceManager.AUGMENT_REQUEST_CONTENT_BUNDLE_KEY; import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE; import android.annotation.CallbackExecutor; @@ -23,6 +24,7 @@ import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.app.Service; import android.app.ondeviceintelligence.Content; @@ -30,14 +32,18 @@ import android.app.ondeviceintelligence.Feature; import android.app.ondeviceintelligence.IProcessingSignal; import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.IStreamingResponseCallback; -import android.app.ondeviceintelligence.ITokenCountCallback; +import android.app.ondeviceintelligence.ITokenInfoCallback; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager; import android.app.ondeviceintelligence.ProcessingSignal; -import android.app.ondeviceintelligence.StreamingResponseReceiver; +import android.app.ondeviceintelligence.ProcessingOutcomeReceiver; +import android.app.ondeviceintelligence.StreamedProcessingOutcomeReceiver; +import android.app.ondeviceintelligence.TokenInfo; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.CancellationSignal; +import android.os.Handler; +import android.os.HandlerExecutor; import android.os.IBinder; import android.os.ICancellationSignal; import android.os.OutcomeReceiver; @@ -75,8 +81,8 @@ import java.util.function.Consumer; * * <pre> * {@literal - * <service android:name=".SampleTrustedInferenceService" - * android:permission="android.permission.BIND_ONDEVICE_TRUSTED_INFERENCE_SERVICE" + * <service android:name=".SampleSandboxedInferenceService" + * android:permission="android.permission.BIND_ONDEVICE_SANDBOXED_INFERENCE_SERVICE" * android:isolatedProcess="true"> * </service>} * </pre> @@ -85,18 +91,18 @@ import java.util.function.Consumer; */ @SystemApi @FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) -public abstract class OnDeviceTrustedInferenceService extends Service { - private static final String TAG = OnDeviceTrustedInferenceService.class.getSimpleName(); +public abstract class OnDeviceSandboxedInferenceService extends Service { + private static final String TAG = OnDeviceSandboxedInferenceService.class.getSimpleName(); /** * The {@link Intent} that must be declared as handled by the service. To be supported, the * service must also require the - * {@link android.Manifest.permission#BIND_ON_DEVICE_TRUSTED_INFERENCE_SERVICE} + * {@link android.Manifest.permission#BIND_ON_DEVICE_SANDBOXED_INFERENCE_SERVICE} * permission so that other applications can not abuse it. */ @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) public static final String SERVICE_INTERFACE = - "android.service.ondeviceintelligence.OnDeviceTrustedInferenceService"; + "android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService"; private IRemoteStorageService mRemoteStorageService; @@ -107,7 +113,7 @@ public abstract class OnDeviceTrustedInferenceService extends Service { @Override public final IBinder onBind(@NonNull Intent intent) { if (SERVICE_INTERFACE.equals(intent.getAction())) { - return new IOnDeviceTrustedInferenceService.Stub() { + return new IOnDeviceSandboxedInferenceService.Stub() { @Override public void registerRemoteStorageService(IRemoteStorageService storageService) { Objects.requireNonNull(storageService); @@ -115,50 +121,48 @@ public abstract class OnDeviceTrustedInferenceService extends Service { } @Override - public void requestTokenCount(Feature feature, Content request, + public void requestTokenInfo(int callerUid, Feature feature, Content request, ICancellationSignal cancellationSignal, - ITokenCountCallback tokenCountCallback) { + ITokenInfoCallback tokenInfoCallback) { Objects.requireNonNull(feature); - Objects.requireNonNull(tokenCountCallback); - OnDeviceTrustedInferenceService.this.onCountTokens(feature, + Objects.requireNonNull(tokenInfoCallback); + OnDeviceSandboxedInferenceService.this.onTokenInfoRequest(callerUid, + feature, request, CancellationSignal.fromTransport(cancellationSignal), - wrapTokenCountCallback(tokenCountCallback)); + wrapTokenInfoCallback(tokenInfoCallback)); } @Override - public void processRequestStreaming(Feature feature, Content request, + public void processRequestStreaming(int callerUid, Feature feature, Content request, int requestType, ICancellationSignal cancellationSignal, IProcessingSignal processingSignal, IStreamingResponseCallback callback) { Objects.requireNonNull(feature); - Objects.requireNonNull(request); Objects.requireNonNull(callback); - OnDeviceTrustedInferenceService.this.onProcessRequestStreaming(feature, + OnDeviceSandboxedInferenceService.this.onProcessRequestStreaming(callerUid, + feature, request, requestType, CancellationSignal.fromTransport(cancellationSignal), ProcessingSignal.fromTransport(processingSignal), - wrapStreamingResponseCallback(callback) - ); + wrapStreamingResponseCallback(callback)); } @Override - public void processRequest(Feature feature, Content request, + public void processRequest(int callerUid, Feature feature, Content request, int requestType, ICancellationSignal cancellationSignal, IProcessingSignal processingSignal, IResponseCallback callback) { Objects.requireNonNull(feature); - Objects.requireNonNull(request); Objects.requireNonNull(callback); - - OnDeviceTrustedInferenceService.this.onProcessRequest(feature, request, - requestType, CancellationSignal.fromTransport(cancellationSignal), + OnDeviceSandboxedInferenceService.this.onProcessRequest(callerUid, feature, + request, requestType, + CancellationSignal.fromTransport(cancellationSignal), ProcessingSignal.fromTransport(processingSignal), - wrapResponseCallback(callback) - ); + wrapResponseCallback(callback)); } @Override @@ -167,7 +171,7 @@ public abstract class OnDeviceTrustedInferenceService extends Service { Objects.requireNonNull(processingState); Objects.requireNonNull(callback); - OnDeviceTrustedInferenceService.this.onUpdateProcessingState(processingState, + OnDeviceSandboxedInferenceService.this.onUpdateProcessingState(processingState, wrapOutcomeReceiver(callback) ); } @@ -178,35 +182,37 @@ public abstract class OnDeviceTrustedInferenceService extends Service { } /** - * Invoked when caller wants to obtain a count of number of tokens present in the passed in - * Request associated with the provided feature. + * Invoked when caller wants to obtain token info related to the payload in the passed + * content, associated with the provided feature. * The expectation from the implementation is that when processing is complete, it - * should provide the token count in the {@link OutcomeReceiver#onResult}. + * should provide the token info in the {@link OutcomeReceiver#onResult}. * + * @param callerUid UID of the caller that initiated this call chain. * @param feature feature which is associated with the request. * @param request request that requires processing. * @param cancellationSignal Cancellation Signal to receive cancellation events from client and * configure a listener to. - * @param callback callback to populate failure and full response for the provided + * @param callback callback to populate failure or the token info for the provided * request. */ @NonNull - public abstract void onCountTokens( - @NonNull Feature feature, + public abstract void onTokenInfoRequest( + int callerUid, @NonNull Feature feature, @NonNull Content request, @Nullable CancellationSignal cancellationSignal, - @NonNull OutcomeReceiver<Long, + @NonNull OutcomeReceiver<TokenInfo, OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> callback); /** * Invoked when caller provides a request for a particular feature to be processed in a * streaming manner. The expectation from the implementation is that when processing the * request, - * it periodically populates the {@link StreamingResponseReceiver#onNewContent} to continuously + * it periodically populates the {@link StreamedProcessingOutcomeReceiver#onNewContent} to continuously * provide partial Content results for the caller to utilize. Optionally the implementation can - * provide the complete response in the {@link StreamingResponseReceiver#onResult} upon + * provide the complete response in the {@link StreamedProcessingOutcomeReceiver#onResult} upon * processing completion. * + * @param callerUid UID of the caller that initiated this call chain. * @param feature feature which is associated with the request. * @param request request that requires processing. * @param requestType identifier representing the type of request. @@ -218,13 +224,12 @@ public abstract class OnDeviceTrustedInferenceService extends Service { */ @NonNull public abstract void onProcessRequestStreaming( - @NonNull Feature feature, - @NonNull Content request, + int callerUid, @NonNull Feature feature, + @Nullable Content request, @OnDeviceIntelligenceManager.RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, - @NonNull StreamingResponseReceiver<Content, Content, - OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> callback); + @NonNull StreamedProcessingOutcomeReceiver callback); /** * Invoked when caller provides a request for a particular feature to be processed in one shot @@ -233,6 +238,7 @@ public abstract class OnDeviceTrustedInferenceService extends Service { * should * provide the complete response in the {@link OutcomeReceiver#onResult}. * + * @param callerUid UID of the caller that initiated this call chain. * @param feature feature which is associated with the request. * @param request request that requires processing. * @param requestType identifier representing the type of request. @@ -244,13 +250,12 @@ public abstract class OnDeviceTrustedInferenceService extends Service { */ @NonNull public abstract void onProcessRequest( - @NonNull Feature feature, - @NonNull Content request, + int callerUid, @NonNull Feature feature, + @Nullable Content request, @OnDeviceIntelligenceManager.RequestType int requestType, @Nullable CancellationSignal cancellationSignal, @Nullable ProcessingSignal processingSignal, - @NonNull OutcomeReceiver<Content, - OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> callback); + @NonNull ProcessingOutcomeReceiver callback); /** @@ -335,6 +340,26 @@ public abstract class OnDeviceTrustedInferenceService extends Service { } } + + /** + * Returns the {@link Executor} to use for incoming IPC from request sender into your service + * implementation. For e.g. see + * {@link ProcessingOutcomeReceiver#onDataAugmentRequest(Content, + * Consumer)} where we use the executor to populate the consumer. + * <p> + * Override this method in your {@link OnDeviceSandboxedInferenceService} implementation to + * provide the executor you want to use for incoming IPC. + * + * @return the {@link Executor} to use for incoming IPC from {@link OnDeviceIntelligenceManager} + * to {@link OnDeviceSandboxedInferenceService}. + */ + @SuppressLint("OnNameExpected") + @NonNull + public Executor getCallbackExecutor() { + return new HandlerExecutor(Handler.createAsync(getMainLooper())); + } + + private RemoteCallback wrapResultReceiverAsReadOnly( @NonNull Consumer<Map<String, FileInputStream>> resultConsumer, @NonNull Executor executor) { @@ -355,10 +380,9 @@ public abstract class OnDeviceTrustedInferenceService extends Service { }); } - private OutcomeReceiver<Content, - OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> wrapResponseCallback( + private ProcessingOutcomeReceiver wrapResponseCallback( IResponseCallback callback) { - return new OutcomeReceiver<>() { + return new ProcessingOutcomeReceiver() { @Override public void onResult(@androidx.annotation.NonNull Content response) { try { @@ -378,13 +402,23 @@ public abstract class OnDeviceTrustedInferenceService extends Service { Slog.e(TAG, "Error sending result: " + e); } } + + @Override + public void onDataAugmentRequest(@NonNull Content content, + @NonNull Consumer<Content> contentCallback) { + try { + callback.onDataAugmentRequest(content, wrapRemoteCallback(contentCallback)); + + } catch (RemoteException e) { + Slog.e(TAG, "Error sending augment request: " + e); + } + } }; } - private StreamingResponseReceiver<Content, Content, - OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> wrapStreamingResponseCallback( + private StreamedProcessingOutcomeReceiver wrapStreamingResponseCallback( IStreamingResponseCallback callback) { - return new StreamingResponseReceiver<>() { + return new StreamedProcessingOutcomeReceiver() { @Override public void onNewContent(@androidx.annotation.NonNull Content content) { try { @@ -413,17 +447,43 @@ public abstract class OnDeviceTrustedInferenceService extends Service { Slog.e(TAG, "Error sending result: " + e); } } + + @Override + public void onDataAugmentRequest(@NonNull Content content, + @NonNull Consumer<Content> contentCallback) { + try { + callback.onDataAugmentRequest(content, wrapRemoteCallback(contentCallback)); + + } catch (RemoteException e) { + Slog.e(TAG, "Error sending augment request: " + e); + } + } }; } - private OutcomeReceiver<Long, - OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> wrapTokenCountCallback( - ITokenCountCallback tokenCountCallback) { + private RemoteCallback wrapRemoteCallback( + @androidx.annotation.NonNull Consumer<Content> contentCallback) { + return new RemoteCallback( + result -> { + if (result != null) { + getCallbackExecutor().execute(() -> contentCallback.accept( + result.getParcelable(AUGMENT_REQUEST_CONTENT_BUNDLE_KEY, + Content.class))); + } else { + getCallbackExecutor().execute( + () -> contentCallback.accept(null)); + } + }); + } + + private OutcomeReceiver<TokenInfo, + OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException> wrapTokenInfoCallback( + ITokenInfoCallback tokenInfoCallback) { return new OutcomeReceiver<>() { @Override - public void onResult(Long tokenCount) { + public void onResult(TokenInfo tokenInfo) { try { - tokenCountCallback.onSuccess(tokenCount); + tokenInfoCallback.onSuccess(tokenInfo); } catch (RemoteException e) { Slog.e(TAG, "Error sending result: " + e); } @@ -433,7 +493,7 @@ public abstract class OnDeviceTrustedInferenceService extends Service { public void onError( OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerProcessingException exception) { try { - tokenCountCallback.onFailure(exception.getErrorCode(), exception.getMessage(), + tokenInfoCallback.onFailure(exception.getErrorCode(), exception.getMessage(), exception.getErrorParams()); } catch (RemoteException e) { Slog.e(TAG, "Error sending failure: " + e); diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 52bad21e156d..9d80d153f865 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -7955,12 +7955,12 @@ android:protectionLevel="signature|privileged" /> - <!-- @SystemApi Allows an app to bind the on-device trusted service. + <!-- @SystemApi Allows an app to bind the on-device sandboxed service. <p>Protection level: signature|privileged @hide @FlaggedApi("android.app.ondeviceintelligence.flags.enable_on_device_intelligence") --> - <permission android:name="android.permission.BIND_ON_DEVICE_TRUSTED_SERVICE" + <permission android:name="android.permission.BIND_ON_DEVICE_SANDBOXED_INFERENCE_SERVICE" android:protectionLevel="signature"/> diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 4f20fceef8d1..9d902c94ffe4 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -4673,8 +4673,8 @@ <!-- The component name for the default system on-device intelligence service, --> <string name="config_defaultOnDeviceIntelligenceService" translatable="false"></string> - <!-- The component name for the default system on-device trusted inference service. --> - <string name="config_defaultOnDeviceTrustedInferenceService" translatable="false"></string> + <!-- The component name for the default system on-device sandboxed inference service. --> + <string name="config_defaultOnDeviceSandboxedInferenceService" translatable="false"></string> <!-- Component name that accepts ACTION_SEND intents for requesting ambient context consent for wearable sensing. --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 06bcd26417e0..4b716543c726 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3916,7 +3916,7 @@ <java-symbol type="string" name="config_ambientContextEventArrayExtraKey" /> <java-symbol type="string" name="config_defaultWearableSensingService" /> <java-symbol type="string" name="config_defaultOnDeviceIntelligenceService" /> - <java-symbol type="string" name="config_defaultOnDeviceTrustedInferenceService" /> + <java-symbol type="string" name="config_defaultOnDeviceSandboxedInferenceService" /> <java-symbol type="string" name="config_retailDemoPackage" /> <java-symbol type="string" name="config_retailDemoPackageSignature" /> diff --git a/services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerService.java b/services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerService.java index 0abe50f12772..71800efae292 100644 --- a/services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerService.java +++ b/services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerService.java @@ -32,12 +32,13 @@ import android.app.ondeviceintelligence.IOnDeviceIntelligenceManager; import android.app.ondeviceintelligence.IProcessingSignal; import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.IStreamingResponseCallback; -import android.app.ondeviceintelligence.ITokenCountCallback; +import android.app.ondeviceintelligence.ITokenInfoCallback; import android.app.ondeviceintelligence.OnDeviceIntelligenceManager; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; +import android.os.Binder; import android.os.Bundle; import android.os.ICancellationSignal; import android.os.ParcelFileDescriptor; @@ -47,11 +48,12 @@ import android.os.RemoteException; import android.os.UserHandle; import android.provider.DeviceConfig; import android.service.ondeviceintelligence.IOnDeviceIntelligenceService; -import android.service.ondeviceintelligence.IOnDeviceTrustedInferenceService; +import android.service.ondeviceintelligence.IOnDeviceSandboxedInferenceService; import android.service.ondeviceintelligence.IRemoteProcessingService; import android.service.ondeviceintelligence.IRemoteStorageService; import android.service.ondeviceintelligence.IProcessingUpdateStatusCallback; import android.service.ondeviceintelligence.OnDeviceIntelligenceService; +import android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService; import android.text.TextUtils; import android.util.Slog; @@ -69,7 +71,7 @@ import java.util.Set; * This is the system service for handling calls on the * {@link android.app.ondeviceintelligence.OnDeviceIntelligenceManager}. This * service holds connection references to the underlying remote services i.e. the isolated service - * {@link OnDeviceTrustedInferenceService} and a regular + * {@link OnDeviceSandboxedInferenceService} and a regular * service counter part {@link OnDeviceIntelligenceService}. * * Note: Both the remote services run under the SYSTEM user, as we cannot have separate instance of @@ -90,7 +92,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService { protected final Object mLock = new Object(); - private RemoteOnDeviceTrustedInferenceService mRemoteInferenceService; + private RemoteOnDeviceSandboxedInferenceService mRemoteInferenceService; private RemoteOnDeviceIntelligenceService mRemoteOnDeviceIntelligenceService; volatile boolean mIsServiceEnabled; @@ -165,7 +167,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService { } ensureRemoteIntelligenceServiceInitialized(); mRemoteOnDeviceIntelligenceService.post( - service -> service.getFeature(id, featureCallback)); + service -> service.getFeature(Binder.getCallingUid(), id, featureCallback)); } @Override @@ -185,7 +187,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService { } ensureRemoteIntelligenceServiceInitialized(); mRemoteOnDeviceIntelligenceService.post( - service -> service.listFeatures(listFeaturesCallback)); + service -> service.listFeatures(Binder.getCallingUid(), listFeaturesCallback)); } @Override @@ -207,7 +209,8 @@ public class OnDeviceIntelligenceManagerService extends SystemService { } ensureRemoteIntelligenceServiceInitialized(); mRemoteOnDeviceIntelligenceService.post( - service -> service.getFeatureDetails(feature, featureDetailsCallback)); + service -> service.getFeatureDetails(Binder.getCallingUid(), feature, + featureDetailsCallback)); } @Override @@ -227,33 +230,35 @@ public class OnDeviceIntelligenceManagerService extends SystemService { } ensureRemoteIntelligenceServiceInitialized(); mRemoteOnDeviceIntelligenceService.post( - service -> service.requestFeatureDownload(feature, cancellationSignal, + service -> service.requestFeatureDownload(Binder.getCallingUid(), feature, + cancellationSignal, downloadCallback)); } @Override - public void requestTokenCount(Feature feature, + public void requestTokenInfo(Feature feature, Content request, ICancellationSignal cancellationSignal, - ITokenCountCallback tokenCountcallback) throws RemoteException { + ITokenInfoCallback tokenInfoCallback) throws RemoteException { Slog.i(TAG, "OnDeviceIntelligenceManagerInternal prepareFeatureProcessing"); Objects.requireNonNull(feature); Objects.requireNonNull(request); - Objects.requireNonNull(tokenCountcallback); + Objects.requireNonNull(tokenInfoCallback); mContext.enforceCallingOrSelfPermission( Manifest.permission.USE_ON_DEVICE_INTELLIGENCE, TAG); if (!mIsServiceEnabled) { Slog.w(TAG, "Service not available"); - tokenCountcallback.onFailure( + tokenInfoCallback.onFailure( OnDeviceIntelligenceManager.OnDeviceIntelligenceManagerException.ON_DEVICE_INTELLIGENCE_SERVICE_UNAVAILABLE, "OnDeviceIntelligenceManagerService is unavailable", new PersistableBundle()); } - ensureRemoteTrustedInferenceServiceInitialized(); + ensureRemoteInferenceServiceInitialized(); mRemoteInferenceService.post( - service -> service.requestTokenCount(feature, request, cancellationSignal, - tokenCountcallback)); + service -> service.requestTokenInfo(Binder.getCallingUid(), feature, request, + cancellationSignal, + tokenInfoCallback)); } @Override @@ -267,7 +272,6 @@ public class OnDeviceIntelligenceManagerService extends SystemService { Slog.i(TAG, "OnDeviceIntelligenceManagerInternal processRequest"); Objects.requireNonNull(feature); Objects.requireNonNull(responseCallback); - Objects.requireNonNull(request); mContext.enforceCallingOrSelfPermission( Manifest.permission.USE_ON_DEVICE_INTELLIGENCE, TAG); if (!mIsServiceEnabled) { @@ -277,9 +281,10 @@ public class OnDeviceIntelligenceManagerService extends SystemService { "OnDeviceIntelligenceManagerService is unavailable", new PersistableBundle()); } - ensureRemoteTrustedInferenceServiceInitialized(); + ensureRemoteInferenceServiceInitialized(); mRemoteInferenceService.post( - service -> service.processRequest(feature, request, requestType, + service -> service.processRequest(Binder.getCallingUid(), feature, request, + requestType, cancellationSignal, processingSignal, responseCallback)); } @@ -293,7 +298,6 @@ public class OnDeviceIntelligenceManagerService extends SystemService { IStreamingResponseCallback streamingCallback) throws RemoteException { Slog.i(TAG, "OnDeviceIntelligenceManagerInternal processRequestStreaming"); Objects.requireNonNull(feature); - Objects.requireNonNull(request); Objects.requireNonNull(streamingCallback); mContext.enforceCallingOrSelfPermission( Manifest.permission.USE_ON_DEVICE_INTELLIGENCE, TAG); @@ -304,9 +308,10 @@ public class OnDeviceIntelligenceManagerService extends SystemService { "OnDeviceIntelligenceManagerService is unavailable", new PersistableBundle()); } - ensureRemoteTrustedInferenceServiceInitialized(); + ensureRemoteInferenceServiceInitialized(); mRemoteInferenceService.post( - service -> service.processRequestStreaming(feature, request, requestType, + service -> service.processRequestStreaming(Binder.getCallingUid(), feature, + request, requestType, cancellationSignal, processingSignal, streamingCallback)); } @@ -346,7 +351,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService { Bundle processingState, IProcessingUpdateStatusCallback callback) { try { - ensureRemoteTrustedInferenceServiceInitialized(); + ensureRemoteInferenceServiceInitialized(); mRemoteInferenceService.post( service -> service.updateProcessingState( processingState, callback)); @@ -363,22 +368,24 @@ public class OnDeviceIntelligenceManagerService extends SystemService { }; } - private void ensureRemoteTrustedInferenceServiceInitialized() throws RemoteException { + private void ensureRemoteInferenceServiceInitialized() throws RemoteException { synchronized (mLock) { if (mRemoteInferenceService == null) { String serviceName = mContext.getResources().getString( - R.string.config_defaultOnDeviceTrustedInferenceService); + R.string.config_defaultOnDeviceSandboxedInferenceService); validateService(serviceName, true); - mRemoteInferenceService = new RemoteOnDeviceTrustedInferenceService(mContext, + mRemoteInferenceService = new RemoteOnDeviceSandboxedInferenceService(mContext, ComponentName.unflattenFromString(serviceName), UserHandle.SYSTEM.getIdentifier()); mRemoteInferenceService.setServiceLifecycleCallbacks( new ServiceConnector.ServiceLifecycleCallbacks<>() { @Override public void onConnected( - @NonNull IOnDeviceTrustedInferenceService service) { + @NonNull IOnDeviceSandboxedInferenceService service) { try { ensureRemoteIntelligenceServiceInitialized(); + mRemoteOnDeviceIntelligenceService.post( + intelligenceService -> intelligenceService.notifyInferenceServiceConnected()); service.registerRemoteStorageService( getIRemoteStorageService()); } catch (RemoteException ex) { @@ -433,7 +440,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService { } checkServiceRequiresPermission(serviceInfo, - Manifest.permission.BIND_ON_DEVICE_TRUSTED_SERVICE); + Manifest.permission.BIND_ON_DEVICE_SANDBOXED_INFERENCE_SERVICE); if (!isIsolatedService(serviceInfo)) { throw new SecurityException( "Call required an isolated service, but the configured service: " diff --git a/services/core/java/com/android/server/ondeviceintelligence/RemoteOnDeviceTrustedInferenceService.java b/services/core/java/com/android/server/ondeviceintelligence/RemoteOnDeviceSandboxedInferenceService.java index cc8e78804bb6..69ba1d2fb599 100644 --- a/services/core/java/com/android/server/ondeviceintelligence/RemoteOnDeviceTrustedInferenceService.java +++ b/services/core/java/com/android/server/ondeviceintelligence/RemoteOnDeviceSandboxedInferenceService.java @@ -22,18 +22,18 @@ import static android.content.Context.BIND_INCLUDE_CAPABILITIES; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.service.ondeviceintelligence.IOnDeviceTrustedInferenceService; -import android.service.ondeviceintelligence.OnDeviceTrustedInferenceService; +import android.service.ondeviceintelligence.IOnDeviceSandboxedInferenceService; +import android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService; import com.android.internal.infra.ServiceConnector; /** - * Manages the connection to the remote on-device trusted inference service. Also, handles unbinding + * Manages the connection to the remote on-device sand boxed inference service. Also, handles unbinding * logic set by the service implementation via a SecureSettings flag. */ -public class RemoteOnDeviceTrustedInferenceService extends - ServiceConnector.Impl<IOnDeviceTrustedInferenceService> { +public class RemoteOnDeviceSandboxedInferenceService extends + ServiceConnector.Impl<IOnDeviceSandboxedInferenceService> { /** * Creates an instance of {@link ServiceConnector} * @@ -43,12 +43,12 @@ public class RemoteOnDeviceTrustedInferenceService extends * {@link Context#unbindService unbinding} * @param userId to be used for {@link Context#bindServiceAsUser binding} */ - RemoteOnDeviceTrustedInferenceService(Context context, ComponentName serviceName, + RemoteOnDeviceSandboxedInferenceService(Context context, ComponentName serviceName, int userId) { super(context, new Intent( - OnDeviceTrustedInferenceService.SERVICE_INTERFACE).setComponent(serviceName), + OnDeviceSandboxedInferenceService.SERVICE_INTERFACE).setComponent(serviceName), BIND_FOREGROUND_SERVICE | BIND_INCLUDE_CAPABILITIES, userId, - IOnDeviceTrustedInferenceService.Stub::asInterface); + IOnDeviceSandboxedInferenceService.Stub::asInterface); // Bind right away connect(); |