Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
refactor: remove VPN firewall service and associated tool definitions and UI permissions
Rishabh Bajpai781048cffed7
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xmlindex 72fe24d..ae7e07e 100644--- a/app/src/main/AndroidManifest.xml+++ b/app/src/main/AndroidManifest.xml@@ -155,16 +155,6 @@</intent-filter></service>- <!-- Tier 3: VpnService — local kill-switch firewall (blocks all traffic; user consents once). -->- <service- android:name=".service.GotchaVpnService"- android:exported="false"- android:label="@string/app_name"- android:permission="android.permission.BIND_VPN_SERVICE">- <intent-filter>- <action android:name="android.net.VpnService" />- </intent-filter>- </service><!-- Scheduled SMS delivery receiver --><receiverdiff --git a/app/src/main/java/com/gotcha/agent/AgentEngine.kt b/app/src/main/java/com/gotcha/agent/AgentEngine.ktindex 3f5d016..d083ecd 100644--- a/app/src/main/java/com/gotcha/agent/AgentEngine.kt+++ b/app/src/main/java/com/gotcha/agent/AgentEngine.kt@@ -447,7 +447,9 @@ class AgentEngine(val roundToolResults = history.drop(historySizeBeforeTools).filter { it.role == "tool" }.joinToString("\n") { it.textContent }- val roundSignature = toolCalls.joinToString(",") { "${it.function.name}:${it.function.arguments}" } + "|" + roundToolResults+ val roundSignature = toolCalls.joinToString(",") {+ "${it.function.name}:${it.function.arguments}"+ } + "|" + roundToolResultsif (roundSignature == lastRoundSignature) {repeatedRoundCount++if (repeatedRoundCount >= MAX_REPEATED_TOOL_ROUNDS) {@@ -774,7 +776,7 @@ class AgentEngine("You are in MONITOR (read-only) mode. You are STRICTLY FORBIDDEN from making " +"any changes to the device — no writing files, no calling, no sending messages, " +"no dismissing notifications, no UI automation (tap/swipe/input), no device " +- "admin actions, no firewall changes, and no shell/root commands. You may ONLY " ++ "admin actions, and no shell/root commands. You may ONLY " +"inspect, list, read, and observe. This constraint overrides all other instructions.\n" +"</system-reminder>"AgentMode.OPERATOR ->diff --git a/app/src/main/java/com/gotcha/service/GotchaVpnService.kt b/app/src/main/java/com/gotcha/service/GotchaVpnService.ktdeleted file mode 100644index 5450be1..0000000--- a/app/src/main/java/com/gotcha/service/GotchaVpnService.kt+++ /dev/null@@ -1,120 +0,0 @@-package com.gotcha.service--import android.content.Intent-import android.net.VpnService-import android.os.ParcelFileDescriptor-import java.io.FileInputStream--/**- * Tier 3 — VpnService.- *- * A **local kill-switch firewall**: it establishes a tun interface that routes *all*- * device traffic into this app and then discards every packet, so nothing reaches the- * network. There is no remote server and no packet inspection — traffic is simply- * black-holed while the tunnel is up, which is the classic no-server VpnService use- * (an on-device "block all internet" switch).- *- * Unlike the other Tier 3 components, the enable step is gated by the system VPN consent- * dialog rather than a Settings toggle: [android.net.VpnService.prepare] returns a consent- * Intent the UI must launch once. After the user consents, [VpnTool] starts this service.- *- * The service exposes a static [isRunning] flag so the stateless [com.gotcha.tools.VpnTool]- * can report status without holding a binding.- */-class GotchaVpnService : VpnService() {-- private var vpnInterface: ParcelFileDescriptor? = null- private var worker: Thread? = null-- override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {- return when (intent?.action) {- ACTION_STOP -> {- teardown()- stopSelf()- START_NOT_STICKY- }- else -> {- establish()- START_STICKY- }- }- }-- /** Bring up the tun interface routing everything into this app (then drop it). */- private fun establish() {- if (vpnInterface != null) return- val builder = Builder()- .setSession("Gotcha Firewall")- .addAddress("10.0.0.2", 32)- .addRoute("0.0.0.0", 0)- // Also swallow IPv6 where the device supports it, so v6 traffic can't leak past- // the block. Guarded because some devices reject an IPv6 config outright.- try {- builder.addAddress("fd00::2", 128).addRoute("::", 0)- } catch (_: Exception) {- // IPv6 not available; IPv4 block still applies.- }-- vpnInterface = try {- builder.establish()- } catch (_: Exception) {- null- }- isRunning = vpnInterface != null-- // Drain and discard packets so the tun buffer doesn't back up. Reading blocks- // until a packet arrives; we never write anything back, so nothing is forwarded.- vpnInterface?.let { pfd ->- worker = Thread {- val input = FileInputStream(pfd.fileDescriptor)- val buffer = ByteArray(MAX_PACKET)- try {- while (!Thread.interrupted()) {- if (input.read(buffer) < 0) break- }- } catch (_: Exception) {- // Interface closed on teardown; exit the loop.- }- }.apply {- isDaemon = true- start()- }- }- }-- private fun teardown() {- worker?.interrupt()- worker = null- try {- vpnInterface?.close()- } catch (_: Exception) {- // Already closed.- }- vpnInterface = null- isRunning = false- }-- /** The user revoked the VPN from system settings / another VPN took over. */- override fun onRevoke() {- teardown()- stopSelf()- super.onRevoke()- }-- override fun onDestroy() {- teardown()- super.onDestroy()- }-- companion object {- const val ACTION_START = "com.gotcha.vpn.START"- const val ACTION_STOP = "com.gotcha.vpn.STOP"-- private const val MAX_PACKET = 32_767-- /** True while the blocking tunnel is established; false otherwise. */- @Volatile- var isRunning: Boolean = false- private set- }-}diff --git a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt b/app/src/main/java/com/gotcha/tools/ToolDefinitions.ktindex d73d48c..bae5fc9 100644--- a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt+++ b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt@@ -1645,31 +1645,6 @@ object ToolDefinitions {})- // ---- Tier 3 addition: VpnService (local traffic firewall) ------ val setFirewall = tool(- "set_firewall",- "Enable or disable a local VPN that blocks ALL device network traffic — an on-device " +- "internet kill-switch. Nothing is inspected or sent anywhere; while it is on, every " +- "packet is dropped so no app can reach the network. Enabling needs a one-time system " +- "VPN consent the first time.",- schema {- putJsonObject("properties") {- putJsonObject("enabled") {- put("type", "boolean")- put("description", "true to block all network traffic, false to restore connectivity.")- }- }- putJsonArray("required") { add("enabled") }- }- )-- val getFirewallStatus = tool(- "get_firewall_status",- "Report whether the local traffic-blocking VPN firewall is currently on or off.",- schema { putJsonObject("properties") {} }- )-// ---- Tier 4 additions (privileged / rooted execution) ----val checkRoot = tool(@@ -1758,8 +1733,7 @@ object ToolDefinitions {readNotifications, dismissNotifications, mediaControl,showOverlay, hideOverlay,lockScreen, disableCamera, setPasswordPolicy,- // Tier 3 addition: VpnService firewall- setFirewall, getFirewallStatus,+// Tier 4 additions: privileged / rooted executioncheckRoot, runRootCommand, writeSecureSettings)diff --git a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt b/app/src/main/java/com/gotcha/tools/ToolExecutor.ktindex b698325..82ec249 100644--- a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt+++ b/app/src/main/java/com/gotcha/tools/ToolExecutor.kt@@ -58,7 +58,6 @@ class ToolExecutor(private val notificationTool = NotificationTool(appContext)private val overlayTool = OverlayTool(appContext)private val deviceAdminTool = DeviceAdminTool(appContext)- private val vpnTool = VpnTool(appContext)// Tier 4 toolsprivate val rootTool = RootTool()@@ -441,10 +440,7 @@ class ToolExecutor("set_password_policy" -> deviceAdminTool.setPasswordPolicy(args.requireInt("min_length") ?: return missing("min_length"))- "set_firewall" -> vpnTool.setFirewall(- args["enabled"]?.jsonPrimitive?.booleanOrNull ?: return missing("enabled")- )- "get_firewall_status" -> vpnTool.getFirewallStatus()+// ---- Tier 4 ----"check_root" -> rootTool.checkRoot()"run_root_command" -> rootTool.runRootCommand(args.requireString("command") ?: return missing("command"))diff --git a/app/src/main/java/com/gotcha/tools/ToolRegistry.kt b/app/src/main/java/com/gotcha/tools/ToolRegistry.ktindex 6d589b2..05d047d 100644--- a/app/src/main/java/com/gotcha/tools/ToolRegistry.kt+++ b/app/src/main/java/com/gotcha/tools/ToolRegistry.kt@@ -38,7 +38,6 @@ object ToolRegistry {"websearch", "webfetch","get_clipboard","read_screen", "read_notifications",- "get_firewall_status","check_root")diff --git a/app/src/main/java/com/gotcha/tools/VpnTool.kt b/app/src/main/java/com/gotcha/tools/VpnTool.ktdeleted file mode 100644index 63c8483..0000000--- a/app/src/main/java/com/gotcha/tools/VpnTool.kt+++ /dev/null@@ -1,57 +0,0 @@-package com.gotcha.tools--import android.content.Context-import android.content.Intent-import android.net.VpnService-import com.gotcha.service.GotchaVpnService--/**- * Tier 3 — controls the [GotchaVpnService] local kill-switch firewall.- *- * Enabling needs the one-time system VPN consent: [VpnService.prepare] returns a consent- * Intent when the user has not authorized a VPN for this app. In that case the tool returns- * the [ToolResult.VPN_CONSENT] marker so `MainActivity` can launch the consent dialog, matching- * the "grant, then ask again" flow used by the other special-access tools. Once consent is on- * record, `prepare` returns null and the tool starts/stops the service.- */-class VpnTool(private val context: Context) {-- /** Turn the traffic-blocking VPN on ([enabled] = true) or off (false). */- fun setFirewall(enabled: Boolean): ToolResult {- if (!enabled) {- if (!GotchaVpnService.isRunning) return ToolResult.ok("The network firewall is already off.")- context.startService(stopIntent())- return ToolResult.ok("Network firewall disabled — traffic can flow normally again.")- }-- // Enabling: check we hold VPN consent first.- val consent = VpnService.prepare(context)- if (consent != null) {- return ToolResult.permissionNeeded(- ToolResult.VPN_CONSENT,- "Blocking network traffic needs your one-time VPN permission. I have opened the " +- "system consent dialog — please allow it for Gotcha and ask again."- )- }- context.startService(startIntent())- return ToolResult.ok(- "Network firewall enabled — a local VPN is now blocking ALL device network traffic " +- "(nothing is inspected or sent anywhere). Ask me to disable it to restore connectivity."- )- }-- /** Report whether the blocking VPN is currently up. */- fun getFirewallStatus(): ToolResult = ToolResult.ok(- if (GotchaVpnService.isRunning) {- "The network firewall is ON — all traffic is blocked."- } else {- "The network firewall is OFF — traffic flows normally."- }- )-- private fun startIntent() =- Intent(context, GotchaVpnService::class.java).setAction(GotchaVpnService.ACTION_START)-- private fun stopIntent() =- Intent(context, GotchaVpnService::class.java).setAction(GotchaVpnService.ACTION_STOP)-}diff --git a/app/src/main/java/com/gotcha/ui/PermissionItems.kt b/app/src/main/java/com/gotcha/ui/PermissionItems.ktindex 37186b4..d2a5595 100644--- a/app/src/main/java/com/gotcha/ui/PermissionItems.kt+++ b/app/src/main/java/com/gotcha/ui/PermissionItems.kt@@ -207,8 +207,8 @@ fun allPermissionGroups(): List<PermissionGroup> = listOf(}),PermissionItem(- "Device Admin",- "Lock screen, enforce password policy",+ "Device Admin (Optional)",+ "DANGEROUS: Lock screen, enforce password policy. Only enable if you really need these.",null,"special:device_admin",{ c ->@@ -253,26 +253,6 @@ fun allPermissionGroups(): List<PermissionGroup> = listOf(null,"special:overlay_access",{ c -> Settings.canDrawOverlays(c) }- ),- PermissionItem(- "VPN",- "Block all network traffic (firewall kill-switch)",- null,- "special:vpn_consent",- { c ->- try {- val cm = c.getSystemService(Context.CONNECTIVITY_SERVICE) as? android.net.ConnectivityManager- cm?.let { mgr ->- val network = mgr.activeNetwork- if (network != null) {- mgr.getNetworkCapabilities(network)- ?.hasTransport(android.net.NetworkCapabilities.TRANSPORT_VPN) ?: false- } else {- false- }- } ?: false- } catch (_: SecurityException) { false }- })))diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.ktindex 2933b92..3be2765 100644--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt@@ -313,8 +313,8 @@ fun SettingsScreen(}ExposedDropdownMenuBox(expanded = modelExpanded,- onExpandedChange = {- modelExpanded = it+ onExpandedChange = {+ modelExpanded = itif (it) refreshChatModelsAction()}) {@@ -362,8 +362,8 @@ fun SettingsScreen(}ExposedDropdownMenuBox(expanded = subAgentModelExpanded,- onExpandedChange = {- subAgentModelExpanded = it+ onExpandedChange = {+ subAgentModelExpanded = itif (it) refreshChatModelsAction()}) {@@ -410,7 +410,7 @@ fun SettingsScreen(}ExposedDropdownMenuBox(expanded = navigatorModelExpanded,- onExpandedChange = {+ onExpandedChange = {navigatorModelExpanded = itif (it) refreshChatModelsAction()}@@ -580,8 +580,8 @@ fun SettingsScreen()ExposedDropdownMenuBox(expanded = ttsModelExpanded,- onExpandedChange = {- ttsModelExpanded = it+ onExpandedChange = {+ ttsModelExpanded = itif (it) refreshAudioModelsAction()}) {@@ -602,7 +602,9 @@ fun SettingsScreen(onDismissRequest = { ttsModelExpanded = false }) {DropdownMenuItem(- text = { Text(if (refreshingModels) "Refreshing…" else "🔄 Refresh audio models…") },+ text = {+ Text(if (refreshingModels) "Refreshing…" else "🔄 Refresh audio models…")+ },onClick = { refreshAudioModelsAction() })if (availableTtsModels.isEmpty()) {@@ -662,8 +664,8 @@ fun SettingsScreen()ExposedDropdownMenuBox(expanded = sttModelExpanded,- onExpandedChange = {- sttModelExpanded = it+ onExpandedChange = {+ sttModelExpanded = itif (it) refreshAudioModelsAction()}) {@@ -684,7 +686,9 @@ fun SettingsScreen(onDismissRequest = { sttModelExpanded = false }) {DropdownMenuItem(- text = { Text(if (refreshingModels) "Refreshing…" else "🔄 Refresh audio models…") },+ text = {+ Text(if (refreshingModels) "Refreshing…" else "🔄 Refresh audio models…")+ },onClick = { refreshAudioModelsAction() })if (availableSttModels.isEmpty()) {