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