Pango Platform
HomeConsole
  • What is Pango Developer Platform
  • Getting started
    • Sign up on the Management Console
    • Create a new project
    • Switch projects
    • Change console settings
    • Edit your profile
    • Try out the demo app
    • Keep exploring
    • Deprecation and Sunset
  • Console details
    • Dashboard
      • General
      • Location loading
    • Users
      • User page
    • Active sessions
    • Network
      • Countries
      • Locations
      • Pools
        • Optimal location
        • Location rules
    • Settings
      • General
        • Project config description (JSON format)
          • Server selector (JSON format)
          • Request selector (JSON format)
      • Authentication methods
        • Auth Plugin requirements
      • VPN
        • General
        • VPN Bypass list
        • Client Networks
      • Member
    • Export Data
    • Log
  • SDK
    • Unified VPN SDK for Android
      • Setup
        • Application Setup
        • Proguard Rules, Notification, and Analytics Configurations
        • Backend URL Configuration
      • Usage
        • Initialization
        • VPN Interface
        • Backend interface
      • Features
        • Hydra Protocol
          • Location profile (Hydra only)
        • Custom sdk dependencies
        • Deferred VPN Service Initialization
        • Authentication
        • Client Network List (CNL)
        • OpenVPN transport
        • Wireguard Transport
        • Reconnection strategy
        • Single Protocol SDK
        • Killswitch
        • Domain route via VPN
        • Process route via VPN
        • Process Bypass
        • Domain Bypass
        • Traffic rules
        • VPN Node DNS Configuration
        • Multihop
          • Optimal Location
      • Exceptions
      • Version migration
      • Changelog
    • Unified VPN SDK for Apple
      • Setup
        • Application Setup
        • Network Extension Setup
          • Network Extension Setup for tvOS
        • Backend URL Configuration
      • Usage
        • Single Protocol SDK
        • Unified SDK
        • Logging
        • Decoding Encoded VPN SDK Logs
      • Features
        • Deferred VPN Service Initialization
        • Authentication
        • Wireguard Transport
        • Reconnection strategy
        • Killswitch
        • Domain Bypass
        • Multihop
          • Optimal Location
        • Client Network List (CNL)
        • Domain route via VPN
      • Changelog
      • API Reference
    • IPSEC VPN SDK for Apple
    • Unified VPN SDK for Windows
      • Setup
        • Backend URL Configuration
        • Service command line arguments
        • ARM Platform Support
      • Usage
        • CoreAPI
        • Events
        • Generating a Unique Device Identifier
        • Error processing
        • Pipe Messaging
      • Features
        • Traffic protection
          • Killswitch
          • Prevent IP Leaks
          • Block Local Networks
        • Other
          • Firewall
            • DNS Monitor
            • Process Bypass
            • Domain Bypass
            • Process route via VPN
            • Domain route via VPN
          • Throttling
          • Optimal Location
          • Common issues
        • Hydra Protocol
          • CustomDNS, UserDNS, MultiHop, VpnProfiles
        • OpenVPN Protocol
        • Wireguard Protocol
        • IPSec Protocol
      • Collecting Debug Logs
      • Changelog
    • Unified VPN SDK for Routers
      • SDK. Shared library.
      • Configuration Interface (CI)
        • Unix Domain Sockets CI
        • REST API CI
    • Unified VPN SDK Feature Comparison By Platform
    • Unified VPN SDK
      • Features
        • Personal Bridge
    • Tunnel Vision and Tunnel Crack Prevention
  • REST API
    • Partner API
  • Sample applications
    • Unified VPN SDK demo for Windows
    • Hydra VPN SDK demo for iOS
    • IPSEC VPN SDK demo for iOS
    • Unified VPN SDK demo for Android
    • Hydra VPN SDK demo for OpenWRT
    • OpenVPN configuration file
  • Resources
    • Use cases
      • Public VPN
      • Business VPN
        • Creating a Business VPN Project
        • Wi-Fi Security for Business
      • Application anti-blocking
    • How-to
      • Create a Firebase project for User Authentication
      • AWS CloudFront Distribution of the Platform URL
      • How can I get Shared Secret key from iTunes Connect for In-App Purchase
  • FAQ
    • General
      • VPN Platform Flow
      • What data is collected by the Platform?
      • What analytic data is collected by your SDK?
      • How the Platform restricts access to our data?
      • Why DNS Leak tests often indicate positive result?
      • Do we need to perform endpoint health checks?
      • How is the VPN exit node found?
      • How are streams re-marked if VPN is enabled/disabled on an active flow?
      • Is there a maximum number of supported devices?
      • Are both IPv4 and IPv6 supported?
      • What is the MTU of the tunnel?
      • Are any redundancy measures in terms of reliability provided?
      • Is there any load balancing?
      • Do you block broadcast and multicast to/from the VPN?
    • List of Open Source libs
