@@ -3,20 +3,17 @@ package tech.httptoolkit.android
3
3
import android.net.VpnService
4
4
import android.content.Intent
5
5
import android.app.*
6
+ import android.content.pm.PackageManager
6
7
import android.graphics.BitmapFactory
7
8
import android.os.Build
8
9
import android.os.ParcelFileDescriptor
9
10
import android.util.Log
10
11
import androidx.core.app.NotificationCompat
11
- import androidx.core.app.ServiceCompat.stopForeground
12
12
import androidx.localbroadcastmanager.content.LocalBroadcastManager
13
13
import com.lipisoft.toyshark.socket.IProtectSocket
14
14
import com.lipisoft.toyshark.socket.SocketProtector
15
15
import io.sentry.Sentry
16
- import io.sentry.android.AndroidSentryClientFactory
17
16
import java.io.*
18
- import java.net.DatagramSocket
19
- import java.net.Socket
20
17
21
18
private const val ALL_ROUTES = " 0.0.0.0"
22
19
private 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 {
128
125
}
129
126
130
127
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
+
131
137
if (vpnInterface == null ) {
132
138
app!! .pauseEvents() // Try not to send events while the VPN is active, it's unnecessary noise
133
139
app!! .trackEvent(" VPN" , " vpn-started" )
134
140
vpnInterface = Builder ()
135
141
.addAddress(VPN_IP_ADDRESS , 32 )
136
142
.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
+ }
137
150
.setSession(getString(R .string.app_name))
138
151
.establish()
139
152
0 commit comments