Skip to main content

VPN

The KapeVpn module provides everything needed for VPN connectivity: server discovery, tunnel lifecycle, connection status, and network protection. It supports the WireGuard, Lightway, and OpenVPN protocols.

Guides​

  • Connecting — VPN consent, connection modes, status, traffic stats, errors, pausing
  • VPN Protocol — selecting WireGuard, Lightway, or OpenVPN, and the network transport (TCP/UDP)
  • Server Locations — fetching and filtering locations
  • OpenVPN Endpoint Discovery — the full OpenVPN payload (.ovpn contents, MTU, cert DN, XOR value) and its credentials, without linking the tunnel libraries
  • Dedicated IP — setup stages, connecting to a Dedicated IP, renewal
  • VPN Service — KapeVpnService setup and manifest registration
  • Network Protection — kill switch, split tunneling, on-demand rules, custom DNS
  • Licensed VPN features — the 15 VPN features your SDK license gates, and what a refusal looks like
  • HTTPS Proxy — routing Lightway TCP through a client-supplied HTTPS proxy
  • Connection Analytics — VpnConnectionAnalytics reliability events

Complete Example​

import com.kape.platformsdk.auth.KapeAuthClient
import com.kape.platformsdk.auth.LoginResult
import com.kape.platformsdk.core.KapeProductType
import com.kape.platformsdk.core.KapeSDKSettings
import com.kape.platformsdk.core.KapeSdkHandle
import com.kape.platformsdk.vpn.KapeConnectionMode
import com.kape.platformsdk.vpn.KapeVpnManager
import com.kape.platformsdk.vpn.lightway.bridge.KapeLightwaySupport
import com.kape.platformsdk.vpn.openvpn.bridge.KapeOpenVpnSupport
import com.kape.platformsdk.vpn.wireguard.bridge.KapeWireGuardSupport

// Initialize
val settings = KapeSDKSettings.fromXml(context, R.xml.kape_sdk_settings)
val handle = KapeSdkHandle(settings, context)

// Authenticate
val auth = KapeAuthClient(handle)
when (auth.login(context)) {
is LoginResult.Success -> {
val vpn =
KapeVpnManager(
handle,
protocols = listOf(KapeWireGuardSupport, KapeLightwaySupport, KapeOpenVpnSupport),
)

// Fetch locations — scoped to the protocol vpn will connect with
val locations = vpn.createLocationService()
locations.fetchLocations()

// Grant VPN consent (launch the returned Intent if non-null), then connect.
// vpn.prepare(activity)?.let { consentLauncher.launch(it) } // Activity context required

// Connect — auto picks the highest-rated smart location
vpn.connect(KapeConnectionMode.Auto)

// Or connect to a specific server
// vpn.connect(KapeConnectionMode.Manual(locations.allLocations.value.first().id))

// Observe
viewModelScope.launch {
vpn.connectionStatus.collect { println(it) }
}

// Later: disconnect
// vpn.disconnect()

// Signing out: tear the tunnel and its configuration down, then log out
// vpn.signOut()
// auth.logout()
}
else -> { /* handle cancellation or error */ }
}