IsolatedWorker

public interface IsolatedWorker

android.adservices.ondevicepersonalization.IsolatedWorker


该接口包含为处理从操作系统向 IsolatedService 发出的请求而需要实现的方法。IsolatedService会在IsolatedWorker 并根据请求的类型调用以下方法之一。IsolatedService 在 Binder 线程上调用该方法,并且 IsolatedWorker 应 将长时间运行的操作分流到工作器线程。每个方法的使用方参数 返回结果。

摘要

公共方法

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

处理已完成的下载。

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

处理由向平台提供的跟踪网址 EventUrlProvider(嵌入到由 onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer)

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

处理来自应用的请求。

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

为作为结果返回的结果生成 HTML onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer)

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

生成用于联合计算作业的单个训练示例。

公共方法

onDownloadCompleted(下载完成)

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

处理已完成的下载。平台使用 IsolatedService 的软件包清单,会在下载后调用此函数 已完成,并将 REMOTE_DATA 表从 将 IsolatedService#getRemoteData(RequestToken) 替换为此方法的结果。

参数
input DownloadCompletedInput:下载处理程序参数。 此值不能为 null

consumer Consumer:接收结果的回调。可通过开启 null 进行调用 出错。如果使用 null 调用,则不会对 REMOTE_DATA 表进行任何更新。

如果此方法抛出 RuntimeException,则不会对 REMOTE_DATA 表。

onEvent

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

处理由向平台提供的跟踪网址 EventUrlProvider(嵌入到由 onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer)。平台将 EVENTS 表更新为 EventOutput#getEventLogRecord()

参数
input EventInput:计算事件数据所需的参数。 此值不能为 null

consumer Consumer:接收结果的回调。可通过开启 null 进行调用 出错。如果使用 null 进行调用,则不会向 EVENTS 表写入任何数据。

如果此方法抛出 RuntimeException,则不会向 EVENTS 写入任何数据 表格。

onExecute

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

处理来自应用的请求。当应用调用的 OnDevicePersonalizationManager#execute(ComponentName, PersistableBundle, java.util.concurrent.Executor, OutcomeReceiver) 引用指定的 IsolatedService

参数
input ExecuteInput:从调用应用请求参数。 此值不能为 null

consumer Consumer:接收结果 ExecuteOutput 的回调。应调用 null。错误会作为 OnDevicePersonalizationException,错误代码为 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED。为避免泄露私密内容 数据传递给发起调用的应用,无法获得更详细的错误报告。如果 IsolatedService 需要向其后端报告错误统计信息,则应使用错误数据填充 ExecuteOutput 以进行日志记录,并依赖 Federated Analytics 进行汇总 查看错误报告。

如果此方法抛出 RuntimeException,也会将该事件报告给 以 OnDevicePersonalizationException 的形式调用应用,错误代码为 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED

onRender

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

为作为结果返回的结果生成 HTML onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer)。在客户端应用调用 OnDevicePersonalizationManager#requestSurfacePackage(SurfacePackageToken, IBinder, int, int, int, java.util.concurrent.Executor, OutcomeReceiver)。 平台将在围栏内的 WebView 中呈现此 HTML 帧。

参数
input RenderInput:渲染请求的参数。 此值不能为 null

consumer Consumer:接收结果的回调。应在 null 处于启用状态时调用 出错。错误会作为 OnDevicePersonalizationException 传播到发起调用的应用,错误代码为 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED

如果此方法抛出 RuntimeException,也会报告给调用 以 OnDevicePersonalizationException 的形式返回,错误代码为 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED

onTrainingExample

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

生成用于联合计算作业的单个训练示例。

参数
input TrainingExampleInput:生成训练示例所需的参数。 此值不能为 null

consumer Consumer:完成时要调用的回调。 此值不能为 null