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├── client # NAPI-based update client
30├── engine # Update client engine
31│ ├── etc # rc configuration files for the update client engine
32│ ├── include # Header files for the update client engine
33│ ├── sa_profile # SA profiles
34│ └── src # Source code of the update client engine
35├── interfaces # Update client APIs
36│ └── innerkits # SA APIs
37├── kits # External APIs
38│ └── js # JS APIs for the update app
39└── tests # Test code
40 └── unittest # Unit test code for the update client
41```
42
43## Description<a name="section208mcpsimp"></a>
44
45### JS APIs<a name="section210mcpsimp"></a>
46
47<a name="table212mcpsimp"></a>
48<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>
49</td>
50<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>
51</td>
52</tr>
53<tr id="row223mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p16387178102716"><a name="p16387178102716"></a><a name="p16387178102716"></a>checkNewVersion</p>
54</td>
55<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>
56</td>
57</tr>
58<tr id="row228mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p1884710150275"><a name="p1884710150275"></a><a name="p1884710150275"></a>download()</p>
59</td>
60<td class="cellrowborder" valign="top" width="48%"><p id="p232mcpsimp"><a name="p232mcpsimp"></a><a name="p232mcpsimp"></a>Downloads the update package. </p>
61</td>
62</tr>
63<tr id="row233mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p7326722162717"><a name="p7326722162717"></a><a name="p7326722162717"></a>upgrade()</p>
64</td>
65<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>
66</td>
67</tr>
68<tr id="row238mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p4981103002720"><a name="p4981103002720"></a><a name="p4981103002720"></a>getNewVersionInfo()</p>
69</td>
70<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>
71</td>
72</tr>
73<tr id="row243mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p568117524271"><a name="p568117524271"></a><a name="p568117524271"></a>setUpdatePolicy</p>
74</td>
75<td class="cellrowborder" valign="top" width="48%"><p id="p247mcpsimp"><a name="p247mcpsimp"></a><a name="p247mcpsimp"></a>Sets the update policy.</p>
76</td>
77</tr>
78<tr id="row248mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p19534844192712"><a name="p19534844192712"></a><a name="p19534844192712"></a>getUpdatePolicy</p>
79</td>
80<td class="cellrowborder" valign="top" width="48%"><p id="p252mcpsimp"><a name="p252mcpsimp"></a><a name="p252mcpsimp"></a>Obtains the update policy.</p>
81</td>
82</tr>
83</tbody>
84</table>
85
86### Usage<a name="section253mcpsimp"></a>
87
881. Import **libupdateclient**.
89
90```
91import client from 'libupdateclient.z.so'
92```
93
942. Obtain the **Updater** object.
95
96```
97let updater = client.getUpdater('OTA');
98```
99
1003. Obtain the new version information.
101
102```
103updater.getNewVersionInfo(info => {
104 info "New version information"
105});
106```
107
1084. Checks for a new version.
109
110```
111updater.checkNewVersion(info => {
112 info "New version information"
113});
114```
115
1165. Download the new version and monitor the download process.
117
118```
119updater.download();
120updater.on("downloadProgress", progress => {
121 progress "Download progress information"
122});
123```
124
1256. Start the update.
126
127```
128updater.upgrade();
129updater.on("upgradeProgress", progress => {
130 progress "Update progress information"
131});
132```
133
1347. Set the update policy.
135
136```
137updater.setUpdatePolicy(result => {
138 result "Update policy setting result"
139});
140```
141
1428. Check the update policy.
143
144```
145updater.getUpdatePolicy(policy => {
146 policy "Update policy"
147});
148```
149
150## Repositories Involved<a name="section366mcpsimp"></a>
151
152Update subsystem
153
154update\_app
155
156**update\_updateservice**
157
158update\_updater
159
160
README_zh.md
1# 升级服务组件<a name="ZH-CN_TOPIC_0000001102254666"></a>
2
3- [简介](#section184mcpsimp)
4- [目录](#section193mcpsimp)
5- [说明](#section208mcpsimp)
6 - [JS接口说明](#section210mcpsimp)
7 - [使用说明](#section253mcpsimp)
8
9- [相关仓](#section366mcpsimp)
10
11## 简介<a name="section184mcpsimp"></a>
12
13升级服务组件是一个SA\(System Ability\), 由OHOS 的init 进程负责启动。
14
15升级服务器引擎主要功能包括:
16
171、查找可用的升级包
18
192、下载升级包
20
213、设置/获取升级策略
22
234、触发升级
24
25## 目录<a name="section193mcpsimp"></a>
26
27```
28base/update/updateservice # 升级服务代码仓目录
29├── client # 升级客户端napi 接口目录
30├── engine # 升级客户端引擎服务目录
31│ ├── etc # 升级客户端引擎rc配置文件目录
32│ ├── include # 升级客户端引擎头文件目录
33│ ├── sa_profile # SA 配置文件目录
34│ └── src # 升级客户端引擎源码目录
35├── interfaces # 升级客户端接口目录
36│ └── innerkits # SA 接口定义和封装目录
37├── kits # 对外接口封装目录
38│ └── js # 提供给升级客户端应用的JS 接口目录
39└── tests # 测试代码目录
40 └── unittest # 升级客户端UT代码目录
41```
42
43## 说明<a name="section208mcpsimp"></a>
44
45### JS接口说明<a name="section210mcpsimp"></a>
46
47<a name="table212mcpsimp"></a>
48<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="b220mcpsimp"><a name="b220mcpsimp"></a><a name="b220mcpsimp"></a>接口</strong></p>
49</td>
50<td class="cellrowborder" valign="top" width="48%"><p id="p222mcpsimp"><a name="p222mcpsimp"></a><a name="p222mcpsimp"></a>说明</p>
51</td>
52</tr>
53<tr id="row223mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p16387178102716"><a name="p16387178102716"></a><a name="p16387178102716"></a>checkNewVersion</p>
54</td>
55<td class="cellrowborder" valign="top" width="48%"><p id="p227mcpsimp"><a name="p227mcpsimp"></a><a name="p227mcpsimp"></a>检查是否有可用的升级包版本</p>
56</td>
57</tr>
58<tr id="row228mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p1884710150275"><a name="p1884710150275"></a><a name="p1884710150275"></a>download()</p>
59</td>
60<td class="cellrowborder" valign="top" width="48%"><p id="p232mcpsimp"><a name="p232mcpsimp"></a><a name="p232mcpsimp"></a>下载升级包</p>
61</td>
62</tr>
63<tr id="row233mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p7326722162717"><a name="p7326722162717"></a><a name="p7326722162717"></a>upgrade()</p>
64</td>
65<td class="cellrowborder" valign="top" width="48%"><p id="p237mcpsimp"><a name="p237mcpsimp"></a><a name="p237mcpsimp"></a>将升级命令写入到misc分区,最终调用reboot命令,进入到updater 子系统中。</p>
66</td>
67</tr>
68<tr id="row238mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p4981103002720"><a name="p4981103002720"></a><a name="p4981103002720"></a>getNewVersionInfo()</p>
69</td>
70<td class="cellrowborder" valign="top" width="48%"><p id="p242mcpsimp"><a name="p242mcpsimp"></a><a name="p242mcpsimp"></a>升级完成后,获取升级后的版本信息</p>
71</td>
72</tr>
73<tr id="row243mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p568117524271"><a name="p568117524271"></a><a name="p568117524271"></a>setUpdatePolicy</p>
74</td>
75<td class="cellrowborder" valign="top" width="48%"><p id="p247mcpsimp"><a name="p247mcpsimp"></a><a name="p247mcpsimp"></a>设置升级策略</p>
76</td>
77</tr>
78<tr id="row248mcpsimp"><td class="cellrowborder" valign="top" width="52%"><p id="p19534844192712"><a name="p19534844192712"></a><a name="p19534844192712"></a>getUpdatePolicy</p>
79</td>
80<td class="cellrowborder" valign="top" width="48%"><p id="p252mcpsimp"><a name="p252mcpsimp"></a><a name="p252mcpsimp"></a>获取升级策略</p>
81</td>
82</tr>
83</tbody>
84</table>
85
86### 使用说明<a name="section253mcpsimp"></a>
87
881,导入updateclient lib
89
90```
91import client from 'libupdateclient.z.so'
92```
93
942,获取update对象
95
96```
97let updater = client.getUpdater('OTA');
98```
99
1003,获取新版本信息
101
102```
103updater.getNewVersionInfo(info => {
104 info "新版本信息"
105});
106```
107
1084,检查新版本
109
110```
111updater.checkNewVersion(info => {
112 info "新版本信息"
113});
114```
115
1165,下载新版本,并监听下载进程
117
118```
119updater.download();
120updater.on("downloadProgress", progress => {
121 progress "下载进度信息"
122});
123```
124
1256,启动升级
126
127```
128updater.upgrade();
129updater.on("upgradeProgress", progress => {
130 progress "升级进度信息"
131});
132```
133
1347,设置升级策略
135
136```
137updater.setUpdatePolicy(result => {
138 result "设置升级策略结果"
139});
140```
141
1428,查看升级策略
143
144```
145updater.getUpdatePolicy(policy => {
146 policy "升级策略"
147});
148```
149
150## 相关仓<a name="section366mcpsimp"></a>
151
152升级子系统
153
154update\_app
155
156**update\_updateservice**
157
158update\_updater
159
160