public final 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 methods

final void

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

static final @NonNull SdkSandboxManagerCompat
from(@NonNull Context context)

Creates SdkSandboxManagerCompat.

final @NonNull List<@NonNull AppOwnedSdkSandboxInterfaceCompat>

Fetches all AppOwnedSdkSandboxInterfaceCompat that are registered by the app.

final @NonNull List<@NonNull SandboxedSdkCompat>

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

final @NonNull SandboxedSdkCompat
loadSdk(@NonNull String sdkName, @NonNull Bundle params)

Load SDK in a SDK sandbox java process or locally.

final void

Registers AppOwnedSdkSandboxInterfaceCompat for an app process.

final void

Removes an SdkSandboxProcessDeathCallbackCompat that was previously added using SdkSandboxManagerCompat.addSdkSandboxProcessDeathCallback

final void
startSdkSandboxActivity(
    @NonNull Activity fromActivity,
    @NonNull IBinder sdkActivityToken
)

Starts an Activity in the SDK sandbox.

final void

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

final void

Unregisters AppOwnedSdkSandboxInterfaceCompat for an app process.

Public methods

addSdkSandboxProcessDeathCallback

Added in 1.0.0-alpha14
public final void addSdkSandboxProcessDeathCallback(
    @NonNull Executor callbackExecutor,
    @NonNull SdkSandboxProcessDeathCallbackCompat callback
)

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
@NonNull Executor callbackExecutor

the Executor on which to invoke the callback

@NonNull SdkSandboxProcessDeathCallbackCompat callback

the SdkSandboxProcessDeathCallbackCompat which will receive SDK sandbox lifecycle events.

from

Added in 1.0.0-alpha14
public static final @NonNull SdkSandboxManagerCompat from(@NonNull Context context)

Creates SdkSandboxManagerCompat.

Parameters
@NonNull Context context

Application context

Returns
@NonNull SdkSandboxManagerCompat

SdkSandboxManagerCompat object.

getAppOwnedSdkSandboxInterfaces

Added in 1.0.0-alpha14
public final @NonNull List<@NonNull AppOwnedSdkSandboxInterfaceCompatgetAppOwnedSdkSandboxInterfaces()

Fetches all AppOwnedSdkSandboxInterfaceCompat that are registered by the app.

getSandboxedSdks

Added in 1.0.0-alpha14
public final @NonNull List<@NonNull SandboxedSdkCompatgetSandboxedSdks()

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

Returns
@NonNull List<@NonNull SandboxedSdkCompat>

List of SandboxedSdkCompat containing all currently loaded sdks

See also
getSandboxedSdks

loadSdk

public final @NonNull SandboxedSdkCompat loadSdk(@NonNull String sdkName, @NonNull Bundle params)

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
@NonNull String sdkName

name of the SDK to be loaded.

@NonNull Bundle params

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

Returns
@NonNull SandboxedSdkCompat

SandboxedSdkCompat from SDK on a successful run.

See also
loadSdk

registerAppOwnedSdkSandboxInterface

Added in 1.0.0-alpha14
public final void registerAppOwnedSdkSandboxInterface(
    @NonNull AppOwnedSdkSandboxInterfaceCompat appOwnedSdk
)

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
@NonNull AppOwnedSdkSandboxInterfaceCompat appOwnedSdk

the AppOwnedSdkSandboxInterfaceCompat to be registered

startSdkSandboxActivity

Added in 1.0.0-alpha14
public final void startSdkSandboxActivity(
    @NonNull Activity fromActivity,
    @NonNull IBinder sdkActivityToken
)

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
@NonNull Activity fromActivity

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

@NonNull IBinder sdkActivityToken

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

unloadSdk

Added in 1.0.0-alpha14
public final void unloadSdk(@NonNull String sdkName)

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
@NonNull String sdkName

name of the SDK to be unloaded.

See also
unloadSdk

unregisterAppOwnedSdkSandboxInterface

Added in 1.0.0-alpha14
public final void unregisterAppOwnedSdkSandboxInterface(@NonNull String sdkName)

Unregisters AppOwnedSdkSandboxInterfaceCompat for an app process.

Parameters
@NonNull String sdkName

the name under which AppOwnedSdkSandboxInterfaceCompat was registered.