# PrivacySandboxService

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

*** ** * ** ***


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

<br />

*** ** * ** ***

> [!CAUTION]
> **This annotation is deprecated.**   
> This library is no longer supported.

Entry point for an SDK service running in the Privacy Sandbox.

There must be exactly one interface annotated with @PrivacySandboxService in your SDK module. This will be the first point of communication once the app has successfully loaded your SDK in the Privacy Sandbox.

On the SDK side, the tools will generate a class called `AbstractSandboxedSdkProviderCompat`, containing an abstract factory method to create this service. This must be implemented by SDK developers, returning an implementation of the `https://developer.android.com/reference/androidx/privacysandbox/tools/PrivacySandboxService` annotated interface. This implementation should then be named in the SDK's `build.gradle` as the `compatSdkProviderClassName`.

For example:

```
package com.example.mysdk

class MySdkSandboxedSdkProvider : AbstractSandboxedSdkProviderCompat() {
    override fun createMySdk(context: Context): MySdk = MySdkImpl(context)
}
```

On the app side, the tools will generate a factory class for the service containing a static function (prefixed with "wrapTo") which should be used to convert an IBinder to the `https://developer.android.com/reference/androidx/privacysandbox/tools/PrivacySandboxService` annotated interface.

For example:

```
val sandboxManagerCompat = SdkSandboxManagerCompat.from(this)
val sandboxedSdk = sandboxManagerCompat.loadSdk("com.example.mysdk", Bundle.EMPTY)
val mySdk = MySdkFactory.wrapToMySdk(sandboxedSdk.getInterface()!!)
```

Like `https://developer.android.com/reference/androidx/privacysandbox/tools/PrivacySandboxInterface`, interfaces annotated with `https://developer.android.com/reference/androidx/privacysandbox/tools/PrivacySandboxService` have restrictions on allowed methods and types. See `https://developer.android.com/reference/androidx/privacysandbox/tools/PrivacySandboxInterface` documentation for details.