# AppFunctionAccessLevel

Artifact: [androidx.appfunctions:appfunctions](https://developer.android.com/jetpack/androidx/releases/appfunctions) [View Source](https://cs.android.com/search?q=file:androidx/appfunctions/AppFunctionAccessLevel.kt+class:androidx.appfunctions.AppFunctionAccessLevel) Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

*** ** * ** ***


```
@ExperimentalAppFunctionsApi
@Target(allowedTargets = [AnnotationTarget.FUNCTION, AnnotationTarget.CLASS])
@Retention(value = AnnotationRetention.BINARY)
public annotation AppFunctionAccessLevel
```

<br />

*** ** * ** ***

Defines the caller access level of an app function.

If an app function is not annotated with `https://developer.android.com/reference/androidx/appfunctions/AppFunctionAccessLevel`, it defaults to `https://developer.android.com/reference/androidx/appfunctions/metadata/AppFunctionMetadata#ACCESS_LEVEL_ANDROID_TRUSTED()`, meaning it is accessible to any caller holding the `android.permission.EXECUTE_APP_FUNCTIONS` permission.

The Android framework natively enforces access restrictions starting in Android 17.2 (`android.os.Build.SdkVersionFull.CINNAMON_BUN_2`). On earlier platform versions, setting `https://developer.android.com/reference/androidx/appfunctions/AppFunctionAccessLevel#(kotlin.Int,kotlin.Boolean)` to `true` enables Jetpack to enforce access restrictions instead of the platform.

Backwards compatibility enforcement on platform versions prior to Android 17.2 is a best-effort verification mechanism using caller tokens and incurs an IPC verification overhead for foreign callers. Additionally, access-level-based state filtering on pre-17.2 platforms is only applied when callers query via Jetpack's `AppFunctionManager.getAppFunctionStates`; direct queries using platform framework APIs on pre-17.2 platforms will see all indexed functions when the caller has the `android.permission.EXECUTE_APP_FUNCTIONS` permission.

When `https://developer.android.com/reference/androidx/appfunctions/AppFunctionAccessLevel#(kotlin.Int,kotlin.Boolean)` is set to `false`, access level checks are skipped on pre-17.2 platforms, allowing any caller certified for AppFunctions to execute the function, while devices running Android 17.2+ continue to enforce the declared `https://developer.android.com/reference/androidx/appfunctions/AppFunctionAccessLevel#(kotlin.Int,kotlin.Boolean)`. To prevent a function from being exposed or executable on platforms prior to Android 17.2 when backwards compatibility enforcement is disabled, the function should only be enabled or registered at runtime on devices running Android 17.2+ (e.g., using `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` or `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)`).

Example usage for service-based functions:

```
@AppFunctionDeclaration(isDescribedByKDoc = false)
@AppFunctionAccessLevel(
    level = AppFunctionMetadata.ACCESS_LEVEL_SELF,
    isCompatEnforcementEnabled = true,
)
fun executeTask(params: TaskParams): TaskResult { ... }
```

Example usage for dynamically registered functions:

```
@AppFunctionSignature(
    scope = AppFunctionMetadata.SCOPE_GLOBAL,
    appFunctionXmlFileName = "dynamic_signature_definitions",
    isDescribedByKDoc = false,
)
@AppFunctionAccessLevel(
    level = AppFunctionMetadata.ACCESS_LEVEL_SELF,
    isCompatEnforcementEnabled = true,
)
fun interface DynamicTaskSignature {
    suspend fun executeTask(params: TaskParams): TaskResult
}
```

## Summary

| ### Public methods |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/appfunctions/AppFunctionAccessLevel#getLevel()()` minimum access level required to invoke the function. |
| `final boolean` | `https://developer.android.com/reference/androidx/appfunctions/AppFunctionAccessLevel#isCompatEnforcementEnabled()()` whether Jetpack should enforce access restrictions on platform versions prior to Android 17.2. |

## Public methods

### getLevel

```
public final int getLevel()
```

minimum access level required to invoke the function. Possible values are `https://developer.android.com/reference/androidx/appfunctions/metadata/AppFunctionMetadata#ACCESS_LEVEL_SELF()` (strictly restricted to callers with the same UID as the hosting application), `https://developer.android.com/reference/androidx/appfunctions/metadata/AppFunctionMetadata#ACCESS_LEVEL_SYSTEM()`, and `https://developer.android.com/reference/androidx/appfunctions/metadata/AppFunctionMetadata#ACCESS_LEVEL_ANDROID_TRUSTED()`.

### isCompatEnforcementEnabled

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
public final boolean isCompatEnforcementEnabled()
```

whether Jetpack should enforce access restrictions on platform versions prior to Android 17.2.