class SdkSandboxManagerCompat


Compat version of SdkSandboxManager.

Provides APIs to load androidx.privacysandbox.sdkruntime.core.SandboxedSdkProviderCompat into SDK sandbox process or locally, and then interact with them.

SdkSandbox process is a java process running in a separate uid range. Each app has its own SDK sandbox process.

First app needs to declare SDKs it depends on in its AndroidManifest.xml using tag. App can only load SDKs it depends on into the SDK sandbox process.

For loading SDKs locally App need to bundle and declare local SDKs in assets/RuntimeEnabledSdkTable.xml with following format:

com.sdk1 assets/RuntimeEnabledSdk-com.sdk1/CompatSdkConfig.xml com.sdk2 assets/RuntimeEnabledSdk-com.sdk2/CompatSdkConfig.xml

Each local SDK should have config with following format:

RuntimeEnabledSdk-sdk.package.name/dex/classes.dex RuntimeEnabledSdk-sdk.package.name/dex/classes2.dex RuntimeEnabledSdk-sdk.package.name/res com.sdk.EntryPointClass com.test.sdk.RPackage 123

Summary

Public companion functions

SdkSandboxManagerCompat
from(context: Context)

Creates SdkSandboxManagerCompat.

Public functions

Unit

Adds a callback which gets registered for SDK sandbox lifecycle events, such as SDK sandbox death.

List<AppOwnedSdkSandboxInterfaceCompat>

Fetches all AppOwnedSdkSandboxInterfaceCompat that are registered by the app.

List<SandboxedSdkCompat>

Fetches information about Sdks that are loaded in the sandbox or locally.

suspend SandboxedSdkCompat
loadSdk(sdkName: String, params: Bundle)

Load SDK in a SDK sandbox java process or locally.

Unit

Registers AppOwnedSdkSandboxInterfaceCompat for an app process.

Unit

Removes an SdkSandboxProcessDeathCallbackCompat that was previously added using SdkSandboxManagerCompat.addSdkSandboxProcessDeathCallback

Unit
startSdkSandboxActivity(
    fromActivity: Activity,
    sdkActivityToken: IBinder
)

Starts an Activity in the SDK sandbox.

Unit
unloadSdk(sdkName: String)

Unloads an SDK that has been previously loaded by the caller.

Unit

Unregisters AppOwnedSdkSandboxInterfaceCompat for an app process.

Public companion functions

from

Added in 1.0.0-alpha15
fun from(context: Context): SdkSandboxManagerCompat

Creates SdkSandboxManagerCompat.

Parameters
context: Context

Application context

Returns
SdkSandboxManagerCompat

SdkSandboxManagerCompat object.

Public functions

addSdkSandboxProcessDeathCallback

Added in 1.0.0-alpha15
fun addSdkSandboxProcessDeathCallback(
    callbackExecutor: Executor,
    callback: SdkSandboxProcessDeathCallbackCompat
): Unit

Adds a callback which gets registered for SDK sandbox lifecycle events, such as SDK sandbox death. If the sandbox has not yet been created when this is called, the request will be stored until a sandbox is created, at which point it is activated for that sandbox. Multiple callbacks can be added to detect death.

Parameters
callbackExecutor: Executor

the Executor on which to invoke the callback

callback: SdkSandboxProcessDeathCallbackCompat

the SdkSandboxProcessDeathCallbackCompat which will receive SDK sandbox lifecycle events.

getAppOwnedSdkSandboxInterfaces

Added in 1.0.0-alpha15
fun getAppOwnedSdkSandboxInterfaces(): List<AppOwnedSdkSandboxInterfaceCompat>

Fetches all AppOwnedSdkSandboxInterfaceCompat that are registered by the app.

getSandboxedSdks

Added in 1.0.0-alpha15
fun getSandboxedSdks(): List<SandboxedSdkCompat>

Fetches information about Sdks that are loaded in the sandbox or locally.

Returns
List<SandboxedSdkCompat>

List of SandboxedSdkCompat containing all currently loaded sdks

See also
getSandboxedSdks

loadSdk

suspend fun loadSdk(sdkName: String, params: Bundle): SandboxedSdkCompat

Load SDK in a SDK sandbox java process or locally.

App should already declare SDKs it depends on in its AndroidManifest using tag. App can only load SDKs it depends on into the SDK Sandbox process.

When client application loads the first SDK, a new SdkSandbox process will be created, otherwise other SDKs will be loaded into the same sandbox which already created for the client application.

Alternatively App could bundle and declare local SDKs dependencies in assets/RuntimeEnabledSdkTable.xml to load SDKs locally.

This API may only be called while the caller is running in the foreground. Calls from the background will result in a LoadSdkCompatException being thrown.

Parameters
sdkName: String

name of the SDK to be loaded.

params: Bundle

additional parameters to be passed to the SDK in the form of a Bundle as agreed between the client and the SDK.

Returns
SandboxedSdkCompat

SandboxedSdkCompat from SDK on a successful run.

See also
loadSdk

registerAppOwnedSdkSandboxInterface

Added in 1.0.0-alpha15
fun registerAppOwnedSdkSandboxInterface(
    appOwnedSdk: AppOwnedSdkSandboxInterfaceCompat
): Unit

Registers AppOwnedSdkSandboxInterfaceCompat for an app process.

Registering an AppOwnedSdkSandboxInterfaceCompat that has same name as a previously registered interface will result in IllegalStateException.

AppOwnedSdkSandboxInterfaceCompat.name refers to the name of the interface.

Parameters
appOwnedSdk: AppOwnedSdkSandboxInterfaceCompat

the AppOwnedSdkSandboxInterfaceCompat to be registered

startSdkSandboxActivity

Added in 1.0.0-alpha15
fun startSdkSandboxActivity(
    fromActivity: Activity,
    sdkActivityToken: IBinder
): Unit

Starts an Activity in the SDK sandbox.

This function will start a new Activity in the same task of the passed fromActivity and pass it to the SDK that shared the passed sdkActivityToken that identifies a request from that SDK to stat this Activity.

Parameters
fromActivity: Activity

the Activity will be used to start the new sandbox Activity by calling Activity#startActivity against it.

sdkActivityToken: IBinder

the identifier that is shared by the SDK which requests the Activity.

unloadSdk

Added in 1.0.0-alpha15
fun unloadSdk(sdkName: String): Unit

Unloads an SDK that has been previously loaded by the caller.

It is not guaranteed that the memory allocated for this SDK will be freed immediately.

Parameters
sdkName: String

name of the SDK to be unloaded.

See also
unloadSdk

unregisterAppOwnedSdkSandboxInterface

Added in 1.0.0-alpha15
fun unregisterAppOwnedSdkSandboxInterface(sdkName: String): Unit

Unregisters AppOwnedSdkSandboxInterfaceCompat for an app process.

Parameters
sdkName: String

the name under which AppOwnedSdkSandboxInterfaceCompat was registered.