59 lines
2.8 KiB
Python
59 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercise download network requests with real Android 9 framework classes.
|
|
|
|
This verifies capability matching and JobInfo construction, not a device,
|
|
WorkManager execution, internet connectivity, or OEM background scheduling.
|
|
"""
|
|
from pathlib import Path
|
|
import fcntl
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import urllib.request
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
WORK = Path(os.environ.get('TMPDIR', '/root/.hermes/cache/scratch')) / 'reelbox-network-test'
|
|
FRAMEWORK_URL = 'https://repo.maven.apache.org/maven2/org/robolectric/android-all/9-robolectric-4913185-2/android-all-9-robolectric-4913185-2.jar'
|
|
FRAMEWORK_SHA256 = 'cf4aed5e458deb48ddc0ca92fc25156e6f478d9d5c1d948cdd1817a67ee11b32'
|
|
|
|
|
|
def main():
|
|
WORK.mkdir(parents=True, exist_ok=True)
|
|
framework = WORK / 'android-all.jar'
|
|
if not framework.exists() or hashlib.sha256(framework.read_bytes()).hexdigest() != FRAMEWORK_SHA256:
|
|
with urllib.request.urlopen(FRAMEWORK_URL, timeout=90) as response:
|
|
blob = response.read()
|
|
assert hashlib.sha256(blob).hexdigest() == FRAMEWORK_SHA256, 'Framework checksum mismatch'
|
|
framework.write_bytes(blob)
|
|
classes = WORK / 'classes'
|
|
classes.mkdir(exist_ok=True)
|
|
source = ROOT / 'third_party/background_downloader/android/src/main/kotlin/com/bbflight/background_downloader/DownloadNetworkPolicy.java'
|
|
test = ROOT / 'tool/android/DownloadNetworkPolicyProbe.java'
|
|
with (ROOT / '.tooling.lock').open('a') as lock:
|
|
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
(WORK / 'verification.json').unlink(missing_ok=True)
|
|
command = ['javac', '-J-Xmx128m', '--release', '17', '-cp', str(framework), '-d', str(classes), str(test)]
|
|
if source.exists():
|
|
command.append(str(source))
|
|
subprocess.run(command, check=True, timeout=90)
|
|
result = subprocess.run(['java', '-Xmx192m', '-cp', os.pathsep.join([str(classes), str(framework)]),
|
|
'com.bbflight.background_downloader.DownloadNetworkPolicyProbe'],
|
|
check=False, capture_output=True, text=True, timeout=90)
|
|
print(result.stdout, end='')
|
|
if result.returncode:
|
|
print(result.stderr, end='')
|
|
raise subprocess.CalledProcessError(result.returncode, result.args)
|
|
assert 'PASS DownloadNetworkPolicy:' in result.stdout
|
|
(WORK / 'verification.json').write_text(json.dumps({
|
|
'passed': True,
|
|
'framework_sha256': FRAMEWORK_SHA256,
|
|
'stdout': result.stdout,
|
|
'scope': 'real Android 9 framework capability matching and JobInfo construction; no device or WorkManager execution',
|
|
'android_hardware_verified': False,
|
|
}, indent=2) + '\n')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|