The app is the GUI and the runtime, each in SDL's activity (dist/android): the menu extracts and
recompiles on the phone, then the game opens.
The menu (MainActivity) is scarletnx-gui as libmain.so, in the YoRHa theme. Taps and the back button
drive it (see GUI). Its data folder is in the app's own storage, .scarletnx/ in its files
(/data/data/org.scarletnx/files): games/ goes there, the extractions in its cache/work/, the games' logs in
its state/ and the menu's own files in its config/ and state/ (Usage). It needs no permission and nothing slows it down as the shared storage's
FUSE does; it goes with the app, which Android 10 and later ask about before uninstalling it. The system's Files app
shows it as ScarletNX, to copy dumps, keys and saves in and out, and the Data row's Open Folder in the menu's Folders (Settings > App > Folders) opens it there.
Settings > App > Folders may move the data, the games or the extractions to the shared storage; it asks first, as
games may run slower there, and takes the folder at a second tap.
HOME stays the app's own files, for .switch/prod.keys. An older version kept the data in /sdcard/ScarletNX
(or, without All files access, in the app's files themselves): as long as its games/ or keys are there, the
menu lists them as it opens, with the space each takes; nothing is moved. So are the menu's own files an older
version kept in the app's files themselves, out of the Files app's reach, which the menu no longer reads: while the
app is in testing, Clear storage in its Android settings takes them, with everything else of the app's
(Deprecations).
Loading (a Load item, Install Keys) opens its screen, a box the whole width, and a tap in the box
opens the system's file picker. A game's file is read by its path, so the app asks for access to the files when
it starts (all files from Android 11): the picker's path, or for a document without one the file its descriptor
opens. A cloud's document has none and is refused, its URI in the message. Wherever the dump is, its extraction
goes to the data folder's cache/work/, in the app's storage. Games lists the games there and the dumps put
there, to be prepared.
The driver runs as a child of the menu, as on a desktop, from libscarletnx-run.so: an executable named so
that Android installs it with the libraries, the only files of its own an app may execute. It loads the runtime,
libscarletnx.so, beside it. It cannot open a window there, so it ends at Ready <game> and the menu opens it.
libscarletnx.so holds every driver the app's build has, the 3DS, Vita and GBA ones too: the menu runs those
through libscarletnx-run.so with the driver's name first (scarletnx-3ds), as Windows does. The app has no Linux
driver; Load Linux ARM ELF is greyed, and Enter on it says so.
A game of Games goes through it too, recompiled first when another version of the app made it.
Behind other apps the driver keeps going: a notification shows the game, its step and a bar, and a tap on it returns to the menu. A run that ends there leaves a notification saying so, and its game opens once the menu shows. The queue's recompiles (R, B: GUI) go on the same way, the notification following the one running once no run of the menu's does, and saying Recompiled or Failed at the end; while a game started from the menu plays, until the menu shows again, they go gently. The first run asks to show it (Android 13) and to lift the battery limit; on a phone whose maker adds its own limit (Samsung, Xiaomi, OPPO, vivo, Huawei...) it names the setting, with a button to its screen.
A game runs in GameActivity, in a process of its own: the runtime's main with --game=recompiled/<game>.
Its process ends with the game, and the menu comes back on its first screen. <game>_code.so loads where it is;
from a game folder on the shared storage, which maps nothing executable, the runtime loads a copy in the app's
cache. The back button opens the
game's menu over it, in the menu's look (a gamepad's Home does on every system): the on-screen controls'
settings, the touch screen's, and Exit; back again returns to the game. A GBA, DS or Vita game has no menu: the
back button edits the layout of its on-screen controls, and a second one within 3 seconds, which a line over the game
says, closes it. Leaving a game for the home screen keeps it:
its window is made anew when it comes back.
A game by its title ID: the intent org.scarletnx.action.PLAY (PlayActivity), its extra title_id the
game's title ID, plays the recompiled game whose folder that ID names (recompiled/<title ID>/) as Play on its
row of Games does, with the updates, settings and GPU driver it has there. From a computer:
adb shell am start -a org.scarletnx.action.PLAY --es title_id 0100ABCD00010000
The menu comes in front and starts the game. An ID no recompiled game has, or one that is no title ID (16 hex digits), is said with that ID; while the setup shows, the game starts once it ends, and a run on the screen or a box over it keeps it from starting, said the same way. While a game plays, a PLAY of that game brings it back in front; of another, a toast names the one asked for.
Shortcuts: a long press on the app's icon lists the games played last, newest first, as many as the home screen shows (Android 7.1 and later), and a game's box in Games (a finger held on it) has Add to Home Screen, which the home screen asks about before it adds the game (Android 8 and later). Both are for a game whose folder its title ID names, with its name and icon as Games shows them, and open it as the PLAY above does.
GPU drivers: on arm64 with an Adreno, a Mali or an Xclipse GPU, from Android 9, a game can run with a Vulkan
driver package the player added (Turnip's releases for an Adreno and PanVK's for a Mali, as Eden takes them;
RADV's port to Xclipse, from Android 14) in place of the system's,
picked for every game or for one in Settings > App > GPU Drivers (GUI). An Adreno is known by
/dev/kgsl-3d0, a Mali by /dev/mali0 or /dev/mali, an Xclipse by a render node of /dev/dri whose kernel
driver DRM names amdgpu, the one RADV opens. The runtime loads
either itself (src/common/gpu/vk/gpu_driver_android.c, after libadrenotools): a game that picked a package
opens a second copy of Android's Vulkan loader in a linker namespace of its own, where libscarletnx-gpu-hook.so,
the one library this adds to the app's libraries folder, takes the two calls that copy opens its driver with, and
the package's library is opened for whichever driver it asks for. The linker's functions for namespaces are found in
the linker's own symbol table, at the address the kernel gives the process (AT_BASE). libhardware.so, which
PanVK asks for, is not in an app's by-name search, so it is opened by its path before the driver. The packages are
unpacked into the app's own storage (gpu_drivers/ of the user's data folder), as the linker loads libraries from
alone. A game's log says the package it asked for and, after the Vulkan instance, the driver Android's loader asked
for with the library it has, then vulkan: GPU driver <name> runs: its libraries are mapped; a package that did not
open stops the game, saying why (the system's driver is opened in its place first, so that the instance is made and
the game can say it), as does a package that lists no Vulkan device (Turnip on an Xclipse, RADV on an Adreno), with
the package and the GPU. On Android 16 the system's vulkan.adreno.so is in the process as the app starts, so a
package of that soname, Qualcomm's own, loads from a copy in its folder's unique/, each library under its name
with the case of its last letter changed and the names inside written over to match
(src/common/utilities/gpu_driver_stage.c). Download Driver fetches them over HTTPS through libcurl, trusting the
Mozilla root certificates the build carries (curl's extract of them, cmake/cacert.cmake), as Eden does with its
own OpenSSL.
Share Log, in the menu, asks how; its Share Zip saves the message on the screen, the last run's output (last-run.log, which the
menu keeps on every system), the menu's own log and fatal errors (scarletnx-console-<date>.log, scarletnx-error.log,
GUI) and the newest game log, none when it is older than the game played last, as summary.txt of
scarletnx-logs-<date>.zip in the data folder's state/share/, the logs themselves beside it, then opens that folder
in the Files app, to share from there.
How the last start ended. The menu's log, and a game's of the game's last run, say a start that did not end
with an exit (GUI), with the reason Android 11 and later keep for that process (ApplicationExitInfo): low
memory, crash native, user requested, signaled and the others, the process, its status, its importance and
the memory it held, and the system's own words. Android 10 and earlier keep none, and the line says so. The menu
asks the same of the game's process when a game it started ends, and on its next start when it was ended with the
game: the setup's Last Run page, or the run's screen, says it (GUI). At Debug's
Log level 2 the menu's log also has a state: line at its start and at each change of the thermal status (Android
10 and later) and of Battery Saver.
The app runs on arm64 phones and on x86_64 Android (the emulator, some tablets and Chromebooks): the recompiler makes the code of the device it runs on, with arm64's or x86-64's native back end. It installs from Android 5.0 (API 21). A game needs Vulkan 1.3: on a device without it (Android 5.0 and 6.0 have no Vulkan at all) the menu still prepares games, and a game says what it lacks. The fingers reach a game's touch screen (Touch screen, in the game's menu or the Settings, turns them off or adds a mouse). The buttons and sticks are on the screen, over the game (Usage), and a gamepad works beside them; the menu's On-screen controls item hides them. A GBA, DS or Vita game has its console's, which its own Settings (Settings at the foot of Games) hide.
Made from docs/hosts/android-app.md at 69237645142c. GPL-3.0-or-later.