• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { AsyncCallback, BussinessError } from "./basic";
17
18/**
19 * A static class to do update for device.
20 *
21 * @since 6
22 * @syscap SystemCapability.Updater.update_service
23 */
24declare namespace update {
25    /**
26     * Enumerates new version package types.
27     *
28     * @since 6
29     */
30    export enum PackageTypes {
31        PACKAGE_TYPE_NORMAL = 1,
32        PACKAGE_TYPE_BASE = 2,
33        PACKAGE_TYPE_CUST = 3,
34        PACKAGE_TYPE_PRELOAD = 4,
35        PACKAGE_TYPE_COTA = 5,
36        PACKAGE_TYPE_VERSION = 6,
37        PACKAGE_TYPE_PATCH = 7
38    }
39
40    /**
41     * Represents new version results after update version check.
42     *
43     * @since 6
44     */
45    export interface CheckResult {
46        /**
47         * New version name
48         *
49         * @since 6
50         */
51        versionName: number;
52
53        /**
54         * New version code
55         *
56         * @since 6
57         */
58        versionCode: string;
59
60        /**
61         * New version package size
62         *
63         * @since 6
64         */
65        size: number;
66
67        /**
68         * New version verify information
69         *
70         * @since 6
71         */
72        verifyInfo: string;
73
74        /**
75         * New version package type
76         *
77         * @since 6
78         */
79        packageType: PackageTypes;
80
81        /**
82         * New version description ID
83         *
84         * @since 6
85         */
86        descriptionId: string;
87    }
88
89    /**
90     * Represents new version description information.
91     *
92     * @since 6
93     */
94    export interface DescriptionInfo {
95        /**
96         * description ID
97         *
98         * @since 6
99         */
100        descriptionId: string;
101
102        /**
103         * description content
104         *
105         * @since 6
106         */
107        content: string;
108    }
109
110    /**
111     * Enumerates new version status.
112     *
113     * @since 6
114     */
115    export enum NewVersionStatus {
116        /**
117         * New version check with system error
118         *
119         * @since 6
120         */
121        VERSION_STATUS_ERR = -1,
122
123        /**
124         * New version detected
125         *
126         * @since 6
127         */
128        VERSION_STATUS_NEW = 0,
129
130        /**
131         * No New version
132         *
133         * @since 6
134         */
135        VERSION_STATUS_NONE = 1,
136
137        /**
138         * Server busy
139         *
140         * @since 6
141         */
142        VERSION_STATUS_BUSY = 2
143    }
144
145    /**
146     * Represents new version information.
147     *
148     * @since 6
149     */
150    export interface NewVersionInfo {
151        /**
152         * Update Check Status
153         *
154         * @since 6
155         */
156        status: NewVersionStatus;
157
158        /**
159         * New version check error message
160         *
161         * @since 6
162         */
163        errMsg: string;
164
165        /**
166         * New version check results
167         *
168         * @since 6
169         */
170        checkResults: Array<CheckResult>;
171
172        /**
173         * New version check description
174         *
175         * @since 6
176         */
177        descriptionInfo: Array<DescriptionInfo>;
178    }
179
180    /**
181     * Enumerates update status.
182     *
183     * @since 6
184     */
185    export enum UpdateState {
186        UPDATE_STATE_INIT = 0,
187        UPDATE_STATE_CHECK_VERSION_ON = 10,
188        UPDATE_STATE_CHECK_VERSION_FAIL,
189        UPDATE_STATE_CHECK_VERSION_SUCCESS,
190        UPDATE_STATE_DOWNLOAD_ON = 20,
191        UPDATE_STATE_DOWNLOAD_PAUSE,
192        UPDATE_STATE_DOWNLOAD_CANCEL,
193        UPDATE_STATE_DOWNLOAD_FAIL,
194        UPDATE_STATE_DOWNLOAD_SUCCESS,
195        UPDATE_STATE_VERIFY_ON = 30,
196        UPDATE_STATE_VERIFY_FAIL,
197        UPDATE_STATE_VERIFY_SUCCESS,
198        UPDATE_STATE_PACKAGE_TRANS_ON = 70,
199        UPDATE_STATE_PACKAGE_TRANS_FAIL,
200        UPDATE_STATE_PACKAGE_TRANS_SUCCESS,
201        UPDATE_STATE_INSTALL_ON = 80,
202        UPDATE_STATE_INSTALL_FAIL,
203        UPDATE_STATE_INSTALL_SUCCESS,
204        UPDATE_STATE_UPDATE_ON = 90,
205        UPDATE_STATE_UPDATE_FAIL,
206        UPDATE_STATE_UPDATE_SUCCESS
207    }
208
209    /**
210     * Represents update progress information.
211     *
212     * @since 6
213     */
214    export interface Progress {
215        /**
216         * update progress percent
217         *
218         * @since 6
219         */
220        percent: number;
221
222        /**
223         * update status
224         *
225         * @since 6
226         */
227        status: UpdateState;
228
229        /**
230         * update end reason
231         *
232         * @since 6
233         */
234        endReason: string;
235    }
236
237    /**
238     * Enumerates install mode for new version packages.
239     *
240     * @since 6
241     */
242    export enum InstallMode {
243        /**
244         * Normal update.
245         *
246         * @since 6
247         */
248        INSTALL_MODE_NORMAL,
249
250        /**
251         * Update at night
252         *
253         * @since 6
254         */
255        INSTALL_MODE_NIGHT,
256
257        /**
258         * Auto update
259         *
260         * @since 6
261         */
262        INSTALL_MODE_AUTO
263    }
264
265    /**
266     * Represents update policy.
267     *
268     * @since 6
269     */
270    export interface UpdatePolicy {
271        /**
272         * Enable auto download new packages or not
273         *
274         * @since 6
275         */
276        autoDownload: boolean;
277
278        /**
279         * New packages auto installation mode
280         *
281         * @since 6
282         */
283        installMode: INSTALL_MODE;
284
285        /**
286         * Auto installation time interval
287         *
288         * @since 6
289         */
290        autoUpgradeInterval: Array<number>;
291    }
292
293    /**
294     * Called when the signal status changes. You need to implement this method in a child class.
295     * Unlike {@code onSignalStatus(status: number)}, a signal source is specified in this method.
296     *
297     * @param status Indicates the signal status.
298     *               The value {@code 0} indicates that the signal is stable,
299     *               {@code 1} indicates that no signal is available,
300     *               {@code 2} indicates that the signal is not supported,
301     *               and {@code 3} indicates that the signal is unstable.
302     * @param source Indicates the signal source. For details about available values,
303     *               see {@link @system.tv.SourceIndices}.
304     * @since 6
305     */
306    export interface UpdateProgressCallback {
307        (progress: Progress): void;
308    }
309
310    /**
311     * A static class to do update for the specified device.
312     *
313     * @since 6
314     */
315    export interface Updater {
316        /**
317        * Check new version.
318        *
319        * @since 6
320        */
321        checkNewVersion(callback: AsyncCallback<NewVersionInfo>): void;
322        checkNewVersion(): Promise<NewVersionInfo>;
323
324        /**
325         * Trigger download new version packages.
326         * apps should listen to downloadProgress event
327         *
328         * @since 6
329         */
330        download(): void;
331
332        /**
333         * Install packages for the device.
334         * apps should listen to upgradeProgress event
335         *
336         * @since 6
337         */
338        upgrade(): void;
339
340        /**
341         * Get new version information for the newly installed package.
342         *
343         * @since 6
344         */
345        getNewVersionInfo(callback: AsyncCallback<NewVersionInfo>): void;
346        getNewVersionInfo(): Promise<NewVersionInfo>;
347
348        /**
349         * Get current update policy.
350         *
351         * @since 6
352         */
353        getUpdatePolicy(callback: AsyncCallback<UpdatePolicy>): void;
354        getUpdatePolicy(): Promise<UpdatePolicy>;
355
356        /**
357         * Set update policy.
358         *
359         * @since 6
360         */
361        setUpdatePolicy(policy: UpdatePolicy, callback: AsyncCallback<number>): void;
362        setUpdatePolicy(policy: UpdatePolicy): Promise<number>;
363
364        /**
365         * Reboot to apply upgrade package.
366         *
367         * @since 6
368         */
369        applyNewVersion(callback: AsyncCallback<number>): void;
370        applyNewVersion(): Promise<number>;
371
372        /**
373         * Reboot to clean userdata.
374         *
375         * @since 6
376         */
377        rebootAndCleanUserData(callback: AsyncCallback<number>): void;
378        rebootAndCleanUserData(): Promise<number>;
379
380        /**
381         * verify update package.
382         * apps should listen to verifyProgress event
383         *
384         * @since 6
385         */
386        verifyUpdatePackage(upgradeFile: string, certsFile: string): void;
387
388        /**
389         * Subscribe to download/upgrade/verify progress events
390         *
391         * @since 6
392         */
393        on(eventType: 'downloadProgress', callback: UpdateProgressCallback): void;
394        on(eventType: 'upgradeProgress', callback: UpdateProgressCallback): void;
395        on(eventType: 'verifyProgress', callback: UpdateProgressCallback): void;
396
397        /**
398         * Unsubscribe to download/upgrade/verify progress events
399         *
400         * @since 6
401         */
402        off(eventType: 'downloadProgress', callback?: UpdateProgressCallback): void;
403        off(eventType: 'upgradeProgress', callback?: UpdateProgressCallback): void;
404        off(eventType: 'verifyProgress', callback?: UpdateProgressCallback): void;
405
406        /**
407         * cancel download packages for the device.
408         *
409         * @since 6
410         */
411        cancel(): void;
412    }
413
414    export type UpdateTypes =
415        'OTA' |
416        'patch';
417
418    /**
419     * Get Updater handler for the calling device.
420     *
421     * @return Updater handler to perform actual update
422     * @since 6
423     */
424    function getUpdater(upgradeFile: string, updateType?: UpdateTypes): Updater;
425
426    /**
427     * Get Updater handler for the specified device.
428     *
429     * @return Updater handler to perform actual update
430     * @since 6
431     */
432    function getUpdaterForOther(upgradeFile: string, device: string, updateType?: UpdateTypes): Updater;
433
434    /**
435     * Get Updater handler from other device to trigger update for the calling device.
436     *
437     * @return Updater handler to perform actual update
438     * @since 6
439     */
440    function getUpdaterFromOther(upgradeFile: string, device: string, updateType?: UpdateTypes): Updater;
441}
442
443export default update;
444