#!/usr/bin/env python3 """COMPUTATION lane for DetoxDroid (com.flx_apps.digitaldetox). This app has NO calculator. Its input->output surfaces are: (A) NumberPickerDialogs — a feature-detail tile shows a right-aligned value ("0 min"); tapping it opens a dialog with a vertical number WHEEL and Cancel/Save. Swiping up on the wheel increments by the feature's step; Save writes the new value back to the tile; Cancel leaves it unchanged. The tile value is the app's COMPUTED output for "start + N*step". (B) The Commitment Password "Select Features to Lock" counter — a live "N of 5 features selected" TextView = f(checked feature checkboxes), driven by the All / None buttons and the 5 per-feature checkboxes. Every test here provides an INPUT (N wheel up-swipes, or All/None + K checkbox taps) and asserts the EXACT resulting OUTPUT VALUE STRING the running original app produced. All expected strings below were OBSERVED live on the original; none is computed from source, a constant, or my own arithmetic. GROUND TRUTH observed live on the original (steps VERIFIED on-device): Grayscale 'Allowed Daily Color Screen Time' default '0 min', step 15 min 1 up-swipe -> Save -> tile '15 min'; 2 -> '30 min'; 3 -> '45 min'. Disable Apps 'Allowed Daily Screen Time' default '0 min', step 1 min 1 -> '1 min'; 2 -> '2 min'. (NOT 15 min here — VERIFIED live.) Break 'Time Until Warning' default '3 min', step 1 min 1 -> '4 min'; 3 -> '6 min'. Pause 'Pause Duration' default '3 min', step 1 min 3 -> '6 min'. Pause 'Minimum Time Between Pauses' default '0 min', step 1 min 3 -> '3 min'. Commitment 'Select Features to Lock' counter (starts '0 of 5 features selected'): None -> '0 of 5'; None+1 checkbox -> '1 of 5'; +2 -> '2 of 5'; All -> '5 of 5'; All then None -> '0 of 5'. Picker WHEEL recipe (VERIFIED): the value tile is the right-aligned TextView (x-centre > 800) whose text ends in ' min'. Tapping it opens the dialog; the SELECTED wheel value is the ' min' TextView nearest the wheel centre (y~1237-1279). One up-swipe of 105px (ms=500) moves the wheel exactly ONE step; re-ui() between swipes and always re-read the centred value from the fresh dump. Save writes the centred value back to the tile; Cancel discards it. A detail can carry TWO value tiles (Pause), so the tile is read back at the y-position of the tile that was opened. Long-press produces NO UI in this app, so the tap-tile -> wheel-swipe -> Save flow is the only way to set a value. """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 # Home discriminator — unique to Home, gone on every child surface. HOME_FAB = "Run/Stop DetoxDroid" # One wheel step = a 105px up-swipe held for 500ms (VERIFIED end-to-end). SWIPE_DY = 105 SWIPE_MS = 500 # ── value readers (always from a FRESH ui()) ───────────────────────────────── def _norm(s): """Normalise a value string for comparison: decode the raw newline entity, drop a trailing 'used' sub-label line, collapse inner whitespace.""" s = (s or "").replace(" ", "\n") s = s.split("\n")[0] return " ".join(s.split()).strip() def _value_tiles(ns): """Every right-aligned feature-tile value node (a ' min' TextView with x-centre > 800 that is NOT the 'N min used' sub-label). A detail can carry more than one (Pause has 'Pause Duration' + 'Minimum Time Between Pauses'), so callers disambiguate by y-position.""" out = [] for n in ns: if "TextView" not in n.get("class", ""): continue raw = n.get("text", "") if "used" in raw or not _norm(raw).endswith("min"): continue b = n.get("_bounds") if not b or (b[0] + b[2]) // 2 <= 800: continue out.append(n) return out def tile_value(ns, near_y=None): """The feature tile's right-aligned value string (the COMPUTED output written back after Save). With `near_y`, returns the value of the tile whose centre-y is closest to it (so the correct setting is read on a detail with several value tiles); without it, returns the topmost.""" tiles = _value_tiles(ns) if not tiles: return None if near_y is None: tiles.sort(key=lambda n: n["_bounds"][1]) else: tiles.sort(key=lambda n: abs(n["_center"][1] - near_y)) return _norm(tiles[0].get("text", "")) def _digit_min_texts(ns): """All ' min' value TextViews (used to locate the wheel's centred value).""" out = [] for n in ns: if "TextView" not in n.get("class", ""): continue t = _norm(n.get("text", "")) b = n.get("_bounds") if b and t.endswith("min") and any(c.isdigit() for c in t): out.append(n) return out def wheel_selected(ns, near_y): """The wheel's centred (highlighted) value node — the ' min' TextView whose centre-y is closest to `near_y` (the wheel centre).""" h = get_screen_info()["height"] cands = [n for n in _digit_min_texts(ns) if 200 < n["_center"][1] < h - 200] if not cands: return None cands.sort(key=lambda n: abs(n["_center"][1] - near_y)) return cands[0] def counter_text(ns): """The Commitment 'N of 5 features selected' counter string, or None.""" for n in ns: if "features selected" in n.get("text", ""): return n.get("text", "").strip() return None def feature_checkboxes(ns): """The 5 per-feature CheckBoxes on the Commitment 'Select Features to Lock' section — the CheckBox class nodes below the buttons (y>1150). The top-bar activation Switch is a checkable *View* at y<300 and is EXCLUDED, so we never toggle it (the feature stays OFF).""" cbs = [n for n in ns if "CheckBox" in n.get("class", "") and n.get("_bounds") and n["_bounds"][1] > 1150] cbs.sort(key=lambda n: n["_bounds"][1]) return cbs # ── NAMED navigation helpers (each backs a declared depth via and_enter*) ───── def _home(): restart_app() return wait_for_foreground() def and_enter_feature(tile_text): """HOME -> a feature detail (depth 1), located by its Home tile text.""" if not _home(): return False node = scroll_into_view(tile_text) if node is None or not tap_node(node): return False and_enter(tile_text) return True def and_enter_picker(tile_text, setting_label, default_val): """HOME -> feature detail -> the NumberPickerDialog for `setting_label` (depth 2). Returns (before_value, opened_center_y): the tile value observed BEFORE opening (read on the detail) and the y-centre of the tile that was opened (used to read the same tile back after Save). Returns (None, None) on failure. Confirms the dialog by finding its Save button.""" if not and_enter_feature(tile_text): return None, None scroll_into_view(setting_label) ns = ui() # the value tile whose text is the default and which sits on the right edge val_node = None for n in _value_tiles(ns): if _norm(n.get("text", "")) == default_val: val_node = n break if val_node is None: val_node = find_node(ns, text=default_val) if val_node is None: return None, None before_value = _norm(val_node.get("text", "")) opened_y = val_node["_center"][1] if not tap_node(val_node) or find_node_ci(ui(), "Save") is None: return None, None and_enter("picker_dialog") return before_value, opened_y def step_wheel_up(ns, n_steps): """Swipe the wheel up `n_steps` times (one step per swipe), re-ui() between, and RETURN (centred_value_string, fresh_dump) after the last swipe. `ns` is the fresh dump with the dialog already open.""" sel = wheel_selected(ns, near_y=1258) # wheel centre band if sel is None: return None, ns for _ in range(n_steps): cx, cy = sel["_center"] swipe(cx, cy, cx, cy - SWIPE_DY, ms=SWIPE_MS) ns = ui() sel = wheel_selected(ns, near_y=cy) or sel return _norm(sel.get("text", "")), ns def picker_set_and_save(tile_text, setting_label, default_val, n_steps): """Full flow: open the picker, swipe up n_steps, tap Save, read the tile's resulting value back (from a fresh dump, at the opened tile's y-position). Returns (before_value, tile_value_after, wheel_value_before_save).""" before_value, opened_y = and_enter_picker(tile_text, setting_label, default_val) if before_value is None: return None, None, None wheel_val, ns = step_wheel_up(ui(), n_steps) save = find_node(ns, text="Save") or find_node_ci(ns, "Save") if save is None or not tap_node(save): return before_value, None, wheel_val return before_value, tile_value(ui(), near_y=opened_y), wheel_val # ══════════════════════════════════════════════════════════════════════════════ # GRAYSCALE 'Allowed Daily Color Screen Time' — step 15 min (default '0 min') # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("computation_grayscale_15min", "computation_grayscale_wheel_vlm")) def test_grayscale_1_step(): clear_data() # positive/negative: the answer must be ABSENT (still 0) before, PRESENT after. before, opened_y = and_enter_picker("Automatic Grayscale", "Allowed Daily Color Screen Time", "0 min") absent_before = before == "0 min" # VLM on the wheel rendering while the dialog is open (fine-grained: shape). vlm_assert("computation_grayscale_wheel", "Is a vertical scrollable number-picker WHEEL shown in the centre of " "this dialog, with one value highlighted in the middle and the " "adjacent values faded above and below it?", RESULTS_DIR, depth=2, jump_kind="none", tag="shape") wheel_val, ns = step_wheel_up(ui(), 1) save = find_node(ns, text="Save") or find_node_ci(ns, "Save") saved = save is not None and tap_node(save) got = tile_value(ui(), near_y=opened_y) ok = absent_before and saved and got == "15 min" record("computation_grayscale_15min", ok, "" if ok else "behavior_wrong: 1 up-swipe (+15 min) from '0 min' should " "read '15 min'; absent_before=%s wheel=%r tile=%r" % (absent_before, wheel_val, got), depth=2, jump_kind="value", expect="15 min") @and_test(expects=("computation_grayscale_30min",)) def test_grayscale_2_steps(): clear_data() before, tile_val, wheel = picker_set_and_save( "Automatic Grayscale", "Allowed Daily Color Screen Time", "0 min", 2) ok = before == "0 min" and tile_val == "30 min" record("computation_grayscale_30min", ok, "" if ok else "behavior_wrong: 2 up-swipes (+30 min) should read " "'30 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="30 min") @and_test(expects=("computation_grayscale_45min",)) def test_grayscale_3_steps(): clear_data() before, tile_val, wheel = picker_set_and_save( "Automatic Grayscale", "Allowed Daily Color Screen Time", "0 min", 3) ok = before == "0 min" and tile_val == "45 min" record("computation_grayscale_45min", ok, "" if ok else "behavior_wrong: 3 up-swipes (+45 min) should read " "'45 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="45 min") @and_test(expects=("computation_grayscale_cancel_unchanged",)) def test_grayscale_cancel_unchanged(): """Cancel path: swipe up once, tap Cancel -> the tile stays at '0 min'.""" clear_data() before, opened_y = and_enter_picker("Automatic Grayscale", "Allowed Daily Color Screen Time", "0 min") wheel_val, ns = step_wheel_up(ui(), 1) # move wheel to 15 min but do NOT save cancel = find_node(ns, text="Cancel") or find_node_ci(ns, "Cancel") cancelled = cancel is not None and tap_node(cancel) after = tile_value(ui(), near_y=opened_y) ok = before == "0 min" and cancelled and after == "0 min" record("computation_grayscale_cancel_unchanged", ok, "" if ok else "behavior_wrong: Cancel after moving the wheel to '15 min' " "must leave the tile at '0 min'; before=%r wheel=%r after=%r" % (before, wheel_val, after), depth=2, jump_kind="value", expect="0 min") @and_test(expects=("computation_grayscale_save_reopen_idempotent",)) def test_grayscale_save_reopen_idempotent(): """Set 15 min, Save, reopen -> the wheel's centred value starts at '15 min' (the saved value round-trips into the picker, not a reset to 0).""" clear_data() before, tile_val, _ = picker_set_and_save( "Automatic Grayscale", "Allowed Daily Color Screen Time", "0 min", 1) set_ok = before == "0 min" and tile_val == "15 min" reopened = False centred = None if set_ok: tile = None for n in _value_tiles(ui()): if _norm(n.get("text", "")) == "15 min": tile = n break if tile is not None and tap_node(tile) and find_node_ci(ui(), "Save") is not None: reopened = True sel = wheel_selected(ui(), near_y=1258) centred = _norm(sel.get("text", "")) if sel else None c = find_node_ci(ui(), "Cancel") # close without changing if c is not None: tap_node(c) ok = set_ok and reopened and centred == "15 min" record("computation_grayscale_save_reopen_idempotent", ok, "" if ok else "behavior_wrong: after saving '15 min' the reopened wheel " "should be centred on '15 min'; set=%s reopened=%s centred=%r" % (set_ok, reopened, centred), depth=2, jump_kind="value", expect="15 min") # ══════════════════════════════════════════════════════════════════════════════ # DISABLE APPS 'Allowed Daily Screen Time' — step 1 min (default '0 min') # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("computation_disableapps_1min",)) def test_disableapps_1_step(): clear_data() before, tile_val, wheel = picker_set_and_save( "Disable Apps", "Allowed Daily Screen Time", "0 min", 1) ok = before == "0 min" and tile_val == "1 min" record("computation_disableapps_1min", ok, "" if ok else "behavior_wrong: 1 up-swipe (+1 min) from '0 min' should " "read '1 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="1 min") @and_test(expects=("computation_disableapps_2min",)) def test_disableapps_2_steps(): clear_data() before, tile_val, wheel = picker_set_and_save( "Disable Apps", "Allowed Daily Screen Time", "0 min", 2) ok = before == "0 min" and tile_val == "2 min" record("computation_disableapps_2min", ok, "" if ok else "behavior_wrong: 2 up-swipes (+2 min) should read " "'2 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="2 min") # ══════════════════════════════════════════════════════════════════════════════ # BREAK 'Time Until Warning' — step 1 min (default '3 min') # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("computation_break_4min",)) def test_break_1_step(): clear_data() before, tile_val, wheel = picker_set_and_save( "Break Infinite Scrolling", "Time Until Warning", "3 min", 1) ok = before == "3 min" and tile_val == "4 min" record("computation_break_4min", ok, "" if ok else "behavior_wrong: 1 up-swipe (+1 min) from '3 min' should " "read '4 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="4 min") @and_test(expects=("computation_break_6min",)) def test_break_3_steps(): clear_data() before, tile_val, wheel = picker_set_and_save( "Break Infinite Scrolling", "Time Until Warning", "3 min", 3) ok = before == "3 min" and tile_val == "6 min" record("computation_break_6min", ok, "" if ok else "behavior_wrong: 3 up-swipes (+3 min) from '3 min' should " "read '6 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="6 min") # ══════════════════════════════════════════════════════════════════════════════ # PAUSE 'Pause Duration' — step 1 min (default '3 min') # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("computation_pause_duration_6min",)) def test_pause_duration_3_steps(): clear_data() before, tile_val, wheel = picker_set_and_save( "Pause Button", "Pause Duration", "3 min", 3) ok = before == "3 min" and tile_val == "6 min" record("computation_pause_duration_6min", ok, "" if ok else "behavior_wrong: 3 up-swipes (+3 min) from '3 min' should " "read '6 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="6 min") # ══════════════════════════════════════════════════════════════════════════════ # PAUSE 'Minimum Time Between Pauses' — step 1 min (default '0 min') # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("computation_pause_mintime_3min",)) def test_pause_mintime_3_steps(): clear_data() before, tile_val, wheel = picker_set_and_save( "Pause Button", "Minimum Time Between Pauses", "0 min", 3) ok = before == "0 min" and tile_val == "3 min" record("computation_pause_mintime_3min", ok, "" if ok else "behavior_wrong: 3 up-swipes (+3 min) from '0 min' should " "read '3 min'; before=%r wheel=%r tile=%r" % (before, wheel, tile_val), depth=2, jump_kind="value", expect="3 min") # ══════════════════════════════════════════════════════════════════════════════ # COMMITMENT PASSWORD counter — 'N of 5 features selected' = f(checkboxes) # (Only the feature-lock checkboxes / All / None are touched; the activation # Switch is NEVER toggled, so the feature is not enabled.) # ══════════════════════════════════════════════════════════════════════════════ def _open_commitment(): """HOME -> Commitment Password detail (depth 1). Returns the fresh dump or []""" if not and_enter_feature("Commitment Password"): return [] return ui() @and_test(expects=("computation_commit_none_0of5",)) def test_commit_none_zero(): clear_data() ns = _open_commitment() none_btn = find_node(ns, text="None") if ns else None tapped = none_btn is not None and tap_node(none_btn) got = counter_text(ui()) ok = tapped and got == "0 of 5 features selected" record("computation_commit_none_0of5", ok, "" if ok else "behavior_wrong: tapping 'None' should read " "'0 of 5 features selected'; got %r" % got, depth=1, jump_kind="value", expect="0 of 5 features selected") @and_test(expects=("computation_commit_one_1of5",)) def test_commit_check_one(): clear_data() ns = _open_commitment() none_btn = find_node(ns, text="None") if ns else None if none_btn is not None: tap_node(none_btn) ns = ui() before = counter_text(ns) cbs = feature_checkboxes(ns) checked = bool(cbs) and tap_node(cbs[0]) ns2 = ui() got = counter_text(ns2) cb_state = feature_checkboxes(ns2) cb_checked = bool(cb_state) and cb_state[0].get("checked") == "true" ok = (before == "0 of 5 features selected" and checked and got == "1 of 5 features selected" and cb_checked) record("computation_commit_one_1of5", ok, "" if ok else "behavior_wrong: None then one checkbox should read " "'1 of 5 features selected'; before=%r after=%r cb_checked=%s" % (before, got, cb_checked), depth=1, jump_kind="value", expect="1 of 5 features selected") @and_test(expects=("computation_commit_two_2of5",)) def test_commit_check_two(): clear_data() ns = _open_commitment() none_btn = find_node(ns, text="None") if ns else None if none_btn is not None: tap_node(none_btn) cbs = feature_checkboxes(ui()) t1 = bool(cbs) and tap_node(cbs[0]) cbs2 = feature_checkboxes(ui()) # re-find (coords stable but safe) t2 = len(cbs2) > 1 and tap_node(cbs2[1]) got = counter_text(ui()) ok = t1 and t2 and got == "2 of 5 features selected" record("computation_commit_two_2of5", ok, "" if ok else "behavior_wrong: None then two checkboxes should read " "'2 of 5 features selected'; t1=%s t2=%s got=%r" % (t1, t2, got), depth=1, jump_kind="value", expect="2 of 5 features selected") @and_test(expects=("computation_commit_all_5of5",)) def test_commit_all(): clear_data() ns = _open_commitment() all_btn = find_node(ns, text="All") if ns else None tapped = all_btn is not None and tap_node(all_btn) # counter is usually still visible; scroll it into view only if it slipped off got = counter_text(ui()) if got is None: c = scroll_into_view("features selected") got = c.get("text", "").strip() if c else None ok = tapped and got == "5 of 5 features selected" record("computation_commit_all_5of5", ok, "" if ok else "behavior_wrong: tapping 'All' should read " "'5 of 5 features selected'; got %r" % got, depth=1, jump_kind="value", expect="5 of 5 features selected") @and_test(expects=("computation_commit_all_then_none_0of5",)) def test_commit_all_then_none(): """Round-trip: All -> '5 of 5', then None -> back to '0 of 5'.""" clear_data() ns = _open_commitment() all_btn = find_node(ns, text="All") if ns else None t_all = all_btn is not None and tap_node(all_btn) mid = counter_text(ui()) none_btn = find_node(ui(), text="None") t_none = none_btn is not None and tap_node(none_btn) got = counter_text(ui()) if got is None: c = scroll_into_view("features selected") got = c.get("text", "").strip() if c else None ok = (t_all and mid == "5 of 5 features selected" and t_none and got == "0 of 5 features selected") record("computation_commit_all_then_none_0of5", ok, "" if ok else "behavior_wrong: All then None should round-trip to " "'0 of 5 features selected'; mid=%r got=%r" % (mid, got), depth=1, jump_kind="value", expect="0 of 5 features selected") @and_test(expects=("computation_commit_check_uncheck_0of5",)) def test_commit_check_then_uncheck(): """Tap one checkbox (->1 of 5) then tap it again (->0 of 5): the counter maps exactly to the number of checked boxes both up and down.""" clear_data() ns = _open_commitment() none_btn = find_node(ns, text="None") if ns else None if none_btn is not None: tap_node(none_btn) cbs = feature_checkboxes(ui()) up = bool(cbs) and tap_node(cbs[0]) c1 = counter_text(ui()) cbs2 = feature_checkboxes(ui()) down = bool(cbs2) and tap_node(cbs2[0]) c2 = counter_text(ui()) ok = (up and c1 == "1 of 5 features selected" and down and c2 == "0 of 5 features selected") record("computation_commit_check_uncheck_0of5", ok, "" if ok else "behavior_wrong: check then uncheck one box should go " "1 of 5 -> 0 of 5; c1=%r c2=%r" % (c1, c2), depth=1, jump_kind="value", expect="0 of 5 features selected") # ══════════════════════════════════════════════════════════════════════════════ # PER-FEATURE INDEPENDENCE: setting Grayscale to 15 min leaves Disable Apps at 0. # Two same-shaped pickers must not share one backing value. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("computation_picker_per_feature_independent",)) def test_picker_per_feature_independent(): clear_data() before, gray_val, _ = picker_set_and_save( "Automatic Grayscale", "Allowed Daily Color Screen Time", "0 min", 1) gray_ok = before == "0 min" and gray_val == "15 min" # now open Disable Apps' Allowed Daily Screen Time: it must still be '0 min' disable_default = None b2, _y = and_enter_picker("Disable Apps", "Allowed Daily Screen Time", "0 min") if b2 is not None: sel = wheel_selected(ui(), near_y=1258) disable_default = _norm(sel.get("text", "")) if sel else None c = find_node_ci(ui(), "Cancel") if c is not None: tap_node(c) ok = gray_ok and disable_default == "0 min" record("computation_picker_per_feature_independent", ok, "" if ok else "behavior_wrong: setting Grayscale to '15 min' must NOT " "change Disable Apps' Allowed Daily Screen Time (still '0 min'); " "gray=%r disable_default=%r" % (gray_val, disable_default), depth=2, jump_kind="value", expect="0 min") # ══════════════════════════════════════════════════════════════════════════════ # DONUT CHART (VLM #2) — the one genuinely rendered visual on Home: a canvas the # dump cannot fully express. Existence-only, depth 0. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("computation_home_donut_vlm",)) def test_home_donut_chart(): restart_app() wait_for_foreground() ui() # settle the tree before the screenshot vlm_assert("computation_home_donut", "Is there a circular ring / donut chart made of one or more coloured " "arc segments near the TOP of the screen (a hollow circle with a " "number in its centre), above the list of feature rows?", RESULTS_DIR, depth=0, jump_kind="none", tag="shape") TESTS = [ test_grayscale_1_step, test_grayscale_2_steps, test_grayscale_3_steps, test_grayscale_cancel_unchanged, test_grayscale_save_reopen_idempotent, test_disableapps_1_step, test_disableapps_2_steps, test_break_1_step, test_break_3_steps, test_pause_duration_3_steps, test_pause_mintime_3_steps, test_commit_none_zero, test_commit_check_one, test_commit_check_two, test_commit_all, test_commit_all_then_none, test_commit_check_then_uncheck, test_picker_per_feature_independent, test_home_donut_chart, ] if __name__ == "__main__": run_suite(TESTS, "computation")