IT. Expert System.

Android Reference

VpnService.Builder


android.net

Class VpnService.Builder

  • Enclosing class:
    VpnService


    public class VpnService.Builder
    extends Object
    Helper class to create a VPN interface. This class should be always used within the scope of the outer VpnService.
    See Also:
    VpnService
    • Constructor Detail

      • VpnService.Builder

        public VpnService.Builder()
    • Method Detail

      • setSession

        public VpnService.Builder setSession(String session)
        Set the name of this session. It will be displayed in system-managed dialogs and notifications. This is recommended not required.
      • setConfigureIntent

        public VpnService.Builder setConfigureIntent(PendingIntent intent)
        Set the PendingIntent to an activity for users to configure the VPN connection. If it is not set, the button to configure will not be shown in system-managed dialogs.
      • setMtu

        public VpnService.Builder setMtu(int mtu)
        Set the maximum transmission unit (MTU) of the VPN interface. If it is not set, the default value in the operating system will be used.
        Throws:
        IllegalArgumentException - if the value is not positive.
      • addDnsServer

        public VpnService.Builder addDnsServer(InetAddress address)
        Add a DNS server to the VPN connection. Both IPv4 and IPv6 addresses are supported. If none is set, the DNS servers of the default network will be used.
        Throws:
        IllegalArgumentException - if the address is invalid.
      • establish

        public ParcelFileDescriptor establish()
        Create a VPN interface using the parameters supplied to this builder. The interface works on IP packets, and a file descriptor is returned for the application to access them. Each read retrieves an outgoing packet which was routed to the interface. Each write injects an incoming packet just like it was received from the interface. The file descriptor is put into non-blocking mode by default to avoid blocking Java threads. To use the file descriptor completely in native space, see ParcelFileDescriptor.detachFd(). The application MUST close the file descriptor when the VPN connection is terminated. The VPN interface will be removed and the network will be restored by the system automatically.

        To avoid conflicts, there can be only one active VPN interface at the same time. Usually network parameters are never changed during the lifetime of a VPN connection. It is also common for an application to create a new file descriptor after closing the previous one. However, it is rare but not impossible to have two interfaces while performing a seamless handover. In this case, the old interface will be deactivated when the new one is created successfully. Both file descriptors are valid but now outgoing packets will be routed to the new interface. Therefore, after draining the old file descriptor, the application MUST close it and start using the new file descriptor. If the new interface cannot be created, the existing interface and its file descriptor remain untouched.

        An exception will be thrown if the interface cannot be created for any reason. However, this method returns null if the application is not prepared or is revoked. This helps solve possible race conditions between other VPN applications.

        Returns:
        ParcelFileDescriptor of the VPN interface, or null if the application is not prepared.
        Throws:
        IllegalArgumentException - if a parameter is not accepted by the operating system.
        IllegalStateException - if a parameter cannot be applied by the operating system.
        SecurityException - if the service is not properly declared in AndroidManifest.xml.
        See Also:
        VpnService


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 3318 / . Delta: 0.03114 с