Skip to content

Commit

Permalink
Java Wrapper for VPN Service
Browse files Browse the repository at this point in the history
  • Loading branch information
consuelita committed Feb 9, 2023
1 parent 5964573 commit 5d02888
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,5 @@ package org.operatorfoundation.moonbouncevpnservice

class CapacitorPlugin
{
fun startVPN()
{

}

fun stopVPN()
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.operatorfoundation.moonbouncevpnservice;

import android.content.Context;

public class MoonbounceJava
{
MoonbounceKotlin moonbounceKotlin;

public MoonbounceJava(Context context, String serverIP, Integer serverPort, String disallowedApp, String excludeIP)
{
moonbounceKotlin = new MoonbounceKotlin(context, serverIP, serverPort, disallowedApp, excludeIP);
}
public void startVPN()
{
moonbounceKotlin.startVPN();
}

public void stopVPN()
{
moonbounceKotlin.stopVPN();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.operatorfoundation.moonbouncevpnservice

import android.content.Context
import android.content.Intent

class MoonbounceKotlin(val context: Context, var ipAddress: String, var serverPort: Int, var disallowedApp: String? = null, var excludeRoute: String? = null)
{
var vpnServiceIntent: Intent? = null

fun startVPN()
{
if (vpnServiceIntent == null)
{
vpnServiceIntent = Intent(context, MBAKVpnService::class.java)
}

println("MainActivity Server IP Address: $ipAddress")
println("MainActivity Server Port: $serverPort")
println("MainActivity Disallowed App: $disallowedApp")
println("MainActivity Exclude Route: $excludeRoute")

vpnServiceIntent!!.putExtra(SERVER_IP, ipAddress)
vpnServiceIntent!!.putExtra(SERVER_PORT, serverPort)

if (!disallowedApp.isNullOrEmpty())
{
vpnServiceIntent!!.putExtra(DISALLOWED_APP, disallowedApp)
}

if (!excludeRoute.isNullOrEmpty())
{
vpnServiceIntent!!.putExtra(EXCLUDE_ROUTE, excludeRoute)
}

// Start the VPN Service
context.startService(vpnServiceIntent)
}

fun stopVPN()
{
context.stopService(vpnServiceIntent)
}
}

0 comments on commit 5d02888

Please sign in to comment.