Powered by GitBook
On this page
  • SessionConfig
  • Examples
  • Start VPN with an optimal server
  • Start VPN for chrome only
  • Analytics Reasons
  • Starting a VPN session
  • Stopping a VPN Session
  • Restarting a VPN Session
  • Updating Session Configuration
  • Listening for VPN Status and Traffic Updates
  • Getting Current VPN State
  • VPN States
  • Checking VPN Permissions
  • Getting Current VPN Session Information

Was this helpful?

  1. SDK
  2. Unified VPN SDK for Android
  3. Usage

VPN Interface

PreviousInitializationNextBackend interface

Last updated 8 months ago

Was this helpful?

The VPN Interface allows you to configure and control VPN sessions using the UnifiedSDK class. This document provides an overview of the available methods and classes for managing VPN sessions.

SessionConfig

The SessionConfig class is used to configure VPN sessions. It provides the following Builder methods:

  • withTransport(transportName) - Set the transport name to start the session with. Useful when multiple transports are available.

  • withPolicy(appPolicy) - Define the app policy to use. Available options:

    • AppPolicy.forAll() - VPN will be available for all apps.

    • AppPolicy.newBuilder().policy(AppPolicy.POLICY_FOR_LIST) - Specify a list of apps allowed to use VPN.

    • AppPolicy.newBuilder().policy(AppPolicy.POLICY_EXCEPT_LIST) - Specify a list of apps not allowed to use VPN.

  • withReason(reason) - Define the reason for starting the session using unified.vpn.sdk.TrackingConstants.GprReasons. Used for analytics.

  • withLocation(location) - Define the virtual location for the session.

  • withCountry(country) - Define the virtual country for the session.

  • withPrivateGroup(group) - Define a private server for the session.

  • withVpnParams(params) - Define VPN tunnel parameters, such as DNS servers and additional routes.

  • addDnsRule(rule) - Add a DNS rule for the session. More on page. For Hydra transport only.

  • addProxyRule(rule) - Add a proxy rule for the session. More on page. For Hydra transport only.

  • withFireshieldConfig(config) - Define categorization service rules. More on resource page. For Hydra transport only

  • withTransportFallback(fallbackOrder) - Define the order of transports to fallback when an error occurs.

  • keepVpnOnReconnect() - Enable the kill switch to prevent traffic while the SDK is in the connection process or handling connection errors.

Examples

Start VPN with an optimal server

final SessionConfig session = new SessionConfig.Builder()
                .withLocation(UnifiedSDK.COUNTRY_OPTIMAL)
                .withReason(TrackingConstants.GprReasons.M_UI)
                .build();

Start VPN for chrome only

final List<String> apps = new ArrayList<String();
apps.add("com.google.chrome");
final SessionConfig session = new SessionConfig.Builder()
                .withLocation(UnifiedSDK.COUNTRY_OPTIMAL)
                .withReason(TrackingConstants.GprReasons.M_UI)
                .appPolicy(AppPolicy.newBuilder().policy(AppPolicy.POLICY_FOR_LIST).appList(apps).build())
                .build();

Analytics Reasons

The following constants are used to specify the reason for starting the VPN session:

  • M_UI - Manually started from the user interface

  • M_SYSTEM - Manually started from the system

  • M_OTHER - Manually started from another place

  • A_APP_RUN - Automatically started on app run

  • A_RECONNECT - Automatically started on reconnect

  • A_ERROR - Automatically started after an error

  • A_SLEEP - Automatically started after sleep

  • A_NETWORK - Automatically started on a network event

  • A_OTHER - Automatically started for other reasons

These constants are defined in the TrackingConstants.GprReasons enum and can be used with the withReason method when building the SessionConfig.

Starting a VPN session

To start a VPN session:

final SessionConfig sessionConfig = new SessionConfig.Builder()
    .build()

