OnDevicePersonalizationManager
public
class
OnDevicePersonalizationManager
extends Object
java.lang.Object | |
↳ | android.adservices.ondevicepersonalization.OnDevicePersonalizationManager |
OnDevicePersonalizationManager 提供 API,可讓應用程式在獨立程序中載入 IsolatedService
並與其互動。應用程式可以要求 IsolatedService
產生要在應用程式檢視區塊階層中的 SurfaceView
中顯示的內容,並將永久結果寫入裝置端儲存空間,以便用於跨裝置統計分析的 Federated Analytics 或聯合學習來使用模型訓練。呼叫應用程式無法直接存取顯示的內容與永久輸出。
摘要
公用方法 | |
---|---|
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 物件傳回清單中的項目可能為空值,以表示服務沒有該特定途徑的輸出內容。如果發生錯誤,接收器會傳回以下其中一個例外狀況:如未安裝處理常式套件或沒有有效的 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
。途徑套件會包含 View
,其中包含之前在 OnDevicePersonalization 沙箱中執行 #execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver)
呼叫的結果。
參數 | |
---|---|
surfacePackageToken |
SurfacePackageToken :先前呼叫 #execute(ComponentName, PersistableBundle, Executor, OutcomeReceiver) 時傳回的 SurfacePackageToken 參照。此值不能為 null 。 |
surfaceViewHostToken |
IBinder :SurfaceView 的 hostToken,在將 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 。 |