AppFunctionCompatService


@RequiresApi(value = 36)
abstract class AppFunctionCompatService : AppFunctionService


Abstract base class to provide app functions to the system.

This class wraps AppFunctionService functionalities and provides an API that uses androidx.appfunctions classes.

Include the following in the manifest:

<service android:name=".YourService"
android:permission="android.permission.BIND_APP_FUNCTION_SERVICE">
<intent-filter>
<action android:name="android.app.appfunctions.AppFunctionService" />
</intent-filter>
</service>

Summary

Public constructors

Public functions

abstract suspend ExecuteAppFunctionResponse

Called by the system to execute a specific app function.

open Unit

Implementing class can override this method to perform cleanup but should always call the superclass implementation.

final Unit
onExecuteFunction(
    request: ExecuteAppFunctionRequest,
    callingPackage: String,
    signingInfo: SigningInfo,
    cancellationSignal: CancellationSignal,
    callback: OutcomeReceiver<ExecuteAppFunctionResponseAppFunctionException>
)

Implements AppFunctionService.onExecuteFunction and delegates the execution to executeFunction when called by the system.

Inherited functions

From android.app.appfunctions.AppFunctionService
final IBinder
onBind(p0: Intent?)
From android.content.Context
From android.content.ContextWrapper
open Boolean
bindIsolatedService(
    p0: Intent,
    p1: Int,
    p2: String,
    p3: Executor,
    p4: ServiceConnection
)
open Boolean
bindService(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags
)
open Boolean
open Boolean
bindService(
    p0: Intent,
    p1: Context.BindServiceFlags,
    p2: Executor,
    p3: ServiceConnection
)
open Boolean
bindService(p0: Intent, p1: Int, p2: Executor, p3: ServiceConnection)
open Boolean
bindServiceAsUser(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags,
    p3: UserHandle
)
open Boolean
open Int
open Int
open IntArray
open Int
open Int
open IntArray
open Int
checkContentUriPermissionFull(p0: Uri, p1: Int, p2: Int, p3: Int)
open Int
checkPermission(p0: String, p1: Int, p2: Int)
open Int
open Int
checkUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int)
open Int
checkUriPermission(p0: Uri?, p1: String?, p2: String?, p3: Int, p4: Int, p5: Int)
open IntArray
checkUriPermissions(p0: MutableList<Uri>, p1: Int, p2: Int, p3: Int)
open Unit

This function is deprecated. Deprecated in Java

