@@ -3,20 +3,17 @@ package tech.httptoolkit.android
33import android.net.VpnService
44import android.content.Intent
55import android.app.*
6+ import android.content.pm.PackageManager
67import android.graphics.BitmapFactory
78import android.os.Build
89import android.os.ParcelFileDescriptor
910import android.util.Log
1011import androidx.core.app.NotificationCompat
11- import androidx.core.app.ServiceCompat.stopForeground
1212import androidx.localbroadcastmanager.content.LocalBroadcastManager
1313import com.lipisoft.toyshark.socket.IProtectSocket
1414import com.lipisoft.toyshark.socket.SocketProtector
1515import io.sentry.Sentry
16- import io.sentry.android.AndroidSentryClientFactory
1716import java.io.*
18- import java.net.DatagramSocket
19- import java.net.Socket
2017
2118private const val ALL_ROUTES = " 0.0.0.0"
2219private const val VPN_IP_ADDRESS = " 169.254.61.43" // Random link-local IP, this will be the tunnel's IP
@@ -128,12 +125,28 @@ class ProxyVpnService : VpnService(), IProtectSocket {
128125 }
129126
130127 private fun startVpn (proxyConfig : ProxyConfig ) {
128+ val packages = packageManager.getInstalledApplications(PackageManager .GET_META_DATA )
129+
130+ val packageNames = packages.map { pkg -> pkg.packageName }
131+ val isGenymotion = packageNames.any {
132+ // This check could be stricter (com.genymotion.genyd), but right now it doesn't seem to
133+ // have any false positives, and it's very flexible to changes in genymotion itself.
134+ name -> name.startsWith(" com.genymotion" )
135+ }
136+
131137 if (vpnInterface == null ) {
132138 app!! .pauseEvents() // Try not to send events while the VPN is active, it's unnecessary noise
133139 app!! .trackEvent(" VPN" , " vpn-started" )
134140 vpnInterface = Builder ()
135141 .addAddress(VPN_IP_ADDRESS , 32 )
136142 .addRoute(ALL_ROUTES , 0 )
143+ .apply {
144+ // For some reason, with Genymotion the whole device crashes if we intercept
145+ // blindly, but intercepting every single application explicitly is fine.
146+ if (isGenymotion) {
147+ packageNames.forEach { name -> addAllowedApplication(name) }
148+ }
149+ }
137150 .setSession(getString(R .string.app_name))
138151 .establish()
139152
0 commit comments