fix(phase-1/m2.4b): encrypted imports were a silent no-op on-device

Manual Waydroid pass (phone exports encrypted -> re-imports the same
file through the real UI) caught it: the confirm dialog closed but no
import ran and no snackbar appeared. PassphraseDialog.onConfirm's
shared preamble nulls all URI slots before routing on mode, and the
IMPORT branch never re-armed pendingImportUri -- so the preview
confirm dialog's Import button read null and skipped viewModel.import
entirely. Plain-JSON imports bypass the passphrase dialog, which is
why every scripted desktop leg (M2.1-2.5) stayed green.

Fix: re-arm pendingImportUri in the IMPORT branch before preview;
wrong-pw/dismiss paths still null it and zero the retained chars.

Verified on-device after rebuild + `waydroid app install`: export
snackbar, magic-sniffed "Decrypt backup" sheet, 4-note preview, and
the dedupe snackbar "Imported 0 note(s), skipped 4 already imported."

Also lands the Waydroid test rig used for the pass (tools/WAYDROID_
TESTING.md + tools/inject2.c: uinput tap/move/key/text/swipe injector)
and the full M2.4b write-up in DESKTOP_FEASIBILITY.md. M2 exit
criteria met: bidirectional lossless round-trip plain+encrypted.
This commit is contained in:
Incido Developer committed 2026-10-06 05:40:44 +13:00
1 parent 29288b0370
commit 561d16eb0c
4 files changed
+412

No files matched your search

