Clip practice navigation to the app viewport

Keep sliding docks inside the content frame so Android retained system-bar
pixels cannot preserve their labels after a practice starts.

Cover retained raster pixels, native navigation edges, and repeated Android
starts from Practice and Lumi.
This commit is contained in:
waozi committed 2026-11-19 18:12:19 -03:00
1 parent 6062d3e497
commit d3628b76f6
7 files changed
+518 -4

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@
- Use the private Harmony Lumi chat from the owner's Android debug build.
- Backspace and text corrections work again; recover unfinished practices and backups, add photos reliably and reset break timers after time away.
- Switch practices smoothly, pick an astral exercise and claim daily coins; account sync is now called Mesh. Keep an active practice visible in picture-in-picture. Practice downloads show clear progress.
- Start practices without navigation leftovers; switch practices smoothly, pick an astral exercise and claim daily coins; account sync is now called Mesh. Keep an active practice visible in picture-in-picture. Practice downloads show clear progress.
- Read Tao Te Ching art on its own page; find Photos and Radio in Apps, with clearer feedback and appearance controls.
## [2.1.63] - 2026-11-05
+1 -1
View File
@@ -5,7 +5,7 @@
- Download practices with clear progress and more reliable content delivery.
- Practice figures move more naturally: feet step and pivot instead of sliding, toes stay above the floor, knees and elbows straighten smoothly, hands turn without flipping, and the side plank rolls over to the second side.
- Recover unfinished practices after an unexpected close; restore a last good data copy from Settings.
- Changing practices keeps the page steady and fades from the previous practice.
- Starting practices leaves no navigation leftovers; changing practices keeps the page steady and fades from the previous practice.
- Choose an astral exercise with its guide and narration; adjust audio together and follow clearer Sun Salutation cues.
## [1.6.11] - 2026-11-05
+14
View File
@@ -258,6 +258,20 @@ shared-progress-ui-test: $(TARGET)
practice-images-ui-test: $(TARGET)
@sh tests/practice_images_ui_test.sh $(abspath $(TARGET))
.PHONY: practice-start-ui-test
practice-start-ui-test: $(TARGET)
@env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \
python3 tests/practice_start_ui_test.py $(abspath $(TARGET))
.PHONY: practice-start-device-test
practice-start-device-test:
@python3 tests/android_practice_start_device.py
.PHONY: practice-frame-clip-test
test: practice-frame-clip-test
practice-frame-clip-test: $(ZIRAN_BIN)
@python3 tests/practice_frame_clip_test.py $(ZIRAN_BIN)
.PHONY: apps-diary-editing-test
apps-diary-editing-test: $(TARGET)
sh tests/apps_diary_test.sh $(abspath $(TARGET)) --editing-only
+5 -2
View File
@@ -340,6 +340,10 @@ app_update_draw :: (vapp: *void, viewport: Rectangle) {
logical_frame) != 0 {
return
}
// Sliding navigation can extend beyond the content viewport. Keep its
// paint inside the frame: Android retains the pixels behind system bars,
// which the content canvas does not repaint on subsequent frames.
TreeSetChildClip(app.ui.session, 0, logical_frame)
#if #defined(ANDROID_BUILD) {
if AndroidAccessibilityInput(app.ui.session, HostSeconds()) {
app.ui.pointer_active = true
@@ -372,8 +376,7 @@ app_update_draw :: (vapp: *void, viewport: Rectangle) {
app_route_transition_draw(app, logical_frame, HostSeconds())
app_finish_frame(app)
} else {
// A native window is the viewport, so its raster needs the camera's
// transform but no clipping; the canvas clips to the viewport.
// The camera maps the clipped widget frame onto the content viewport.
#if #defined(PLATFORM_WEB) {
CanvasDraw.BeginScissorMode(cast(s32)viewport.x, cast(s32)viewport.y,
full_width, full_height)
+223
View File
@@ -0,0 +1,223 @@
#!/usr/bin/env python3
"""Verify practice-start pixels on the USB Moto with a disposable profile.
Run against the separately installed debug verification APK. Its profile is
renamed aside and restored even on failure. Captures contain only test data.
"""
import argparse
import contextlib
import io
import json
from pathlib import Path
import shlex
import sqlite3
import subprocess
import time
from PIL import Image
ROOT = Path(__file__).resolve().parents[1]
OUTPUT = ROOT / "backup/practice-start/moto"
PACKAGE = "xyz.waozi.inbe.verification"
PROFILE = "files/inbe"
PRESERVED = PROFILE + ".practice-start-preserved"
SERIAL = "ZE2223BQZT"
def adb(*arguments, check=True, timeout=60):
return subprocess.run(["adb", "-s", SERIAL, *map(str, arguments)], check=check,
capture_output=True, timeout=timeout)
def shell(*arguments, check=True):
return adb("shell", shlex.join(list(map(str, arguments))), check=check).stdout.decode().strip()
def private(*arguments):
return shell("run-as", PACKAGE, *arguments)
def exists(path):
return adb("shell", shlex.join(["run-as", PACKAGE, "sh", "-c", "test -e " + shlex.quote(path)]),
check=False).returncode == 0
def stop():
shell("am", "force-stop", PACKAGE)
def start():
result = shell("am", "start", "-W", "-n", PACKAGE + "/xyz.waozi.inbe.MainActivity")
assert "Error:" not in result, result
deadline = time.monotonic() + 45
while time.monotonic() < deadline:
time.sleep(1)
if capture("startup").getpixel((10, 300)) != (0, 0, 0):
return
pid = shell("pidof", PACKAGE).split()[0]
log = shell("logcat", "-d", "--pid=" + pid, "-t", "150")
(OUTPUT / "startup-failure.log").write_text(log)
raise AssertionError("Native app UI did not become ready; see startup-failure.log")
def capture(label):
activities = shell("dumpsys", "activity", "activities")
assert any(PACKAGE + "/" in line for line in activities.splitlines() if "mResumedActivity:" in line)
data = adb("exec-out", "screencap", "-p").stdout
(OUTPUT / (label + ".png")).write_bytes(data)
return Image.open(io.BytesIO(data)).convert("RGB")
def tap_start_practice(picture):
# The wide green Start Practice button is unique in this seeded mono page.
# Use pixels because UIAutomator can refuse idle snapshots during animation.
rows = []
for y in range(900, 1450):
left = picture.getpixel((60, y))
if left == picture.getpixel((360, y)) == picture.getpixel((660, y)) and \
left[1] > left[0] + 10 and left[1] > left[2] + 10:
rows.append(y)
assert rows, "Start Practice button did not appear"
bottom = rows[-1]
top = bottom
for row in reversed(rows[:-1]):
if row != top - 1:
break
top = row
assert bottom - top > 20, "Start Practice button was clipped"
shell("input", "tap", 360, (top + bottom) // 2)
def bars_clear(picture):
width, height = picture.size
assert (width, height) == (720, 1560), "This oracle is for the USB Moto's three-button navigation"
for bounds in ((2, height - 48, 42, height - 4), (width - 42, height - 48, width - 2, height - 4),
(2, 4, 24, 42), (width - 24, 4, width - 2, 42)):
assert picture.crop(bounds).getextrema() == ((0, 0), (0, 0), (0, 0)), \
("Practice navigation painted over Android system bars", bounds)
def put_database(path):
remote = "/data/local/tmp/breeze-practice-start.db"
adb("push", path, remote)
shell("chmod", "644", remote)
private("cp", remote, PROFILE + "/inbe.db")
shell("rm", "-f", remote)
private("rm", "-f", PROFILE + "/inbe.db-wal", PROFILE + "/inbe.db-shm")
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--page", choices=("practice", "lumi", "all"), default="all")
args = parser.parse_args()
assert shell("getprop", "ro.product.model") == "moto e6 play"
assert shell("getprop", "ro.build.version.sdk") == "28"
assert not exists(PRESERVED), "Restore an earlier interrupted practice-start test first"
OUTPUT.mkdir(parents=True, exist_ok=True)
state = dict(isolated=False, restored=False, preserved=False)
status = OUTPUT / "state.json"
def save():
status.write_text(json.dumps(state, indent=2) + "\n")
stop()
try:
if exists(PROFILE):
private("mv", PROFILE, PRESERVED)
state["preserved"] = True
state["isolated"] = True
save()
private("mkdir", "-p", PROFILE)
private("touch", PROFILE + "/.practice-start-test")
start()
stop()
database = OUTPUT / "fixture.db"
for suffix in ("", "-wal"):
result = adb("exec-out", "run-as", PACKAGE, "cat", PROFILE + "/inbe.db" + suffix, check=False)
path = Path(str(database) + suffix)
if result.returncode == 0:
path.write_bytes(result.stdout)
else:
path.unlink(missing_ok=True)
pages = ("practice", "lumi") if args.page == "all" else (args.page,)
for page in pages:
for placement, edge in ((2, "bottom"), (4, "top")):
with contextlib.closing(sqlite3.connect(database)) as db:
user = db.execute("SELECT id FROM users LIMIT 1").fetchone()[0]
settings = dict(language="en", language_setup_done=1, apps_setup_done=1,
tutorial_seen=1, habits_guide_seen=1, lumi_guides_seen=127,
launcher_guide_seen=1, lumi_introduced=1, lumi_online=0,
package_updates_allowed=0, enabled_apps=63,
main_tab=1 if page == "practice" else 4, theme=9,
theme_source=0, theme_mode=1, ui_scale=10,
navigation_placement=placement, picture_in_picture=0,
voice_narration_enabled=0, guide_narration_enabled=0,
audio_enabled=0, music_volume=0,
app_last_seen_version="2.1.63")
for key, value in settings.items():
db.execute("INSERT INTO settings(user_id,key,value,updated_at) VALUES(?,?,?,1) "
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value",
(user, key, str(value)))
db.commit()
with contextlib.closing(sqlite3.connect(OUTPUT / "seed.db")) as target:
db.backup(target)
target.execute("PRAGMA wal_checkpoint(TRUNCATE)")
for repetition in range(2):
put_database(OUTPUT / "seed.db")
start()
if "mInputShown=true" in shell("dumpsys", "input_method"):
shell("input", "keyevent", "4")
time.sleep(.5)
label = page + "-" + edge + "-" + str(repetition)
before = capture(label + "-before")
bars_clear(before)
if page == "practice":
tap_start_practice(before)
else:
# Tap the drawn composer, not Android's hidden IME bridge.
# Its position is fixed in this 720x1560 mono/scale-10 fixture.
shell("input", "tap", 150, 1308 if edge == "bottom" else 1418)
time.sleep(1)
shell("input", "text", "start%swhm")
time.sleep(1)
capture(label + "-typed")
if "mInputShown=true" in shell("dumpsys", "input_method"):
shell("input", "keyevent", "4")
time.sleep(.5)
# Android's multiline Enter is not the visible Send action.
shell("input", "tap", 650, 1308 if edge == "bottom" else 1418)
# IME delivery and local intent handling are asynchronous.
# Animated practice screens need not become UIAutomator-idle.
deadline = time.monotonic() + 15
while True:
time.sleep(.6)
picture = capture(label + "-running")
red, green, blue = picture.getpixel((280, 740))
if green > red + 10 and green > blue + 10:
break
assert time.monotonic() < deadline, \
(label, "The WHM practice circle did not appear")
bars_clear(picture)
canvas = picture.getpixel((10, 300))
assert picture.crop((10, 1380, 710, 1470)).getextrema() == \
tuple((channel, channel) for channel in canvas), \
(label, "Stale paint remains below the practice")
time.sleep(1)
bars_clear(capture(label + "-settled"))
stop()
print(label + ": practice visible, system bars and lower page clear", flush=True)
state["result"] = "passed"
finally:
stop()
if exists(PROFILE):
assert exists(PROFILE + "/.practice-start-test"), "Refusing to remove unmarked data"
private("rm", "-rf", PROFILE)
if state["preserved"]:
private("mv", PRESERVED, PROFILE)
state.update(isolated=False, restored=True)
save()
print("USB Moto practice starts: mono scale 10, Lumi and Practice, repeated top/bottom starts leave system bars clear")
if __name__ == "__main__":
main()
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env python3
"""Replay Breeze's frame prelude against retained Android raster pixels.
The actual BeginFrame block is compiled with Kryon's tree and Pixmap renderer.
An animated dock crosses each content edge; system-bar pixels must stay black
both while it crosses the edge and after its commands disappear.
"""
import os
from pathlib import Path
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[1]
OUTPUT = ROOT / "build/practice-frame-clip-test"
OUTPUT.mkdir(parents=True, exist_ok=True)
compiler = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / "build/packages/ziran/build/bin/ziran"
source = (ROOT / "src/app/application_frame.zi").read_text()
start = source.index(' if cast(s32)BeginFrame(app.ui.session, Layout.KeyHash("inbe/frame"),')
end = source.index(' #if #defined(ANDROID_BUILD)', start)
prelude = source[start:end]
fixture = '''Pixels :: #import "pixmap";
Box :: #import "kryon/box";
Layout :: #import "kryon/layout";
#import "drawing_props"
#import "geometry"
#import "session"
#import "tree_draw"
#import "kryon/tree"
#import "paint_queue"
Ui :: struct { session: Session }
App :: struct { ui: Ui }
BeginViewport :: (app: *App, logical_frame: Rectangle) {
''' + prelude + '''}
WIDTH :: 48
HEIGHT :: 80
BLACK :: 0xff000000
CANVAS :: 0xfff4f8f7
pixels: [WIDTH * HEIGHT]u32;
OutsideClear :: () -> bool {
for y: 0..HEIGHT - 1 {
for x: 0..WIDTH - 1 {
if (x < 6 || x >= 42 || y < 8 || y >= 64) &&
pixels[y * WIDTH + x] != cast(u32)BLACK { return false }
}
}
return true
}
#program_export
main :: () -> s32 {
session := SessionOpen()
if !SessionValid(session) { return 1 }
defer { unused CloseSession(session); Pixels.PixmapCloseWorkers() }
app := App.{.ui = Ui.{.session = session}}
viewport := Rectangle.{6.0, 8.0, 36.0, 56.0}
for edge: cast(s32)0..3 {
for index: 0..pixels.count - 1 { pixels[index] = cast(u32)BLACK }
// No whole-surface clear between frames, as in the retained app.
for step: 0..6 {
if !Pixels.PixmapScale(1.0, 1.0) ||
!Pixels.PixmapResumeInto(WIDTH, HEIGHT, pixels[:], true) { return 2 }
BeginViewport(*app, viewport)
Box.Draw(session, Box.Props.{.bounds = viewport,
.fill = Color.{.r = 244, .g = 248, .b = 247, .a = 255}})
if step < 6 {
offset := cast(float32)step * 2.0
dock := Rectangle.{6.0, 56.0 + offset, 36.0, 8.0}
if edge == 1 { dock = .{6.0, 8.0 - offset, 36.0, 8.0} }
if edge == 2 { dock = .{6.0 - offset, 8.0, 8.0, 56.0} }
if edge == 3 { dock = .{34.0 + offset, 8.0, 8.0, 56.0} }
// Widget paint and the raw sidebar fill inherit the frame clip.
Box.Draw(session, Box.Props.{.bounds = dock,
.fill = Color.{.r = 240, .g = 40, .b = 30, .a = 255}})
PaintRoundedFill(session, -1, dock, 2.0, 4,
Color.{.r = 240, .g = 40, .b = 30, .a = 255})
}
result := EndFrameRetained(session, true)
Pixels.PixmapEndInto()
if cast(s32)result.status != 0 { return 3 }
if !OutsideClear() { return 10 + edge }
}
// Once the dock is gone, every content pixel is clean canvas.
for y: 8..63 {
for x: 6..41 {
if pixels[y * WIDTH + x] != cast(u32)CANVAS { return 20 + edge }
}
}
}
return 0
}
'''
path = OUTPUT / "practice_frame_clip.zi"
path.write_text(fixture)
env = {key: value for key, value in os.environ.items() if key not in (
"DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "SESSION_MANAGER")}
env.update(HARMONY_DESKTOP_RECOVERY="0", YUE_DESKTOP_RECOVERY="0")
generated = OUTPUT / "c"
subprocess.run([str(compiler), "build", "--project", "--offline", "--target=c", "--define", "ANDROID_BUILD",
"--root", str(ROOT), "--prune-stale", "-o", str(generated), str(path)],
cwd=ROOT, env=env, check=True)
includes = [part for folder in sorted({p.parent for p in generated.rglob("*.h")} | {generated})
for part in ("-iquote", str(folder))]
archive = compiler.resolve().parent.parent / "libziran.a"
subprocess.run([env.get("CC", "cc"), "-std=c11", "-O2", "-ffunction-sections", "-fdata-sections",
*includes, *map(str, sorted(generated.rglob("*.c"))), str(archive),
"-Wl,--gc-sections", "-ldl", "-lm", "-lpthread", "-o", str(OUTPUT / "test")],
cwd=ROOT, env=env, check=True)
subprocess.run([str(OUTPUT / "test")], cwd=ROOT, env=env, check=True)
print("Retained Android practice frame: all dock edges stay within the viewport and clear after animation")
+163
View File
@@ -0,0 +1,163 @@
#!/usr/bin/env python3
"""Practice starts keep sliding navigation paint inside the app viewport.
Use the real app and Kryon tree on a private display. On Android the pixels
outside this viewport belong to the system bars and survive retained frames.
"""
import ast
import contextlib
import json
import os
from pathlib import Path
import sqlite3
import subprocess
import sys
import tempfile
import time
from PIL import Image
from ui_driver import UiDriver
ROOT = Path(__file__).resolve().parents[1]
OUTPUT = ROOT / "build/practice-start-ui-test"
OUTPUT.mkdir(parents=True, exist_ok=True)
ENV = {key: value for key, value in os.environ.items() if key not in (
"DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS",
"SESSION_MANAGER", "GDK_DISPLAY")}
ENV.update(HARMONY_DESKTOP_RECOVERY="0", YUE_DESKTOP_RECOVERY="0", APP_NO_TRAY="1",
SDL_AUDIODRIVER="dummy", SDL_VIDEODRIVER="x11")
def stop(process):
if process.poll() is None:
process.terminate()
try:
process.wait(timeout=5)
except subprocess.TimeoutExpired:
process.kill()
process.wait(timeout=5)
def command(*arguments):
return subprocess.check_output(arguments, env=ENV, text=True, timeout=10).strip()
def state(window):
value = command("xprop", "-id", window, "_HARMONY_APP_STATE")
return json.loads(ast.literal_eval(value.split(" = ", 1)[1]))
def navigation_inside_viewport(nodes):
root = next(node for node in nodes if node["kind"] == "screen")
navigation = {node["index"] for node in nodes if node["kind"] == "navigation_bar"}
descendants = set(navigation)
for node in nodes:
if node["parent"] in descendants:
descendants.add(node["index"])
if node["index"] not in descendants or not node["visible"]:
continue
x, y = node["visible_x"], node["visible_y"]
width, height = node["visible_width"], node["visible_height"]
assert x >= root["x"] - 1 and y >= root["y"] - 1 and \
x + width <= root["x"] + root["width"] + 1 and \
y + height <= root["y"] + root["height"] + 1, \
("Sliding navigation escapes the content viewport", root, node)
return bool(navigation)
with contextlib.ExitStack() as stack:
display_log = stack.enter_context((OUTPUT / "display.log").open("w"))
display = subprocess.Popen(["Xvfb", "-noreset", "-displayfd", "1", "-screen", "0",
"1000x1000x24", "-nolisten", "tcp"], env=ENV,
stdout=subprocess.PIPE, stderr=display_log)
stack.callback(stop, display)
number = display.stdout.readline().decode().strip()
display.stdout.close()
assert number.isdecimal() and display.poll() is None, "Private display did not start"
ENV["DISPLAY"] = ":" + number
driver = UiDriver(OUTPUT / "driver")
ENV.update(driver.environment())
profile = Path(stack.enter_context(tempfile.TemporaryDirectory(dir=OUTPUT, prefix="profile-")))
ENV["APP_DATA_ROOT"] = str(profile)
@contextlib.contextmanager
def application(label):
log_path = OUTPUT / (label + ".log")
with log_path.open("w") as log:
app = subprocess.Popen([sys.argv[1]], cwd=ROOT, env=ENV, stdout=log, stderr=log)
driver.attach(app, log_path)
try:
deadline = time.monotonic() + 30
while time.monotonic() < deadline:
assert app.poll() is None, "App exited during startup"
found = subprocess.run(["xdotool", "search", "--onlyvisible", "--pid", str(app.pid)],
env=ENV, capture_output=True, text=True, timeout=5)
if found.returncode == 0 and (profile / "inbe.db").exists():
window = found.stdout.splitlines()[0]
command("xdotool", "windowsize", window, "390", "844")
driver.wait(role="screen")
yield window
break
time.sleep(.1)
else:
raise AssertionError("App window did not appear")
finally:
stop(app)
with application("initialize"):
driver.wait_idle()
for placement, edge in ((2, "bottom"), (4, "top"), (1, "left"), (3, "right")):
for page, tab in (("practice", 1), ("lumi", 4)):
with sqlite3.connect(profile / "inbe.db") as db:
user = db.execute("SELECT id FROM users LIMIT 1").fetchone()[0]
settings = dict(language="en", language_setup_done=1, apps_setup_done=1,
tutorial_seen=1, habits_guide_seen=1, lumi_guides_seen=127,
launcher_guide_seen=1, lumi_introduced=1, lumi_online=0,
package_updates_allowed=0, enabled_apps=63, main_tab=tab,
theme=9, theme_source=0, theme_mode=1, ui_scale=10,
navigation_placement=placement, picture_in_picture=0,
voice_narration_enabled=0, guide_narration_enabled=0, audio_enabled=0, music_volume=0,
app_last_seen_version="2.1.63")
for key, value in settings.items():
db.execute("INSERT INTO settings(user_id,key,value,updated_at) VALUES(?,?,?,1) "
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value",
(user, key, str(value)))
label = edge + "-" + page
with application(label) as window:
for repetition in range(2):
if page == "practice":
driver.press(label="Start Practice", settle=False)
else:
driver.press(role="text_area")
driver.type("start whm")
driver.key("enter")
deadline = time.monotonic() + 8
try:
while True:
nodes = driver.tree()
has_navigation = navigation_inside_viewport(nodes)
if state(window)["practice_running"] and not has_navigation:
break
assert time.monotonic() < deadline, "Practice navigation did not retract"
assert state(window)["screen"] == 1, "WHM did not start"
path = OUTPUT / (label + "-" + str(repetition) + ".png")
command("import", "-window", window, str(path))
with Image.open(path) as picture:
# Empty strips under the old dock and beside the circle
# must contain only canvas, not the old page or dock.
for bounds in ((0, 760, 390, 840), (0, 100, 30, 260),
(360, 100, 390, 260)):
assert len(picture.crop(bounds).getcolors(2) or []) == 1, \
(label, repetition, "Stale paint below navigation", bounds)
except BaseException:
(OUTPUT / (label + "-failure.json")).write_text(json.dumps(driver.last, indent=2))
raise
driver.press(label="Close")
driver.press(label="Exit")
driver.press(label="Practice" if page == "practice" else "Lumi", role="button")
if page == "practice":
driver.wait(label="Start Practice")
else:
driver.wait(role="text_area")
print("Practice starts: mono scale 10, all navigation edges, Lumi and Practice, repeated starts stay clipped and clear")