PrivacySandboxInterface


@Retention(value = AnnotationRetention.RUNTIME)
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation PrivacySandboxInterface


Annotated interfaces used by the app to communicate with the SDK in the Privacy Sandbox.

Functions in a PrivacySandboxInterface annotated interface must obey the following rules:

Suspend functions operate as follows:

  • The main thread is used by default

  • App cancellations are propagated to SDK coroutines

  • Cancellation exceptions thrown by SDKs are packaged and rethrown as valid CancellationExceptions

Additionally, all exceptions thrown by SDK suspend function implementations are wrapped and rethrown to app developers as PrivacySandboxException with a full stack trace. Errors in non-suspend functions will not be rethrown.

PrivacySandboxInterface annotated interfaces may not extend any interface except for androidx.privacysandbox.ui.core.SandboxedUiAdapter, which can be used to provide SDK content in an app's UI. These interfaces may also have any other functions that are normally allowed.

Usage example:

@PrivacySandboxInterface
interface
MyInterface {
suspend fun doSomething(request: Request): Response
suspend fun getMyInterface(input: MyInterface): MyInterface
suspend fun getNullableInterface(input: MySecondInterface): MySecondInterface?
fun setListener(listener: MyCallback)
fun appendValue(x: Int)
}

Summary

Public constructors

Public constructors

PrivacySandboxInterface

PrivacySandboxInterface()