Skip to content

Commit 3845957

Browse files
committed
Fix interception on Genymotion
1 parent dbfd4f7 commit 3845957

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ package tech.httptoolkit.android
33
import android.net.VpnService
44
import android.content.Intent
55
import android.app.*
6+
import android.content.pm.PackageManager
67
import android.graphics.BitmapFactory
78
import android.os.Build
89
import android.os.ParcelFileDescriptor
910
import android.util.Log
1011
import androidx.core.app.NotificationCompat
11-
import androidx.core.app.ServiceCompat.stopForeground
1212
import androidx.localbroadcastmanager.content.LocalBroadcastManager
1313
import com.lipisoft.toyshark.socket.IProtectSocket
1414
import com.lipisoft.toyshark.socket.SocketProtector
1515
import io.sentry.Sentry
16-
import io.sentry.android.AndroidSentryClientFactory
1716
import java.io.*
18-
import java.net.DatagramSocket
19-
import java.net.Socket
2017

2118
private const val ALL_ROUTES = "0.0.0.0"
2219
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 {
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

Comments
 (0)