[**Added in Android UpsideDownCakePrivacySandbox**](https://developer.android.com/preview)  

# IsolatedWorker


`
public


interface
IsolatedWorker
`


`


`

|-----------------------------------------------------------|
| android.adservices.ondevicepersonalization.IsolatedWorker |

<br />

*** ** * ** ***

Interface with methods that need to be implemented to handle requests from the OS to an [IsolatedService](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedService). The [IsolatedService](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedService) creates an instance of [IsolatedWorker](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker) on
each request and calls one of the methods below, depending the type of the request. The [IsolatedService](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedService) calls the method on a Binder thread and the [IsolatedWorker](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker) should
offload long running operations to a worker thread. The consumer parameter of each method is used
to return results.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ||
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` default void` | ` `[onDownloadCompleted](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onDownloadCompleted(android.adservices.ondevicepersonalization.DownloadCompletedInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.DownloadCompletedOutput>))`(`[DownloadCompletedInput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/DownloadCompletedInput)` input, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[DownloadCompletedOutput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/DownloadCompletedOutput)`> consumer) ` Handles a completed download.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` default void` | ` `[onEvent](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onEvent(android.adservices.ondevicepersonalization.EventInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.EventOutput>))`(`[EventInput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/EventInput)` input, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[EventOutput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/EventOutput)`> consumer) ` Handles an event triggered by a request to a platform-provided tracking URL [EventUrlProvider](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/EventUrlProvider) that was embedded in the HTML output returned by [onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer)](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onRender(android.adservices.ondevicepersonalization.RenderInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.RenderOutput>)). |
| ` default void` | ` `[onExecute](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.ExecuteOutput>))`(`[ExecuteInput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/ExecuteInput)` input, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[ExecuteOutput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/ExecuteOutput)`> consumer) ` Handles a request from an app.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` default void` | ` `[onRender](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onRender(android.adservices.ondevicepersonalization.RenderInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.RenderOutput>))`(`[RenderInput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/RenderInput)` input, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[RenderOutput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/RenderOutput)`> consumer) ` Generates HTML for the results that were returned as a result of [onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer)](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.ExecuteOutput>)).                                                                                                                                                                                                  |
| ` default void` | ` `[onTrainingExample](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onTrainingExample(android.adservices.ondevicepersonalization.TrainingExampleInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.TrainingExampleOutput>))`(`[TrainingExampleInput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/TrainingExampleInput)` input, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[TrainingExampleOutput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/TrainingExampleOutput)`> consumer) ` Generate a single training example used for federated computation job.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

## Public methods

### onDownloadCompleted

[**Added in Android UpsideDownCakePrivacySandbox**](https://developer.android.com/preview)  

```
public void onDownloadCompleted (DownloadCompletedInput input, 
                Consumer<DownloadCompletedOutput> consumer)
```

Handles a completed download. The platform downloads content using the parameters defined in
the package manifest of the [IsolatedService](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedService), calls this function after the download
is complete, and updates the REMOTE_DATA table from
[IsolatedService#getRemoteData(RequestToken)](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedService#getRemoteData(android.adservices.ondevicepersonalization.RequestToken)) with the result of this method.

<br />

|                                                                                                                                                               Parameters                                                                                                                                                                ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `input`    | `DownloadCompletedInput`: Download handler parameters. This value cannot be `null`. <br />                                                                                                                                                                                                                                  |
| `consumer` | `Consumer`: Callback that receives the result. Should be called with `null` on an error. If called with `null`, no updates are made to the REMOTE_DATA table. If this method throws a [RuntimeException](https://developer.android.com/reference/java/lang/RuntimeException), no updates are made to the REMOTE_DATA table. |

### onEvent

[**Added in Android UpsideDownCakePrivacySandbox**](https://developer.android.com/preview)  

```
public void onEvent (EventInput input, 
                Consumer<EventOutput> consumer)
