Disallow some problematic app from the VPN (#126)

This commit is contained in:
John Maguire 2023-05-15 17:10:20 -04:00 committed by GitHub
parent f7a7093879
commit cfca253ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.net.*
import android.os.*
import android.system.OsConstants
@ -115,6 +116,15 @@ class NebulaVpnService : VpnService() {
builder.setMetered(false)
}
// Disallow some common, known-problematic apps
// TODO Make this user configurable
// Android Auto Wireless (https://github.com/DefinedNet/mobile_nebula/issues/102)
disallowApp(builder, "com.google.android.projection.gearhead")
// Chromecast (https://github.com/DefinedNet/mobile_nebula/issues/102)
disallowApp(builder, "com.google.android.apps.chromecast.app")
// RCS / Jibe
disallowApp(builder, "com.google.android.apps.messaging")
// Add our unsafe routes
site!!.unsafeRoutes.forEach { unsafeRoute ->
val unsafeIPNet = mobileNebula.MobileNebula.parseCIDR(unsafeRoute.route)
@ -142,6 +152,15 @@ class NebulaVpnService : VpnService() {
sendSimple(MSG_IS_RUNNING, 1)
}
private fun disallowApp(builder: Builder, name: String) {
try {
builder.addDisallowedApplication(name)
} catch (e: PackageManager.NameNotFoundException) {
return
}
}
// Used to detect network changes (wifi -> cell or vice versa) and rebinds the udp socket/updates LH
private fun registerNetworkCallback() {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager