The update_engine Daemon
The update_engine is the core system daemon responsible for downloading, verifying, and applying OTA updates in Android. Originally developed for ChromeOS, it was ported to Android to manage A/B and Virtual A/B update processes in the background.
It is heavily integrated with the Binder IPC system, allowing apps (like the System Updater UI or Google Play Services) to trigger and monitor updates.
Architecture and the UpdateAttempter
The central component of update_engine is the UpdateAttempter. It manages the state machine for the entire update lifecycle.
States include:
IDLE: Waiting for a trigger.CHECKING_FOR_UPDATE: Communicating with the OTA server.DOWNLOADING: Fetching the payload.UPDATING: Writing blocks to disk.UPDATED_NEED_REBOOT: The update is complete.
C++ State Machine Snapshot
// system/update_engine/update_attempter.h
class UpdateAttempter {
public:
void Update(const std::string& app_version,
const std::string& omaha_url,
bool interactive);
// Status callback for Binder clients
void SetStatusAndNotify(UpdateStatus status);
private:
// The current state of the update process
UpdateStatus status_{UpdateStatus::IDLE};
// Handles the payload application
std::unique_ptr<ActionProcessor> processor_;
};
The Payload Application Pipeline
update_engine processes the update payload using a pipeline of Action objects managed by an ActionProcessor.
- InstallPlanAction: Creates a plan containing the partitions to update and their target sizes.
- DownloadAction: Streams the payload from the network. It passes downloaded bytes directly to the
DeltaPerformer. - FilesystemVerifierAction: Hashes the written partitions and compares them against the expected hashes in the payload manifest.
- PostinstallRunnerAction: Mounts the newly updated partitions and runs specialized scripts.
The Download Manager
The Download Manager relies on libcurl to fetch the OTA package. A critical design feature is that update_engine rarely saves the OTA package to disk. Instead, the DownloadAction pipes the data stream directly to the DeltaPerformer, which parses the protobuf manifest and executes the block replacement operations on the fly.
Postinstall Scripts
Postinstall scripts are essential for preparing the new slot before the user reboots. For example, the dexopt process runs during post-install to pre-compile Android applications for the new OS version.
Inspecting update_engine Logs
To debug OTA issues, inspecting the update_engine logs is mandatory.
# View real-time logs during an update
adb logcat -s update_engine
# Read persistent update_engine logs
adb shell cat /data/misc/update_engine_log/update_engine.*