Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# IsolatedWorker

*** ** * ** ***

` public interface IsolatedWorker `   
` `

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

<br />

*** ** * ** ***

<br />

**This interface was deprecated in API level 37.**   

The ODP APIs are deprecated and will not be supported in future Android releases. There is no direct replacement API available. Developers currently integrated with these APIs must cease further integration efforts. For comprehensive details regarding this deprecation and the future roadmap of Privacy Sandbox on Android, please consult the official Privacy Sandbox developer documentation and announcements: <https://privacysandbox.google.com>

Interface with methods that need to be implemented to handle requests from the OnDevicePersonalization service to an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService`. The `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService` creates an instance of `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker` on each request and calls one of the methods below, depending the type of the request. The `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService` calls the method on a Binder thread and the `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker` should offload long running operations to a worker thread. The `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker` should use the `receiver` parameter of each method to return results. If any of these methods throws a `https://developer.android.com/reference/java/lang/RuntimeException`, the platform treats it as an unrecoverable error in the `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService` and ends processing the request.

## Summary

| ### Public methods ||
|---|---|
| ` default void` | ` https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onDownloadCompleted(android.adservices.ondevicepersonalization.DownloadCompletedInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.DownloadCompletedOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)(https://developer.android.com/reference/android/adservices/ondevicepersonalization/DownloadCompletedInput input, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/adservices/ondevicepersonalization/DownloadCompletedOutput, https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException> receiver) ` Handles a completed download. |
| ` default void` | ` https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onEvent(android.adservices.ondevicepersonalization.EventInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.EventOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)(https://developer.android.com/reference/android/adservices/ondevicepersonalization/EventInput input, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/adservices/ondevicepersonalization/EventOutput, https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException> receiver) ` Handles an event triggered by a request to a platform-provided tracking URL `https://developer.android.com/reference/android/adservices/ondevicepersonalization/EventUrlProvider` that was embedded in the HTML output returned by `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onRender(android.adservices.ondevicepersonalization.RenderInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.RenderOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)`. |
| ` default void` | ` https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.ExecuteOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)(https://developer.android.com/reference/android/adservices/ondevicepersonalization/ExecuteInput input, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/adservices/ondevicepersonalization/ExecuteOutput, https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException> receiver) ` Handles a request from an app. |
| ` default void` | ` https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onRender(android.adservices.ondevicepersonalization.RenderInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.RenderOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)(https://developer.android.com/reference/android/adservices/ondevicepersonalization/RenderInput input, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/adservices/ondevicepersonalization/RenderOutput, https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException> receiver) ` Generates HTML for the results that were returned as a result of `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.ExecuteOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)`. |
| ` default void` | ` https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onTrainingExamples(android.adservices.ondevicepersonalization.TrainingExamplesInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.TrainingExamplesOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)(https://developer.android.com/reference/android/adservices/ondevicepersonalization/TrainingExamplesInput input, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/adservices/ondevicepersonalization/TrainingExamplesOutput, https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException> receiver) ` Generate a list of training examples used for federated compute job. |
| ` default void` | ` https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onWebTrigger(android.adservices.ondevicepersonalization.WebTriggerInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.WebTriggerOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)(https://developer.android.com/reference/android/adservices/ondevicepersonalization/WebTriggerInput input, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/adservices/ondevicepersonalization/WebTriggerOutput, https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException> receiver) ` Handles a Web Trigger event from a browser. |

## Public methods

### onDownloadCompleted

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onDownloadCompleted (DownloadCompletedInput input, 
                OutcomeReceiver<DownloadCompletedOutput, IsolatedServiceException> receiver)
```

Handles a completed download. The platform downloads content using the parameters defined in the package manifest of the `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService`, calls this function after the download is complete, and updates the REMOTE_DATA table from `https://developer.android.com/reference/android/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 /> |
| `receiver` | `OutcomeReceiver`: Callback that receives the result `https://developer.android.com/reference/android/adservices/ondevicepersonalization/DownloadCompletedOutput` or an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException`. If this method returns a `null` result or exception via the callback, or throws a `https://developer.android.com/reference/java/lang/RuntimeException`, no updates are made to the REMOTE_DATA table. |

### onEvent

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onEvent (EventInput input, 
                OutcomeReceiver<EventOutput, IsolatedServiceException> receiver)
```

Handles an event triggered by a request to a platform-provided tracking URL `https://developer.android.com/reference/android/adservices/ondevicepersonalization/EventUrlProvider` that was embedded in the HTML output returned by `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onRender(android.adservices.ondevicepersonalization.RenderInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.RenderOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)`. The platform updates the EVENTS table with `https://developer.android.com/reference/android/adservices/ondevicepersonalization/EventOutput#getEventLogRecord()`.

<br />

