VcnManager
open class VcnManager
kotlin.Any | |
↳ | android.net.vcn.VcnManager |
VcnManager publishes APIs for applications to configure and manage Virtual Carrier Networks.
A VCN creates a virtualization layer to allow carriers to aggregate heterogeneous physical networks, unifying them as a single carrier network. This enables infrastructure flexibility on the part of carriers without impacting user connectivity, abstracting the physical network technologies as an implementation detail of their public network.
Each VCN virtualizes a carrier's network by building tunnels to a carrier's core network over carrier-managed physical links and supports a IP mobility layer to ensure seamless transitions between the underlying networks. Each VCN is configured based on a Subscription Group (see ) and aggregates all networks that are brought up based on a profile or suggestion in the specified Subscription Group.
The VCN can be configured to expose one or more android.net.Network
(s), each with different capabilities, allowing for APN virtualization.
If a tunnel fails to connect, or otherwise encounters a fatal error, the VCN will attempt to reestablish the connection. If the tunnel still has not reconnected after a system-determined timeout, the VCN Safe Mode (see below) will be entered.
The VCN Safe Mode ensures that users (and carriers) have a fallback to restore system connectivity to update profiles, diagnose issues, contact support, or perform other remediation tasks. In Safe Mode, the system will allow underlying cellular networks to be used as default. Additionally, during Safe Mode, the VCN will continue to retry the connections, and will automatically exit Safe Mode if all active tunnels connect successfully.
Apps targeting Android 15 or newer should check the existence of android.content.pm.PackageManager#FEATURE_TELEPHONY_SUBSCRIPTION
before querying the service. If the feature is absent, android.content.Context#getSystemService may return null.
Requires the PackageManager#FEATURE_TELEPHONY_SUBSCRIPTION
feature which can be detected using PackageManager.hasSystemFeature(String)
.
Summary
Nested classes | |
---|---|
abstract |
VcnStatusCallback is the interface for Carrier apps to receive updates for their VCNs. |
Constants | |
---|---|
static Int |
Value indicating that an error with this Gateway Connection's configuration occurred. |
static Int |
Value indicating that an internal failure occurred in this Gateway Connection. |
static Int |
Value indicating that a Network error occurred with this Gateway Connection. |
static Int |
Value indicating that the VCN for the subscription group is active. |
static Int |
Value indicating that the VCN for the subscription group is inactive. |
static Int |
Value indicating that the VCN for the subscription group is not configured, or that the callback is not privileged for the subscription group. |
static Int |
Value indicating that the VCN for the subscription group is in Safe Mode. |
Public methods | |
---|---|
open Unit |
clearVcnConfig(subscriptionGroup: ParcelUuid) Clears the VCN configuration for a given subscription group. |
open MutableList<ParcelUuid!> |
Retrieves the list of Subscription Groups for which a VCN Configuration has been set. |
open Unit |
registerVcnStatusCallback(subscriptionGroup: ParcelUuid, executor: Executor, callback: VcnManager.VcnStatusCallback) Registers the given callback to receive status updates for the specified subscription. |
open Unit |
setVcnConfig(subscriptionGroup: ParcelUuid, config: VcnConfig) Sets the VCN configuration for a given subscription group. |
open Unit |
Unregisters the given callback. |
Constants
VCN_ERROR_CODE_CONFIG_ERROR
static val VCN_ERROR_CODE_CONFIG_ERROR: Int
Value indicating that an error with this Gateway Connection's configuration occurred.
For example, this error code will be returned after authentication failures.
Value: 1
VCN_ERROR_CODE_INTERNAL_ERROR
static val VCN_ERROR_CODE_INTERNAL_ERROR: Int
Value indicating that an internal failure occurred in this Gateway Connection.
Value: 0
VCN_ERROR_CODE_NETWORK_ERROR
static val VCN_ERROR_CODE_NETWORK_ERROR: Int
Value indicating that a Network error occurred with this Gateway Connection.
For example, this error code will be returned if an underlying android.net.Network
for this Gateway Connection is lost, or if an error occurs while resolving the connection endpoint address.
Value: 2
VCN_STATUS_CODE_ACTIVE
static val VCN_STATUS_CODE_ACTIVE: Int
Value indicating that the VCN for the subscription group is active.
A VCN is active if a VcnConfig
is present for the subscription, the provisioning package is privileged, and the VCN is not in Safe Mode. In other words, a VCN is considered active while it is connecting, fully connected, and disconnecting.
Value: 2
VCN_STATUS_CODE_INACTIVE
static val VCN_STATUS_CODE_INACTIVE: Int
Value indicating that the VCN for the subscription group is inactive.
A VCN is inactive if a VcnConfig
is present for the subscription group, but the provisioning package is not privileged.
Value: 1
VCN_STATUS_CODE_NOT_CONFIGURED
static val VCN_STATUS_CODE_NOT_CONFIGURED: Int
Value indicating that the VCN for the subscription group is not configured, or that the callback is not privileged for the subscription group.
Value: 0
VCN_STATUS_CODE_SAFE_MODE
static val VCN_STATUS_CODE_SAFE_MODE: Int
Value indicating that the VCN for the subscription group is in Safe Mode.
A VCN will be put into Safe Mode if any of the gateway connections were unable to establish a connection within a system-determined timeout (while underlying networks were available).
Value: 3
Public methods
clearVcnConfig
open fun clearVcnConfig(subscriptionGroup: ParcelUuid): Unit
Clears the VCN configuration for a given subscription group.
An app that has carrier privileges for any of the subscriptions in the given group may clear a VCN configuration. This API is ONLY permitted for callers running as the primary user. Any active VCN associated with this configuration will be torn down.
Requires carrier privileges
Parameters | |
---|---|
subscriptionGroup |
ParcelUuid: the subscription group that the configuration should be applied to This value cannot be null . |
Exceptions | |
---|---|
java.lang.SecurityException |
if the caller does not have carrier privileges, is not the owner of the associated configuration, or is not running as the primary user |
java.io.IOException |
if the configuration failed to be cleared from disk. This may occur due to temporary disk errors, or more permanent conditions such as a full disk. |
getConfiguredSubscriptionGroups
open fun getConfiguredSubscriptionGroups(): MutableList<ParcelUuid!>
Retrieves the list of Subscription Groups for which a VCN Configuration has been set.
The returned list will include only subscription groups for which an associated VcnConfig
exists, and the app is either:
- Carrier privileged for that subscription group, or
- Is the provisioning package of the config
Return | |
---|---|
MutableList<ParcelUuid!> |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.SecurityException |
if the caller is not running as the primary user |
registerVcnStatusCallback
open fun registerVcnStatusCallback(
subscriptionGroup: ParcelUuid,
executor: Executor,
callback: VcnManager.VcnStatusCallback
): Unit
Registers the given callback to receive status updates for the specified subscription.
Callbacks can be registered for a subscription before VcnConfig
s are set for it.
A VcnStatusCallback
may only be registered for one subscription at a time. VcnStatusCallback
s may be reused once unregistered.
A VcnStatusCallback
will only be invoked if the registering package has carrier privileges for the specified subscription at the time of invocation.
A VcnStatusCallback
is eligible to begin receiving callbacks once it is registered and there is a VCN active for its specified subscription group (this may happen after the callback is registered).
VcnStatusCallback.onStatusChanged(int)
will be invoked on registration with the current status for the specified subscription group's VCN. If the registrant is not privileged for this subscription group, VCN_STATUS_CODE_NOT_CONFIGURED
will be returned.
Parameters | |
---|---|
subscriptionGroup |
ParcelUuid: The subscription group to match for callbacks This value cannot be null . |
executor |
Executor: The Executor to be used for invoking callbacks This value cannot be null . |
callback |
VcnManager.VcnStatusCallback: The VcnStatusCallback to be registered This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if callback is currently registered with VcnManager |
setVcnConfig
open fun setVcnConfig(
subscriptionGroup: ParcelUuid,
config: VcnConfig
): Unit
Sets the VCN configuration for a given subscription group.
An app that has carrier privileges for any of the subscriptions in the given group may set a VCN configuration. If a configuration already exists for the given subscription group, it will be overridden. Any active VCN(s) may be forced to restart to use the new configuration.
This API is ONLY permitted for callers running as the primary user.
Requires carrier privileges
Parameters | |
---|---|
subscriptionGroup |
ParcelUuid: the subscription group that the configuration should be applied to This value cannot be null . |
config |
VcnConfig: the configuration parameters for the VCN This value cannot be null . |
Exceptions | |
---|---|
java.lang.SecurityException |
if the caller does not have carrier privileges for the provided subscriptionGroup, or is not running as the primary user |
java.io.IOException |
if the configuration failed to be saved and persisted to disk. This may occur due to temporary disk errors, or more permanent conditions such as a full disk. |
unregisterVcnStatusCallback
open fun unregisterVcnStatusCallback(callback: VcnManager.VcnStatusCallback): Unit
Unregisters the given callback.
Once unregistered, the callback will stop receiving status updates for the subscription it was registered with.
Parameters | |
---|---|
callback |
VcnManager.VcnStatusCallback: The callback to be unregistered This value cannot be null . |