From da341f48cc33e5495b6fb6a8f3b77e632b910ab7 Mon Sep 17 00:00:00 2001 From: consuelita Date: Mon, 3 Apr 2023 16:44:10 -0500 Subject: [PATCH] 1.0.6 - Broadcast Receiver for Plugins --- app/src/main/AndroidManifest.xml | 13 ++++--- moonbounceVPNService/build.gradle | 2 +- .../moonbouncevpnservice/MoonbounceKotlin.kt | 13 +++++-- .../MoonbouncePluginStatusReceiver.kt | 39 +++++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbouncePluginStatusReceiver.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2e7b538..7fc285b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,11 +13,13 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MoonbounceAndroidKotlin" > - - + + + + @@ -37,6 +39,7 @@ + \ No newline at end of file diff --git a/moonbounceVPNService/build.gradle b/moonbounceVPNService/build.gradle index e9d1af8..c69e538 100644 --- a/moonbounceVPNService/build.gradle +++ b/moonbounceVPNService/build.gradle @@ -32,7 +32,7 @@ android { dependencies { implementation 'androidx.core:core-ktx:1.8.0' implementation 'com.github.OperatorFoundation:FlowerAndroid:1.0.20' - implementation 'com.github.OperatorFoundation:TransmissionAndroid:1.1.0' + implementation 'com.github.OperatorFoundation:TransmissionAndroid:1.1.3' //implementation 'com.github.operatorfoundation:shapeshifterandroidkotlin:3.2.0' testImplementation 'junit:junit:4.13.2' diff --git a/moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbounceKotlin.kt b/moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbounceKotlin.kt index e1e67a3..76b5f10 100644 --- a/moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbounceKotlin.kt +++ b/moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbounceKotlin.kt @@ -1,12 +1,19 @@ package org.operatorfoundation.moonbouncevpnservice -import android.content.ComponentName -import android.content.Context -import android.content.Intent +import android.content.* class MoonbounceKotlin(val context: Context, var ipAddress: String, var serverPort: Int, var disallowedApp: String? = null, var excludeRoute: String? = null) { var vpnServiceIntent: Intent? = null + var vpnStatusReceiver: BroadcastReceiver + + init { + val filter = IntentFilter() + filter.addAction(MBAKVpnService.vpnStatusNotification) + vpnStatusReceiver = MoonbouncePluginStatusReceiver() + + context.registerReceiver(vpnStatusReceiver, filter) + } fun startVPN(): ComponentName? { diff --git a/moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbouncePluginStatusReceiver.kt b/moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbouncePluginStatusReceiver.kt new file mode 100644 index 0000000..f65d7c5 --- /dev/null +++ b/moonbounceVPNService/src/main/java/org/operatorfoundation/moonbouncevpnservice/MoonbouncePluginStatusReceiver.kt @@ -0,0 +1,39 @@ +package org.operatorfoundation.moonbouncevpnservice + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.widget.Toast + +class MoonbouncePluginStatusReceiver: BroadcastReceiver() +{ + override fun onReceive(context: Context, intent: Intent) + { + // This method is called when the BroadcastReceiver is receiving an Intent broadcast. + val statusString: String + + if (intent.action == MBAKVpnService.vpnStatusNotification) + { + if (intent.hasExtra(MBAKVpnService.VPN_CONNECTED_STATUS)) + { + val connected = intent.getBooleanExtra(MBAKVpnService.VPN_CONNECTED_STATUS, false) + + statusString = if (connected) { + "VPN connected." + } else { + "VPN failed to connect." + } + } + else + { + statusString = "Received a VPN connection notification that did not provide a status." + } + } + else + { + statusString = "Received an unknown notification: ${intent.action}" + } + + Toast.makeText(context, statusString, Toast.LENGTH_LONG).show() + } +} \ No newline at end of file