open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
createWindowContext(p0: Display, p1: Int, p2: Bundle?)
open Array<String>
open Boolean
open Boolean
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
enforcePermission(p0: String, p1: Int, p2: Int, p3: String?)
open Unit
enforceUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int, p4: String)
open Unit
enforceUriPermission(
    p0: Uri?,
    p1: String?,
    p2: String?,
    p3: Int,
    p4: Int,
    p5: Int,
    p6: String?
)
open Array<String>
open Context
open ApplicationInfo
open AssetManager
open AttributionSource
open String?
open Context
open File
open ClassLoader
open File
open ContentResolver
open File
open File
open Int
open File
getDir(p0: String, p1: Int)
open Display?
open File?
open Array<File>
open File?
open Array<File>
open Array<File>
open File
open File
open Executor
open Looper
open File
open File
open Array<File>
open String
open String
open PackageManager
open String
open String
open ContextParams?
open Resources
open SharedPreferences
open Any
open String?
open Resources.Theme
open Drawable

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Unit
grantUriPermission(p0: String, p1: Uri, p2: Int)
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open FileInputStream
open FileOutputStream
open SQLiteDatabase
open SQLiteDatabase
openOrCreateDatabase(
    p0: String,
    p1: Int,
    p2: SQLiteDatabase.CursorFactory,
    p3: DatabaseErrorHandler?
)
open Drawable

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Intent?
open Intent?
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?
)
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?,
    p4: Int
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
revokeUriPermission(p0: String, p1: Uri, p2: Int)
open Unit
open Unit
open Unit
sendBroadcast(p0: Intent, p1: String?, p2: Bundle?)
open Unit
open Unit
open Unit
open Unit
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: Bundle?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: Int,
    p2: String?,
    p3: String?,
    p4: BroadcastReceiver?,
    p5: Handler?,
    p6: String?,
    p7: Bundle?,
    p8: Bundle?
)
open Unit
sendOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcast(
    p0: Intent,
    p1: BroadcastReceiver?,
    p2: Handler?,
    p3: Int,
    p4: String?,
    p5: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit
open ComponentName?
open Boolean
open Unit
startIntentSender(p0: IntentSender, p1: Intent?, p2: Int, p3: Int, p4: Int)
open Unit
startIntentSender(
    p0: IntentSender,
    p1: Intent?,
    p2: Int,
    p3: Int,
    p4: Int,
    p5: Bundle?
)
open ComponentName?
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
From android.app.Service
open Unit
open Unit
Application
Int
open Unit
open Unit
open Unit

This function is deprecated.

open Unit
open Unit
onStart(p0: Intent, p1: Int)

This function is deprecated. Deprecated in Java

open Int
onStartCommand(p0: Intent, p1: Int, p2: Int)
open Unit
open Unit
open Unit
onTimeout(p0: Int, p1: Int)
open Unit
open Boolean
Unit
Unit
startForeground(p0: Int, p1: Notification, p2: Int)
Unit

This function is deprecated. Deprecated in Java

Unit
Unit
Unit
Boolean

Public constructors

AppFunctionCompatService

Added in 1.0.0-alpha05
AppFunctionCompatService()

Public functions

executeFunction

@MainThread
abstract suspend fun executeFunction(request: ExecuteAppFunctionRequest): ExecuteAppFunctionResponse

Called by the system to execute a specific app function.

This method is the entry point for handling all app function requests in an app. When the system needs your AppFunctionService to perform a function, it will invoke this method.

Each function you've registered is identified by a unique identifier. This identifier doesn't need to be globally unique, but it must be unique within your app. For example, a function to order food could be identified as "orderFood".

You can determine which function to execute by using ExecuteAppFunctionRequest.functionIdentifier. This allows your service to route the incoming request to the appropriate logic for handling the specific function.

This method is always triggered in the main thread. You should run heavy tasks on a worker thread.

Exception Handling

When an error occurs during execution, implementations have two options to report the failure:

  1. Throw an appropriate androidx.appfunctions.AppFunctionException.

  2. Return an ExecuteAppFunctionResponse.Error by wrapping an androidx.appfunctions.AppFunctionException.

This allows the agent to better understand the cause of the failure. For example, if an input argument is invalid, throw or wrap an androidx.appfunctions.AppFunctionInvalidArgumentException with a detailed message explaining why it is invalid.

Any unhandled exception other than androidx.appfunctions.AppFunctionException will be reported as androidx.appfunctions.AppFunctionAppUnknownException.

Cancellation

The agent app can cancel the execution of an app function at any time. When this happens, the coroutine executing this executeFunction will be cancelled. Implementations should handle the kotlinx.coroutines.CancellationException appropriately, for example, by ceasing any ongoing work and releasing resources.

Parameters
request: ExecuteAppFunctionRequest

The function execution request.

onDestroy

@CallSuper
open fun onDestroy(): Unit

Implementing class can override this method to perform cleanup but should always call the superclass implementation.

onExecuteFunction

Added in 1.0.0-alpha05
final fun onExecuteFunction(
    request: ExecuteAppFunctionRequest,
    callingPackage: String,
    signingInfo: SigningInfo,
    cancellationSignal: CancellationSignal,
    callback: OutcomeReceiver<ExecuteAppFunctionResponseAppFunctionException>
): Unit

Implements AppFunctionService.onExecuteFunction and delegates the execution to executeFunction when called by the system.

Parameters
request: ExecuteAppFunctionRequest

The function execution request.

callingPackage: String

The package name of the app that is requesting the execution. It is strongly recommended that you do not alter your function’s behavior based on this value. Your function should behave consistently for all callers to ensure a predictable experience.

signingInfo: SigningInfo

The signing information of the app that is requesting the execution. It is strongly recommended that you do not alter your function’s behavior based on this value. Your function should behave consistently for all callers to ensure a predictable experience.

cancellationSignal: CancellationSignal

A signal to cancel the execution.

callback: OutcomeReceiver<ExecuteAppFunctionResponseAppFunctionException>

A callback to report back the result or error.