Skip to content

fix(clipboard): coordinate copy verifiably reaches the system clipboard (#92)#93

Merged
jfuginay merged 1 commit into
mainfrom
fix/92-clipboard-write
Jun 12, 2026
Merged

fix(clipboard): coordinate copy verifiably reaches the system clipboard (#92)#93
jfuginay merged 1 commit into
mainfrom
fix/92-clipboard-write

Conversation

@jfuginay

Copy link
Copy Markdown
Contributor

Closes #92.

Repro evidence (first — house rule: end-to-end reproducer before any fix)

Verdict: could NOT reproduce the failure. The original write path (LocalClipboardManager.setText(AnnotatedString), Compose BOM 2024.12.01 / ui 1.7.6 — LocalClipboardManager is not deprecated until 1.8, and the 1.7.6 bytecode confirms setTextsetPrimaryClip(ClipData.newPlainText(...))) lands a pasteable clip everywhere I could test, including the reporter's exact press-and-HOLD gesture.

Oracle 1 — instrumented tests (system-clipboard read-back via platform ClipboardManager)

Exercise the exact MapScreen path: composition-resolved manager, write from a clickable's onClick, including a 900 ms hold (past the long-press timeout) before release. Assert against the platform clipboard (text/plain MIME + exact item text + coerceToText), with a pre-seeded sentinel so a stale clipboard can't fake a pass.

Starting 2 tests on engie_emulator(AVD) - 16          # stock Android 16 / API 36
  composeManagerWrite_landsAsPlainTextInSystemClipboard  PASSED (2.38s)
  heldClickRelease_runsCopyBranch_andClipLands           PASSED (4.65s)

Starting 2 tests on SM-X210 - 16                      # Samsung One UI (Galaxy Tab A9+), real OEM clipboard manager
  composeManagerWrite_landsAsPlainTextInSystemClipboard  PASSED (2.21s)
  heldClickRelease_runsCopyBranch_andClipLands           PASSED (2.38s)

Oracle 2 — real app, real gesture, real third-party paste (adb drive on engie_emulator)

input swipe 540 900 540 900 700        # long-press map → radial opens
uiautomator: "Copy Coords" → [509,1105][572,1168]
input swipe 540 1136 540 1136 900      # press AND HOLD the Copy item 900 ms → release
→ snackbar: "Copied 39.24430, -123.15008"
→ Android system clipboard overlay appears with the same text (OS-level confirmation the clip landed)

am start -a android.intent.action.SENDTO -d smsto:5551234   # Google Messages = different uid
input keyevent 279                      # KEYCODE_PASTE into the compose field
uiautomator: EDITTEXT CONTENT: '39.24430, -123.15008'   ← exact match, cross-app

adb shell cmd clipboard get-primary-clip and dumpsys clipboard are both unavailable on API 36, so the platform read-back from a focused activity + the cross-app paste are the oracles.

Root cause

Not reproducible on stock API 36 or Samsung One UI 16 — the write path is correct on these targets. The one real defect that IS provable from the code: the success toast was unconditional over a void write API. ClipboardManager.setText returns nothing, so whatever happened on Gavin's device (OEM clipboard manager interference, a focus race, a ROM-side silent drop), the app claimed "Copied" without knowing.

The fix (hardening — pending device confirmation from the reporter)

  • CoordClipboard (new): writes via the platform ClipboardManager with ClipData.newPlainText, then reads the clip back and compares before reporting success. Never throws; OEM rejections and focus-blocked read-backs fail closed (wrongly admitting failure beats wrongly claiming success).
  • MapScreen radial copy branch: toast is now honest — map.toast.copied only when the read-back matches, new map.toast.copyFailed (en + zh-Hant) otherwise. If Gavin's device drops the write, he now gets a failure toast = a signal we can chase, instead of a lie.
  • ClipboardWriteInstrumentedTest: pins the write+verify contract and the held-click gesture on device. Re-ran post-fix: green on both emulator and SM-X210; full UI drive re-verified on the fixed build (verified toast + OS clipboard overlay + share sheet + cross-app paste into Messages all agree: 9.26736, -0.05022).

Verification

  • ./gradlew assembleDebug./gradlew testDebugUnitTest ✅ (CI parity)
  • connectedDebugAndroidTest (clipboard class): ✅ engie_emulator API 36, ✅ SM-X210 One UI 16
  • No manifest/permission changes; scope limited to the copy path

Follow-up for the reporter

If the failure persists on Gavin's device with this build, the new failure toast tells us the write is genuinely being rejected there — next ask: device model/ROM + whether a clipboard-manager/keyboard app is installed. If he still sees a success toast with nothing pasteable, the clip verifiably reached his system clipboard and something on-device is clearing it afterwards.

🤖 Generated with Claude Code

…efore claiming success (#92)

Field report (#92): radial "Copy Coords" shows the confirmation toast
but third-party apps paste nothing.

Repro first (house rule) — could NOT fault the original write path:
- Instrumented tests exercising the exact MapScreen path (composition-
  resolved LocalClipboardManager + setText(AnnotatedString), Compose
  BOM 2024.12.01 / ui 1.7.6) pass on stock API 36 (engie_emulator) and
  Samsung One UI 16 (SM-X210), including the reported press-and-HOLD-
  then-release gesture: the clip lands as text/plain, content intact
  per platform ClipboardManager read-back.
- Full UI drive of the real app (long-press map → radial → hold "Copy
  Coords" 900 ms → release) landed "39.24430, -123.15008" cross-app:
  KEYCODE_PASTE into Google Messages reproduced the exact text.

So this ships as hardening, pending device confirmation from the
reporter. The only seam left in the old path was an unconditional
success toast over a void write API. The copy branch now writes
through the platform ClipboardManager (ClipData.newPlainText) and
reads the clip back BEFORE toasting — "Copied" only when the read-back
matches, the new map.toast.copyFailed (en + zh-Hant) otherwise. An
OEM-side silent drop now surfaces as an honest failure (and gives us a
signal to chase) instead of lying to the operator.

- CoordClipboard: verified platform write; never throws — OEM
  rejections and focus-blocked read-backs fail closed
- MapScreen: radial copy branch gates the toast on the verified result
- ClipboardWriteInstrumentedTest: pins write+verify and the held-click
  gesture on device against the system clipboard third-party pastes
  coerce from

Verified: assembleDebug + testDebugUnitTest green (CI parity);
connectedDebugAndroidTest green on engie_emulator (API 36) and
SM-X210 (One UI 16); fixed build re-driven end-to-end — verified
toast, OS clipboard overlay, share sheet, and a cross-app paste all
agree on the same coordinate.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jfuginay jfuginay merged commit 7f9a7d2 into main Jun 12, 2026
1 check passed
jfuginay added a commit that referenced this pull request Jun 12, 2026
- versionName 0.35.4 -> 0.35.5, versionCode 92 -> 93
- carries #93 (coordinate copy verifies the system clipboard write and
  reports failure honestly, #92 — priority-client field report)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy coordinates: clipboard unpastable in third-party apps despite confirmation toast

1 participant