Using the micro VPN library

The following image represents the micro VPN workflow:

Micro VPN diagram

Starting tunnel

Ensure that the app starts the tunnel before making any other calls to micro VPN. The MicroVPNSDK.startTunnel(…) method must be called to start the tunnel. This method starts the micro VPN network tunnel asynchronously. The app must invoke the #startTunnel(activity, messenger) method from an activity and pass that activity instance as an argument to this method. The #startTunnel(context, messenger) method can be called to start the tunnel on app launch, but this method requires a valid session to exist before starting the tunnel. This method also takes a messenger object that is needed for asynchronous communication. The #startTunnel(…) method returns the result or status of the operation using the messenger object back to the app’s handler.

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //For more details about this method refer javadocs
        MicroVPNSDK.startTunnel(this, new Messenger(handler));
    }
<!--NeedCopy-->

The messenger object must have a custom handler that overrides the Handler#handleMessage() method. When the tunnel starts successfully or fails to start, it returns success or failure messages using the input messenger object. When the Citrix Gateway cookie expires, a cookie expiry message is sent using this messenger. If the value of msg.what is 0 (zero), then tunnel is established successfully. Supported Codes (msg.what) are described in the following section:

Sample code for reference:

private final Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        ResponseStatusCode responseStatusCode = ResponseStatusCode.fromId(msg.what);
        switch (responseStatusCode)
        {
            case START_TUNNEL_SUCCESS:
                Log.i(TAG, "Tunnel started successfully.");
                networkTunnelRunning = true;
                sessionExpired = false;
                break;
            case START_TUNNEL_FAILED:
                Log.e(TAG, "Failed to start tunnel.");
                networkTunnelRunning = false;
                break;
            case TUNNEL_ALREADY_RUNNING:
                Log.i(TAG, "Tunnel is already running.");
                networkTunnelRunning = true;
                sessionExpired = false;
                break;
            case SESSION_EXPIRED:
                Log.i(TAG, "Session Expired.");
                networkTunnelRunning = false;
                sessionExpired = true;
                break;
            case FOUND_LEGACY_MODE:
                Log.e(TAG, "Cannot start tunnel for Legacy ManagementMode.");
                networkTunnelRunning = false;
                sessionExpired = false;
                break;
            case FOUND_NON_WEBSSO_MODE:
                Log.e(TAG, "Cannot start tunnel for NetworkAccess mode other than Tunneled - Web SSO.");
                networkTunnelRunning = false;
                sessionExpired = false;
                break;
            case FOUND_NON_MANAGED_APP:
                Log.e(TAG, "Could not retrieve policies. \n This could be because of the following reasons: \n\t 1. SecureHub is not installed.\n\t 2. SecureHub enrollment is not completed.\n\t 3. App is not managed through CEM.");
                networkTunnelRunning = false;
                sessionExpired = false;
                break;
            case NO_NETWORK_CONNECTION:
                Log.e(TAG, "Failed to start tunnel. No Network.");
                networkTunnelRunning = false;
                sessionExpired = false;
                break;
            case INVALID_APP_CONFIGURATION_DATA:
                Log.e(TAG, "Invalid App Configuration Data.");
                appConfigDataValid = false;
                break;
            case INVALID_OAUTH_TOKEN:
                Log.e(TAG, "Invalid OAuth Token.");
                oauthTokenValid = false;
                break;
            case APP_LOCKED:
                Log.e("Failed to start tunnel. App is in locked state.");
                break;
            default:
                super.handleMessage(msg);
                break;
        }
    }
};
<!--NeedCopy-->

Error Codes (msg.what) for handleMessage:

  • 0 = Tunnel started successfully.
  • 1 = Tunnel failed to start.
  • 2 = Tunnel is already running.
  • 3 = Session is expired. Start tunnel is required.
  • 4 = App is wrapped in MDX mode.
  • 5 = Network Access mode is not Tunneled - Web SSO. The tunnel can be started only in Tunneled - Web SSO mode for explicit SDK app.
  • 6 = App is not managed. Unable to retrieve policies.
  • 7 = No network connection.
  • 8 = Invalid app configuration data.
  • 9 = Invalid OAuth token.
  • 10 = App is in locked state.
Using the micro VPN library