IsolatedWorker

public interface IsolatedWorker

android.adservices.ondevicepersonalization.IsolatedWorker


Interface with methods that need to be implemented to handle requests from the OS to an IsolatedService. The IsolatedService creates an instance of IsolatedWorker on each request and calls one of the methods below, depending the type of the request. The IsolatedService calls the method on a Binder thread and the 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(DownloadCompletedInput input, Consumer<DownloadCompletedOutput> consumer)

Handles a completed download.

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

Handles an event triggered by a request to a platform-provided tracking URL EventUrlProvider that was embedded in the HTML output returned by onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer).

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

Handles a request from an app.

default 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).

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

Generate a single training example used for federated computation job.

Public methods

onDownloadCompleted

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, calls this function after the download is complete, and updates the REMOTE_DATA table from IsolatedService#getRemoteData(RequestToken) with the result of this method.

Parameters
input DownloadCompletedInput: Download handler parameters. This value cannot be null.

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, no updates are made to the REMOTE_DATA table.

onEvent

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

Handles an event triggered by a request to a platform-provided tracking URL EventUrlProvider that was embedded in the HTML output returned by onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer). The platform updates the EVENTS table with EventOutput#getEventLogRecord().

Parameters
input EventInput: The parameters needed to compute event data. This value cannot be null.

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, no data is written to the EVENTS table.

onExecute

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.

Parameters
input ExecuteInput: Request Parameters from the calling app. This value cannot be null.

consumer Consumer: Callback that receives the result ExecuteOutput. Should be called with null on an error. The error is propagated to the calling app as an OnDevicePersonalizationException with error code OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED. To avoid leaking private data to the calling app, more detailed error reporting is not available. If the IsolatedService needs to report error stats to its backend, it should populate ExecuteOutput with error data for logging, and rely on Federated Analytics to aggregate the error reports.

If this method throws a RuntimeException, that is also reported to calling apps as an OnDevicePersonalizationException with error code OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED.

onRender

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). Called when a client app calls OnDevicePersonalizationManager#requestSurfacePackage(SurfacePackageToken, IBinder, int, int, int, java.util.concurrent.Executor, OutcomeReceiver). The platform will render this HTML in an WebView inside a fenced frame.

Parameters
input RenderInput: Parameters for the render request. This value cannot be null.

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 with error code OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED.

If this method throws a RuntimeException, that is also reported to calling apps as an OnDevicePersonalizationException with error code OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED.

onTrainingExample

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

Generate a single training example used for federated computation job.

Parameters
input TrainingExampleInput: The parameters needed to generate the training example. This value cannot be null.

consumer Consumer: Callback to be invoked on completion. This value cannot be null.