Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

fix(screen): report the capture source on both paths, and drop the latch

booboosui27b4cfcd72c4
diff --git a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
index a86b98a..8840e7f 100644
--- a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
+++ b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
@@ -1335,10 +1335,13 @@ class BodyCoreService : Service() {
// service does not already claim `mediaProjection`, and adding the type
// is only legal while we are visible — which is now, by definition:
// this result came back from an Activity.
- captureWanted = true
- promoteForWhileInUse()
+ promoteWhileInUse(withCapture = true)
val started = if (::capture.isInitialized) capture.start(resultCode, data) else false
- if (!started) captureWanted = false
+ // Recomputed from what actually happened rather than remembered: if the
+ // platform refused the projection, the type we just claimed is one we
+ // are not entitled to and has to come off. The same call puts it back
+ // when a session is granted again, which Android 14 requires anyway.
+ promoteWhileInUse(withCapture = false)
postNotification()
return started
}
@@ -1545,20 +1548,6 @@ class BodyCoreService : Service() {
*/
private lateinit var capture: net.kuafuai.andee.screen.ScreenCapture
- /**
- * A capture consent has been granted, whether or not the projection is
- * built yet.
- *
- * Read by [whileInUseType] and separate from `capture.isAvailable()` for
- * one reason: the foreground service type has to be claimed *before*
- * `getMediaProjection` is called on Android 14, so there is a moment where
- * we are entitled to the type and do not yet hold a projection. Without
- * this the type would be added one step too late and the capture would be
- * refused on exactly the version that needs it most.
- */
- @Volatile
- private var captureWanted = false
-
/**
* Add every while-in-use type we are now entitled to.
*
@@ -1573,8 +1562,19 @@ class BodyCoreService : Service() {
* runtime in two independent directions: record permission revoked, or a
* capture consent that Android 14 makes per-session.
*/
- fun promoteForWhileInUse() {
- val type = whileInUseType() ?: return
+ fun promoteForWhileInUse() = promoteWhileInUse(withCapture = false)
+
+ /**
+ * @param withCapture claim `mediaProjection` even though no projection
+ * exists yet. Needed exactly once, at [offerScreenCapture]: Android 14
+ * refuses `getMediaProjection` to an app whose foreground service does
+ * not already carry the type, so there is a real moment where we must
+ * claim it ahead of holding it. Everywhere else the type follows
+ * availability, which is what keeps it from being claimed forever after a
+ * user stops the projection from the privacy chip.
+ */
+ private fun promoteWhileInUse(withCapture: Boolean) {
+ val type = whileInUseType(withCapture) ?: return
runCatching {
startForeground(NOTIFY_BODY, buildNotification(), type)
}.onFailure {
@@ -1582,14 +1582,14 @@ class BodyCoreService : Service() {
}
}
- private fun whileInUseType(): Int? {
+ private fun whileInUseType(withCapture: Boolean): Int? {
var t = 0
if (checkSelfPermission(android.Manifest.permission.RECORD_AUDIO) ==
android.content.pm.PackageManager.PERMISSION_GRANTED
) {
t = t or android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
}
- if (::capture.isInitialized && (captureWanted || capture.isAvailable())) {
+ if (withCapture || (::capture.isInitialized && capture.isAvailable())) {
t = t or android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
}
if (t == 0) return null
diff --git a/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt b/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt
index eca61e3..24ad6d5 100644
--- a/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt
+++ b/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt
@@ -359,17 +359,25 @@ object ToolSchemas {
[FALLBACK · REQUIRES A REASON] Capture the current screen as a PNG
(downscaled to 1280 on the long side — proportions preserved).
- Every screenshot arrives with an 8x12 AIM GRID drawn on it, labelled
- A1 (top-left) to H12 (bottom-right), each label printed at the CENTRE
- of its cell. This is the device's way of taking the arithmetic out of
- aiming: read the cell the target sits in and which third of it, and
- pass them straight to tap_by_coordinates as {"cell": "D7", "part":
- "bottom-right"} — no pixel measuring, no rescaling, nothing to get
- wrong. For anything not clearly bigger than a cell, first pass the
- same cell and part to zoom_screen_region: it shows a red crosshair
- where the tap would land, so you can confirm or re-aim off the
- magnified image (its grid is lowercase, and a lowercase label means
- "this was read off the zoom").
+ Every screenshot taken with accessibility on arrives with an 8x12 AIM
+ GRID drawn on it, labelled A1 (top-left) to H12 (bottom-right), each
+ label printed at the CENTRE of its cell. This is the device's way of
+ taking the arithmetic out of aiming: read the cell the target sits in
+ and which third of it, and pass them straight to tap_by_coordinates as
+ {"cell": "D7", "part": "bottom-right"} — no pixel measuring, no
+ rescaling, nothing to get wrong. For anything not clearly bigger than a
+ cell, first pass the same cell and part to zoom_screen_region: it shows
+ a red crosshair where the tap would land, so you can confirm or re-aim
+ off the magnified image (its grid is lowercase, and a lowercase label
+ means "this was read off the zoom").
+
+ **With accessibility off this is the one screen tool that still works**
+ (through MediaProjection, once the user has allowed it) — and then the
+ image arrives with NO grid, NO element list and no shot_id. Those three
+ all exist to aim a tap, and there are no taps on that path: every other
+ screen.* tool answers "accessibility is off". The response states which
+ way in it used (`source`); on "media_projection" you may describe what
+ you see and must not claim to have acted on it.
Every screenshot now arrives WITH the current element list attached
(`elements`, same e-numbers as get_screen_element) whenever the tree
diff --git a/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt b/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt
index 907c9f3..d9a4892 100644
--- a/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt
+++ b/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt
@@ -1699,6 +1699,13 @@ class ScreenController(
.put("width", w)
.put("height", h)
.put("bytes", bytes.size)
+ // Which way in this picture came through, named rather than
+ // implied. The other value is
+ // [ScreenCapture.SOURCE_MEDIA_PROJECTION], whose shots carry no
+ // aim grid and no element list — so "no `source` field" would
+ // have to mean "rich", and a third source later would silently
+ // inherit that meaning. Both are spelled out instead.
+ .put(ScreenCapture.SOURCE, ScreenCapture.SOURCE_ACCESSIBILITY)
// Lets the response the brain saw be matched to the file on
// disk. Absent when the log is off.
.also { if (shotId != null) it.put("shot_id", shotId) }