Files
OrbitTv/tools/check_editions.py
T

97 lines
6.2 KiB
Python

#!/usr/bin/env python3
"""
The editions check in the release gate (Paul, 10 November 2026). Reads what was actually built, never the source:
- the household APK, the Play APK, and the Play bundle (.aab), whose manifest is converted with aapt2 and read the same way;
- both editions are tv.orbit.classic, with versionCode = build x 10 + 0 (household) and + 2 (Play), above every code in
tools/known-version-codes.txt (and in ORBIT_APKS when that folder is there), the reserved 390 recovery build included;
- the Play APK and bundle hold no install permission, no PackageInstaller, no room-update or test hooks, no server address;
- the household APK still has its updater, install permission and install check;
- nothing is signed: no v1 signature files and no APK signing block.
check_editions.py <household.apk> <play.apk> <play.aab> <aapt2>
"""
import os, re, subprocess, sys, tempfile, zipfile
household_apk, play_apk, play_aab, aapt2 = sys.argv[1:5]
here = os.path.dirname(os.path.abspath(__file__))
problems = []
def badging(apk):
out = subprocess.run([aapt2, "dump", "badging", apk], capture_output=True, text=True, check=True).stdout
m = re.search(r"package: name='([^']*)' versionCode='(\d+)' versionName='([^']*)'", out)
return m[1], int(m[2]), m[3], sorted(set(re.findall(r"uses-permission: name='([^']*)'", out)))
def aab_as_apk(aab, into):
"""The bundle's base module, as aapt2 reads it: its proto manifest and resources converted to an ordinary APK."""
proto = os.path.join(into, "proto.apk"); binary = os.path.join(into, "binary.apk")
with zipfile.ZipFile(aab) as z, zipfile.ZipFile(proto, "w") as out:
for n in z.namelist():
if not n.startswith("base/"): continue
rest = n[len("base/"):]
if rest == "manifest/AndroidManifest.xml": out.writestr("AndroidManifest.xml", z.read(n))
elif rest == "resources.pb" or rest.startswith("res/"): out.writestr(rest, z.read(n))
subprocess.run([aapt2, "convert", "--output-format", "binary", "-o", binary, proto], check=True, capture_output=True)
return binary
def dex(path):
with zipfile.ZipFile(path) as z:
return b"".join(z.read(n) for n in z.namelist() if re.search(r"(^|/)classes\d*\.dex$", n) or n.startswith(("assets/", "base/assets/")))
def signed(path):
with zipfile.ZipFile(path) as z:
if any(re.match(r"META-INF/.*\.(RSA|DSA|EC|SF)$", n) for n in z.namelist()): return True
return b"APK Sig Block 42" in open(path, "rb").read()
known = []
for line in open(os.path.join(here, "known-version-codes.txt")):
if line.strip() and not line.startswith("#"):
code, package, name = line.split()[:3]; known.append((int(code), package, name))
apks = os.environ.get("ORBIT_APKS", "/home/pauljd/Documents/OrbitTV/apks")
if os.path.isdir(apks):
for root, _, files in os.walk(apks):
for f in files:
if f.endswith(".apk"):
try: p, c, n, _ = badging(os.path.join(root, f)); known.append((c, p, n))
except Exception: pass
highest = max(c for c, p, _ in known if p.startswith("tv.orbit.classic"))
with tempfile.TemporaryDirectory() as tmp:
editions = {"household APK": badging(household_apk), "Play APK": badging(play_apk), "Play bundle": badging(aab_as_apk(play_aab, tmp))}
for label, (package, code, name, perms) in editions.items():
print(f"{label}: {package} versionCode {code} versionName {name}")
if package != "tv.orbit.classic": problems.append(f"{label} is {package}, not tv.orbit.classic")
hh, pa, bu = (editions[k][1] for k in ("household APK", "Play APK", "Play bundle"))
build = hh // 10
if hh % 10 != 0: problems.append(f"household code {hh} doesn't end in 0")
if pa != build * 10 + 2 or bu != pa: problems.append(f"Play codes {pa}/{bu} aren't {build * 10 + 2}")
if hh <= highest: problems.append(f"household code {hh} isn't above the highest code built so far, {highest}")
recovery = build * 10 + 9
if any(c == recovery for c, _, _ in known): problems.append(f"this build's recovery code {recovery} is already used")
print(f"highest earlier code {highest} (reserved recovery 390 included); this build {build}: household {hh}, Play {pa}, recovery slot {recovery}")
for label in ("Play APK", "Play bundle"):
if "android.permission.REQUEST_INSTALL_PACKAGES" in editions[label][3]: problems.append(f"{label} asks for REQUEST_INSTALL_PACKAGES")
if "android.permission.REQUEST_INSTALL_PACKAGES" not in editions["household APK"][3]: problems.append("household APK lost REQUEST_INSTALL_PACKAGES")
forbidden = [b"android/content/pm/PackageInstaller", b"RoomUpdates", b"ROOM_UPDATE", b"/room/orbit.apk", b"InstallSnapshotReceiver",
b"INSTALL_SNAPSHOT", b"PlaybackTestActivity", b"orbit_play_test", b"orbit_shadow_catalogue", b"orbit_provider_catalogue",
b"orbit_frame_rate", b"orbit_avi", b"orbit_timing", b"orbit_requests", b"PlaytestFileActivity", b"playtest-approved", b"appboxmanager"]
for label, path in (("Play APK", play_apk), ("Play bundle", play_aab)):
found = [f.decode() for f in forbidden if f in dex(path)]
if found: problems.append(f"{label} contains: {', '.join(found)}")
required = [b"android/content/pm/PackageInstaller", b"RoomUpdates", b"InstallSnapshotReceiver", b"orbit_shadow_catalogue"]
missing = [r.decode() for r in required if r not in dex(household_apk)]
if missing: problems.append(f"household APK is missing: {', '.join(missing)}")
for bad in (b"PlaytestFileActivity", b"playtest-approved", b"appboxmanager"):
if bad in dex(household_apk): problems.append(f"household APK contains {bad.decode()}")
# Shared features are in both: Rooms, profiles, Taste, Continue Watching, the Arcade.
for need in (b"RoomSync", b"Profiles", b"TasteEvent", b"ContinueWatching", b"tv/orbit/classic/arcade"):
for label, path in (("household APK", household_apk), ("Play APK", play_apk), ("Play bundle", play_aab)):
if need not in dex(path): problems.append(f"{label} is missing shared {need.decode()}")
for label, path in (("household APK", household_apk), ("Play APK", play_apk), ("Play bundle", play_aab)):
if signed(path): problems.append(f"{label} is signed")
if problems:
print("Editions check FAILED:"); [print(" - " + p) for p in problems]; sys.exit(1)
print("Editions check passed: same app id, codes in order, Play isolated, household intact, all unsigned.")