# VcnConfig.Builder

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/net/vcn/VcnConfig.Builder "View this page in Java")  

```
class Builder
```

|---|------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                         ||
| ↳ | [android.net.vcn.VcnConfig.Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#) |

This class is used to incrementally build[VcnConfig](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig)objects.

## Summary

|                                                                                                              Public constructors                                                                                                               ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#Builder(android.content.Context))`(`context:` `[Context](https://developer.android.com/reference/kotlin/android/content/Context.html#)`)` <br /> |

|                                                                                                                                                                                                                                                                             Public methods                                                                                                                                                                                                                                                                             ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [VcnConfig.Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#) | [addGatewayConnectionConfig](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#addGatewayConnectionConfig(android.net.vcn.VcnGatewayConnectionConfig))`(`gatewayConnectionConfig:` `[VcnGatewayConnectionConfig](https://developer.android.com/reference/kotlin/android/net/vcn/VcnGatewayConnectionConfig)`)` Adds a configuration for an individual gateway connection.                                                       |
| [VcnConfig](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig)                  | [build](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#build())`()` Builds and validates the VcnConfig.                                                                                                                                                                                                                                                                                                                      |
| [VcnConfig.Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#) | [setRestrictedUnderlyingNetworkTransports](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#setRestrictedUnderlyingNetworkTransports(kotlin.collections.MutableSet))`(`transports:` `[MutableSet](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-set/index.html)<[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)!>`)` Sets transports that will be restricted by the VCN. |

## Public constructors

### Builder

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(context: Context)
```

|                                                           Parameters                                                           ||
|-----------|---------------------------------------------------------------------------------------------------------------------|
| `context` | [Context](https://developer.android.com/reference/kotlin/android/content/Context.html#):This value cannot be`null`. |

## Public methods

### addGatewayConnectionConfig

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun addGatewayConnectionConfig(gatewayConnectionConfig: VcnGatewayConnectionConfig): VcnConfig.Builder
```

Adds a configuration for an individual gateway connection.

|                                                                                                              Parameters                                                                                                               ||
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `gatewayConnectionConfig` | [VcnGatewayConnectionConfig](https://developer.android.com/reference/kotlin/android/net/vcn/VcnGatewayConnectionConfig):the configuration for an individual gateway connection This value cannot be`null`. |

|                                                                                                                           Return                                                                                                                           ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [VcnConfig.Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#) | this[Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#)instance, for chaining This value cannot be`null`. |

|                                                                                                                                                                                                                  Exceptions                                                                                                                                                                                                                  ||
|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if a VcnGatewayConnectionConfig has already been set for this[VcnConfig](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig)with the same GatewayConnection name (as returned via[android.net.vcn.VcnGatewayConnectionConfig#getGatewayConnectionName()](https://developer.android.com/reference/kotlin/android/net/vcn/VcnGatewayConnectionConfig#getGatewayConnectionName())). |

### build

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): VcnConfig
```

Builds and validates the VcnConfig.

|                                                                       Return                                                                       ||
|---------------------------------------------------------------------------------------|-------------------------------------------------------------|
| [VcnConfig](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig) | an immutable VcnConfig instance This value cannot be`null`. |

### setRestrictedUnderlyingNetworkTransports

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setRestrictedUnderlyingNetworkTransports(transports: MutableSet<Int!>): VcnConfig.Builder
```

Sets transports that will be restricted by the VCN.

In general, apps will not be able to bind to, or use a restricted network. In other words, unless the network type is marked restricted, any app can opt to use underlying networks, instead of through the VCN.

|                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                     ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `transports` | [MutableSet](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-set/index.html)\<[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)!\>:transports that will be restricted by VCN. Networks that include any of the transports will be marked as restricted.[android.net.NetworkCapabilities#TRANSPORT_WIFI](https://developer.android.com/reference/kotlin/android/net/NetworkCapabilities.html#TRANSPORT_WIFI:kotlin.Int)is marked restricted by default. This value cannot be`null`. |

|                                                                                                                           Return                                                                                                                           ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [VcnConfig.Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#) | this[Builder](https://developer.android.com/reference/kotlin/android/net/vcn/VcnConfig.Builder#)instance, for chaining This value cannot be`null`. |

|                                        Exceptions                                        ||
|--------------------------------------|----------------------------------------------------|
| `java.lang.IllegalArgumentException` | if the input contains unsupported transport types. |

**See Also**

- [android.net.NetworkCapabilities#NET_CAPABILITY_NOT_RESTRICTED](https://developer.android.com/reference/kotlin/android/net/NetworkCapabilities.html#NET_CAPABILITY_NOT_RESTRICTED:kotlin.Int)