APM is a C++17 package manager for Android with a Linux emulator mode. It ships three binaries. apm is the CLI, apmd handles package operations, and amsd applies Android Module System (AMS) overlays and runs module hooks. The project is GPL-3.0-or-later.
- Read each affected area before editing, including callers, headers, build definitions, runtime scripts, and relevant docs. The existing maintainer profile is in
.github/agents/apm-code-maintainer.agent.md. - Follow the surrounding C++ and shell style. Reuse the config, filesystem, logging, and protocol helpers. Preserve existing CLI behavior, on-disk formats, and upgrade paths unless the change explicitly revises them.
- Update both
CMakeLists.txtandAndroid.bpwhen source files, include paths, or link dependencies change. Several files undersrc/apmdalso build into the CLI oramsd. Check each consumer of shared code. - Use the implementation and tracked examples to resolve discrepancies in the documentation. Start with README.md and the wiki index. Check CLI and operations when changing a command and app repositories when changing bundle behavior.
| Area | Start here |
|---|---|
| CLI | src/apm/apm.cpp contains dispatch, help, authentication prompts, progress rendering, and local commands. Also see commands/search.cpp, transport.cpp, and ipc_client.cpp in the same tree. |
| Package daemon | src/apmd/apmd.cpp initializes runtime state and handles Android startup migrations. ipc_server.cpp handles authorization, request dispatch, and repository cache coordination. install_manager.cpp manages package lifecycles, export_path.cpp generates shell shims, and factory_reset.cpp implements reset and scoped cache wipes. |
| APKs and app bundles | src/apmd/apk_installer.cpp handles direct APK operations. app_installer.cpp stages repository bundles and apk_metadata.cpp reads binary APK manifests. src/core/app_repo.cpp parses definitions and selects GitHub release assets. |
| AMS | src/amsd/amsd.cpp coordinates boot, safe mode, and service readiness. Its ipc_server.cpp, request_dispatcher.cpp, and security_manager.cpp handle AMS socket requests. src/ams/module_manager.cpp owns ZIP installation, overlay backends, lifecycle hooks, and module state. module_info.cpp parses module metadata. |
| Shared core | src/core/ holds runtime configuration and logging, source and index handling, downloads, dependency resolution, status and manual package metadata, archive handling, and shared session state. Public interfaces are under src/core/include/. |
| Utilities | src/util/ contains filesystem helpers, daemon process locking, SHA-256 and MD5 digest helpers, and OpenPGP verification and key import under crypto/. |
| Repository examples | Repositories/PackageRepos/ contains Termux .repo examples. Repositories/AppRepos/ contains the MicroG .apprepo example. |
- Resolve paths through
src/core/config.cppand its header. Android keeps persistent APM state in/data/apm, shell-facing installs and shims in/data/local/tmp/apm, and AMS state in/data/ams. The Linux emulator uses$HOME/APMEmulator/data/apmand$HOME/APMEmulator/ams. For layout changes, check startup migration, shell permissions and labels, and the reset and cache-wipe scopes. - IPC uses UNIX sockets. On Android,
apmdlistens at abstract socket@apmdandamsdlistens at/data/ams/amsd.sock. The emulator usesapmd.socketandamsd.socketin the corresponding roots. The CLI defaults toapmd, including for its module commands. AMS also exposes module operations through its own dispatcher. - For IPC changes, trace the CLI call, the shared wire format in
src/apmd/include/protocol.hppandsrc/apmd/protocol.cpp, and the relevant daemon handler. Preserve framing, escaping, response IDs, progress events, and final response handling. Check authorization at the daemon boundary.apmdissues sessions and both daemons validate them using shared state. Keep tokens, PINs, and recovery answers out of logs. src/apmd/export_path.cppproduces the command index, shims, and shell environment files. For package or runtime path changes, check shim rebuilds, collisions with system commands and other packages, and the Termux environment. Coordinate shell startup changes with the flashable hooksapm-sh-pathandapm-bash-path.
- Debian and Termux sources use
.repofiles, while APK bundles use.apprepofiles in the same sources directory. Followrepo_index.cppandrelease_parser.cppfor Release and Packages metadata. Keep Release signature policy (Trusted), index and payload checksum checks, and detached package signature policy (Deb-Signatures) intact. Android repository indexes usePackages.gzor plainPackages. Individual package payloads support additional compression formats. - Repository installs use dependency resolution and the dpkg-style status database. Termux has its own runtime prefix, dependency handling, and wrappers. Local
package-installgoes through the CLI and manual package metadata. Tar-style manual packages usepackage-info.jsonand a validated install prefix. Trace install, remove, and upgrade paths when changing persisted state or ownership of installed files. - Both local and daemon-backed
.debinstallation use the shareddeb_extractor.cpp,archive_decompressor.cpp, andtar_extractor.cpp. The code parses ar containers and uses native gzip, XZ/LZMA, bzip2, and Zstandard decoders before invokingtar. Preserve input validation, archive path and link checks, decompression limits, and temporary-file cleanup. - Direct APK installs use Android
pmor stage into the AMSapm-system-appsmodule. App repository bundles stage intoapm-app-<id>modules and use separate status keys. Preserve plan confirmation, downloaded size and SHA-256 verification, manifest-derived package IDs, permission validation, and rollback of module and status writes. System app changes take effect after reboot. - AMS modules use
module-info.json,state.json, andoverlay/{system,vendor,product}. Check both daemons when changing module lifecycle behavior, and check safe mode, boot readiness, overlay application, and hook ordering when changing startup behavior. See AMS module development and the AMS architecture.
Standalone builds use CMake 3.24 or newer and Ninja. CMake uses static BoringSSL archives and headers under prebuilt/boringssl/, builds bundled curl, and fetches archive codecs through cmake/ArchiveCompression.cmake. Android needs matching NDK archives under build-<abi>/ inside the prebuilt tree. A Linux emulator build needs native Linux archives under build-x86_64/ or build-x86/ inside that tree. Verify the target platform when staging archives because Android x86 prebuilts use the same directory names.
For an Android NDK build, use the wrapper with an explicit ABI. It defaults to API 34 and accepts API 29 or newer. --all covers arm64-v8a, armeabi-v7a, x86_64, and x86. The wrapper recreates the selected build directory and publishes the compilation database at the repository root.
./build_android.sh --abi arm64-v8aFor Linux emulator checks, configure a separate build directory to preserve the existing build cache. Start apmd and amsd with --emulator and use an isolated home directory shared by the daemons and CLI. Once apmd has created its socket, the emulator-built CLI detects it automatically. Use apm --help and apm ping as smoke checks.
cmake -S . -B build-emulator -G Ninja -DAPM_EMULATOR_MODE=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build-emulator --parallel- The default build leaves
APM_BUILD_TESTSoff. The current checkout lacks thetests/sources and Python fixtures referenced by CMake's archive and app repository regression targets. With those files present, configure with-DAPM_BUILD_TESTS=ON, build, and runctest --test-dir <build-dir> --output-on-failure. - For shell changes, run
bash -non host build scripts andsh -non Android/recovery scripts. Check the twoaddon.dfragments together because the installer generates one script from them. - Validate Android-only behavior on a suitable test device or ROM when available, especially init/SELinux, boot overlays,
pmintegration, and recovery deployment. Report which checks ran and which require a device or missing prerequisites.
apm-flashable-new/is the LineageOS Recovery template.build_recovery_zip.shrebuilds by default, stages all three binaries, and emits an ABI-specific ZIP at the repository root. The slot-awareMETA-INF/com/google/android/update-binarychooses the target and generates the OTA survival hook fromsystem/addon.d/. Keep its file permissions and payload paths aligned with the ZIP builder.- Edit SELinux policy in
selinux-contexting/and sync the tracked mirror atapm-flashable-new/system/etc/selinux/. Init service definitions live underapm-flashable-new/system/etc/init/and are also referenced by Soong. Check init service names, file and property contexts, and boot ordering together when those interfaces change. - Update root
THIRD_PARTY_NOTICESand its flashable copy if bundled codec licensing or versions change. Keep support for archive decoding in the native codec path. The flashablesystem/xbin/tree is helper payload, and the ZIP builder can copy additional helpers fromprebuilt/xz/. - Keep build outputs, staged BoringSSL prebuilts, generated compilation databases, and recovery ZIPs out of commits. See build and deployment, the recovery template guide, and the BoringSSL helper guide.