As an atomic service developer, you can enable or disable update detection for your atomic service. You will receive notifications indicating whether a new version is available. If an update is detected, the new version can be automatically downloaded, and you will be notified upon successful download.
When your atomic service encounters critical bugs or security vulnerabilities, and an updated version has already been released on AppGallery, this feature enables update detection, allowing you to prompt users to install the latest version.

The atomic service calls the on API for detecting atomic service updates.
The on API notifies the atomic service of whether a new version is available via a callback.
The atomic service calls the off API to cancel the update detection after receiving the callback indicating that no new version is available or the download is complete.
The update service provides the following APIs. For details, please refer to the API reference.
| API | Description |
|---|---|
| on(type: 'updateChange', callback: Callback<UpdateSessionState>, timeout?: number): void | Detects atomic service updates. |
| off(type: 'updateChange', callback?: Callback<UpdateSessionState>): void | Cancels the detection of atomic service updates. This API must be used together with the on API. |
Import the updateManager module and related common modules.
import { updateManager } from '@kit.AppGalleryKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { abilityManager } from '@kit.AbilityKit'; The input parameter is a callback of the Callback<UpdateSessionState> type.
let callback = (state: updateManager.UpdateSessionState) => {
if (state.code === updateManager.RequestErrorCode.NO_UPGRADE) {
hilog.info (0, 'TAG', `on success, no need update`);
updateManager.off('updateChange');
} else if (state.code === updateManager.RequestErrorCode.NEED_UPGRADE) {
hilog.info (0, 'TAG', `on success, need update`);
} else if (state.code === updateManager.RequestErrorCode.DOWNLOADED) {
hilog.info (0, 'TAG', `on success, need update and download success`);
// Call the off API to cancel update detection after receiving the callback indicating that the download is complete.
updateManager.off('updateChange');
// Display a pop-up to notify users of the new version and prompt them to restart the atomic service.
abilityManager.restartSelfAtomicService(getContext());
}
}; Call the on API to detect atomic service updates.
try {
updateManager.on('updateChange', callback, 20);
} catch (error) {
hilog.error(0, 'TAG', `on Error.code is ${error.code}, message is ${error.message}`);
}