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)
处理由对平台提供的跟踪网址 |
default
void
|
onExecute(ExecuteInput input, Consumer<ExecuteOutput> consumer)
处理来自应用的请求。 |
default
void
|
onRender(RenderInput input, Consumer<RenderOutput> consumer)
为因 |
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 表进行更新。如果此方法抛出 |
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 表。
如果此方法抛出 |
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 汇总错误报告。
如果此方法抛出 |
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 。如果此方法抛出 |
onTrainingExample
public void onTrainingExample (TrainingExampleInput input, Consumer<TrainingExampleOutput> consumer)
生成用于联合计算作业的单个训练示例。
参数 | |
---|---|
input |
TrainingExampleInput :生成训练样本所需的参数。此值不能为 null 。 |
consumer |
Consumer :完成时调用的回调。
此值不能为 null 。 |