sdk.getVpn().start(sessionConfig, new CompletableCallback() {
    @Override
    public void complete() {
        // Handle successful completion of VPN start
    }

    @Override
    public void error(@NonNull VpnException e) {
        // Handle error during VPN start
    }
});
  1. Obtain an instance of the UnifiedSdk class by calling the getInstance() method.

  2. Start the VPN session by calling the start() method on the getVpn() instance of the UnifiedSdk.

  • The complete() method will be called when the VPN session starts successfully. You can add your logic to handle the successful start of the VPN here.

  • The error() method will be called if an error occurs during the VPN start process. You can handle the error case and take appropriate actions based on the VpnException received.

Make sure you have the necessary permissions and configurations in your Android manifest file for the VPN functionality to work properly.

Stopping a VPN Session

To stop a VPN session:

sdk.getVpn().stop(TrackingConstants.GprReasons.M_UI, new CompletableCallback() {
    @Override
    public void complete() {
        // VPN session stopped successfully
    }

    @Override
    public void error(@NonNull VpnException e) {
        // Failed to stop VPN session
    }
});

Restarting a VPN Session

To restart a VPN session with a new configuration without entering the IDLE state:

final SessionConfig session = //create session config
sdk.getVpn().restart(session, new CompletableCallback() {
    @Override
    public void complete() {
        // VPN session restarted successfully
    }

    @Override
    public void error(@NonNull VpnException e) {
        // Failed to restart VPN session
    }
});

Updating Session Configuration

You can update certain VPN session configurations without restarting the VPN session. Currently, the SDK supports updating the following for the Hydra transport:

  • Fireshield rules

  • DNS Rules

  • Proxy Rules

Example:

final SessionConfig session = //create session config
sdk.getVpn().updateConfig(session, new CompletableCallback() {
    @Override
    public void complete() {
        // Session configuration updated successfully
    }

    @Override
    public void error(@NonNull VpnException e) {
        // Failed to update session configuration
    }
});

Listening for VPN Status and Traffic Updates

To listen for VPN status and traffic updates:

UnifiedSDK.addVpnStateListener(new VpnStateListener() {
    @Override
    public void vpnStateChanged(@NonNull VpnState vpnState) {
        // Handle VPN state change
    }

    @Override
    public void vpnError(@NonNull VpnException e) {
        // Handle VPN error
    }
});

UnifiedSDK.addTrafficListener(new TrafficListener() {
    @Override
    public void onTrafficUpdate(long rx, long tx) {
        // Handle traffic update
    }
});

// To stop listening for updates
UnifiedSDK.removeTrafficListener(...);
UnifiedSDK.removeVpnStateListener(...);

Getting Current VPN State

To get the current VPN state:

UnifiedSDK.getVpnState(new Callback<VpnState>() {
    @Override
    public void success(@NonNull VpnState vpnState) {
        // Handle VPN state
    }

    @Override
    public void failure(@NonNull VpnException e) {
        // Handle failure to get VPN state
    }
});

VPN States

  • IDLE - No active VPN session.

  • CONNECTING_PERMISSIONS - Requesting system VPN permission.

  • CONNECTING_CREDENTIALS - Loading backend information to establish a connection.

  • CONNECTING_VPN - Transport connection in progress.

  • DISCONNECTING - Disconnection started.

  • CONNECTED - VPN session is active and connected.

  • PAUSED - VPN session paused due to an error, network change, or waiting to restore the VPN session.

  • UNKNOWN - Not used, reserved.

  • ERROR - Not used, reserved.

Checking VPN Permissions

To check if the app has system VPN permissions granted:

final boolean granted = VpnPermissions.granted();

To request VPN permissions without connecting to the VPN:

VpnPermissions.request(new CompletableCallback() {
    @Override
    public void complete() {
        // Permission granted
    }

    @Override
    public void error(@NonNull VpnException e) {
        // Failed to get permission
    }
});

Getting Current VPN Session Information

To get the current VPN session information:

UnifiedSdk.getStatus(new Callback<SessionInfo>() {
    @Override
    public void success(@NonNull SessionInfo sessionInfo) {
        // Handle session information (e.g., get sessionInfo.getConnectionStatus().getSuccessInfo())
    }

    @Override
    public void failure(@NonNull VpnException e) {
        // Handle failure to get session information
    }
});

Create a SessionConfig object using the SessionConfig.Builder class. You can customize the session configuration by .

Traffic rules
Traffic rules
Fireshield
setting various options in the builder