OnDevicePersonalizationManager

public class OnDevicePersonalizationManager
extends Object

java.lang.Object
   ↳ android.adservices.ondevicepersonalization.OnDevicePersonalizationManager


OnDevicePersonalizationManager 为应用提供了用于加载 IsolatedService(在隔离进程中)并与之交互。 应用可以请求 IsolatedService 以生成要显示的内容 在应用视图层次结构中的 SurfaceView 内,并且还会写入 将永久性结果发送到设备端存储,可供 Federated Analytics 用于 跨设备统计分析或通过联合学习进行模型训练。显示的 调用方应用无法直接访问内容和持久输出。

摘要

公共方法

void execute(ComponentName handler, PersistableBundle params, Executor executor, OutcomeReceiver<List<SurfacePackageToken>, Exception> receiver)

在 OnDevicePersonalization 沙盒中执行 IsolatedService

void requestSurfacePackage(SurfacePackageToken surfacePackageToken, IBinder surfaceViewHostToken, int displayId, int width, int height, Executor executor, OutcomeReceiver<SurfaceControlViewHost.SurfacePackageException> receiver)

请求将 SurfaceControlViewHost.SurfacePackage 插入 SurfaceView

继承的方法

公共方法

执行

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 ComponentNameIsolatedServiceComponentName。 此值不能为 null

params PersistableBundlePersistableBundle 从调用应用程序传递到 IsolatedService。此参数的预期内容已定义 由IsolatedService提供。平台不会解读此参数。 此值不能为 null

executor Executor:要在其上调用回调的 Executor。 此值不能为 null。 通过此 Executor 分派回调和监听器事件,从而让您能够轻松控制要使用的线程。如需通过应用的主线程分派事件,可以使用 Context.getMainExecutor()。 否则,请提供分派给相应线程的 Executor

receiver OutcomeReceiver:会返回 SurfacePackageToken 对象的列表,其中每个对象都是 对 RenderingConfig 返回的不透明引用, IsolatedService,或者在失败时返回 Exception。返回的 SurfacePackageToken 对象可用于后续 requestSurfacePackage(android.adservices.ondevicepersonalization.SurfacePackageToken, android.os.IBinder, int, int, int, java.util.concurrent.Executor, android.os.OutcomeReceiver) 调用以在视图中显示结果。发起调用的应用 IsolatedService必须就此列表的预期大小达成一致。 返回的 SurfacePackageToken 对象列表中的条目可能为 null, 表明该服务没有针对该特定 Surface 的输出。 如果发生错误,接收器会返回以下某个异常: 如果处理程序包含一个 PackageManager.NameNotFoundException, 软件包未安装或没有有效的 ODP 清单。 如果未找到处理程序类,则返回 ClassNotFoundException。 如果处理程序执行失败,则返回 OnDevicePersonalizationException

requestSurfacePackage

public void requestSurfacePackage (SurfacePackageToken surfacePackageToken, 
                IBinder surfaceViewHostToken, 
                int displayId, 
                int width, 
                int height, 
                Executor executor, 
                OutcomeReceiver<SurfaceControlViewHost.SurfacePackageException> receiver)

请求将 SurfaceControlViewHost.SurfacePackage 插入 SurfaceView。Surface 包将包含 将 View 替换为之前对 #execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver)跑步倒计时 OnDevicePersonalization 沙盒。

参数
surfacePackageToken SurfacePackageToken:对之前返回的 SurfacePackageToken 的引用 对 #execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver) 的调用。 此值不能为 null

surfaceViewHostToken IBinderSurfaceView 的 hostToken,为 SurfaceView.getHostToken() 返回了 SurfaceView 已添加到视图层次结构中。 此值不能为 null

displayId int:要在其上显示 SurfaceControlViewHost.SurfacePackage,由 Context.getDisplay().getDisplayId()

width intSurfaceControlViewHost.SurfacePackage 的宽度 (以像素为单位)。

height intSurfaceControlViewHost.SurfacePackage 的高度 (以像素为单位)。

executor Executor:要在其上调用回调的 Executor。此值不能为 null。 通过此 Executor 分派回调和监听器事件,从而让您能够轻松控制要使用的线程。如需通过应用的主线程分派事件,可以使用 Context.getMainExecutor()。 否则,请提供分派给相应线程的 Executor

receiver OutcomeReceiver:此方法会返回 成功时 SurfaceControlViewHost.SurfacePackage,或 失败时为 Exception。异常类型为 如果处理程序执行失败,则为 OnDevicePersonalizationException。 此值不能为 null