# SandboxedSdkProviderCompat

# SandboxedSdkProviderCompat

Artifact:[androidx.privacysandbox.sdkruntime:sdkruntime-core](https://developer.android.com/jetpack/androidx/releases/privacysandbox-sdkruntime)  
[View Source](https://cs.android.com/search?q=file:androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat.kt+class:androidx.privacysandbox.sdkruntime.core.SandboxedSdkProviderCompat)  
Added in[1.0.0-alpha18](https://developer.android.com/jetpack/androidx/releases/privacysandbox-sdkruntime#1.0.0-alpha18)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat "View this page in Java")

<br />

```
abstract class SandboxedSdkProviderCompat
```

<br />

*** ** * ** ***

Compat version of[android.app.sdksandbox.SandboxedSdkProvider](https://developer.android.com/reference/android/app/sdksandbox/SandboxedSdkProvider.html).

Encapsulates API which SDK sandbox can use to interact with SDKs loaded into it.

SDK has to implement this abstract class to generate an entry point for SDK sandbox to be able to call it through.  

|                                                     See also                                                     |
|------------------------------------------------------------------------------------------------------------------|---|
| [SandboxedSdkProvider](https://developer.android.com/reference/android/app/sdksandbox/SandboxedSdkProvider.html) |   |

## Summary

|                                                                             ### Public constructors                                                                              |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SandboxedSdkProviderCompat](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#SandboxedSdkProviderCompat())`()` |

|                                                            ### Public functions                                                            |
|--------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                              | [attachContext](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#attachContext(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`)` Sets the SDK[Context](https://developer.android.com/reference/android/content/Context.html)which can then be received using[SandboxedSdkProviderCompat.context](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#context()) |
| `open `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                       | [beforeUnloadSdk](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#beforeUnloadSdk())`()` Does the work needed for the SDK to free its resources before being unloaded.                                                                                                                                                                                                                                                                                                                             |
| `abstract `[SandboxedSdkCompat](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkCompat) | [onLoadSdk](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#onLoadSdk(android.os.Bundle))`(params: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`)` Does the work needed for the SDK to start handling requests.                                                                                                                                                                                                                                                       |

|                               ### Public properties                                |
|------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Context](https://developer.android.com/reference/android/content/Context.html)`?` | [context](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#context()) Context previously set through[SandboxedSdkProviderCompat.attachContext](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#attachContext(android.content.Context)). |

## Public constructors

### SandboxedSdkProviderCompat

Added in[1.0.0-alpha18](https://developer.android.com/jetpack/androidx/releases/privacysandbox-sdkruntime#1.0.0-alpha18)  

```
SandboxedSdkProviderCompat()
```  

## Public functions

### attachContext

Added in[1.0.0-alpha18](https://developer.android.com/jetpack/androidx/releases/privacysandbox-sdkruntime#1.0.0-alpha18)  

```
fun attachContext(context: Context): Unit
```

Sets the SDK[Context](https://developer.android.com/reference/android/content/Context.html)which can then be received using[SandboxedSdkProviderCompat.context](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#context())

This is called before[SandboxedSdkProviderCompat.onLoadSdk](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#onLoadSdk(android.os.Bundle))is invoked. No operations requiring a[Context](https://developer.android.com/reference/android/content/Context.html)should be performed before then, as[SandboxedSdkProviderCompat.context](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#context())will return null until this method has been called.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|-----------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | The new base context. |

|                                                          Throws                                                          |
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------|
| [kotlin.IllegalStateException](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html) | if a base context has already been set. |

|                                                                     See also                                                                     |
|--------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [attachContext](https://developer.android.com/reference/android/app/sdksandbox/SandboxedSdkProvider.html#attachContext(android.content.Context)) |   |

### beforeUnloadSdk

Added in[1.0.0-alpha18](https://developer.android.com/jetpack/androidx/releases/privacysandbox-sdkruntime#1.0.0-alpha18)  

```
open fun beforeUnloadSdk(): Unit
```

Does the work needed for the SDK to free its resources before being unloaded.

This function is called by the SDK sandbox manager before it unloads the SDK. The SDK should fail any invocations on the Binder previously returned to the client through[SandboxedSdkCompat.getInterface](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkCompat#getInterface())

The SDK should not do any long-running tasks here, like I/O and network calls.  

|                                                           See also                                                            |
|-------------------------------------------------------------------------------------------------------------------------------|---|
| [beforeUnloadSdk](https://developer.android.com/reference/android/app/sdksandbox/SandboxedSdkProvider.html#beforeUnloadSdk()) |   |

### onLoadSdk

Added in[1.0.0-alpha18](https://developer.android.com/jetpack/androidx/releases/privacysandbox-sdkruntime#1.0.0-alpha18)  

```
abstract fun onLoadSdk(params: Bundle): SandboxedSdkCompat
```

Does the work needed for the SDK to start handling requests.

This function is called by the SDK sandbox after it loads the SDK.

SDK should do any work to be ready to handle upcoming requests. It should not do any long-running tasks here, like I/O and network calls. Doing so can prevent the SDK from receiving requests from the client. Additionally, it should not do initialization that depends on other SDKs being loaded into the SDK sandbox.

The SDK should not do any operations requiring a[Context](https://developer.android.com/reference/android/content/Context.html)object before this method has been called.  

|                                     Parameters                                     |
|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| `params: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html) | list of params passed from the client when it loads the SDK. This can be empty. |

|                                                             Returns                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SandboxedSdkCompat](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkCompat) | Returns a[SandboxedSdkCompat](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkCompat), passed back to the client. The IBinder used to create the[SandboxedSdkCompat](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkCompat)object will be used by the client to call into the SDK. |

|                                                                                     Throws                                                                                      |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
| [androidx.privacysandbox.sdkruntime.core.LoadSdkCompatException](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/LoadSdkCompatException) | if initialization failed. |

|                                                              See also                                                              |
|------------------------------------------------------------------------------------------------------------------------------------|---|
| [onLoadSdk](https://developer.android.com/reference/android/app/sdksandbox/SandboxedSdkProvider.html#onLoadSdk(android.os.Bundle)) |   |

## Public properties

### context

Added in[1.0.0-alpha18](https://developer.android.com/jetpack/androidx/releases/privacysandbox-sdkruntime#1.0.0-alpha18)  

```
val context: Context?
```

Context previously set through[SandboxedSdkProviderCompat.attachContext](https://developer.android.com/reference/kotlin/androidx/privacysandbox/sdkruntime/core/SandboxedSdkProviderCompat#attachContext(android.content.Context)). This will return null if no context has been previously set.