Skip to content

Commit

Permalink
1.0.6 - Broadcast Receiver for Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
consuelita committed Apr 3, 2023
1 parent 59dc61a commit da341f4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
13 changes: 8 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MoonbounceAndroidKotlin" >
<receiver
android:name="org.operatorfoundation.moonbounceAndroidKotlin.StatusReceiver"
android:enabled="true"
android:exported="true">
</receiver>

<receiver
android:name="org.operatorfoundation.moonbounceAndroidKotlin.StatusReceiver"
android:enabled="true"
android:exported="true">
</receiver>

<activity
android:name=".MainActivity"
android:exported="true" >
Expand All @@ -37,6 +39,7 @@
<action android:name="android.net.VpnService" />
</intent-filter>
</service>

</application>

</manifest>
2 changes: 1 addition & 1 deletion moonbounceVPNService/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit da341f4

Please sign in to comment.