Android: a picture in a chat is clipped to the bubble's 30 dp corner, sent and received. Checked on the Rabbit with the dev app (the sandbox now has a made-up picture each way). Both: voip.ms gives a picture we sent with no words the text "MMS Sent", like the "MMS Received" already dropped; that goes too, from new messages and (once) from ones already stored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
7.3 KiB
Python
124 lines
7.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Fill the *dev* app (me.teafry.voipmessages.dev) on a connected device with
|
|
made-up conversations, for testing without anyone's real messages or accounts.
|
|
Its config is marked sandbox, so the app never goes online.
|
|
|
|
python3 android/build.py --dev --install && python3 android/tools/push_sandbox.py
|
|
|
|
With --relay URL (and RELAY_TOKEN / RELAY_KEY in the environment) the dev app
|
|
also gets relay settings, e.g. a throwaway local server/bubble_relay.py reached
|
|
through `adb reverse tcp:18080 tcp:<port>` with --relay http://127.0.0.1:18080.
|
|
|
|
Uses the same copy-in mechanism as the desktop installer: files are piped
|
|
through `adb shell run-as` into the app's private storage.
|
|
"""
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sqlite3
|
|
import subprocess
|
|
import struct
|
|
import tempfile
|
|
import zlib
|
|
import time
|
|
from pathlib import Path
|
|
|
|
PKG = "me.teafry.voipmessages.dev"
|
|
VOIP, GV = "5415550100", "5415550177"
|
|
GROUP = "5415550101,5415550102,5415550103"
|
|
|
|
|
|
def gradient_png(w: int, h: int) -> bytes:
|
|
raw = b"".join(b"\0" + bytes(c for x in range(w) for c in (x * 255 // w, y * 255 // h, 160)) for y in range(h))
|
|
chunk = lambda t, b: struct.pack(">I", len(b)) + t + b + struct.pack(">I", zlib.crc32(t + b))
|
|
return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw)) + chunk(b"IEND", b"")
|
|
|
|
|
|
def push(local: Path, name: str):
|
|
with open(local, "rb") as f:
|
|
subprocess.run(["adb", "shell", f"run-as {PKG} sh -c 'cat > files/{name}'"], stdin=f, check=True)
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--relay", help="relay URL as the Rabbit reaches it (token and key from RELAY_TOKEN / RELAY_KEY)")
|
|
args = ap.parse_args()
|
|
subprocess.run(["adb", "shell", "am", "force-stop", PKG], check=True)
|
|
# Fresh: no history, and no relay cursors left from an earlier run.
|
|
subprocess.run(["adb", "shell", f"run-as {PKG} sh -c 'mkdir -p files && rm -f files/messages.db* shared_prefs/relay.xml'"], check=True)
|
|
with tempfile.TemporaryDirectory() as d:
|
|
db = Path(d) / "messages.db"
|
|
con = sqlite3.connect(db)
|
|
con.executescript("""
|
|
CREATE TABLE messages (id INTEGER PRIMARY KEY, did TEXT NOT NULL, contact TEXT NOT NULL, direction TEXT NOT NULL,
|
|
body TEXT NOT NULL, ts INTEGER NOT NULL, kind TEXT NOT NULL DEFAULT 'sms', status TEXT NOT NULL DEFAULT 'delivered',
|
|
media_json TEXT, error TEXT, sender TEXT);
|
|
CREATE TABLE read_state (did TEXT NOT NULL, contact TEXT NOT NULL, last_read_ts INTEGER NOT NULL, archived_at INTEGER,
|
|
marked_unread INTEGER NOT NULL DEFAULT 0, name TEXT, name_ts INTEGER, PRIMARY KEY (did, contact));
|
|
CREATE TABLE kv (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
CREATE TABLE gv_threads (did TEXT NOT NULL, contact TEXT NOT NULL, thread_id TEXT NOT NULL, PRIMARY KEY (did, contact));
|
|
""")
|
|
now = int(time.time() * 1000)
|
|
m = 60_000
|
|
rows = [
|
|
(1001, VOIP, "5415550110", "in", "Are we still on for Saturday?", now - 300 * m, None),
|
|
(1002, VOIP, "5415550110", "out", "Yep! 10am at the market", now - 290 * m, None),
|
|
# A Spanish iPhone's tapback, and an edit (Reactions.java, Edits.java).
|
|
(1004, VOIP, "5415550110", "in", "Le encanta “Yep! 10am at the market”", now - 289 * m, None),
|
|
(1005, VOIP, "5415550110", "in", "Can you grab coffee on the way", now - 288 * m, None),
|
|
(1006, VOIP, "5415550110", "in", "Edited to “Can you grab coffee and bagels on the way?”", now - 286 * m, None),
|
|
(1003, VOIP, "5415550111", "in", "Your table is ready", now - 2000 * m, None),
|
|
(2**52 + 1, GV, "5415550120", "in", "Package left at the front door", now - 90 * m, None),
|
|
(2**52 + 2, GV, "5415550120", "out", "Thanks!", now - 85 * m, None),
|
|
(2**52 + 3, GV, GROUP, "in", "Who is bringing snacks to the hike?", now - 40 * m, "5415550101"),
|
|
(2**52 + 4, GV, GROUP, "in", "I can do chips", now - 38 * m, "5415550102"),
|
|
(2**52 + 5, GV, GROUP, "in", "and salsa", now - 37 * m, "5415550102"),
|
|
(2**52 + 6, GV, GROUP, "out", "I'll bring cookies 🍪", now - 30 * m, None),
|
|
(2**52 + 7, GV, GROUP, "in", "Perfect, see everyone at 9. This one is a longer message to check how wrapping looks on the little screen.", now - 5 * m, "5415550103"),
|
|
]
|
|
# Enough chats that the list scrolls (the search box hides above the top).
|
|
for i in range(12):
|
|
rows.append((3000 + i, VOIP, f"54155502{i:02d}", "in", f"Filler chat number {i + 1}", now - (3000 + i * 400) * m, None))
|
|
# A long history, to see how fast a big chat opens.
|
|
LONG = "5415550130"
|
|
for i in range(4000):
|
|
rows.append((10_000 + i, VOIP, LONG, "in" if i % 3 else "out", f"Message {i + 1} of a long chat", now - (8000 - i) * 30_000, None))
|
|
# A group you've named, whose members match other searches too.
|
|
NAMED = "5415550101,5415550140"
|
|
rows.append((2**52 + 20, GV, NAMED, "in", "Booked the cabin!", now - 600 * m, "5415550140"))
|
|
con.execute("INSERT INTO read_state (did, contact, last_read_ts, name, name_ts) VALUES (?, ?, 0, 'Cabin trip', ?)", (GV, NAMED, now))
|
|
# The Rabbit's SIM (did 'sim', ids from 2^51 like Sim.java's).
|
|
SIM_BASE = 2**51
|
|
rows.append((SIM_BASE + 1, "sim", "5415550150", "in", "Texting your SIM number now", now - 20 * m, None))
|
|
rows.append((SIM_BASE + 2, "sim", "5415550150", "out", "Got it, this is the SIM", now - 19 * m, None))
|
|
con.executemany("INSERT INTO messages (id, did, contact, direction, body, ts, sender) VALUES (?,?,?,?,?,?,?)", rows)
|
|
# Pictures both ways (a made-up gradient), to see their corners.
|
|
pic = Path(d) / "sandbox-pic.png"
|
|
pic.write_bytes(gradient_png(400, 300))
|
|
ref = json.dumps([{"file": "sandbox-pic.png", "mime": "image/png", "width": 400, "height": 300}])
|
|
con.execute("INSERT INTO messages (id, did, contact, direction, body, ts, kind, media_json) VALUES (1007, ?, '5415550110', 'in', 'Look at this', ?, 'mms', ?)", (VOIP, now - 280 * m, ref))
|
|
con.execute("INSERT INTO messages (id, did, contact, direction, body, ts, kind, media_json) VALUES (1008, ?, '5415550110', 'out', '', ?, 'mms', ?)", (VOIP, now - 279 * m, ref))
|
|
con.execute("INSERT INTO kv VALUES ('unread_floor', '0')")
|
|
con.execute("INSERT INTO gv_threads VALUES (?, ?, 'g.demo')", (GV, GROUP))
|
|
con.commit()
|
|
con.close()
|
|
cfg = Path(d) / "config.json"
|
|
cfg.write_text(json.dumps({
|
|
"sandbox": True,
|
|
"voipms": {"username": "sandbox", "password": "sandbox"},
|
|
"gvoice": {"number": GV, "cookies": {}},
|
|
"dids": [{"did": VOIP, "description": "Demo"}],
|
|
"defaultDid": VOIP,
|
|
**({"relay": {"url": args.relay, "token": os.environ["RELAY_TOKEN"], "key": os.environ["RELAY_KEY"]}} if args.relay else {}),
|
|
}))
|
|
push(db, "messages.db")
|
|
push(cfg, "config.json")
|
|
subprocess.run(["adb", "shell", f"run-as {PKG} mkdir -p files/media"], check=True)
|
|
push(pic, "media/sandbox-pic.png")
|
|
subprocess.run(["adb", "shell", "am", "start", "-n", f"{PKG}/me.teafry.voipmessages.MainActivity"], check=True)
|
|
print("sandbox data pushed to", PKG)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|