OnDevicePersonalizationManager
public
class
OnDevicePersonalizationManager
extends Object
java.lang.Object | |
↳ | android.adservices.ondevicepersonalization.OnDevicePersonalizationManager |
OnDevicePersonalizationManager 为应用提供相应 API,用于在隔离的进程中加载 IsolatedService
并与其进行交互。
应用可以请求 IsolatedService
以生成内容,使其在应用视图层次结构的 SurfaceView
中显示,还可以将永久性结果写入设备端存储空间,可供 Federated Analytics 用于跨设备统计分析,或 Federated Learning 用于模型训练。调用应用无法直接访问显示的内容和永久性输出。
总结
公共方法 | |
---|---|
void
|
execute(ComponentName handler, PersistableBundle params, Executor executor, OutcomeReceiver<List<SurfacePackageToken>, Exception> receiver)
在 OnDevicePersonalization 沙盒中执行 |
void
|
requestSurfacePackage(SurfacePackageToken surfacePackageToken, IBinder surfaceViewHostToken, int displayId, int width, int height, Executor executor, OutcomeReceiver<SurfaceControlViewHost.SurfacePackage, Exception> receiver)
请求将 |
继承的方法 | |
---|---|
公共方法
执行
public void execute (ComponentName handler, PersistableBundle params, Executor executor, OutcomeReceiver<List<SurfacePackageToken>, Exception> receiver)
在 OnDevicePersonalization 沙盒中执行 IsolatedService
。平台会在隔离的进程中绑定到指定的 IsolatedService
,并使用调用方提供的参数调用 IsolatedWorker#onExecute(ExecuteInput, java.util.function.Consumer)
。当 IsolatedService
执行完毕后,平台会将引用服务结果的令牌返回给调用方。这些令牌随后可用于在调用应用的 SurfaceView
中显示结果。
参数 | |
---|---|
handler |
ComponentName :IsolatedService 的 ComponentName 。此值不能为 null 。 |
params |
PersistableBundle :从发起调用的应用传递到 IsolatedService 的 PersistableBundle 。此参数的预期内容由 IsolatedService 定义。平台不会解读此参数。
此值不能为 null 。 |
executor |
Executor :要在其上调用回调的 Executor 。此值不能为 null 。
通过此 Executor 分派回调和监听器事件,从而让您能够轻松控制要使用的线程。如需通过应用的主线程分派事件,可以使用 Context.getMainExecutor() 。
否则,请提供可分派给适当线程的 Executor 。 |
receiver |
OutcomeReceiver :这将返回一个 SurfacePackageToken 对象列表,其中每个对象都是对 IsolatedService 返回的 RenderingConfig 的不透明引用,或者在失败时返回 Exception 。返回的 SurfacePackageToken 对象可以在后续 requestSurfacePackage(android.adservices.ondevicepersonalization.SurfacePackageToken, android.os.IBinder, int, int, int, java.util.concurrent.Executor, android.os.OutcomeReceiver) 调用中使用,以便在视图中显示结果。发起调用的应用和 IsolatedService 必须就此列表的预期大小达成一致。
返回的 SurfacePackageToken 对象列表中的条目可能为 null,以表明该服务对该特定 surface 没有输出。
如果发生错误,接收器会返回以下异常之一:如果处理程序软件包未安装或没有有效的 ODP 清单,则返回 PackageManager.NameNotFoundException 。如果找不到处理程序类,则返回 ClassNotFoundException 。如果处理程序执行失败,则返回 OnDevicePersonalizationException 。 |
requestSurfacePackage
public void requestSurfacePackage (SurfacePackageToken surfacePackageToken, IBinder surfaceViewHostToken, int displayId, int width, int height, Executor executor, OutcomeReceiver<SurfaceControlViewHost.SurfacePackage, Exception> receiver)
请求将 SurfaceControlViewHost.SurfacePackage
插入调用方应用内的 SurfaceView
中。Surface 软件包将包含一个 View
,其中包含先前在 OnDevicePersonalization 沙盒中运行的 #execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver)
调用后获得的内容。
参数 | |
---|---|
surfacePackageToken |
SurfacePackageToken :对先前调用 #execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver) 的 SurfacePackageToken 的引用。
此值不能为 null 。 |
surfaceViewHostToken |
IBinder :SurfaceView 的主机令牌,在将 SurfaceView 添加到视图层次结构后,由 SurfaceView.getHostToken() 返回。此值不能为 null 。 |
displayId |
int :要显示 SurfaceControlViewHost.SurfacePackage 的逻辑屏幕的整数 ID,由 Context.getDisplay().getDisplayId() 返回。 |
width |
int :SurfaceControlViewHost.SurfacePackage 的宽度(以像素为单位)。 |
height |
int :SurfaceControlViewHost.SurfacePackage 的高度(以像素为单位)。 |
executor |
Executor :要在其上调用回调的 Executor 。此值不能为 null 。
通过此 Executor 分派回调和监听器事件,从而让您能够轻松控制要使用的线程。如需通过应用的主线程分派事件,可以使用 Context.getMainExecutor() 。
否则,请提供可分派给适当线程的 Executor 。 |
receiver |
OutcomeReceiver :此方法会在成功时返回 SurfaceControlViewHost.SurfacePackage ,或在失败时返回 Exception 。如果处理程序执行失败,则异常类型为 OnDevicePersonalizationException 。
此值不能为 null 。 |