# Update Service - [Introduction](#section184mcpsimp) - [Directory Structure](#section193mcpsimp) - [Description](#section208mcpsimp) - [JS APIs](#section210mcpsimp) - [Usage](#section253mcpsimp) - [Repositories Involved](#section366mcpsimp) ## Introduction The update service is a system ability \(SA\) started by the init process of OHOS to implement an update. The update service provides the following functions: 1. Searching for available update packages 2. Downloading update packages 3. Setting and obtaining the update policy 4. Triggering an update ## Directory Structure ``` base/update/updateservice # Update service code ├── interfaces # Update client APIs │ ├── kits # External APIs │ │ └── js # JS APIs for the update app │ └── inner_api # SA APIs ├── frameworks # module which is not independent's implement │ └── js # JS APIs │ └── napi # napi │ └── client # NAPI-based update client ├── services # module which is independent's implement │ ├── callback # callback API │ └── engine # Update client engine │ ├── etc # rc configuration files for the update client engine │ ├── include # Header files for the update client engine │ ├── sa_profile # SA profiles │ └── src # Source code of the update client engine ├── test # Test code │ ├── unittest # Unit test code for the update client │ └── fuzztest # Fuzz test code for the update client ├── BUILD.gn # compile entrance └── bundle.json # module description file ``` ## Description ### JS APIs

API

Description

checkNewVersion

Checks whether a new update package is available.

download()

Downloads the update package.

upgrade()

Writes the update command to the misc partition and runs the reboot command to access the updater.

getNewVersionInfo()

Obtains the version information after a version update.

setUpgradePolicy

Sets the upgrade policy.

getUpgradePolicy

Obtains the upgrade policy.

### Usage 1. Import **libupdateclient**. ``` import client from 'libupdateclient.z.so' ``` 2. Obtain the **Updater** object. ``` let updater = client.getUpdater('OTA'); ``` 3. Obtain the new version information. ``` updater.getNewVersionInfo(info => { info "New version information" }); ``` 4. Checks for a new version. ``` updater.checkNewVersion(info => { info "New version information" }); ``` 5. Download the new version and monitor the download process. ``` updater.download(); updater.on("downloadProgress", progress => { progress "Download progress information" }); ``` 6. Start the update. ``` updater.upgrade(); updater.on("upgradeProgress", progress => { progress "Update progress information" }); ``` 7. Set the update policy. ``` updater.setUpgradePolicy(result => { result "Update policy setting result" }); ``` 8. Check the update policy. ``` updater.getUpgradePolicy(policy => { policy "Update policy" }); ``` ## Repositories Involved Update subsystem [update\_app](https://gitee.com/openharmony/update_app) **update\_updateservice** [update\_updater](https://gitee.com/openharmony/update_updater)