Added in API level 35

IsolatedService


abstract class IsolatedService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.adservices.ondevicepersonalization.IsolatedService

Base class for services that are started by ODP on a call to OnDevicePersonalizationManager#execute(ComponentName, PersistableBundle, java.util.concurrent.Executor, OutcomeReceiver) and run in an isolated process. The service can produce content to be displayed in a android.view.SurfaceView in a calling app and write persistent results to on-device storage, which can be consumed by Federated Analytics for cross-device statistical analysis or by Federated Learning for model training. Client apps use OnDevicePersonalizationManager to interact with an IsolatedService.

Summary

Inherited constants
Public constructors

Public methods
EventUrlProvider

Returns an EventUrlProvider for the current request.

FederatedComputeScheduler

Returns an FederatedComputeScheduler for the current request.

MutableKeyValueStore
getLocalData(requestToken: RequestToken)

Returns a Data Access Object for the LOCAL_DATA table.

LogReader
getLogReader(requestToken: RequestToken)

Returns a DAO for the REQUESTS and EVENTS tables that provides access to the rows that are readable by the IsolatedService.

ModelManager

Returns an ModelManager for the current request.

KeyValueStore
getRemoteData(requestToken: RequestToken)

Returns a Data Access Object for the REMOTE_DATA table.

UserData?
getUserData(requestToken: RequestToken)

Returns the platform-provided UserData for the current request.

open IBinder?
onBind(intent: Intent)

Handles binding to the IsolatedService.

open Unit

Creates a binder for an IsolatedService.

abstract IsolatedWorker
onRequest(requestToken: RequestToken)

Return an instance of an IsolatedWorker that handles client requests.

Inherited functions

Public constructors

IsolatedService

Added in API level 35
IsolatedService()

Public methods

getEventUrlProvider

Added in API level 35
fun getEventUrlProvider(requestToken: RequestToken): EventUrlProvider

Returns an EventUrlProvider for the current request. The EventUrlProvider provides URLs that can be embedded in HTML. When the HTML is rendered in an android.webkit.WebView, the platform intercepts requests to these URLs and invokes IsolatedWorker#onEvent(EventInput, Consumer).

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service. This value cannot be null.
Return
EventUrlProvider An EventUrlProvider that returns event tracking URLs. This value cannot be null.

getFederatedComputeScheduler

Added in API level 35
fun getFederatedComputeScheduler(requestToken: RequestToken): FederatedComputeScheduler

Returns an FederatedComputeScheduler for the current request. The FederatedComputeScheduler can be used to schedule and cancel federated computation jobs. The federated computation includes federated learning and federated analytic jobs.

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service. This value cannot be null.
Return
FederatedComputeScheduler An FederatedComputeScheduler that returns a federated computation job scheduler. This value cannot be null.

getLocalData

Added in API level 35
fun getLocalData(requestToken: RequestToken): MutableKeyValueStore

Returns a Data Access Object for the LOCAL_DATA table. The LOCAL_DATA table is a persistent key-value store that the service can use to store any data. The contents of this table are visible only to the service running in an isolated process and cannot be sent outside the device.

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service. This value cannot be null.
Return
MutableKeyValueStore A MutableKeyValueStore object that provides access to the LOCAL_DATA table. The methods in the returned MutableKeyValueStore are blocking operations and should be called from a worker thread and not the main thread or a binder thread. This value cannot be null.

getLogReader

Added in API level 35
fun getLogReader(requestToken: RequestToken): LogReader

Returns a DAO for the REQUESTS and EVENTS tables that provides access to the rows that are readable by the IsolatedService.

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service. This value cannot be null.
Return
LogReader A LogReader object that provides access to the REQUESTS and EVENTS table. The methods in the returned LogReader are blocking operations and should be called from a worker thread and not the main thread or a binder thread. This value cannot be null.

getModelManager

Added in API level 35
fun getModelManager(requestToken: RequestToken): ModelManager

Returns an ModelManager for the current request. The ModelManager can be used to do model inference. It only supports Tensorflow Lite model inference now.

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service. This value cannot be null.
Return
ModelManager An ModelManager that can be used for model inference. This value cannot be null.

getRemoteData

Added in API level 35
fun getRemoteData(requestToken: RequestToken): KeyValueStore

Returns a Data Access Object for the REMOTE_DATA table. The REMOTE_DATA table is a read-only key-value store that contains data that is periodically downloaded from an endpoint declared in the tag in the ODP manifest of the service, as shown in the following example.

<code>&lt;!-- Contents of res/xml/OdpSettings.xml --&gt;
  &lt;on-device-personalization&gt;
  &lt;!-- Name of the service subclass --&gt;
  &lt;service "com.example.odpsample.SampleService"&gt;
    &lt;!-- If this tag is present, ODP will periodically poll this URL and
     download content to populate REMOTE_DATA. Adopters that do not need to
     download content from their servers can skip this tag. --&gt;
    &lt;download-settings url="https://example.com/get" /&gt;
  &lt;/service&gt;
  &lt;/on-device-personalization&gt;
  </code>

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service. This value cannot be null.
Return
KeyValueStore A KeyValueStore object that provides access to the REMOTE_DATA table. The methods in the returned KeyValueStore are blocking operations and should be called from a worker thread and not the main thread or a binder thread. This value cannot be null.

getUserData

Added in API level 35
fun getUserData(requestToken: RequestToken): UserData?

Returns the platform-provided UserData for the current request.

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service. This value cannot be null.
Return
UserData? A UserData object. This value may be null.

onBind

Added in API level 35
open fun onBind(intent: Intent): IBinder?

Handles binding to the IsolatedService.

Parameters
intent Intent: The Intent that was used to bind to this service, as given to android.content.Context#bindService. Note that any extras that were included with the Intent at that point will not be seen here. This value cannot be null.
Return
IBinder? This value may be null.

onCreate

Added in API level 35
open fun onCreate(): Unit

Creates a binder for an IsolatedService.

onRequest

Added in API level 35
abstract fun onRequest(requestToken: RequestToken): IsolatedWorker

Return an instance of an IsolatedWorker that handles client requests.

Parameters
requestToken RequestToken: an opaque token that identifies the current request to the service that must be passed to service methods that depend on per-request state. This value cannot be null.
Return
IsolatedWorker This value cannot be null.