@@ -34,8 +34,9 @@ const val EXCLUDE_ROUTES = "ExcludeRoute"
3434const val USE_PLUGGABLE_TRANSPORTS = " UsePluggableTransports"
3535const val STOP_VPN_ACTION = " StopMoonbounce"
3636const val START_VPN_ACTION = " StartMoonbounce"
37+ const val APP_PACKAGE = " CallingActivityClass"
3738
38- class MBAKVpnService : VpnService ()
39+ class MBAKVpnService () : VpnService()
3940{
4041 val sizeInBits = 32
4142 val maxBatchSize = 250 // bytes
@@ -61,6 +62,10 @@ class MBAKVpnService : VpnService()
6162 private var disallowedApps: Array <String >? = null
6263 private var excludeRoutes: Array <String >? = null
6364
65+ // Needed to create an explicit intent for broadcasting status to an explicit application package name
66+ // Defaults to the example app, pass your package name in as an extra in the VPN intent to override this
67+ private var applicationPackageName: String = " org.operatorfoundation.moonbounceAndroidKotlin"
68+
6469 companion object
6570 {
6671 const val vpnStatusNotification = " org.operatorfoundation.moonbounceAndroidKotlin.VPNStatusNotification"
@@ -325,6 +330,7 @@ class MBAKVpnService : VpnService()
325330 val maybeDisallowedApps: Array <String >?
326331 val maybeExcludeRoutes: Array <String >?
327332 val maybeUsePluggableTransports: Boolean
333+ val maybeApplicationPackage: String?
328334
329335 if (intent != null )
330336 {
@@ -334,6 +340,8 @@ class MBAKVpnService : VpnService()
334340 maybeDisallowedApps = intent.getStringArrayExtra(DISALLOWED_APPS )
335341 maybeExcludeRoutes = intent.getStringArrayExtra(EXCLUDE_ROUTES )
336342 maybeUsePluggableTransports = intent.getBooleanExtra(USE_PLUGGABLE_TRANSPORTS , false )
343+ maybeApplicationPackage = intent.getStringExtra(APP_PACKAGE )
344+
337345 this .usePluggableTransport = maybeUsePluggableTransports
338346 }
339347 else
@@ -376,6 +384,11 @@ class MBAKVpnService : VpnService()
376384 excludeRoutes = maybeExcludeRoutes
377385 }
378386
387+ if (maybeApplicationPackage != null )
388+ {
389+ applicationPackageName = maybeApplicationPackage
390+ }
391+
379392 return true
380393 }
381394
@@ -413,6 +426,7 @@ class MBAKVpnService : VpnService()
413426 fun broadcastStatus (action : String , statusDescription : String , status : Boolean )
414427 {
415428 val intent = Intent ()
429+ intent.setPackage(applicationPackageName)
416430 intent.putExtra(statusDescription, status)
417431 intent.action = action
418432 sendBroadcast(intent)
0 commit comments