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.
Fields
public static final int CAPABILITY_IKEV2 = 1 | getVpnCapabilities() bit: an IKEv2 configuration can be installed. |
public static final int CAPABILITY_IPSEC = 2 | getVpnCapabilities() bit: an IPsec configuration can be installed. |
public static final int CAPABILITY_CUSTOM_TUNNEL = 4 | getVpnCapabilities() bit: com.codename1.vpn.tunnel runs here. |
public static final int CAPABILITY_ON_DEMAND = 8 | getVpnCapabilities() bit: on-demand rules are honoured. |
public static final int CAPABILITY_ALWAYS_ON = 16 | Reserved. |
public static final int CAPABILITY_PER_APP = 32 | getVpnCapabilities() bit: per-application routing is offered. |
Methods
public abstract boolean isVpnSupported() | Whether this port can install and control a VPN configuration. |
public abstract boolean isCustomTunnelSupported() | Whether this port can run a packet tunnel this app implements. |
public abstract int getVpnCapabilities() | The CAPABILITY_* bit mask this port supports. |
public abstract int getVpnStatus() | The ordinal of the current com.codename1.vpn.VpnStatus. |
public abstract void installProfile(int requestId, String profileWire) | Installs or replaces the configuration described by profileWire, a com.codename1.impl.vpn.VpnWire record. |
public abstract void removeProfile(int requestId) | Removes the installed configuration. |
public abstract void loadProfile(int requestId) | Answers with the installed configuration as a wire record, or an empty string when none is installed. |
public abstract void startVpn(int requestId) | Brings the tunnel up. |
public abstract void stopVpn(int requestId) | Takes the tunnel down. |
public abstract void setStatusListening(boolean listening) | Starts or stops delivery of status changes to com.codename1.vpn.profile.Vpn#deliverStatusChanged. |
public abstract void startCustomTunnel(int requestId, String setupWire) | Brings up a tunnel the application implements. |
public abstract void stopCustomTunnel(int requestId) | Takes down a tunnel started by startCustomTunnel. |
Field details
CAPABILITY_IKEV2
public static final int CAPABILITY_IKEV2 = 1getVpnCapabilities() bit: an IKEv2 configuration can be installed.CAPABILITY_IPSEC
public static final int CAPABILITY_IPSEC = 2getVpnCapabilities() bit: an IPsec configuration can be installed.CAPABILITY_CUSTOM_TUNNEL
public static final int CAPABILITY_CUSTOM_TUNNEL = 4getVpnCapabilities() 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.
CAPABILITY_ON_DEMAND
public static final int CAPABILITY_ON_DEMAND = 8getVpnCapabilities() 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.
CAPABILITY_ALWAYS_ON
public static final int CAPABILITY_ALWAYS_ON = 16alwaysOn 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.CAPABILITY_PER_APP
public static final int CAPABILITY_PER_APP = 32getVpnCapabilities() bit: per-application routing is offered.Method details
isVpnSupported
public abstract 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
public abstract boolean isCustomTunnelSupported()getVpnCapabilities
public abstract int getVpnCapabilities()CAPABILITY_* bit mask this port supports.getVpnStatus
public abstract int getVpnStatus()com.codename1.vpn.VpnStatus.installProfile
public abstract 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
public abstract void removeProfile(int requestId)loadProfile
public abstract void loadProfile(int requestId)startVpn
public abstract void startVpn(int requestId)stopVpn
public abstract void stopVpn(int requestId)setStatusListening
public abstract void setStatusListening(boolean listening)com.codename1.vpn.profile.Vpn#deliverStatusChanged.startCustomTunnel
public abstract 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
public abstract void stopCustomTunnel(int requestId)startCustomTunnel.