From c839b0d6587c269539f92dac0bf18310dc1e94d4 Mon Sep 17 00:00:00 2001 From: KoheiYamashita Date: Sun, 22 Feb 2026 12:07:22 +0900 Subject: [PATCH] fix: getCurrentPackage returns actual foreground app instead of own overlay rootInActiveWindow was returning PicoClaw's own overlay window, causing current_activity to always report PicoClaw as the foreground app. Now iterates service.windows to find the first TYPE_APPLICATION window that isn't our own package. Co-Authored-By: Claude Opus 4.6 --- .../io/picoclaw/android/assistant/DeviceController.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/io/picoclaw/android/assistant/DeviceController.kt b/android/app/src/main/java/io/picoclaw/android/assistant/DeviceController.kt index 456527641..0405c759b 100644 --- a/android/app/src/main/java/io/picoclaw/android/assistant/DeviceController.kt +++ b/android/app/src/main/java/io/picoclaw/android/assistant/DeviceController.kt @@ -55,7 +55,13 @@ class DeviceController { } fun getCurrentPackage(): String? { - return service?.rootInActiveWindow?.packageName?.toString() + val svc = service ?: return null + val ownPackage = svc.packageName + // Skip our own overlay window and find the actual foreground app + return svc.windows + .filter { it.type == android.view.accessibility.AccessibilityWindowInfo.TYPE_APPLICATION } + .firstOrNull { it.root?.packageName?.toString() != ownPackage } + ?.root?.packageName?.toString() } suspend fun inputText(text: String): Boolean {