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)

處理由平台提供的追蹤網址 EventUrlProvider 提出要求而觸發的事件,該網址內嵌在 onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer) 傳回的 HTML 輸出內容中。

default void onExecute(ExecuteInput input, Consumer<ExecuteOutput> consumer)

處理應用程式的要求。

default void onRender(RenderInput input, Consumer<RenderOutput> consumer)

onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer) 而傳回的結果產生 HTML。

default void onTrainingExample(TrainingExampleInput input, Consumer<TrainingExampleOutput> consumer)

產生用於聯合運算工作的單一訓練範例。

公用方法

onDownloadCompleted

public void onDownloadCompleted (DownloadCompletedInput input, 
                Consumer<DownloadCompletedOutput> consumer)

處理完成的下載作業。平台會使用 IsolatedService 套件資訊清單中定義的參數下載內容,並在下載完成後呼叫此函式,並使用此方法的結果更新 IsolatedService#getRemoteData(RequestToken) 中的 REMOTE_DATA 資料表。

參數
input DownloadCompletedInput:下載處理常式參數。此值不能為 null

consumer Consumer:接收結果的回呼。發生錯誤時應使用 null 呼叫。如果使用 null 呼叫,系統不會更新 REMOTE_DATA 資料表。

如果這個方法擲回 RuntimeException,系統不會對 REMOTE_DATA 資料表進行更新。

onEvent

public void onEvent (EventInput input, 
                Consumer<EventOutput> consumer)

處理由平台提供的追蹤網址 EventUrlProvider 提出要求而觸發的事件,該網址內嵌在 onRender(android.adservices.ondevicepersonalization.RenderInput, java.util.function.Consumer) 傳回的 HTML 輸出內容中。平台使用 EventOutput#getEventLogRecord() 更新「EVENTS」資料表。

參數
input EventInput:計算事件資料所需的參數。此值不能為 null

consumer Consumer:接收結果的回呼。發生錯誤時應使用 null 呼叫。如果使用 null 呼叫,系統不會將資料寫入「EVENTS」資料表。

如果這個方法擲回 RuntimeException,系統不會將資料寫入 EVENTS 資料表。

onRun

public void onExecute (ExecuteInput input, 
                Consumer<ExecuteOutput> consumer)

處理應用程式的要求。當應用程式呼叫參照已命名 IsolatedServiceOnDevicePersonalizationManager#execute(ComponentName, PersistableBundle, java.util.concurrent.Executor, OutcomeReceiver) 時,就會呼叫這個方法。

參數
input ExecuteInput:呼叫應用程式發出的要求參數。此值不能為 null

consumer Consumer:接收結果 ExecuteOutput 的回呼。發生錯誤時應使用 null 呼叫。錯誤將以 OnDevicePersonalizationException (錯誤代碼 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED) 的形式套用至呼叫應用程式。為避免將私人資料外洩至呼叫應用程式,我們不提供更詳細的錯誤報告。如果 IsolatedService 需要向後端回報錯誤統計資料,則應在 ExecuteOutput 中填入錯誤資料以進行記錄,並透過 Federated Analytics 來匯總錯誤報告。

如果這個方法擲回 RuntimeException,系統也會回報呼叫應用程式為含有錯誤代碼 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILEDOnDevicePersonalizationException

onRender

public void onRender (RenderInput input, 
                Consumer<RenderOutput> consumer)

onExecute(android.adservices.ondevicepersonalization.ExecuteInput, java.util.function.Consumer) 而傳回的結果產生 HTML。當用戶端應用程式呼叫 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) 的形式套用至呼叫應用程式。

如果這個方法擲回 RuntimeException,系統也會回報呼叫應用程式為含有錯誤代碼 OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILEDOnDevicePersonalizationException

onTrainingExample

public void onTrainingExample (TrainingExampleInput input, 
                Consumer<TrainingExampleOutput> consumer)

產生用於聯合運算工作的單一訓練範例。

參數
input TrainingExampleInput:產生訓練範例所需的參數。此值不能為 null

consumer Consumer:完成後要叫用的回呼。此值不能為 null