IsolatedWorker
public
interface
IsolatedWorker
android.adservices.ondevicepersonalization.IsolatedWorker |
如要處理 OS 對 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)
產生用於聯合運算工作的單一訓練範例。 |
公用方法
onDownload 完成
public void onDownloadCompleted (DownloadCompletedInput input, Consumer<DownloadCompletedOutput> consumer)
處理完成的下載作業。平台會使用
IsolatedService
的套件資訊清單,會在下載後呼叫此函式
,並更新 REMOTE_DATA 資料表,
將 IsolatedService#getRemoteData(RequestToken)
替換為這個方法的結果。
參數 | |
---|---|
input |
DownloadCompletedInput :下載處理常式參數。
此值不能為 null 。 |
consumer |
Consumer :接收結果的回呼。應在以下項目中使用 null 呼叫
發生錯誤。如果用 null 呼叫,REMOTE_DATA 資料表就不會有任何更新。
如果這個方法擲回 |
onEvent
public void onEvent (EventInput input, Consumer<EventOutput> consumer)
處理由平台提供的追蹤網址 EventUrlProvider
要求觸發的事件,且該事件嵌入在以下程式碼的 HTML 輸出內容中
onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer)
。平台會使用
EventOutput#getEventLogRecord()
。
參數 | |
---|---|
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 填入錯誤資料以供記錄,並依賴聯合分析來匯總
錯誤報告
如果這個方法擲回 |
onRender
public void onRender (RenderInput input, Consumer<RenderOutput> consumer)
為 使用
onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer)
。用戶端應用程式呼叫時呼叫
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 。 |