Table of Contents

Class AndroidVpnService

Namespace
VpnHood.Core.Client.VpnServices.Host.Android
Assembly
VpnHood.Core.Client.VpnServices.Host.Android.dll

Represents the VPN service on Android: Android's own VpnService, which runs the VPN service's host, in a process of its own in Release builds, shows its notification, and answers the app over a binder.

[Service(Name = "crc64198439f88d18e1a7.AndroidVpnService", Process = ":vpnhood_process", Permission = "android.permission.BIND_VPN_SERVICE", Exported = false, ForegroundServiceType = ForegroundService.TypeSystemExempted)]
[IntentFilter(new string[] { "android.net.VpnService" })]
public class AndroidVpnService : VpnService, IComponentCallbacks2, IComponentCallbacks, IJavaObject, IJavaPeerable, IDisposable, IVpnServiceHandler
Inheritance
AndroidVpnService
Implements
Inherited Members

Remarks

The app starts it to connect, and Android starts it by itself for always-on; it promotes itself to the foreground at once, as Android requires, and a refused promotion ends the start. The app reaches it by its Java name (VpnServiceJavaName).

Constructors

AndroidVpnService()

Initializes a new instance of the AndroidVpnService class, as Android makes it.

public AndroidVpnService()

Properties

CanReconnect

Gets a value indicating whether the service may connect again by itself, with no start from the app or the system: false where only the system's start may bring an adapter up.

public bool CanReconnect { get; }

Property Value

bool

Methods

CreateAdapter(VpnAdapterSettings, string?)

Makes the VPN adapter for a connection.

public IVpnAdapter CreateAdapter(VpnAdapterSettings adapterSettings, string? debugData)

Parameters

adapterSettings VpnAdapterSettings

The adapter's settings.

debugData string

The developer's debug switches (DebugData1), or null.

Returns

IVpnAdapter

The adapter, which the client disposes with itself where AutoDisposeVpnAdapter says so, the default.

Remarks

It is AndroidTun's, on this service.

Exceptions

InvalidOperationException

Windows has given the VPN plug-in no channel yet.

ArgumentOutOfRangeException

The settings' queue capacity is less than 1.

CreateClientFactory()

Names the factory that builds the VpnHoodClient for each connection. Return VpnHoodClientFactory for the default composition, or a derived factory to replace a single piece (filters, proxy connector, tracker). The host calls this per connection and keeps ownership of the created client (state wiring and dispose) — the factory must not hold a reference to it.

public VpnHoodClientFactory CreateClientFactory()

Returns

VpnHoodClientFactory

The factory.

Remarks

It is the default one.

OnBind(Intent?)

Return the communication interface to the service.

public override IBinder? OnBind(Intent? intent)

Parameters

intent Intent

The Intent that was used to bind to this service, as given to M:Android.Content.Context.BindService(Android.Content.Intent,Android.Content.IServiceConnection,Android.Content.IServiceConnection). Note that any extras that were included with the Intent at that point will not be seen here.

Returns

IBinder

To be added.

Remarks

OnDestroy()

Called by the system to notify a Service that it is no longer used and is being removed.

public override void OnDestroy()

Remarks

Called by the system to notify a Service that it is no longer used and is being removed. The service should clean up any resources it holds (threads, registered receivers, etc) at this point. Upon return, there will be no more calls in to this Service object and it is effectively dead. Do not call this method directly.

Android reference for

    <pre><code class="lang-csharp">android.app.Service.onDestroy</code></pre>

    .</a>
</format>

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

OnRevoke()

Invoked when the application is revoked.

public override void OnRevoke()

Remarks

OnStartCommand(Intent?, StartCommandFlags, int)

Called by the system every time a client explicitly starts the service by calling android.content.Context#startService, providing the arguments it supplied and a unique integer token representing the start request.

public override StartCommandResult OnStartCommand(Intent? intent, StartCommandFlags flags, int startId)

Parameters

intent Intent

The Intent supplied to android.content.Context#startService, as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except #START_STICKY_COMPATIBILITY.

flags StartCommandFlags

Additional data about this start request.

startId int

A unique integer representing this specific request to start. Use with #stopSelfResult(int).

Returns

StartCommandResult

The return value indicates what semantics the system should use for the service's current started state. It may be one of the constants associated with the #START_CONTINUATION_MASK bits.

Remarks

Called by the system every time a client explicitly starts the service by calling Context.startService(Intent), providing the arguments it supplied and a unique integer token representing the start request. Do not call this method directly. For backwards compatibility, the default implementation calls onStart(Intent, int) and returns either START_STICKY or START_STICKY_COMPATIBILITY. Note that the system calls this on your service's main thread. A service's main thread is the same thread where UI operations take place for Activities running in the same process. You should always avoid stalling the main thread's event loop. When doing long-running operations, network calls, or heavy disk I/O, you should kick off a new thread, or use AsyncTask.

See also:

Android reference for

    <pre><code class="lang-csharp">android.app.Service.onStartCommand</code></pre>

    .</a>
</format>

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

ShowNotification(ConnectionInfo, CancellationToken)

Shows or updates the service's notification, where the platform has one.

public void ShowNotification(ConnectionInfo connectionInfo, CancellationToken cancellationToken)

Parameters

connectionInfo ConnectionInfo

The connection's info.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Remarks

It shows the state in the foreground notification, promoting the service first where it is not yet; a refused promotion is logged.

StopNotification()

Removes the service's notification, where the platform has one.

public void StopNotification()

Remarks

It takes the service out of the foreground and removes its notification.