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 <noreply@anthropic.com>
This commit is contained in:
KoheiYamashita 2026-02-22 12:07:22 +09:00
parent d970fdd0b9
commit c839b0d658

View file

@ -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 {