Class AndroidVpnService
- 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
Methods
CreateAdapter(VpnAdapterSettings, string?)
Makes the VPN adapter for a connection.
public IVpnAdapter CreateAdapter(VpnAdapterSettings adapterSettings, string? debugData)
Parameters
adapterSettingsVpnAdapterSettingsThe adapter's settings.
debugDatastringThe 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
intentIntentThe 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
Return the communication interface to the service. This method returns
null on Intents other than #SERVICE_INTERFACE
action. Applications overriding this method must identify the intent
and return the corresponding interface accordingly.
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.
Portions of this page are modifications based on work created and shared by the
OnRevoke()
Invoked when the application is revoked.
public override void OnRevoke()
Remarks
Invoked when the application is revoked. At this moment, the VPN
interface is already deactivated by the system. The application should
close the file descriptor and shut down gracefully. The default
implementation of this method is calling Service#stopSelf().
Calls to this method may not happen on the main thread of the process.
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
intentIntentThe 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.flagsStartCommandFlagsAdditional data about this start request.
startIdintA 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_MASKbits.
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:
Portions of this page are modifications based on work created and shared by the
ShowNotification(ConnectionInfo, CancellationToken)
Shows or updates the service's notification, where the platform has one.
public void ShowNotification(ConnectionInfo connectionInfo, CancellationToken cancellationToken)
Parameters
connectionInfoConnectionInfoThe connection's info.
cancellationTokenCancellationTokenThe 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.