ContextUnderstanderService


abstract class ContextUnderstanderService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.service.personalcontext.understander.ContextUnderstanderService

This is the base class for understander services to implement, handling service details.

An understander takes hints provided to the Personal Context system and interprets them. This usually means taking one or more hints, running them through models, and generating zero or more ContextInsights based on the hints.

The Personal Context service will manage the lifetime of this service, and this service may be stopped if not utilized for some time. Services should start as rapidly as possible to minimize latency in the Personal Context workflow.

You must declare the service in the AndroidManifest of the app hosting the service with the android.Manifest.permission#BIND_CONTEXT_COMPONENT_SERVICE permission, and include an intent filter with the necessary action indicating that it is a ContextUnderstanderService (SERVICE_INTERFACE). The application must have the android.Manifest.permission#PERSONAL_CONTEXT_RECEIVE_HINTS and android.Manifest.permission#PERSONAL_CONTEXT_PUBLISH_INSIGHTS permissions.

For example:

<uses-permission
          android:name="android.permission.PERSONAL_CONTEXT_RECEIVE_HINTS"/>
      <uses-permission
          android:name="android.permission.PERSONAL_CONTEXT_PUBLISH_INSIGHTS"/>
 
      <service android:name=".ExampleContextUnderstanderService"
              android:exported="true"
              android:permission="android.permission.BIND_CONTEXT_COMPONENT_SERVICE">
          <intent-filter>
              <action android:name=
  "android.service.personalcontext.understander.ContextUnderstanderService" />
          </intent-filter>
      </service>
  

Agent understanders can also provide interactive embedded visualizations to display in client apps that request them. An understander is an agent understander if it was registered with android.service.personalcontext.PersonalContextManager.UnderstanderType#UNDERSTANDER_TYPE_AGENT.

Requests for visualization are surfaced in the onUnderstand(UnderstandRequest) call as an PersonalContextManager.DESTINATION_EMBEDDED in the request. The understander can establish the session by providing a InsightVisualizerSession in the UnderstandResult. All calls on the provided session will be executed on the Executor configured via setExecutor, or on the main looper by default.

Summary

Constants
static String

The Intent action that must be declared as handled by the service.

Inherited constants
Public constructors

Public methods
IBinder?
onBind(intent: Intent?)

Return the communication channel to the service.

open Unit

Called when the understander has been configured and is ready to receive insights.

open Unit
onHandleEvent(packageName: String, event: InsightEvent)

Override this method to receive logging events for actions taken on the insight.

open UnderstandResult

Called when a new hint is available.

Unit
setExecutor(executor: Executor)

Sets the executor to be used when methods are invoked on this service.

Inherited functions

Constants

SERVICE_INTERFACE

static val SERVICE_INTERFACE: String

The Intent action that must be declared as handled by the service.

Value: "android.service.personalcontext.understander.ContextUnderstanderService"

Public constructors

ContextUnderstanderService

ContextUnderstanderService()

Public methods

onBind

fun onBind(intent: Intent?): IBinder?

Return the communication channel to the service. May return null if clients can not bind to the service. The returned android.os.IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent?: This value may be null.
Return
IBinder? This value may be null.

onConnected

open fun onConnected(): Unit

Called when the understander has been configured and is ready to receive insights. Any actions related to this method should complete before returning.

onHandleEvent

open fun onHandleEvent(
    packageName: String,
    event: InsightEvent
): Unit

Override this method to receive logging events for actions taken on the insight.

Invoked when an event has been reported on a ContextInsight originally published by this ContextUnderstanderService.

Parameters
packageName String: the package of the application reporting the event.
This value cannot be null.
event InsightEvent: The reported InsightEvent.
This value cannot be null.

onUnderstand

open fun onUnderstand(request: UnderstandRequest): UnderstandResult

Called when a new hint is available.

As each hint is provided to the Personal Context system it will be forwarded on to understanding components. The understander can take these hints, cache them between calls, and use one or more hints together to generate ContextInsights.

Parameters
request UnderstandRequest: The UnderstandRequest details.
This value cannot be null.
Return
UnderstandResult an UnderstandResult that this ContextUnderstanderService generated by processing the incoming hints.
This value cannot be null.

setExecutor

fun setExecutor(executor: Executor): Unit

Sets the executor to be used when methods are invoked on this service. By default, an Executor running on the main looper is used. This method should be called within onCreate().

Parameters
executor Executor: The Executor to run calls on.