OnDevicePersonalizationManager
open class OnDevicePersonalizationManager
| kotlin.Any | |
| ↳ | android.adservices.ondevicepersonalization.OnDevicePersonalizationManager | 
OnDevicePersonalizationManager provides APIs for apps to load an IsolatedService in an isolated process and interact with it. An app can request an IsolatedService to generate content for display within an android.view.SurfaceView within the app's view hierarchy, and also write persistent results to on-device storage which can be consumed by Federated Analytics for cross-device statistical analysis or by Federated Learning for model training. The displayed content and the persistent output are both not directly accessible by the calling app.
Summary
| Nested classes | |
|---|---|
| open | The result of a call to  | 
| Constants | |
|---|---|
| static Int | Indicates that a feature is present but disabled on the device. | 
| static Int | Indicates that a feature is present and enabled on the device. | 
| static Int | Indicates that a feature is not supported on the device. | 
Constants
FEATURE_DISABLED
static val FEATURE_DISABLED: Int
Indicates that a feature is present but disabled on the device.
Value: 1FEATURE_ENABLED
static val FEATURE_ENABLED: Int
Indicates that a feature is present and enabled on the device.
Value: 0FEATURE_UNSUPPORTED
static val FEATURE_UNSUPPORTED: Int
Indicates that a feature is not supported on the device.
Value: 2Public methods
execute
open fun execute(
service: ComponentName,
params: PersistableBundle,
executor: Executor,
receiver: OutcomeReceiver<OnDevicePersonalizationManager.ExecuteResult!, Exception!>
): Unit
Executes an IsolatedService in the OnDevicePersonalization sandbox. The platform binds to the specified IsolatedService in an isolated process and calls android.adservices.ondevicepersonalization.IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,android.os.OutcomeReceiver) with the caller-provided parameters. When the IsolatedService finishes execution, the platform returns tokens that refer to the results from the service to the caller. These tokens can be subsequently used to display results in a android.view.SurfaceView within the calling app.
| Parameters | |
|---|---|
| service | ComponentName: The ComponentNameof theIsolatedService. This value cannot benull. | 
| params | PersistableBundle: a PersistableBundlethat is passed from the calling app to theIsolatedService. The expected contents of this parameter are defined by theIsolatedService. The platform does not interpret this parameter. This value cannot benull. | 
| executor | Executor: the Executoron which to invoke the callback. This value cannot benull. Callback and listener events are dispatched through thisExecutor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can useContext.getMainExecutor(). Otherwise, provide anExecutorthat dispatches to an appropriate thread. | 
| receiver | OutcomeReceiver<OnDevicePersonalizationManager.ExecuteResult!, Exception!>: This returns a ExecuteResultobject on success or anExceptionon failure. If theIsolatedServicereturned aRenderingConfigto be displayed,ExecuteResult.getSurfacePackageToken()will return a non-nullSurfacePackageToken. TheSurfacePackageTokenobject can be used in a subsequentrequestSurfacePackage(android.adservices.ondevicepersonalization.SurfacePackageToken,android.os.IBinder,int,int,int,java.util.concurrent.Executor,android.os.OutcomeReceiver)call to display the result in a view. The returnedSurfacePackageTokenmay be null to indicate that no output is expected to be displayed for this request. If theIsolatedServicehas returned any output data and the calling app is allowlisted to receive data from this service, theandroid.adservices.ondevicepersonalization.OnDevicePersonalizationManager.ExecuteResult#getOutputData()will return a non-null byte array.In case of an error, the receiver returns one of the following exceptions: Returns a  | 
executeInIsolatedService
open fun executeInIsolatedService(
request: ExecuteInIsolatedServiceRequest,
executor: Executor,
receiver: OutcomeReceiver<ExecuteInIsolatedServiceResponse!, Exception!>
): Unit
Executes an IsolatedService in the OnDevicePersonalization sandbox. The platform binds to the specified IsolatedService in an isolated process and calls android.adservices.ondevicepersonalization.IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,android.os.OutcomeReceiver) with the caller-provided parameters. When the IsolatedService finishes execution, the platform returns tokens that refer to the results from the service to the caller. These tokens can be subsequently used to display results in a android.view.SurfaceView within the calling app.
| Parameters | |
|---|---|
| request | ExecuteInIsolatedServiceRequest: the ExecuteInIsolatedServiceRequestrequest This value cannot benull. | 
| executor | Executor: the Executoron which to invoke the callback. This value cannot benull. Callback and listener events are dispatched through thisExecutor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can useContext.getMainExecutor(). Otherwise, provide anExecutorthat dispatches to an appropriate thread. | 
| receiver | OutcomeReceiver<ExecuteInIsolatedServiceResponse!, Exception!>: This returns a ExecuteInIsolatedServiceResponseobject on success or anExceptionon failure. For success case, refer toExecuteInIsolatedServiceResponse. For error case, the receiver returns anOnDevicePersonalizationExceptionif execution of the handler fails. This value cannot benull. | 
queryFeatureAvailability
open fun queryFeatureAvailability(
featureName: String,
executor: Executor,
receiver: OutcomeReceiver<Int!, Exception!>
): Unit
Get the status of a specific OnDevicePersonalization feature.
| Parameters | |
|---|---|
| featureName | String: the name of the specific feature to check the availability of. This value cannot be null. | 
| executor | Executor: the Executoron which to invoke the callback This value cannot benull. Callback and listener events are dispatched through thisExecutor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can useContext.getMainExecutor(). Otherwise, provide anExecutorthat dispatches to an appropriate thread. | 
| receiver | OutcomeReceiver<Int!, Exception!>: this either returns a value of FeatureStatuson success orExceptionon failure. The exception type isIllegalStateExceptionif the service is not available. This value cannot benull. | 
requestSurfacePackage
open fun requestSurfacePackage(
surfacePackageToken: SurfacePackageToken,
surfaceViewHostToken: IBinder,
displayId: Int,
width: Int,
height: Int,
executor: Executor,
receiver: OutcomeReceiver<SurfaceControlViewHost.SurfacePackage!, Exception!>
): Unit
Requests a android.view.SurfaceControlViewHost.SurfacePackage to be inserted into a android.view.SurfaceView inside the calling app. The surface package will contain an android.view.View with the content from a result of a prior call to execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver) running in the OnDevicePersonalization sandbox.
| Parameters | |
|---|---|
| surfacePackageToken | SurfacePackageToken: a reference to a SurfacePackageTokenreturned by a prior call toexecute(ComponentName, PersistableBundle, Executor, OutcomeReceiver). This value cannot benull. | 
| surfaceViewHostToken | IBinder: the hostToken of the android.view.SurfaceView, which is returned byandroid.view.SurfaceView#getHostToken()after theandroid.view.SurfaceViewhas been added to the view hierarchy. This value cannot benull. | 
| displayId | Int: the integer ID of the logical display on which to display the android.view.SurfaceControlViewHost.SurfacePackage, returned byContext.getDisplay().getDisplayId(). | 
| width | Int: the width of the android.view.SurfaceControlViewHost.SurfacePackagein pixels. | 
| height | Int: the height of the android.view.SurfaceControlViewHost.SurfacePackagein pixels. | 
| executor | Executor: the Executoron which to invoke the callback This value cannot benull. Callback and listener events are dispatched through thisExecutor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can useContext.getMainExecutor(). Otherwise, provide anExecutorthat dispatches to an appropriate thread. | 
| receiver | OutcomeReceiver<SurfaceControlViewHost.SurfacePackage!, Exception!>: This either returns a android.view.SurfaceControlViewHost.SurfacePackageon success, orExceptionon failure. The exception type isOnDevicePersonalizationExceptionif execution of the handler fails. This value cannot benull. | 
