mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
feat(stores): download Amazon engine on demand
This commit is contained in:
1 parent
61482ffee7
commit
9222a1fe4d
28 files changed
+2194
-38
No files matched your search
@@ -83,3 +83,7 @@ pack tracking "$work/tracking" hand_landmarker.task hand_landmarker_lite.task po
|
||||
libopencv_java4.so libmediapipe_tasks_jni.so
|
||||
pack xbox "$linuxfs/droiddeck-xbox" version xodus-cli xodus-service
|
||||
pack comet "$linuxfs/droiddeck-comet" version comet
|
||||
bash "$repo/tools/stores/build-amazon.sh"
|
||||
mkdir "$work/amazon"
|
||||
cp "$repo/app/build/amazon-engine/engine.json" "$repo/app/build/amazon-engine/libdroiddeckamazon.so" "$work/amazon/"
|
||||
pack amazon "$work/amazon" engine.json libdroiddeckamazon.so
|
||||
@@ -1,9 +1,13 @@
|
||||
"""Validate the JNI entry points and Android ELF dependency closure in the actual APK."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import tarfile
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
@@ -13,9 +17,43 @@ SYSTEM = set('libc.so libm.so libdl.so liblog.so libandroid.so libz.so libvulkan
|
||||
EXPORTS = ['Java_com_droiddeck_launcher_stores_StoresNative_nativeVersion',
|
||||
'Java_com_droiddeck_launcher_stores_gog_GogNative_nativeStart',
|
||||
'Java_com_droiddeck_launcher_stores_epic_EpicNative_nativeCall',
|
||||
'Java_com_droiddeck_launcher_stores_epic_EpicNative_nativeInstall',
|
||||
'Java_com_droiddeck_launcher_stores_amazon_AmazonNative_nativeCall',
|
||||
'Java_com_droiddeck_launcher_stores_amazon_AmazonNative_nativeInstall']
|
||||
'Java_com_droiddeck_launcher_stores_epic_EpicNative_nativeInstall']
|
||||
AMAZON_EXPORTS = ['Java_com_droiddeck_launcher_stores_amazon_AmazonNative_native' + name
|
||||
for name in ['EngineAbi', 'Configure', 'Call', 'Fetch', 'Inspect', 'Install', 'Cancel', 'Release']]
|
||||
|
||||
|
||||
def check_amazon_pack(path, readelf):
|
||||
errors = []
|
||||
raw = subprocess.check_output(['zstd', '-dc', str(path)])
|
||||
with tarfile.open(fileobj=io.BytesIO(raw)) as archive:
|
||||
if sorted(archive.getnames()) != ['engine.json', 'libdroiddeckamazon.so']:
|
||||
return ['Amazon pack must contain exactly its manifest and native engine']
|
||||
for member in archive:
|
||||
if not member.isfile():
|
||||
return ['Amazon pack contains a non-regular file']
|
||||
library = archive.extractfile('libdroiddeckamazon.so').read()
|
||||
metadata = json.load(archive.extractfile('engine.json'))
|
||||
if (metadata.get('schema'), metadata.get('engine'), metadata.get('abi'), metadata.get('target')) != (
|
||||
1, 'amazon', 1, 'aarch64-linux-android'):
|
||||
errors.append('Amazon engine metadata is incompatible')
|
||||
if metadata.get('library_sha256') != hashlib.sha256(library).hexdigest():
|
||||
errors.append('Amazon engine digest differs from its manifest')
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
binary = Path(temp) / 'libdroiddeckamazon.so'
|
||||
binary.write_bytes(library)
|
||||
header = subprocess.check_output([readelf, '-h', str(binary)], text=True)
|
||||
if 'AArch64' not in header or 'ELF64' not in header:
|
||||
errors.append('Amazon engine is not Android ARM64')
|
||||
symbols = subprocess.check_output([readelf, '--dyn-syms', '--wide', str(binary)], text=True)
|
||||
exports = {line.split()[-1] for line in symbols.splitlines()
|
||||
if ' GLOBAL ' in line and ' UND ' not in line and line.split()}
|
||||
errors += ['Amazon library missing ' + symbol for symbol in AMAZON_EXPORTS if symbol not in exports]
|
||||
if any(symbol in exports for symbol in EXPORTS):
|
||||
errors.append('Amazon engine still exports other store entry points')
|
||||
dynamic = subprocess.check_output([readelf, '-d', str(binary)], text=True)
|
||||
errors += ['Amazon engine needs missing ' + name for name in re.findall(r'NEEDED.*\[(.*?)\]', dynamic)
|
||||
if name not in SYSTEM]
|
||||
return errors
|
||||
|
||||
|
||||
def check(apk, readelf, stores=True):
|
||||
@@ -41,8 +79,12 @@ def check(apk, readelf, stores=True):
|
||||
exports = {line.split()[-1] for line in symbols.splitlines()
|
||||
if ' GLOBAL ' in line and ' UND ' not in line and line.split()}
|
||||
errors += ['Store library missing ' + symbol for symbol in EXPORTS if symbol not in exports]
|
||||
if any(symbol in exports for symbol in AMAZON_EXPORTS):
|
||||
errors.append('Bundled store library still contains Amazon entry points')
|
||||
elif library is not None:
|
||||
errors.append('Rust was skipped but the APK contains a cached store library')
|
||||
if 'libdroiddeckamazon.so' in libraries:
|
||||
errors.append('APK still bundles the optional Amazon engine')
|
||||
return errors
|
||||
|
||||
|
||||
@@ -51,8 +93,11 @@ if __name__ == '__main__':
|
||||
parser.add_argument('apk')
|
||||
parser.add_argument('--readelf', default='readelf')
|
||||
parser.add_argument('--without-stores', action='store_true')
|
||||
parser.add_argument('--amazon-pack', default='app/build/packs/amazon.tar.zst')
|
||||
args = parser.parse_args()
|
||||
errors = check(args.apk, args.readelf, not args.without_stores)
|
||||
if not args.without_stores:
|
||||
errors += check_amazon_pack(args.amazon_pack, args.readelf)
|
||||
if errors:
|
||||
parser.exit(1, '\n'.join(errors) + '\n')
|
||||
print('APK native exports and dependencies verified')
|
||||
@@ -17,10 +17,14 @@ PACKS = Path('app/build/packs')
|
||||
PACKED = {'assets/linuxfs/usr/local/lib/droiddeck-xbox/': 'xbox', 'assets/linuxfs/usr/local/lib/droiddeck-comet/': 'comet',
|
||||
'assets/directaudio/': 'directaudio'}
|
||||
PACKED_FILES = {'lib/arm64-v8a/libproot.so': ('proot', 'libproot.so'),
|
||||
'lib/arm64-v8a/libproot-loader.so': ('proot', 'libproot-loader.so')}
|
||||
'lib/arm64-v8a/libproot-loader.so': ('proot', 'libproot-loader.so'),
|
||||
'lib/arm64-v8a/libdroiddeckamazon.so': ('amazon', 'libdroiddeckamazon.so'),
|
||||
'assets/store-engines/amazon/engine.json': ('amazon', 'engine.json')}
|
||||
PACKED_LIBRARIES = ['lib/arm64-v8a/libopencv_java4.so', 'lib/arm64-v8a/libmediapipe_tasks_jni.so']
|
||||
PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet']
|
||||
PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'amazon']
|
||||
SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app/src/main/assets/pulseaudio.tzst',
|
||||
'app/src/main/rust/stores/src', 'app/src/main/rust/stores/Cargo.toml',
|
||||
'app/src/main/rust/amazon/Cargo.toml', 'app/src/main/rust/amazon/Cargo.lock', 'tools/stores',
|
||||
'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs',
|
||||
'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env',
|
||||
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/components', 'tools/ci', 'tools/build_local.sh',
|
||||
@@ -61,6 +65,8 @@ def outputs(root):
|
||||
result['assets/' + tree + '/' + path.relative_to(base).as_posix()] = path.relative_to(root).as_posix()
|
||||
for library in ['libproot.so', 'libproot-loader.so', 'libdirectaudiorelay.so']:
|
||||
result['lib/arm64-v8a/' + library] = 'app/src/main/jniLibs/arm64-v8a/' + library
|
||||
result['lib/arm64-v8a/libdroiddeckamazon.so'] = 'app/build/amazon-engine/libdroiddeckamazon.so'
|
||||
result['assets/store-engines/amazon/engine.json'] = 'app/build/amazon-engine/engine.json'
|
||||
result['assets/pulseaudio.tzst'] = 'app/build/prepared-assets/pulseaudio.tzst'
|
||||
result['assets/graphics_driver/adrenotools-turnip25.1.0-quest1.tzst'] = \
|
||||
'app/build/prepared-assets/graphics_driver/adrenotools-turnip25.1.0-quest1.tzst'
|
||||
@@ -71,7 +77,8 @@ def outputs(root):
|
||||
|
||||
|
||||
def required():
|
||||
paths = ['assets/graphics_driver/adrenotools-turnip25.1.0-quest1.tzst']
|
||||
paths = ['lib/arm64-v8a/libdroiddeckamazon.so', 'assets/store-engines/amazon/engine.json']
|
||||
paths += ['assets/graphics_driver/adrenotools-turnip25.1.0-quest1.tzst']
|
||||
paths += [f'assets/graphics_driver/adrenotools-{name}.tzst'
|
||||
for name in ['turnip26.3.0-a6xx', 'turnip26.3.0-quest2']]
|
||||
paths += ['assets/linuxfs/' + name for name in ['libfakeinput.so', 'libblsession.so',
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Amazon engine pilot
|
||||
|
||||
The APK keeps GOG and Epic in `libdroiddeckstores.so`. Amazon is compiled separately
|
||||
as `libdroiddeckamazon.so`, using the same reviewed Rust sources and shared download
|
||||
implementation. Cargo features determine the exported stores; the source is not copied.
|
||||
The separate library duplicates some linked Rust dependencies. Measure combined
|
||||
download size before extending this model to other stores.
|
||||
|
||||
`tools/stores/build-amazon.sh` builds Android ARM64/API 26 with the selected NDK and
|
||||
locked Cargo dependencies. `engine.json` records interface version 1, library digest,
|
||||
source/recipe input digests, Rust compiler and NDK metadata. `tools/packs/build.sh`
|
||||
includes exactly that manifest and library in the Amazon pack. APK validation checks
|
||||
the engine's ARM64 ELF header, JNI exports, dependency closure and digest, and rejects
|
||||
Amazon exports left in the bundled store library. Runtime input checks reject stale
|
||||
pack bytes. CI runs the standalone engine's host tests as a required step.
|
||||
|
||||
The signed APK pins the complete pack SHA-256. Existing main-only publication produces
|
||||
an immutable content-addressed release; PR publication attaches the exact same-run pack
|
||||
to the PR release. This metadata documents the build; it is not an independent signed
|
||||
attestation or a reproducibility claim. Cargo's existing incremental cache is used;
|
||||
this pilot does not introduce independent prebuilt engine reuse or faster CI guarantees.
|
||||
|
||||
Amazon sign-in downloads support on a worker before opening the browser. Signed-in
|
||||
library sync and installation prepare it as needed. Other stores and ordinary startup
|
||||
do not request the pack. Existing library cache, credentials, game paths, sidecars and
|
||||
installed games are retained. Once installed, the pinned pack is usable offline.
|
||||
New APKs reuse an existing pack when its digest is unchanged; changed pins download
|
||||
their exact version rather than loading an arbitrary older engine. Loading verifies
|
||||
the manifest/library and JNI interface before configuring the engine. Unpinned local
|
||||
builds intentionally cannot borrow an arbitrary prior Amazon pack.
|
||||
|
||||
Device validation still needs a fresh Amazon sign-in, existing-account upgrade, failed
|
||||
download/retry, offline relaunch, and cancel/resume installation. Robolectric integrity
|
||||
tests and ELF checks do not substitute for Android native loading and live account tests.
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Record the Amazon engine's build inputs in its APK-pinned add-on pack."""
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def inputs(root=ROOT):
|
||||
paths = ['app/src/main/rust/amazon/Cargo.toml', 'app/src/main/rust/amazon/Cargo.lock',
|
||||
'app/src/main/rust/stores/src/lib.rs', 'app/src/main/rust/stores/src/stores_jni.rs',
|
||||
'app/src/main/rust/stores/src/amazon', 'app/src/main/rust/stores/src/fetch_core.rs',
|
||||
'app/src/main/rust/stores/src/fetch_tuning.rs', 'app/src/main/rust/stores/src/priority.rs',
|
||||
'app/src/main/rust/stores/src/md5_small.rs',
|
||||
'tools/stores/build-amazon.sh', 'tools/stores/amazon-manifest.py']
|
||||
files = []
|
||||
for name in paths:
|
||||
path = root / name
|
||||
files.extend(path.rglob('*') if path.is_dir() else [path])
|
||||
return {p.relative_to(root).as_posix(): hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
for p in sorted(set(files)) if p.is_file() and '__pycache__' not in p.parts}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
out, ndk = map(Path, sys.argv[1:])
|
||||
data = {'schema': 1, 'engine': 'amazon', 'abi': 1, 'target': 'aarch64-linux-android',
|
||||
'platform': 26, 'inputs': inputs(),
|
||||
'rustc': subprocess.check_output(['rustup', 'run', 'stable', 'rustc', '-Vv'], text=True),
|
||||
'ndk': (ndk / 'source.properties').read_text(),
|
||||
'library_sha256': hashlib.sha256((out / 'libdroiddeckamazon.so').read_bytes()).hexdigest()}
|
||||
(out / 'engine.json').write_text(json.dumps(data, sort_keys=True, indent=2) + '\n')
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
repo=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
out="$repo/app/build/amazon-engine"
|
||||
export ANDROID_NDK_HOME=${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-${NDK:-${ANDROID_NDK_LATEST_HOME:-}}}}
|
||||
[[ -d "$ANDROID_NDK_HOME" ]] || { echo 'Android NDK required for Amazon engine' >&2; exit 1; }
|
||||
export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"$repo/app/src/main/rust/stores/target"}
|
||||
export RUSTC=$(rustup which --toolchain stable rustc)
|
||||
mkdir -p "$out"
|
||||
cd "$repo/app/src/main/rust/amazon"
|
||||
rustup run stable cargo ndk --target arm64-v8a --platform 26 --output-dir "$repo/app/build/amazon-native" build --release --locked
|
||||
cp "$repo/app/build/amazon-native/arm64-v8a/libdroiddeckamazon.so" "$out/libdroiddeckamazon.so"
|
||||
python3 "$repo/tools/stores/amazon-manifest.py" "$out" "$ANDROID_NDK_HOME"
|
||||
@@ -0,0 +1,77 @@
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / 'tools/release'))
|
||||
import check_android_libraries as native
|
||||
|
||||
|
||||
class AmazonEngineTest(unittest.TestCase):
|
||||
def pack(self, folder, abi=1, library=b'engine', checksum=None, extra=False):
|
||||
manifest = {'schema': 1, 'engine': 'amazon', 'abi': abi, 'target': 'aarch64-linux-android',
|
||||
'library_sha256': checksum or hashlib.sha256(library).hexdigest()}
|
||||
stream = io.BytesIO()
|
||||
files = {'engine.json': json.dumps(manifest).encode(), 'libdroiddeckamazon.so': library}
|
||||
if extra:
|
||||
files['unexpected'] = b'x'
|
||||
with tarfile.open(fileobj=stream, mode='w') as archive:
|
||||
for name, content in files.items():
|
||||
member = tarfile.TarInfo(name)
|
||||
member.size = len(content)
|
||||
archive.addfile(member, io.BytesIO(content))
|
||||
path = Path(folder) / 'amazon.tar.zst'
|
||||
path.write_bytes(stream.getvalue())
|
||||
return path
|
||||
|
||||
def validate(self, path, missing=False, bundled=False):
|
||||
def command(args, **kwargs):
|
||||
if args[0] == 'zstd':
|
||||
return path.read_bytes()
|
||||
if '-h' in args:
|
||||
return 'ELF64 AArch64'
|
||||
if '-d' in args:
|
||||
return 'NEEDED [libc.so]'
|
||||
symbols = native.AMAZON_EXPORTS[:-1] if missing else native.AMAZON_EXPORTS
|
||||
if bundled:
|
||||
symbols = symbols + native.EXPORTS
|
||||
return '\n'.join(' GLOBAL DEFAULT 1 ' + symbol for symbol in symbols)
|
||||
with patch.object(native.subprocess, 'check_output', side_effect=command):
|
||||
return native.check_amazon_pack(path, 'readelf')
|
||||
|
||||
def test_pack_checks_interface_digest_exports_and_isolation(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
self.assertEqual(self.validate(self.pack(directory)), [])
|
||||
self.assertTrue(self.validate(self.pack(directory, abi=2)))
|
||||
self.assertTrue(self.validate(self.pack(directory, checksum='0' * 64)))
|
||||
self.assertTrue(self.validate(self.pack(directory), missing=True))
|
||||
self.assertTrue(self.validate(self.pack(directory), bundled=True))
|
||||
self.assertTrue(self.validate(self.pack(directory, extra=True)))
|
||||
|
||||
def test_manifest_tracks_amazon_and_shared_inputs(self):
|
||||
inputs = runpy.run_path(str(ROOT / 'tools/stores/amazon-manifest.py'))['inputs']
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
amazon = root / 'app/src/main/rust/stores/src/amazon/example.rs'
|
||||
amazon.parent.mkdir(parents=True)
|
||||
amazon.write_text('amazon')
|
||||
common = root / 'app/src/main/rust/stores/src/fetch_core.rs'
|
||||
common.write_text('common')
|
||||
before = inputs(root)
|
||||
common.write_text('changed')
|
||||
self.assertNotEqual(before, inputs(root))
|
||||
self.assertIn(amazon.relative_to(root).as_posix(), before)
|
||||
|
||||
def test_apk_and_publication_use_optional_pack(self):
|
||||
gradle = (ROOT / 'app/build.gradle').read_text(encoding='utf-8')
|
||||
self.assertIn("'--no-default-features', '--features', 'gog,epic'", gradle)
|
||||
self.assertIn('comet amazon; do', (ROOT / '.github/workflows/publish-packs.yml').read_text())
|
||||
self.assertIn('pack amazon', (ROOT / 'tools/packs/build.sh').read_text())
|
||||
@@ -44,10 +44,11 @@ class RuntimeInputsTest(unittest.TestCase):
|
||||
|
||||
def packs(self):
|
||||
self.pack('tracking', {library.rsplit('/', 1)[1]: b'library' for library in runtime.PACKED_LIBRARIES})
|
||||
proot = {}
|
||||
packed = {}
|
||||
for name, (pack, rel) in runtime.PACKED_FILES.items():
|
||||
proot[rel] = (self.root / runtime.outputs(self.root)[name]).read_bytes()
|
||||
self.pack('proot', proot)
|
||||
packed.setdefault(pack, {})[rel] = (self.root / runtime.outputs(self.root)[name]).read_bytes()
|
||||
for name, files in packed.items():
|
||||
self.pack(name, files)
|
||||
for prefix, name in runtime.PACKED.items():
|
||||
base = self.root / 'app/src/main' / prefix
|
||||
self.pack(name, {path.relative_to(base).as_posix(): path.read_bytes() for path in base.rglob('*') if path.is_file()})
|
||||
|
||||
Reference in new issue
Block a user