@@ -410,6 +410,13 @@ fun SettingsScreen(
// the app.
pendingImportPassphrase = chars.copyOf()
if (importUri != null) {
// v0.4.2.1 hotfix: re-arm the URI slot that
// the shared preamble above just cleared.
// The preview-confirm dialog's Import button
// reads pendingImportUri; leaving it null
// made encrypted imports a silent no-op
// (dialog closed, nothing imported).
pendingImportUri = importUri
scope.launch {
// `chars` is consumed (zeroed) by the
// decrypt step; the retained copy survives.
+38
View File
@@ -461,6 +461,44 @@ Verdict: record, don't redesign (plan wording honoured). The streaming
formatVersion=2 idea stays parked for Phase 2 and becomes *required*
iff attachment libraries approach ~25 MB.
**M2 task 4b — on-device encrypted round-trip (Waydroid): DONE, one real
bug caught and fixed.** Manual UI pass on the Waydroid phone emulator
(rig + capture recipe in `tools/WAYDROID_TESTING.md`, injector in
`tools/inject2.c`). Phone exports encrypted, then re-imports the same
file through the real UI:
```
export: Settings → Export to file… → Encrypted → passphrase → Encrypt &
export → SAF SAVE → snackbar "Encrypted backup exported. Store
the passphrase safely." (file lands 2.77 kB, magic ICDBKP1)
import: Import from file… → picker shows the .incido.json → app sniffs
the magic → "Decrypt backup" single-field sheet → correct pw →
preview "4 note(s) / 0 attachment(s) / Exported from v0.4.2.0 /
Oct 5, 2026" → Import →
snackbar "Imported 0 note(s), skipped 4 already imported."
```
**The bug:** the encrypted import silently did nothing — the confirm
dialog closed but no import ran and no snackbar ever appeared.
`PassphraseDialog.onConfirm` runs a shared preamble that clears all four
URI slots (`pendingImportUri = null`, SettingsScreen.kt:383) *before*
routing on mode; the IMPORT branch previews from a local copy but never
re-arms the slot, so the confirm dialog's Import button read
`pendingImportUri == null` and skipped the whole `viewModel.import`
call. Plain-JSON imports never pass through the passphrase dialog, so
M2.1–M2.5 could not catch this — exactly why the device leg existed.
Fix: the IMPORT branch re-arms `pendingImportUri = importUri` before
launching the preview; wrong-passphrase and dismiss paths still null it
(and zero the retained chars). Verified fixed on-device with the
dedupe snackbar above.
Device-run notes (cost hours; recorded for M3's manual passes): taps
map 1:1 to screenshot pixels; TextButtons ignore Enter until Tab moves
focus onto them (keyboard nav is the reliable path); snackbars expire
before a 3 s-delayed screenshot — burst-capture spectacle at 1 s
intervals; `waydroid shell` needs sudo, but `waydroid app install` and
`pkill -f org.incido.app` from the host need none.
+184
View File
@@ -0,0 +1,184 @@
# Waydroid: APK Install & Functional Testing Guide
Reference notes from the draft/trash feature testing session (23 Sep 2026),
on this machine: KDE Plasma (Wayland), Waydroid full session, Incido app
(package `org.incido.app`).
---
## 1. Prerequisites / environment check
```bash
waydroid status
# Want: Session: RUNNING, Container: RUNNING
```
If the session is not running (session-only command, no root needed):
```bash
waydroid session start # starts the UI session (runs as your user)
```
Starting the **container** (`waydroid container start`) requires root; it is
normally managed by a systemd unit and already running.
The app's data lives on the host at
`~/.local/share/waydroid/data/data/org.incido.app/` but is owned by root —
reading the SQLite DB from the host needs `sudo` (or `sudo waydroid shell`).
If `sudo` demands a password (as on this machine) you **cannot** use root
paths in automated runs — plan to verify through the UI instead.
## 2. Build & install the APK
```bash
cd ~/Desktop/Apps/Incido
./gradlew :app:assembleDebug -q # exit 0 = success
# APK lands at: app/build/outputs/apk/debug/app-debug.apk
waydroid app install app/build/outputs/apk/debug/app-debug.apk
```
Notes learned the hard way:
- `waydroid app install` needs **no root** — always prefer it over any
`adb install` / `cp` into the container.
- There is no attached adb device by default (`adb devices` → empty), so
plain adb workflows do not work unless you enable
`waydroid root`/adb integration first.
- If the app was already running while reinstalling, relaunch it — the
running process may keep the old code:
```bash
waydroid app launch org.incido.app # also no root needed
waydroid app list | grep -i incido # confirm installed package
```
## 3. Screenshots
`scrot`, `import` (ImageMagick is installed but has no usable X display),
and `gnome-screenshot` are **not available**. Use Spectacle in CLI mode:
```bash
spectacle -b -n -o /tmp/shot.png # -b no border, -n output file
```
Read the PNG back with the file-read tool to visually assert UI state.
## 4. Input injection (clicks / typing)
**xdotool does not work** for injecting into Waydroid under Wayland
(`XDG_SESSION_TYPE=wayland`). KWin exposes an XWayland socket, but window
search/injection via xdotool returns nothing useful.
The working solution is a userspace **uinput** injector:
[`tools/inject2.c`](./inject2.c) kept in this repo. Build once:
```bash
mkdir -p /tmp/incido_test && cd /tmp/incido_test
gcc ~/Desktop/Apps/Incido/tools/inject2.c -o inject2
# needs write access to /dev/uinput (group "input" or udev rule)
```
Usage — `click` etc. are SUBCOMMANDS (bare coordinates fail with "bad args"):
```bash
./inject2 move X Y # warp virtual pointer
./inject2 click X Y # warp + left click
./inject2 press # click at current position
./inject2 drag X1 Y1 X2 Y2
./inject2 wheel N # scroll
./inject2 type "text" # virtual keyboard device
./inject2 key NAME # esc, enter, backspace, up, down, left, right, ...
INJECT_HOLD=500000 ./inject2 click X Y # keep uinput devices alive 0.5s
```
### Coordinate mapping (important!)
Screenshots come back at **2560×1440**, but the injector emits absolute
events calibrated for a **1920×1080** screen. Therefore:
```
inject_x = screenshot_x × 0.75
inject_y = screenshot_y × 0.75
```
Measure the target on the screenshot, multiply by 0.75, then click that.
Known-good targets (already in inject2 space):
hamburger `(30, 35)`, drawer Home `(85, 104)`, drawer Drafts `(85, 206)`,
drawer Trash `(101, 403)`, card overflow menu ≈ `(1868, 111)`,
menu "Delete permanently" row ≈ `(1792, 230)`.
### Workflow that worked well
- One `click` + `sleep 1` + `spectacle` per step; read the PNG to assert.
- After deleting the top list item the list **reflows** into the same
position, so the same coordinates can be reused for repeated deletes.
## 5. Known failure mode: injection silently stops
Mid-session (after ~30 min of successful clicks), injected pointer AND
keyboard events stopped reaching the Waydroid window entirely — screenshots
showed no reaction to any input, while `spectacle` still worked and the app
process was alive (`ps -ef | grep incido`).
Things that were tried and did **not** fix it (don't loop on these):
- Re-activating the window via KWin Scripting DBus
(`qdbus6 org.kde.KWin /Scripting ...loadScript/start` with a JS that sets
`workspace.activeWindow`) — the script runs and logs activation, but
input routing is unaffected.
- `waydroid app launch` relaunch of the app.
- Escape/Back key injection.
- Repeated clicks at freshly computed coordinates.
Likely cause: KWin-side routing of the transient uinput device
(created/destroyed per invocation) gets detached — e.g. after the session
loses/gains focus, or the Python Waydroid UI stops hot-plugging newly
created libinput devices.
**Recovery options, cheapest first:**
1. Ask the user to physically click once inside the Waydroid window — this
re-establishes input focus/routing. Then retry a single click.
2. Restart the Waydroid session UI: `waydroid session stop` then
`waydroid session start` (host UI only; the container survives). App
state resets, so capture anything you still need before doing this.
3. Keep ONE long-lived injector process alive (large `INJECT_HOLD`) instead
of create→click→destroy per command, so the device never disappears
between interactions. Prefer this if the failure recurs often.
**Budget rule for agents:** if 3 consecutive injected inputs produce no
visible change in a screenshot, **stop injecting** — verify state another
way (earlier screenshots, or one manual user click) instead of looping.
## 6. Verifying app state without UI (when root IS available)
```bash
sudo waydroid shell
ls /data/data/org.incido.app/databases/
sqlite3 /data/data/org.incido.app/databases/<db>.db \
"SELECT COUNT(*), SUM(is_draft), SUM(deleted) FROM notes;"
```
(`waydroid shell` refuses without root: `ERROR: Action "shell" needs root
access`. On this machine sudo is password-gated, so this path only works
interactively with the user.)
## 7. Quick recipe (end-to-end)
```bash
cd ~/Desktop/Apps/Incido
./gradlew :app:assembleDebug -q && \
waydroid app install app/build/outputs/apk/debug/app-debug.apk && \
waydroid app launch org.incido.app
mkdir -p /tmp/incido_test && cd /tmp/incido_test
gcc ~/Desktop/Apps/Incido/tools/inject2.c -o inject2
./inject2 click 30 35 # open drawer
sleep 1; spectacle -b -n -o step1.png
```
…then screenshot after every action, and remember the ×0.75 scale when
converting screenshot targets into inject2 targets.
+183
View File
@@ -0,0 +1,183 @@
/* one-shot uinput click at absolute screen coords (touch-like), then exits */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/uinput.h>
static int fd;
static void ev(unsigned short t, unsigned short c, int v) {
struct input_event e;
memset(&e, 0, sizeof e);
e.type = t; e.code = c; e.value = v;
if (write(fd, &e, sizeof e) < 0) perror("write");
}
static void tapkey(int code) {
ev(EV_KEY, code, 1); ev(EV_SYN, SYN_REPORT, 0); usleep(15000);
ev(EV_KEY, code, 0); ev(EV_SYN, SYN_REPORT, 0); usleep(15000);
}
static int keyfor(char c, int *shift) {
*shift = 0;
if (c >= 'a' && c <= 'z') return KEY_A + (c - 'a');
if (c >= 'A' && c <= 'Z') { *shift = 1; return KEY_A + (c - 'A'); }
if (c >= '1' && c <= '9') return KEY_1 + (c - '1');
if (c == '0') return KEY_0;
switch (c) {
case '-': return KEY_MINUS;
case '_': *shift = 1; return KEY_MINUS;
case '.': return KEY_DOT;
case ',': return KEY_COMMA;
case '/': return KEY_SLASH;
case ' ': return KEY_SPACE;
case '=': return KEY_EQUAL;
case ';': return KEY_SEMICOLON;
case '~': return KEY_BACKSPACE;
}
return -1;
}
int main(int argc, char **argv) {
if (argc < 2) { fprintf(stderr, "usage: inject2 x y | move x y | key KEYCODE\n"); return 1; }
fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
if (fd < 0) { perror("uinput"); return 1; }
if (!strcmp(argv[1], "key")) {
if (argc < 3) return 1;
ioctl(fd, UI_DEV_SETUP, &(struct uinput_setup){ .id.bustype = 0x11, .id.vendor = 2, .id.product = 3, .id.version = 4, .name = "vkbd" });
for (int k = KEY_A; k <= KEY_Z; k++) ioctl(fd, UI_SET_EVBIT, EV_KEY), ioctl(fd, UI_SET_KEYBIT, k);
for (int k = KEY_1; k <= KEY_9; k++) ioctl(fd, UI_SET_KEYBIT, k);
ioctl(fd, UI_SET_KEYBIT, KEY_0); ioctl(fd, UI_SET_KEYBIT, KEY_TAB); ioctl(fd, UI_SET_KEYBIT, KEY_ENTER);
ioctl(fd, UI_DEV_CREATE, NULL);
usleep(300000);
int code = atoi(argv[2]);
ev(EV_KEY, code, 1); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_KEY, code, 0); ev(EV_SYN, SYN_REPORT, 0);
usleep(100000);
ioctl(fd, UI_DEV_DESTROY, NULL);
close(fd);
return 0;
}
if (!strcmp(argv[1], "paste")) {
ioctl(fd, UI_DEV_SETUP, &(struct uinput_setup){ .id.bustype = 0x11, .id.vendor = 2, .id.product = 3, .id.version = 4, .name = "vkbd" });
ioctl(fd, UI_SET_EVBIT, EV_KEY);
for (int k = KEY_A; k <= KEY_Z; k++) ioctl(fd, UI_SET_KEYBIT, k);
ioctl(fd, UI_SET_KEYBIT, KEY_LEFTCTRL); ioctl(fd, UI_SET_KEYBIT, KEY_ENTER);
ioctl(fd, UI_DEV_CREATE, NULL);
usleep(300000);
ev(EV_KEY, KEY_LEFTCTRL, 1); ev(EV_SYN, SYN_REPORT, 0); usleep(20000);
tapkey(KEY_V);
ev(EV_KEY, KEY_LEFTCTRL, 0); ev(EV_SYN, SYN_REPORT, 0);
usleep(100000);
ioctl(fd, UI_DEV_DESTROY, NULL);
close(fd);
return 0;
}
if (!strcmp(argv[1], "text")) {
if (argc < 3) return 1;
ioctl(fd, UI_DEV_SETUP, &(struct uinput_setup){ .id.bustype = 0x11, .id.vendor = 2, .id.product = 3, .id.version = 4, .name = "vkbd" });
ioctl(fd, UI_SET_EVBIT, EV_KEY);
for (int k = KEY_A; k <= KEY_Z; k++) ioctl(fd, UI_SET_KEYBIT, k);
for (int k = KEY_1; k <= KEY_9; k++) ioctl(fd, UI_SET_KEYBIT, k);
ioctl(fd, UI_SET_KEYBIT, KEY_0); ioctl(fd, UI_SET_KEYBIT, KEY_TAB); ioctl(fd, UI_SET_KEYBIT, KEY_ENTER);
ioctl(fd, UI_SET_KEYBIT, KEY_LEFTSHIFT); ioctl(fd, UI_SET_KEYBIT, KEY_RIGHTSHIFT);
ioctl(fd, UI_SET_KEYBIT, KEY_MINUS); ioctl(fd, UI_SET_KEYBIT, KEY_DOT);
ioctl(fd, UI_SET_KEYBIT, KEY_COMMA); ioctl(fd, UI_SET_KEYBIT, KEY_SLASH);
ioctl(fd, UI_SET_KEYBIT, KEY_SPACE); ioctl(fd, UI_SET_KEYBIT, KEY_EQUAL);
ioctl(fd, UI_SET_KEYBIT, KEY_SEMICOLON); ioctl(fd, UI_SET_KEYBIT, KEY_BACKSPACE);
ioctl(fd, UI_DEV_CREATE, NULL);
usleep(300000);
for (char *p = argv[2]; *p; p++) {
int sh, code = keyfor(*p, &sh);
if (code < 0) continue;
if (sh) ev(EV_KEY, KEY_LEFTSHIFT, 1);
tapkey(code);
if (sh) { ev(EV_KEY, KEY_LEFTSHIFT, 0); ev(EV_SYN, SYN_REPORT, 0); usleep(15000); }
usleep(45000);
}
usleep(100000);
ioctl(fd, UI_DEV_DESTROY, NULL);
close(fd);
return 0;
}
if (!strcmp(argv[1], "swipe") && argc >= 6) {
int x1 = atoi(argv[2]), y1 = atoi(argv[3]), x2 = atoi(argv[4]), y2 = atoi(argv[5]);
ioctl(fd, UI_DEV_SETUP, &(struct uinput_setup){ .id.bustype = 0x11, .id.vendor = 2, .id.product = 3, .id.version = 4, .name = "vt" });
ioctl(fd, UI_SET_EVBIT, EV_KEY);
ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);
ioctl(fd, UI_SET_EVBIT, EV_ABS);
int codes[4] = { ABS_X, ABS_Y, ABS_MT_POSITION_X, ABS_MT_POSITION_Y };
for (int i = 0; i < 4; i++) {
ioctl(fd, UI_SET_ABSBIT, codes[i]);
struct uinput_abs_setup s = { .code = codes[i], .absinfo = { .minimum = 0, .maximum = 1079, .resolution = 10 } };
ioctl(fd, UI_ABS_SETUP, &s);
}
ioctl(fd, UI_SET_ABSBIT, ABS_MT_SLOT);
ioctl(fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
ioctl(fd, UI_DEV_CREATE, NULL);
usleep(300000);
ev(EV_ABS, ABS_MT_TRACKING_ID, 0);
ev(EV_ABS, ABS_MT_POSITION_X, x1); ev(EV_ABS, ABS_MT_POSITION_Y, y1);
ev(EV_KEY, BTN_TOUCH, 1); ev(EV_SYN, SYN_REPORT, 0); usleep(40000);
for (int t = 1; t <= 10; t++) {
ev(EV_ABS, ABS_MT_POSITION_X, x1 + (x2 - x1) * t / 10);
ev(EV_ABS, ABS_MT_POSITION_Y, y1 + (y2 - y1) * t / 10);
ev(EV_SYN, SYN_REPORT, 0); usleep(25000);
}
ev(EV_KEY, BTN_TOUCH, 0); ev(EV_ABS, ABS_MT_TRACKING_ID, -1); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ioctl(fd, UI_DEV_DESTROY, NULL);
close(fd);
return 0;
}
if (argc < 3) return 1;
int x = atoi(argv[2]), y = atoi(argv[3]);
ioctl(fd, UI_DEV_SETUP, &(struct uinput_setup){ .id.bustype = 0x11, .id.vendor = 2, .id.product = 3, .id.version = 4, .name = "vt" });
ioctl(fd, UI_SET_EVBIT, EV_KEY);
ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);
ioctl(fd, UI_SET_EVBIT, EV_ABS);
int codes[4] = { ABS_X, ABS_Y, ABS_MT_POSITION_X, ABS_MT_POSITION_Y };
int maxs[4] = { 1919, 1079, 1919, 1079 };
for (int i = 0; i < 4; i++) {
ioctl(fd, UI_SET_ABSBIT, codes[i]);
struct uinput_abs_setup s = { .code = codes[i], .absinfo = { .minimum = 0, .maximum = maxs[i], .resolution = 10 } };
ioctl(fd, UI_ABS_SETUP, &s);
}
ioctl(fd, UI_SET_ABSBIT, ABS_MT_SLOT);
ioctl(fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
ioctl(fd, UI_DEV_CREATE, NULL);
usleep(300000); /* let InputReader settle */
if (!strcmp(argv[1], "move")) {
ev(EV_ABS, ABS_MT_POSITION_X, x); ev(EV_ABS, ABS_MT_POSITION_Y, y); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_KEY, BTN_TOUCH, 1); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_ABS, ABS_MT_POSITION_X, x + 6); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_ABS, ABS_MT_POSITION_X, x + 10); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_ABS, ABS_MT_POSITION_X, x); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_KEY, BTN_TOUCH, 0); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_ABS, ABS_MT_TRACKING_ID, -1); ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
} else {
ev(EV_ABS, ABS_MT_TRACKING_ID, 0);
ev(EV_ABS, ABS_MT_POSITION_X, x);
ev(EV_ABS, ABS_MT_POSITION_Y, y);
ev(EV_KEY, BTN_TOUCH, 1);
ev(EV_SYN, SYN_REPORT, 0);
usleep(120000);
ev(EV_KEY, BTN_TOUCH, 0);
ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
ev(EV_ABS, ABS_MT_TRACKING_ID, -1);
ev(EV_SYN, SYN_REPORT, 0);
usleep(50000);
}
ioctl(fd, UI_DEV_DESTROY, NULL);
close(fd);
return 0;
}