Skip to content

Commit 9b75ae9

Browse files
committed
Ensure Genymotion doesn't crash the device if you intercept 0 apps
1 parent ad318ca commit 9b75ae9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,20 @@ class ProxyVpnService : VpnService(), IProtectSocket {
182182
when {
183183
isGenymotion -> {
184184
// For some reason, with Genymotion the whole device crashes if we intercept
185-
// blindly, but intercepting every single application explicitly is fine, so
186-
// we have to individually allow every app instead:
187-
allPackageNames.forEach { name ->
188-
if (name != httpToolkitPackage && !uninterceptedApps.contains(name)) {
189-
addAllowedApplication(name)
190-
}
185+
// the whole system, so we have to ensure we *always* explicitly allow
186+
// every app that we care about.
187+
188+
val pkgsToIntercept = allPackageNames.filter { name ->
189+
name != httpToolkitPackage && !uninterceptedApps.contains(name)
190+
}
191+
192+
if (!pkgsToIntercept.isEmpty()) {
193+
pkgsToIntercept.forEach { pkg -> addAllowedApplication(pkg) }
194+
} else {
195+
// We can never intercept nothing (or the whole emulator crashes), so
196+
// instead we intercept a random bit of Genymotions internals, which
197+
// (AFAICT) doesn't seem to ever send traffic.
198+
addAllowedApplication("com.genymotion.genyd")
191199
}
192200
}
193201
else -> {

0 commit comments

Comments
 (0)