HarmonyOS System Ability Manager (SAMgr) Skill
Overview
SAMgr is the daemon-level service registry and lifecycle manager for all system services in HarmonyOS/OpenHarmony. It plays a role analogous to Android's servicemanager + init daemon, with stronger lifecycle governance and native cross-device distributed support.
Knowledge Domains
This skill covers four domains. Load the relevant reference file based on the task:
| Domain | Reference | When to Load |
|---|---|---|
| Architecture & Concepts | references/hm-sa-architecture.md | Understanding SAMgr's role, boot sequence, SA lifecycle, data structures, registration modes |
| API Reference | references/hm-sa-api-reference.md | Writing SA code, Proxy/Stub patterns, registration macros, death notifications |
| Source Code Structure | references/hm-sa-source-structure.md | Navigating the repo, finding files, understanding build config, SA .cfg format |
Quick Reference
SAMgr's Four Roles
- Service Registry — Central table mapping SA ID → proxy object
- Lifecycle Manager — OnStart/OnStop, crash detection, auto-restart
- IPC Router — Local via Binder, cross-device via DSoftBus
- Capability Scheduler — Boot ordering, priority, on-demand loading
SA Lifecycle
Register → Publish → Discovery → IPC Invocation → Reclamation
Core API (C++)
// Get SAMgr client
sptr<ISystemAbilityManager> samgr =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
// Register SA
samgr->AddSystemAbility(saId, new MyAbility());
// Get SA proxy
sptr<IRemoteObject> obj = samgr->GetSystemAbility(saId);
Boot Sequence
init → parse .cfg → SAMgr daemon → foundation (safwk + samgr) → appspawn → apps
Source Repo
- GitHub: https://gitcode.com/openharmony/systemabilitymgr_samgr
- Path:
foundation/systemabilitymgr/samgr/
Fetching Official Docs
To refresh the fetched Huawei developer docs, run:
# Fetch IPC Kit docs (preset)
python3 scripts/fetch_sa_docs.py --preset ipc --out-dir references/fetched-docs
# Fetch a single doc by slug
python3 scripts/fetch_sa_docs.py --slug ipc-rpc-overview --out /tmp/doc.md
# List all known working slugs
python3 scripts/fetch_sa_docs.py --list-slugs
Known working slugs:
ipc-rpc-overview— IPC Kit V13 overview (current)ipc-rpc-overview-0000001427584740-V2— IPC RPC V2 overview (archived)
Key Comparison: Android vs HarmonyOS
| Dimension | Android | HarmonyOS SAMgr |
|---|---|---|
| Service Management | Dispersed (app-driven) | Unified (system-driven) |
| Lifecycle | App-controlled | System-controlled |
| Cross-device | None built-in | Natively supported |
| Crash Recovery | Limited | Auto-restart + client notification |
Recognized SA IDs
| SA ID | Service |
|---|---|
| 3001 | PowerManager |
| 3002 | LocationService |
| 3400 | BundleMgrService |