• Home
Name Date Size #Lines LOC

..--

adapter/default_config/feature_config/standard/12-May-2024-1614

frameworks/js/napi/12-May-2024-4,1773,362

interfaces/12-May-2024-4,4081,988

services/12-May-2024-16,54211,771

test/12-May-2024-1,6501,055

.gitattributesD12-May-2024631 1615

BUILD.gnD12-May-2024964 2825

CODEOWNERSD12-May-2024779 1816

LICENSED12-May-20249.9 KiB178150

OAT.xmlD12-May-20244.1 KiB7215

README.mdD12-May-20246 KiB168130

README_zh.mdD12-May-20245.7 KiB168130

bundle.jsonD12-May-20242.4 KiB6868

hisysevent.yamlD12-May-20241.7 KiB4022

updateengine.gniD12-May-20241.1 KiB2623

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

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├── interfaces             # 升级客户端接口目录
30│   ├── kits               # 对外接口封装目录
31│   │   └── js             # 提供给升级客户端应用的JS 接口目录
32│   └── inner_api          # SA 接口定义和封装目录
33├── frameworks             # 部件无独立进程的实现
34│   └── js                 # JS API的实现
35│       └── napi           # napi代码实现
36│           └── client     # 升级客户端napi 接口目录
37├── services               # 独立进程的实现
38│   ├── callback           # 提供给升级客户端应用的callback接口目录
39│   └── engine             # 升级客户端引擎服务目录
40│       ├── etc            # 升级客户端引擎rc配置文件目录
41│       ├── include        # 升级客户端引擎头文件目录
42│       ├── sa_profile     # SA 配置文件目录
43│       └── src            # 升级客户端引擎源码目录
44├── test                   # 测试代码目录
45│   ├── unittest           # 升级客户端UT代码目录
46│   └── fuzztest           # 升级客户端FT代码目录
47├── BUILD.gn               # 编译入口
48└── bundle.json            # 部件描述文件
49```
50
51## 说明<a name="section208mcpsimp"></a>
52
53### JS接口说明<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="b220mcpsimp"><a name="b220mcpsimp"></a><a name="b220mcpsimp"></a>接口</strong></p>
57</td>
58<td class="cellrowborder" valign="top" width="48%"><p id="p222mcpsimp"><a name="p222mcpsimp"></a><a name="p222mcpsimp"></a>说明</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>检查是否有可用的升级包版本</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>下载升级包</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>将升级命令写入到misc分区,最终调用reboot命令,进入到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>升级完成后,获取升级后的版本信息</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>设置升级策略</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>获取升级策略</p>
89</td>
90</tr>
91</tbody>
92</table>
93
94### 使用说明<a name="section253mcpsimp"></a>
95
961,导入updateclient lib
97
98```
99import client from 'libupdateclient.z.so'
100```
101
1022,获取update对象
103
104```
105let updater = client.getUpdater('OTA');
106```
107
1083,获取新版本信息
109
110```
111updater.getNewVersionInfo(info => {
112	info "新版本信息"
113});
114```
115
1164,检查新版本
117
118```
119updater.checkNewVersion(info => {
120	info "新版本信息"
121});
122```
123
1245,下载新版本,并监听下载进程
125
126```
127updater.download();
128updater.on("downloadProgress", progress => {
129	progress "下载进度信息"
130});
131```
132
1336,启动升级
134
135```
136updater.upgrade();
137updater.on("upgradeProgress", progress => {
138	progress "升级进度信息"
139});
140```
141
1427,设置升级策略
143
144```
145updater.setUpgradePolicy(result => {
146	result "设置升级策略结果"
147});
148```
149
1508,查看升级策略
151
152```
153updater.getUpgradePolicy(policy => {
154	policy "升级策略"
155});
156```
157
158## 相关仓<a name="section366mcpsimp"></a>
159
160升级子系统
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