```

Handles an event triggered by a request to a platform-provided tracking URL [EventUrlProvider](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/EventUrlProvider) that was embedded in the HTML output returned by
[onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer)](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onRender(android.adservices.ondevicepersonalization.RenderInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.RenderOutput>)). The platform updates the EVENTS table with
[EventOutput#getEventLogRecord()](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/EventOutput#getEventLogRecord()).

<br />

|                                                                                                                                                         Parameters                                                                                                                                                          ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `input`    | `EventInput`: The parameters needed to compute event data. This value cannot be `null`. <br />                                                                                                                                                                                                                  |
| `consumer` | `Consumer`: Callback that receives the result. Should be called with `null` on an error. If called with `null`, no data is written to the EVENTS table. If this method throws a [RuntimeException](https://developer.android.com/reference/java/lang/RuntimeException), no data is written to the EVENTS table. |

### onExecute

[**Added in Android UpsideDownCakePrivacySandbox**](https://developer.android.com/preview)  

```
public void onExecute (ExecuteInput input, 
                Consumer<ExecuteOutput> consumer)
```

Handles a request from an app. This method is called when an app calls `OnDevicePersonalizationManager#execute(ComponentName, PersistableBundle,
java.util.concurrent.Executor, OutcomeReceiver)` that refers to a named
[IsolatedService](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedService).

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `input`    | `ExecuteInput`: Request Parameters from the calling app. This value cannot be `null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `consumer` | `Consumer`: Callback that receives the result [ExecuteOutput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/ExecuteOutput). Should be called with `null` on an error. The error is propagated to the calling app as an [OnDevicePersonalizationException](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException) with error code [OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException#ERROR_ISOLATED_SERVICE_FAILED). To avoid leaking private data to the calling app, more detailed error reporting is not available. If the [IsolatedService](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedService) needs to report error stats to its backend, it should populate [ExecuteOutput](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/ExecuteOutput) with error data for logging, and rely on Federated Analytics to aggregate the error reports. If this method throws a [RuntimeException](https://developer.android.com/reference/java/lang/RuntimeException), that is also reported to calling apps as an [OnDevicePersonalizationException](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException) with error code [OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException#ERROR_ISOLATED_SERVICE_FAILED). |

### onRender

[**Added in Android UpsideDownCakePrivacySandbox**](https://developer.android.com/preview)  

```
public void onRender (RenderInput input, 
                Consumer<RenderOutput> consumer)
```

Generates HTML for the results that were returned as a result of
[onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer)](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,%20java.util.function.Consumer<android.adservices.ondevicepersonalization.ExecuteOutput>)). Called when a client app calls
[OnDevicePersonalizationManager#requestSurfacePackage(SurfacePackageToken, IBinder, int, int, int, java.util.concurrent.Executor, OutcomeReceiver)](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationManager#requestSurfacePackage(android.adservices.ondevicepersonalization.SurfacePackageToken,%20android.os.IBinder,%20int,%20int,%20int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.view.SurfaceControlViewHost.SurfacePackage,java.lang.Exception>)).
The platform will render this HTML in an [WebView](https://developer.android.com/reference/android/webkit/WebView) inside a fenced
frame.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `input`    | `RenderInput`: Parameters for the render request. This value cannot be `null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `consumer` | `Consumer`: Callback that receives the result. Should be called with `null` on an error. The error is propagated to the calling app as an [OnDevicePersonalizationException](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException) with error code [OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException#ERROR_ISOLATED_SERVICE_FAILED). If this method throws a [RuntimeException](https://developer.android.com/reference/java/lang/RuntimeException), that is also reported to calling apps as an [OnDevicePersonalizationException](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException) with error code [OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/ondevicepersonalization/OnDevicePersonalizationException#ERROR_ISOLATED_SERVICE_FAILED). |

### onTrainingExample

[**Added in Android UpsideDownCakePrivacySandbox**](https://developer.android.com/preview)  

```
public void onTrainingExample (TrainingExampleInput input, 
                Consumer<TrainingExampleOutput> consumer)
```

Generate a single training example used for federated computation job.

<br />

|                                                           Parameters                                                            ||
|------------|---------------------------------------------------------------------------------------------------------------------|
| `input`    | `TrainingExampleInput`: The parameters needed to generate the training example. This value cannot be `null`. <br /> |
| `consumer` | `Consumer`: Callback to be invoked on completion. This value cannot be `null`. <br />                               |