IsolatedWorker

public interface IsolatedWorker

android.adservices.ondevicepersonalization.IsolatedWorker


需要实现这些方法来处理操作系统向 IsolatedService 发出的请求的接口。IsolatedService 在每个请求时都会创建一个 IsolatedWorker 实例,并根据请求类型调用以下其中一个方法。IsolatedService 在 Binder 线程上调用该方法,IsolatedWorker 应将耗时操作分载到工作线程。每个方法的 consumer 参数用于返回结果。

摘要

公共方法

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) 返回的 HTML 输出中。

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

处理来自应用的请求。

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

生成作为对 onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer) 调用结果返回的结果所对应的 HTML。

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

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

公共方法

onDownloadCompleted

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

处理已完成的下载。平台会使用 IsolatedService 软件包清单中定义的参数下载内容,在下载完成后调用此函数,并使用此方法的结果更新 IsolatedService#getRemoteData(RequestToken) 中的 REMOTE_DATA 表。

参数
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) 返回的 HTML 输出中。平台会使用 EventOutput#getEventLogRecord() 更新 EVENTS 表。

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

consumer Consumer:接收结果的回调。出现错误时应使用 null 调用。如果使用 null 调用,则不会向 EVENTS 表写入数据。

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

onExecute

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

处理来自应用的请求。当应用调用指向具名 IsolatedServiceOnDevicePersonalizationManager#execute(ComponentName, PersistableBundle, java.util.concurrent.Executor, OutcomeReceiver) 时,将调用此方法。

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

consumer Consumer:接收结果 ExecuteOutput 的回调。出现错误时应使用 null 调用。该错误会以 OnDevicePersonalizationException 的形式以及错误代码 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED 传播到调用应用。为避免将私有数据泄露给调用应用,无法提供更详细的错误报告。如果 IsolatedService 需要向其后端报告错误统计信息,则应使用错误数据填充 ExecuteOutput 以进行日志记录,并依靠联合分析来汇总错误报告。

如果此方法抛出 RuntimeException,也会以 OnDevicePersonalizationException 的形式以及错误代码 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED 向调用应用报告该异常。

onRender

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

生成作为对 onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer) 调用结果返回的结果所对应的 HTML。当客户端应用调用 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