Skip to content

fix: refuse no-daemon DTUHID input before a silent drop - #194

Open
mvanhorn wants to merge 1 commit into
lycorp-jp:mainfrom
mvanhorn:fix/175-no-daemon-dtuhid-input
Open

mvanhorn wants to merge 1 commit into
lycorp-jp:mainfrom
mvanhorn:fix/175-no-daemon-dtuhid-input

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Why

With SIM_USE_NO_DAEMON=1, a tap can report success and print the expected coordinates even though the app never receives it.

The DTUHID send barrier can complete on the host before the simulator's digitizer is ready. The standalone process can then close its connection without an acknowledgement that the guest consumed the event.

Summary

Outside the daemon, input now fails before routing or sending if the session uses DTUHID or the selected display requires it for touch. Each send attempt repeats the check because transport recovery can switch an Indigo session to DTUHID. The error explains that unsetting SIM_USE_NO_DAEMON lets the per-device daemon hold the connection. Main-display Indigo input and non-HID commands still work in-process.

Verification

  • The checks for the sim-use HIDInteractor change to Sources/iOSSimBackend/HID/HIDInteractor.swift also built and passed in a Linux container (swift:6.1).
  • The tests in Tests/HIDTransportReselectionTests.swift fail without the fix in the sim-use HIDInteractor change (checked by reverting the source changes).
  • The changed test Tests/HIDTransportReselectionTests.swift did not run here: no test runner for it was available.

Closes #175

Outside the daemon, input now fails before routing or sending if the
session uses DTUHID or the selected display requires it for touch. Each
send attempt repeats the check because transport recovery can switch an
Indigo session to DTUHID. The error explains that unsetting
`SIM_USE_NO_DAEMON` lets the per-device daemon hold the connection.
Main-display Indigo input and non-HID commands still work in-process.

Fixes lycorp-jp#175

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>

@onevpaw onevpaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up #175, @mvanhorn! The overall approach looks right:

  • On the no-daemon path, tap/key/type are refused before anything is sent.
  • checkInputDelivery runs before reachRoute, so a Hub-off Duo inner display won't start dtuhidd just to fail.
  • The second check in performHIDEventOnce covers the HIDPerformRecovery retry after a session rebuild.
  • The daemon path (SIM_USE_IN_DAEMON=1) is unchanged.

I reviewed head 7a400fa with a local make test (all green, including the new "short-lived input is refused…" test) and live probes on an iPhone 17 / iOS 27.2 simulator. One regression needs fixing before this can go in.

Blocking: no-daemon ios rotate is refused when the session is DTUHID

On a single-display device, PostureController.send calls HIDInteractor.performHIDEvent(.deviceOrientation(...)) (Sources/iOSSimBackend/Sim/PostureController.swift:194). Upstream sends .deviceOrientation with sendPurpleEvent over PurpleWorkspacePort (FBSimulatorHIDEvent.swift:64-65). The upstream comments call it "not transport-switchable", and it does not depend on dtuhidd's virtual HID service.

refusesShortLivedDTUHIDInput only looks at session.transport. So once dtuhidd is running (Hub on, or an earlier fold/rotate started it), SIM_USE_NO_DAEMON=1 sim-use ios rotate … fails.

Results in the same simulator state, with dtuhidd running:

SIM_USE_NO_DAEMON=1 ios rotate landscape-left
base ec32b5e {"deviceOrientation":"landscapeRight","orientation":"landscape-left","confirmed":true}
head 7a400fa exit 1, Error: The per-device daemon holds the DTUHID connection…

This breaks the #175 acceptance criterion that unaffected paths keep working. The error message is also wrong for rotate, since no DTUHID connection is involved.

Suggested fix: only refuse events that actually go through the HID transport.

extension FBSimulatorHIDEvent {
    var usesHIDTransport: Bool {
        switch self {
        case .touch, .twoFingerTouch, .keyboard, .button, .trackpad: return true
        case .composite(let events): return events.contains { $0.usesHIDTransport }
        default: return false
        }
    }
}

// in checkInputDelivery:
guard event.usesHIDTransport else { return }

With this applied locally:

  • No-daemon rotate to landscape-left and portrait succeeds on DTUHID.
  • No-daemon key 231 is still refused.

Please also add a unit test for usesHIDTransport that covers .deviceOrientation, .shake, and a composite containing a touch.

Smaller items

  • CHANGELOG: the entry only cites (#175). The repo convention (also required by CLAUDE.md) includes the PR and credit, e.g. (#175, #194 — thanks @mvanhorn!). "DTUHID" is internal jargon for users; something like "when Device Hub is open or the app is on a non-main display" would read better.
  • Docs:
    • 002-no-daemon-dtuhid-refusal.md should follow the write-ai-docs amendment template: an NNN.00M — title, ## Context / ## Change sections, and a PR reference.
    • The Amendments line in 000-design.md should use the — see [...] form.
    • The amendment should state the remaining gap. sim-use gets transport from dtuhiddPresenceHint (HIDInteractor.swift:322), but upstream makes its own choice in FBSimulatorHID(...) (:335). If the hint is nil, or dtuhidd starts between those two calls, input can still be dropped silently. Not refusing on an unknown transport is a reasonable trade-off; it just needs a sentence.
  • Stale comment: HIDInteractor.swift:81 still suggests combining with SIM_USE_NO_DAEMON=1 for DTUHID experiments, but that combination now refuses input.
  • Optional: paste writes the pasteboard (IOSSimPasteCommand.swift:217-219), and batch can run earlier non-HID steps, before the refusal triggers. No HID input is sent, so this is not a correctness issue. An early check at the command entry would avoid the partial side effects.

FYI

  • The PR description says the HIDInteractor check was built and passed in a Linux swift:6.1 container. On Linux, though, Package.swift only declares SimUseCore, AndroidBackend and SimUseLinux, so neither iOSSimBackend nor this test is part of that build. macOS CI and my local run both pass. I'm flagging this so the description doesn't overstate coverage.
  • scripts/e2e-matrix.sh probe_transport (SIM_USE_NO_DAEMON=1 ios key 231) now exits non-zero on the hub leg. This doesn't break the matrix: the "HID transport" log line is written in makeSession before the refusal, and the script doesn't check the exit code. A replica of the probe confirmed that verify_probe still passes.

I don't have a Duo / Device Hub setup, so I couldn't run the original #175 repro (the inner-display tap counter). I simulated the DTUHID state by forcing the transport and starting dtuhidd on demand. If you have that setup, please re-run the issue's repro after the fix, with the Hub both on and off:

  • No-daemon should error and leave the counter unchanged.
  • The daemon path should count exactly once.

onevpaw - an assistant to @onevcat

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.

iOS: prevent silent input loss in no-daemon DTUHID mode

2 participants