feat: simplify receiving and remove arbitrary limits

- Use fixed port 8787 and reconnect automatically after Wi-Fi loss
- Remove session expiry, APK expiry, size caps, and upload deadlines
- Replace manual keys with watch-approved browser access
- Improve streaming, storage recovery, and resource cleanup
- Preserve explicit Android installation consent
- Document retained safeguards and expand emulator coverage
This commit is contained in:
Meghdad committed 2026-10-15 19:50:10 +03:30
1 parent 1a64de5515
commit 6e41db2a74
41 files changed
+1241 -561

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
"""Create a signed, uncompressed APK fixture for large-file transfer tests; never shipped."""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import zipfile
from emulator_utils import ROOT
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--bytes", type=int, default=64 * 1024 * 1024, help="Size of the stored test asset")
args = parser.parse_args()
if args.bytes <= 0:
parser.error("Use a positive asset size.")
source = ROOT / "qa/fixture/build/outputs/apk/debug/qaFixture-debug.apk"
if not source.exists():
raise SystemExit("Build :qaFixture:assembleDebug first.")
sdk = os.environ.get("ANDROID_HOME") or os.environ.get("ANDROID_SDK_ROOT")
if not sdk:
for line in (ROOT / "local.properties").read_text().splitlines():
if line.startswith("sdk.dir="):
sdk = line.removeprefix("sdk.dir=")
versions = sorted((Path(sdk) / "build-tools").glob("*/apksigner"))
if not versions:
raise SystemExit("Install Android SDK Build Tools with apksigner.")
folder = ROOT / "app/build/qa"
folder.mkdir(parents=True, exist_ok=True)
unsigned = folder / "large-unsigned.apk"
output = folder / "large-fixture.apk"
try:
with zipfile.ZipFile(source) as original, zipfile.ZipFile(unsigned, "w") as target:
for entry in original.infolist():
if entry.filename.upper().startswith("META-INF/"):
continue
with original.open(entry) as incoming, target.open(entry, "w") as outgoing:
shutil.copyfileobj(incoming, outgoing, 64 * 1024)
asset = zipfile.ZipInfo("assets/pakkit-transfer-test.bin")
asset.compress_type = zipfile.ZIP_STORED
asset.file_size = args.bytes
block = bytes(64 * 1024)
remaining = args.bytes
with target.open(asset, "w") as stream:
while remaining:
chunk = min(remaining, len(block))
stream.write(block[:chunk])
remaining -= chunk
subprocess.run([str(versions[-1]), "sign", "--ks", str(Path.home() / ".android/debug.keystore"),
"--ks-pass", "pass:android", "--key-pass", "pass:android", "--ks-key-alias", "androiddebugkey",
"--out", str(output), str(unsigned)], check=True)
subprocess.run([str(versions[-1]), "verify", str(output)], check=True)
print(f"{output} ({output.stat().st_size:,} bytes)")
finally:
unsigned.unlink(missing_ok=True)
+2 -4
View File
@@ -61,15 +61,13 @@ def tap_text(serial, label, attempts=6):
def session_url(serial):
tap_text(serial, "View link")
for _ in range(6):
tree = ui(serial)
for node in tree.iter("node"):
value = node.get("text", "")
if value.startswith("http://") and "#" in value:
tap_text(serial, "Back to code")
if value.startswith("http://") and ":8787" in value:
return value
bounds = next(tree.iter("node")).get("bounds")
_, _, width, height = map(int, re.findall(r"\d+", bounds))
adb(serial, "shell", "input", "swipe", str(width // 2), str(height * 3 // 4), str(width // 2), str(height // 4), "300")
raise RuntimeError("No private session link found. Check source approval and emulator Wi-Fi.")
raise RuntimeError("No receiving address found. Check emulator Wi-Fi.")
+22 -3
View File
@@ -13,6 +13,7 @@ parser.add_argument("--watch", required=True, help="Wear OS emulator serial, e.g
parser.add_argument("--browser", help="Optional Android emulator serial with Chrome initialized")
parser.add_argument("--small", action="store_true", help="Run round UI tests at 192dp and 1.3x font size")
parser.add_argument("--skip-build", action="store_true")
parser.add_argument("--large", action="store_true", help="Use app/build/qa/large-fixture.apk for the real browser upload")
args = parser.parse_args()
if args.browser == args.watch:
parser.error("Use distinct Wear OS and Android browser emulator serials.")
@@ -51,7 +52,7 @@ try:
print(output, flush=True)
screenshots = report_dir / ("watch-product-small" if args.small else "watch-product")
screenshots.mkdir(exist_ok=True)
for name in ["home", "scan", "link", "sending", "checking", "ready", "installing", "confirm", "failed", "installed"]:
for name in ["home", "scan", "browser-approval", "sending", "checking", "ready", "installing", "confirm", "failed", "installed"]:
image = adb(args.watch, "exec-out", "cat", f"/sdcard/Android/data/meghdad.pakkit/files/product-review/{name}.png")
(screenshots / f"{name}.png").write_bytes(image)
@@ -78,10 +79,28 @@ if args.browser:
tap_text(args.watch, "Start receiving")
url = session_url(args.watch)
env = dict(os.environ, PAKKIT_SESSION_URL=url, PAKKIT_CDP_URL=f"http://127.0.0.1:{endpoint}")
subprocess.run(["node", str(ROOT / "web-tests/emulator.test.cjs")], cwd=ROOT, env=env, check=True)
remote_fixture = "/sdcard/Android/data/com.android.chrome/files/pakkit-large.apk"
if args.large:
fixture = ROOT / "app/build/qa/large-fixture.apk"
if not fixture.exists():
raise RuntimeError("Run scripts/create-large-fixture.py first.")
adb(args.browser, "shell", "mkdir", "-p", "/sdcard/Android/data/com.android.chrome/files")
adb(args.browser, "push", str(fixture), remote_fixture)
env.update(PAKKIT_TEST_APK=str(fixture), PAKKIT_BROWSER_FILE=remote_fixture)
browser_test = subprocess.Popen(["node", str(ROOT / "web-tests/emulator.test.cjs")], cwd=ROOT, env=env)
try:
tap_text(args.watch, "Allow browser", attempts=12)
if browser_test.wait(timeout=180) != 0:
raise RuntimeError("Android browser transfer failed.")
finally:
if browser_test.poll() is None:
browser_test.terminate()
browser_test.wait(timeout=10)
adb(args.watch, "shell", "am", "start", "-W", "-n", "meghdad.pakkit/.ui.WatchActivity")
tap_text(args.watch, "Remove file")
tap_text(args.watch, "End session")
tap_text(args.watch, "Stop receiving")
finally:
if args.large:
adb(args.browser, "shell", "rm", "-f", "/sdcard/Android/data/com.android.chrome/files/pakkit-large.apk")
adb(args.browser, "forward", "--remove", f"tcp:{endpoint}")
adb(args.watch, "shell", "am", "force-stop", "meghdad.pakkit")