OnDevicePersonalizationManager

public class OnDevicePersonalizationManager
extends Object

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


OnDevicePersonalizationManager 为应用提供用于在独立进程中加载 IsolatedService 并与其进行交互的 API。 应用可以请求 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

继承的方法

Object clone()

创建并返回此对象的副本。

boolean equals(Object obj)

指示某个其他对象是否“等于”此对象。

void finalize()

当垃圾回收功能确定对某个对象没有更多引用时,由垃圾回收器针对该对象调用该方法。

final Class<?> getClass()

返回此 Object 的运行时类。

int hashCode()

返回对象的哈希代码值。

final void notify()

唤醒正在等待此对象的监控器的单个线程。

final void notifyAll()

唤醒等待此对象监视器的所有线程。

String toString()

返回对象的字符串表示。

final void wait(long timeoutMillis, int nanos)

使当前线程处于等待状态,直到其被唤醒(通常在收到通知或被中断时),或者实际经过了一定的时间。

final void wait(long timeoutMillis)

使当前线程处于等待状态,直到其被唤醒(通常在收到通知或被中断时),或者实际经过了一定的时间。

final void wait()

导致当前线程处于等待状态,直到其被唤醒(通常在收到通知或被中断时)

公共方法

执行

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 PersistableBundle:从发起调用的应用传递给 IsolatedServicePersistableBundle。此参数的预期内容由 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.SurfacePackageException> receiver)

请求将 SurfaceControlViewHost.SurfacePackage 插入调用应用内的 SurfaceView。Surface 软件包将包含一个 View,其中包含之前对 OnDevicePersonalization 沙盒中运行的 #execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver) 的调用结果的内容。

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

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

displayId int:要在其上显示 SurfaceControlViewHost.SurfacePackage 的逻辑屏幕的整数 ID,由 Context.getDisplay().getDisplayId() 返回。

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

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

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

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