README.md
1# Update Service<a name="EN-US_TOPIC_0000001102254666"></a>
2
3- [Introduction](#section184mcpsimp)
4- [Directory Structure](#section193mcpsimp)
5- [Description](#section208mcpsimp)
6 - [JS APIs](#section210mcpsimp)
7 - [Usage](#section253mcpsimp)
8
9- [Repositories Involved](#section366mcpsimp)
10
11## Introduction<a name="section184mcpsimp"></a>
12
13The update service is a system ability \(SA\) started by the init process of OHOS to implement an update.
14
15The update service provides the following functions:
16
171. Searching for available update packages
18
192. Downloading update packages
20
213. Setting and obtaining the update policy
22
234. Triggering an update
24
25## Directory Structure<a name="section193mcpsimp"></a>
26
27```
28base/update/updateservice # Update service code
29├── interfaces # Update client APIs
30│ ├── kits # External APIs
31│ │ └── js # JS APIs for the update app
32│ └── inner_api # SA APIs
33├── frameworks # module which is not independent's implement
34│ └── js # JS APIs
35│ └── napi # napi
36│ └── client # NAPI-based update client
37├── services # module which is independent's implement
38│ ├── callback # callback API
39│ └── engine # Update client engine
40│ ├── etc # rc configuration files for the update client engine
41│ ├── include # Header files for the update client engine
42│ ├── sa_profile # SA profiles
43│ └── src # Source code of the update client engine
44├── test # Test code
45│ ├── unittest # Unit test code for the update client
46│ └── fuzztest # Fuzz test code for the update client
47├── BUILD.gn # compile entrance
48└── bundle.json # module description file
49```
50
51## Description<a name="section208mcpsimp"></a>
52
53### JS APIs<a name="section210mcpsimp"></a>
54
55<a name="table212mcpsimp"></a>
56<table><tbody><tr id="row217mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p219mcpsimp"><a name="p219mcpsimp"></a><a name="p219mcpsimp"></a><strong id="b6143153974418"><a name="b6143153974418"></a><a name="b6143153974418"></a>API</strong></p>
57</td>
58<td class="cellrowborder" valign="top" width="48%"><p id="p222mcpsimp"><a name="p222mcpsimp"></a><a name="p222mcpsimp"></a><strong id="b156019475446"><a name="b156019475446"></a><a name="b156019475446"></a>Description</strong></p>
59</td>
60</tr>
61<tr id="row223mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p16387178102716"><a name="p16387178102716"></a><a name="p16387178102716"></a>checkNewVersion</p>
62</td>
63<td class="cellrowborder" valign="top" width="48%"><p id="p227mcpsimp"><a name="p227mcpsimp"></a><a name="p227mcpsimp"></a>Checks whether a new update package is available.</p>
64</td>
65</tr>
66<tr id="row228mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p1884710150275"><a name="p1884710150275"></a><a name="p1884710150275"></a>download()</p>
67</td>
68<td class="cellrowborder" valign="top" width="48%"><p id="p232mcpsimp"><a name="p232mcpsimp"></a><a name="p232mcpsimp"></a>Downloads the update package. </p>
69</td>
70</tr>
71<tr id="row233mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p7326722162717"><a name="p7326722162717"></a><a name="p7326722162717"></a>upgrade()</p>
72</td>
73<td class="cellrowborder" valign="top" width="48%"><p id="p237mcpsimp"><a name="p237mcpsimp"></a><a name="p237mcpsimp"></a>Writes the update command to the misc partition and runs the <strong id="b1069864618574"><a name="b1069864618574"></a><a name="b1069864618574"></a>reboot</strong> command to access the updater.</p>
74</td>
75</tr>
76<tr id="row238mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p4981103002720"><a name="p4981103002720"></a><a name="p4981103002720"></a>getNewVersionInfo()</p>
77</td>
78<td class="cellrowborder" valign="top" width="48%"><p id="p242mcpsimp"><a name="p242mcpsimp"></a><a name="p242mcpsimp"></a>Obtains the version information after a version update.</p>
79</td>
80</tr>
81<tr id="row243mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p568117524271"><a name="p568117524271"></a><a name="p568117524271"></a>setUpgradePolicy</p>
82</td>
83<td class="cellrowborder" valign="top" width="48%"><p id="p247mcpsimp"><a name="p247mcpsimp"></a><a name="p247mcpsimp"></a>Sets the upgrade policy.</p>
84</td>
85</tr>
86<tr id="row248mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p19534844192712"><a name="p19534844192712"></a><a name="p19534844192712"></a>getUpgradePolicy</p>
87</td>
88<td class="cellrowborder" valign="top" width="48%"><p id="p252mcpsimp"><a name="p252mcpsimp"></a><a name="p252mcpsimp"></a>Obtains the upgrade policy.</p>
89</td>
90</tr>
91</tbody>
92</table>
93
94### Usage<a name="section253mcpsimp"></a>
95
961. Import **libupdateclient**.
97
98```
99import client from 'libupdateclient.z.so'
100```
101
1022. Obtain the **Updater** object.
103
104```
105let updater = client.getUpdater('OTA');
106```
107
1083. Obtain the new version information.
109
110```
111updater.getNewVersionInfo(info => {
112 info "New version information"
113});
114```
115
1164. Checks for a new version.
117
118```
119updater.checkNewVersion(info => {
120 info "New version information"
121});
122```
123
1245. Download the new version and monitor the download process.
125
126```
127updater.download();
128updater.on("downloadProgress", progress => {
129 progress "Download progress information"
130});
131```
132
1336. Start the update.
134
135```
136updater.upgrade();
137updater.on("upgradeProgress", progress => {
138 progress "Update progress information"
139});
140```
141
1427. Set the update policy.
143
144```
145updater.setUpgradePolicy(result => {
146 result "Update policy setting result"
147});
148```
149
1508. Check the update policy.
151
152```
153updater.getUpgradePolicy(policy => {
154 policy "Update policy"
155});
156```
157
158## Repositories Involved<a name="section366mcpsimp"></a>
159
160Update subsystem
161
162[update\_app](https://gitee.com/openharmony/update_app)
163
164**update\_updateservice**
165
166[update\_updater](https://gitee.com/openharmony/update_updater)
167
168