Interface VpnBridge


public interface VpnBridge

Internal service-provider interface implemented by each platform port to carry the com.codename1.vpn API onto the native VPN machinery: Apple's NEVPNManager and NETunnelProviderManager, and Android's VpnManager and VpnService.

Application code never touches this interface. It is obtained by the com.codename1.vpn packages from com.codename1.ui.Display#getVpnBridge(), and the base implementation returns null -- which is why the public API degrades to a well-behaved NOT_SUPPORTED on ports that implement nothing.

The same rules as com.codename1.call.spi.CallBridge apply: primitives, strings and byte arrays only; asynchrony by caller-allocated requestId; every operation answers exactly once; unsolicited events marshal to the EDT themselves.

  • Field Details

    • CAPABILITY_IKEV2

      static final int CAPABILITY_IKEV2
      getVpnCapabilities() bit: an IKEv2 configuration can be installed.
      See Also:
    • CAPABILITY_IPSEC

      static final int CAPABILITY_IPSEC
      getVpnCapabilities() bit: an IPsec configuration can be installed.
      See Also:
    • CAPABILITY_CUSTOM_TUNNEL

      static final int CAPABILITY_CUSTOM_TUNNEL

      getVpnCapabilities() bit: com.codename1.vpn.tunnel runs here.

      The extension iOS runs a tunnel in is a target the BUILD generates, so it carries a translated VM exactly as the app target does. What it does not carry is anything else of the app's, which is why the setup travels as data. Android runs the tunnel in a bound VpnService the port ships.

      See Also:
    • CAPABILITY_ON_DEMAND

      static final int CAPABILITY_ON_DEMAND

      getVpnCapabilities() bit: on-demand rules are honoured.

      iOS sets this; Android does not, because its managed profile API has no equivalent and a bit that promised one would send apps down a path that quietly becomes an ordinary manually started tunnel.

      See Also:
    • CAPABILITY_ALWAYS_ON

      static final int CAPABILITY_ALWAYS_ON
      Reserved. No port sets this, and there is no alwaysOn on VpnProfile to pair it with: always-on VPN needs a supervised device and an MDM payload on iOS, and a Settings toggle or a device-owner API on Android. The constant is kept so the bit values below it do not shift if either platform ever opens it up.
      See Also:
    • CAPABILITY_PER_APP

      static final int CAPABILITY_PER_APP
      getVpnCapabilities() bit: per-application routing is offered.
      See Also:
  • Method Details

    • isVpnSupported

      boolean isVpnSupported()

      Whether this port can install and control a VPN configuration.

      Distinct from merely detecting one: com.codename1.io.NetworkManager answers "is a VPN up" on far more platforms than can install one.

    • isCustomTunnelSupported

      boolean isCustomTunnelSupported()
      Whether this port can run a packet tunnel this app implements.
    • getVpnCapabilities

      int getVpnCapabilities()
      The CAPABILITY_* bit mask this port supports.
    • getVpnStatus

      int getVpnStatus()
      The ordinal of the current com.codename1.vpn.VpnStatus.
    • installProfile

      void installProfile(int requestId, String profileWire)

      Installs or replaces the configuration described by profileWire, a com.codename1.impl.vpn.VpnWire record.

      Both platforms show the user a prompt here, and both refuse silently if the app lacks the entitlement, so a port must answer USER_DECLINED or UNAUTHORIZED rather than letting the request hang.

    • removeProfile

      void removeProfile(int requestId)
      Removes the installed configuration.
    • loadProfile

      void loadProfile(int requestId)
      Answers with the installed configuration as a wire record, or an empty string when none is installed.
    • startVpn

      void startVpn(int requestId)
      Brings the tunnel up.
    • stopVpn

      void stopVpn(int requestId)
      Takes the tunnel down.
    • setStatusListening

      void setStatusListening(boolean listening)
      Starts or stops delivery of status changes to com.codename1.vpn.profile.Vpn#deliverStatusChanged.
    • startCustomTunnel

      void startCustomTunnel(int requestId, String setupWire)

      Brings up a tunnel the application implements.

      setupWire is a com.codename1.impl.vpn.TunnelWire record. The application's VpnTunnel is reached through Tunnels.getRegistered() on a port that runs it in this process, and constructed afresh on one that runs it in another.

      Answers through com.codename1.vpn.tunnel.Tunnels#deliverAck, once, including where the user declines the system's consent prompt.

    • stopCustomTunnel

      void stopCustomTunnel(int requestId)
      Takes down a tunnel started by startCustomTunnel(int, String).