| Parameters ||
|---|---|
| `input` | `EventInput`: The parameters needed to compute event data. This value cannot be `null`. <br /> |
| `receiver` | `OutcomeReceiver`: Callback that receives the result `https://developer.android.com/reference/android/adservices/ondevicepersonalization/EventOutput` or an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException`. If this method returns a `null` result or exception via the callback, or throws a `https://developer.android.com/reference/java/lang/RuntimeException`, no data is written to the EVENTS table. |

### onExecute

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onExecute (ExecuteInput input, 
                OutcomeReceiver<ExecuteOutput, IsolatedServiceException> receiver)
```

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 `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService`.

<br />

| Parameters ||
|---|---|
| `input` | `ExecuteInput`: Request Parameters from the calling app. This value cannot be `null`. <br /> |
| `receiver` | `OutcomeReceiver`: Callback that receives the result `https://developer.android.com/reference/android/adservices/ondevicepersonalization/ExecuteOutput` or an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException`. If this method throws a `https://developer.android.com/reference/java/lang/RuntimeException` or returns either `null` or `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException`, the error is indicated to the calling app as an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/OnDevicePersonalizationException` with error code `https://developer.android.com/reference/android/adservices/ondevicepersonalization/OnDevicePersonalizationException#ERROR_ISOLATED_SERVICE_FAILED`. To avoid leaking private data to the calling app, more detailed errors are not reported to the caller. If the `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService` needs to report additional data beyond the error code to its backend servers, it should populate the logging fields in `https://developer.android.com/reference/android/adservices/ondevicepersonalization/ExecuteOutput` with the additional error data for logging, and rely on Federated Analytics for the stats. <br /> |

### onRender

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onRender (RenderInput input, 
                OutcomeReceiver<RenderOutput, IsolatedServiceException> receiver)
```

Generates HTML for the results that were returned as a result of `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedWorker#onExecute(android.adservices.ondevicepersonalization.ExecuteInput,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.ExecuteOutput,android.adservices.ondevicepersonalization.IsolatedServiceException>)`. Called when a client app calls `https://developer.android.com/reference/android/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 `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 /> |
| `receiver` | `OutcomeReceiver`: Callback that receives the result `https://developer.android.com/reference/android/adservices/ondevicepersonalization/RenderOutput` or an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException`. If this method returns a `null` result or exception via the callback, or throws a `https://developer.android.com/reference/java/lang/RuntimeException`, the error is also reported to calling apps as an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/OnDevicePersonalizationException` with error code `https://developer.android.com/reference/android/adservices/ondevicepersonalization/OnDevicePersonalizationException#ERROR_ISOLATED_SERVICE_FAILED`. |

### onTrainingExamples

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onTrainingExamples (TrainingExamplesInput input, 
                OutcomeReceiver<TrainingExamplesOutput, IsolatedServiceException> receiver)
```

Generate a list of training examples used for federated compute job. The platform will call this function when a federated compute job starts. The federated compute job is scheduled by an app through `https://developer.android.com/reference/android/adservices/ondevicepersonalization/FederatedComputeScheduler#schedule(android.adservices.ondevicepersonalization.FederatedComputeScheduleRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.adservices.ondevicepersonalization.FederatedComputeScheduleResponse,java.lang.Exception>)`.

<br />

| Parameters ||
|---|---|
| `input` | `TrainingExamplesInput`: The parameters needed to generate the training example. This value cannot be `null`. <br /> |
| `receiver` | `OutcomeReceiver`: Callback that receives the result `https://developer.android.com/reference/android/adservices/ondevicepersonalization/TrainingExamplesOutput` or an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException`. If this method returns a `null` result or exception via the callback, or throws a `https://developer.android.com/reference/java/lang/RuntimeException`, no training examples is produced for this training session. |

### onWebTrigger

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onWebTrigger (WebTriggerInput input, 
                OutcomeReceiver<WebTriggerOutput, IsolatedServiceException> receiver)
```

Handles a Web Trigger event from a browser. A Web Trigger event occurs when a browser registers a web trigger event with the OS using the [Attribution and Reporting API](https://github.com/WICG/attribution-reporting-api). If the data in the web trigger payload indicates that the event should be forwarded to an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedService`, the platform will call this function with the web trigger data.

<br />

| Parameters ||
|---|---|
| `input` | `WebTriggerInput`: The parameters needed to process Web Trigger event. This value cannot be `null`. <br /> |
| `receiver` | `OutcomeReceiver`: Callback that receives the result `https://developer.android.com/reference/android/adservices/ondevicepersonalization/WebTriggerOutput` or an `https://developer.android.com/reference/android/adservices/ondevicepersonalization/IsolatedServiceException`. Should be called with a `https://developer.android.com/reference/android/adservices/ondevicepersonalization/WebTriggerOutput` object populated with a set of records to be written to the REQUESTS or EVENTS tables. If this method returns a `null` result or exception via the callback, or throws a `https://developer.android.com/reference/java/lang/RuntimeException`, no data is written to the REQUESTS orEVENTS tables. |