• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 9
22 * @syscap SystemCapability.Update.UpdateService
23 * @systemapi hide for inner use.
24 */
25declare namespace update {
26    /**
27     * Get online update handler for the calling device.
28     *
29     * @param upgradeInfo indicates client app and business type
30     * @return online update handler to perform online update
31     * @since 9
32     */
33    function getOnlineUpdater(upgradeInfo: UpgradeInfo): Updater;
34
35    /**
36     * Get restore handler.
37     *
38     * @return restore handler to perform factory reset
39     * @since 9
40     */
41    function getRestorer(): Restorer;
42
43    /**
44     * Get local update handler.
45     *
46     * @return local update handler to perform local update
47     * @since 9
48     */
49    function getLocalUpdater(): LocalUpdater;
50
51    /**
52     * A static class to do online update.
53     *
54     * @since 9
55     * @syscap SystemCapability.Update.UpdateService
56     * @systemapi hide for inner use.
57     */
58    export interface Updater {
59        /**
60         * Check new version.
61         *
62         * @permission ohos.permission.UPDATE_SYSTEM
63         * @since 9
64         */
65        checkNewVersion(callback: AsyncCallback<CheckResult>): void;
66        checkNewVersion(): Promise<CheckResult>;
67
68        /**
69         * Get new version.
70         *
71         * @permission ohos.permission.UPDATE_SYSTEM
72         * @since 9
73         */
74        getNewVersionInfo(callback: AsyncCallback<NewVersionInfo>): void;
75        getNewVersionInfo(): Promise<NewVersionInfo>;
76
77        /**
78         * Get new version description.
79         *
80         * @permission ohos.permission.UPDATE_SYSTEM
81         * @since 9
82         */
83        getNewVersionDescription(versionDigestInfo: VersionDigestInfo, descriptionOptions: DescriptionOptions, callback: AsyncCallback<Array<ComponentDescription>>): void;
84        getNewVersionDescription(versionDigestInfo: VersionDigestInfo, descriptionOptions: DescriptionOptions): Promise<Array<ComponentDescription>>;
85
86        /**
87         * Get current version.
88         *
89         * @permission ohos.permission.UPDATE_SYSTEM
90         * @since 9
91         */
92        getCurrentVersionInfo(callback: AsyncCallback<CurrentVersionInfo>): void;
93        getCurrentVersionInfo(): Promise<CurrentVersionInfo>;
94
95        /**
96         * Get current version description.
97         *
98         * @permission ohos.permission.UPDATE_SYSTEM
99         * @since 9
100         */
101        getCurrentVersionDescription(descriptionOptions: DescriptionOptions, callback: AsyncCallback<Array<ComponentDescription>>): void;
102        getCurrentVersionDescription(descriptionOptions: DescriptionOptions): Promise<Array<ComponentDescription>>;
103
104        /**
105         * Get task info.
106         *
107         * @permission ohos.permission.UPDATE_SYSTEM
108         * @since 9
109         */
110        getTaskInfo(callback: AsyncCallback<TaskInfo>): void;
111        getTaskInfo(): Promise<TaskInfo>;
112
113        /**
114         * Trigger download new version packages.
115         * apps should listen to task update event
116         *
117         * @permission ohos.permission.UPDATE_SYSTEM
118         * @since 9
119         */
120        download(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions, callback: AsyncCallback<void>): void;
121        download(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions): Promise<void>;
122
123        /**
124         * resume download new version packages.
125         * apps should listen to task update event
126         *
127         * @permission ohos.permission.UPDATE_SYSTEM
128         * @since 9
129         */
130        resumeDownload(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions, callback: AsyncCallback<void>): void;
131        resumeDownload(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions): Promise<void>;
132
133        /**
134         * pause download new version packages.
135         * apps should listen to task update event
136         *
137         * @permission ohos.permission.UPDATE_SYSTEM
138         * @since 9
139         */
140        pauseDownload(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions, callback: AsyncCallback<void>): void;
141        pauseDownload(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions): Promise<void>;
142
143        /**
144         * Install packages for the device.
145         * apps should listen to task update event
146         *
147         * @permission ohos.permission.UPDATE_SYSTEM
148         * @since 9
149         */
150        upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions, callback: AsyncCallback<void>): void;
151        upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions): Promise<void>;
152
153        /**
154         * clear error during upgrade.
155         *
156         * @permission ohos.permission.UPDATE_SYSTEM
157         * @since 9
158         */
159        clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions, callback: AsyncCallback<void>): void;
160        clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions): Promise<void>;
161
162        /**
163         * Get current upgrade policy.
164         *
165         * @permission ohos.permission.UPDATE_SYSTEM
166         * @since 9
167         */
168        getUpgradePolicy(callback: AsyncCallback<UpgradePolicy>): void;
169        getUpgradePolicy(): Promise<UpgradePolicy>;
170
171        /**
172         * Set upgrade policy.
173         *
174         * @permission ohos.permission.UPDATE_SYSTEM
175         * @since 9
176         */
177        setUpgradePolicy(policy: UpgradePolicy, callback: AsyncCallback<void>): void;
178        setUpgradePolicy(policy: UpgradePolicy): Promise<void>;
179
180        /**
181         * terminate upgrade task.
182         *
183         * @permission ohos.permission.UPDATE_SYSTEM
184         * @since 9
185         */
186        terminateUpgrade(callback: AsyncCallback<void>): void;
187        terminateUpgrade(): Promise<void>;
188
189        /**
190         * Subscribe task update events
191         *
192         * @since 9
193         */
194        on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void;
195
196        /**
197         * Unsubscribe task update events
198         *
199         * @since 9
200         */
201        off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void;
202    }
203
204    /**
205     * A static class to do restore.
206     *
207     * @since 9
208     * @syscap SystemCapability.Update.UpdateService
209     * @systemapi hide for inner use.
210     */
211    export interface Restorer {
212        /**
213         * Reboot and clean user data.
214         *
215         * @permission ohos.permission.FACTORY_RESET
216         * @since 9
217         */
218        factoryReset(callback: AsyncCallback<void>): void;
219        factoryReset(): Promise<void>;
220    }
221
222    /**
223     * A static class to do local update.
224     *
225     * @since 9
226     * @syscap SystemCapability.Update.UpdateService
227     * @systemapi hide for inner use.
228     */
229    export interface LocalUpdater {
230        /**
231         * Verify local update package.
232         *
233         * @permission ohos.permission.UPDATE_SYSTEM
234         * @since 9
235         */
236        verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string, callback: AsyncCallback<void>): void;
237        verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string): Promise<void>;
238
239        /**
240         * Apply local update package.
241         * apps should listen to task update event
242         *
243         * @permission ohos.permission.UPDATE_SYSTEM
244         * @since 9
245         */
246        applyNewVersion(upgradeFiles: Array<UpgradeFile>, callback: AsyncCallback<void>): void;
247        applyNewVersion(upgradeFiles: Array<UpgradeFile>): Promise<void>;
248
249        /**
250         * Subscribe task update events
251         *
252         * @since 9
253         */
254        on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void;
255
256        /**
257         * Unsubscribe task update events
258         *
259         * @since 9
260         */
261        off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void;
262    }
263
264    /**
265     * Represents upgrade info.
266     *
267     * @since 9
268     */
269    export interface UpgradeInfo {
270        /**
271         * Upgrade client package name
272         *
273         * @since 9
274         */
275        upgradeApp: string;
276
277        /**
278         * BusinessType of upgrade
279         *
280         * @since 9
281         */
282        businessType: BusinessType;
283    }
284
285    /**
286     * Represents business type.
287     *
288     * @since 9
289     */
290    export interface BusinessType {
291        /**
292         * Vendor of business type
293         *
294         * @since 9
295         */
296        vendor: BusinessVendor;
297
298        /**
299         * Type
300         *
301         * @since 9
302         */
303        subType: BusinessSubType;
304    }
305
306    /**
307     * Represents new version check result.
308     *
309     * @since 9
310     */
311    export interface CheckResult {
312        /**
313         * New version exist or not
314         *
315         * @since 9
316         */
317        isExistNewVersion: boolean;
318
319        /**
320         * New version info
321         *
322         * @since 9
323         */
324        newVersionInfo: NewVersionInfo;
325    }
326
327    /**
328     * Represents new version info.
329     *
330     * @since 9
331     */
332    export interface NewVersionInfo {
333        /**
334         * Digest info of new version
335         *
336         * @since 9
337         */
338        versionDigestInfo: VersionDigestInfo;
339
340        /**
341         * New version component array
342         *
343         * @since 9
344         */
345        versionComponents: Array<VersionComponent>;
346    }
347
348    /**
349     * Represents version digest info.
350     *
351     * @since 9
352     */
353    export interface VersionDigestInfo {
354        /**
355         * Version digest value
356         *
357         * @since 9
358         */
359        versionDigest: string;
360    }
361
362    /**
363     * Represents version component info.
364     *
365     * @since 9
366     */
367    export interface VersionComponent {
368        /**
369         * Component id
370         *
371         * @since 9
372         */
373        componentId: string;
374
375        /**
376         * Component type
377         *
378         * @since 9
379         */
380        componentType: ComponentType;
381
382        /**
383         * Upgrade action
384         *
385         * @since 9
386         */
387        upgradeAction: UpgradeAction;
388
389        /**
390         * Display version
391         *
392         * @since 9
393         */
394        displayVersion: string;
395
396        /**
397         * Inner version
398         *
399         * @since 9
400         */
401        innerVersion: string;
402
403        /**
404         * Component size
405         *
406         * @since 9
407         */
408        size: number;
409
410        /**
411         * Effective mode
412         *
413         * @since 9
414         */
415        effectiveMode: EffectiveMode;
416
417        /**
418         * Description info
419         *
420         * @since 9
421         */
422        descriptionInfo: DescriptionInfo;
423    }
424
425    /**
426     * Represents description options.
427     *
428     * @since 9
429     */
430    export interface DescriptionOptions {
431        /**
432         * Description format
433         *
434         * @since 9
435         */
436        format: DescriptionFormat;
437
438        /**
439         * Description language
440         *
441         * @since 9
442         */
443        language: string;
444    }
445
446    /**
447     * Represents version component description.
448     *
449     * @since 9
450     */
451    export interface ComponentDescription {
452        /**
453         * Component id
454         *
455         * @since 9
456         */
457        componentId: string;
458
459        /**
460         * Description info
461         *
462         * @since 9
463         */
464        descriptionInfo: DescriptionInfo;
465    }
466
467    /**
468     * Represents new version description information.
469     *
470     * @since 9
471     */
472    export interface DescriptionInfo {
473        /**
474         * Description content type
475         *
476         * @since 9
477         */
478        descriptionType: DescriptionType;
479
480        /**
481         * Description content
482         *
483         * @since 9
484         */
485        content: string;
486    }
487
488    /**
489     * Represents current version info.
490     *
491     * @since 9
492     */
493    export interface CurrentVersionInfo {
494        /**
495         * OS version
496         *
497         * @since 9
498         */
499        osVersion: string;
500
501        /**
502         * Device name
503         *
504         * @since 9
505         */
506        deviceName: string;
507
508        /**
509         * Current version component array
510         *
511         * @since 9
512         */
513        versionComponents: Array<VersionComponent>;
514    }
515
516    /**
517     * Represents download options.
518     *
519     * @since 9
520     */
521    export interface DownloadOptions {
522        /**
523         * Allow download with the network type
524         *
525         * @since 9
526         */
527        allowNetwork: NetType;
528
529        /**
530         * Upgrade order
531         *
532         * @since 9
533         */
534        order: Order;
535    }
536
537    /**
538     * Represents resume download options.
539     *
540     * @since 9
541     */
542    export interface ResumeDownloadOptions {
543        /**
544         * Allow download with the network type
545         *
546         * @since 9
547         */
548        allowNetwork: NetType;
549    }
550
551    /**
552     * Represents pause download options.
553     *
554     * @since 9
555     */
556    export interface PauseDownloadOptions {
557        /**
558         * Whether allow auto resume when net available
559         *
560         * @since 9
561         */
562        isAllowAutoResume: boolean;
563    }
564
565    /**
566     * Represents upgrade options.
567     *
568     * @since 9
569     */
570    export interface UpgradeOptions {
571        /**
572         * Upgrade order
573         *
574         * @since 9
575         */
576        order: Order;
577    }
578
579    /**
580     * Represents clear error options.
581     *
582     * @since 9
583     */
584    export interface ClearOptions {
585        /**
586         * Clear status error
587         *
588         * @since 9
589         */
590        status: UpgradeStatus;
591    }
592
593    /**
594     * Represents upgrade policy.
595     *
596     * @since 9
597     */
598    export interface UpgradePolicy {
599        /**
600         * Download strategy: open or close
601         *
602         * @since 9
603         */
604        downloadStrategy: boolean;
605
606        /**
607         * Auto upgrade strategy: open or close
608         *
609         * @since 9
610         */
611        autoUpgradeStrategy: boolean;
612
613        /**
614         * Auto upgrade period
615         *
616         * @since 9
617         */
618        autoUpgradePeriods: Array<UpgradePeriod>;
619    }
620
621    /**
622     * Represents upgrade period.
623     *
624     * @since 9
625     */
626    export interface UpgradePeriod {
627        /**
628         * Start time of upgrade period
629         *
630         * @since 9
631         */
632        start: number;
633
634        /**
635         * End time of upgrade period
636         *
637         * @since 9
638         */
639        end: number;
640    }
641
642    /**
643     * Represents task info.
644     *
645     * @since 9
646     */
647    export interface TaskInfo {
648        /**
649         * Whether upgrade task exist
650         *
651         * @since 9
652         */
653        existTask: boolean;
654
655        /**
656         * Task body info
657         *
658         * @since 9
659         */
660        taskBody: TaskBody;
661    }
662
663    /**
664     * Represents event info.
665     *
666     * @since 9
667     */
668    export interface EventInfo {
669        /**
670         * event id
671         *
672         * @since 9
673         */
674        eventId: EventId;
675
676        /**
677         * task body info
678         *
679         * @since 9
680         */
681        taskBody: TaskBody;
682    }
683
684    /**
685     * Represents task body info.
686     *
687     * @since 9
688     */
689    export interface TaskBody {
690        /**
691         * Digest info of new version
692         *
693         * @since 9
694         */
695        versionDigestInfo: VersionDigestInfo;
696
697        /**
698         * Upgrade status
699         *
700         * @since 9
701         */
702        status: UpgradeStatus;
703
704        /**
705         * Upgrade sub status
706         *
707         * @since 9
708         */
709        subStatus: number;
710
711        /**
712         * Upgrade progress
713         *
714         * @since 9
715         */
716        progress: number;
717
718        /**
719         * Install mode
720         *
721         * @since 9
722         */
723        installMode: number;
724
725        /**
726         * Error messages
727         *
728         * @since 9
729         */
730        errorMessages: Array<ErrorMessage>;
731
732        /**
733         * Version component array
734         *
735         * @since 9
736         */
737        versionComponents: Array<VersionComponent>;
738    }
739
740    /**
741     * Represents error message.
742     *
743     * @since 9
744     */
745    export interface ErrorMessage {
746        /**
747         * Error code
748         *
749         * @since 9
750         */
751        errorCode: number;
752
753        /**
754         * Error message
755         *
756         * @since 9
757         */
758        errorMessage: string;
759    }
760
761    /**
762     * Represents event classify info.
763     *
764     * @since 9
765     */
766    export interface EventClassifyInfo {
767        /**
768         * Event classify
769         *
770         * @since 9
771         */
772        eventClassify: EventClassify;
773
774        /**
775         * Extra info
776         *
777         * @since 9
778         */
779        extraInfo: string;
780    }
781
782    /**
783     * Represents upgrade file info.
784     *
785     * @since 9
786     */
787    export interface UpgradeFile {
788        /**
789         * File type
790         *
791         * @since 9
792         */
793        fileType: ComponentType;
794
795        /**
796         * File path
797         *
798         * @since 9
799         */
800        filePath: string;
801    }
802
803    /**
804     * Called when upgrade task info changes.
805     * You need to implement this method in a child class.
806     *
807     * @param eventInfo EventInfo: include eventId and taskBody info.
808     * @since 9
809     */
810    export interface UpgradeTaskCallback {
811        (eventInfo: EventInfo): void;
812    }
813
814    /**
815     * Enumerates call result.
816     *
817     * @since 9
818     */
819    export enum CallResult {
820        SUCCESS = 0,
821        FAIL = 100,
822        UN_SUPPORT = 101,
823        DEV_UPG_INFO_ERR = 102,
824        FORBIDDEN = 103,
825        IPC_ERR = 104,
826        APP_NOT_GRANTED = 200,
827        PARAM_ERR = 401,
828        TIME_OUT = 402,
829        DB_ERROR = 501,
830        IO_ERROR = 502,
831        NET_ERROR = 503
832    }
833
834    /**
835     * Enumerates business vendor type.
836     *
837     * @since 9
838     */
839    export enum BusinessVendor {
840        PUBLIC = "public"
841    }
842
843    /**
844     * Enumerates business sub type.
845     *
846     * @since 9
847     */
848    export enum BusinessSubType {
849        FIRMWARE = 1
850    }
851
852    /**
853     * Enumerates component type.
854     *
855     * @since 9
856     */
857    export enum ComponentType {
858        OTA = 1,
859    }
860
861    /**
862     * Enumerates upgrade action type.
863     *
864     * @since 9
865     */
866    export enum UpgradeAction {
867        UPGRADE = "upgrade",
868        RECOVERY = "recovery"
869    }
870
871    /**
872     * Enumerates effective mode.
873     *
874     * @since 9
875     */
876    export enum EffectiveMode {
877        COLD = 1,
878        LIVE = 2,
879        LIVE_AND_COLD = 3
880    }
881
882    /**
883     * Enumerates description type.
884     *
885     * @since 9
886     */
887    export enum DescriptionType {
888        CONTENT = 0,
889        URI = 1
890    }
891
892    /**
893     * Enumerates description format.
894     *
895     * @since 9
896     */
897    export enum DescriptionFormat {
898        STANDARD = 0,
899        SIMPLIFIED = 1
900    }
901
902    /**
903     * Enumerates network type.
904     *
905     * @since 9
906     */
907    export enum NetType {
908        CELLULAR = 1,
909        METERED_WIFI = 2,
910        NOT_METERED_WIFI = 4,
911        WIFI = 6,
912        CELLULAR_AND_WIFI = 7
913    }
914
915    /**
916     * Enumerates upgrade order.
917     *
918     * @since 9
919     */
920    export enum Order {
921        DOWNLOAD = 1,
922        INSTALL = 2,
923        DOWNLOAD_AND_INSTALL = 3,
924        APPLY = 4,
925        INSTALL_AND_APPLY = 6
926    }
927
928    /**
929     * Enumerates upgrade status.
930     *
931     * @since 9
932     */
933    export enum UpgradeStatus {
934        WAITING_DOWNLOAD = 20,
935        DOWNLOADING = 21,
936        DOWNLOAD_PAUSED = 22,
937        DOWNLOAD_FAIL = 23,
938        WAITING_INSTALL = 30,
939        UPDATING = 31,
940        WAITING_APPLY = 40,
941        APPLYING = 41,
942        UPGRADE_SUCCESS = 50,
943        UPGRADE_FAIL = 51
944    }
945
946    /**
947     * Enumerates event classify.
948     *
949     * @since 9
950     */
951    export enum EventClassify {
952        TASK = 0x01000000
953    }
954
955    /**
956     * Enumerates event id.
957     *
958     * @since 9
959     */
960    export enum EventId {
961        EVENT_TASK_BASE = EventClassify.TASK,
962        EVENT_TASK_RECEIVE,
963        EVENT_TASK_CANCEL,
964        EVENT_DOWNLOAD_WAIT,
965        EVENT_DOWNLOAD_START,
966        EVENT_DOWNLOAD_UPDATE,
967        EVENT_DOWNLOAD_PAUSE,
968        EVENT_DOWNLOAD_RESUME,
969        EVENT_DOWNLOAD_SUCCESS,
970        EVENT_DOWNLOAD_FAIL,
971        EVENT_UPGRADE_WAIT,
972        EVENT_UPGRADE_START,
973        EVENT_UPGRADE_UPDATE,
974        EVENT_APPLY_WAIT,
975        EVENT_APPLY_START,
976        EVENT_UPGRADE_SUCCESS,
977        EVENT_UPGRADE_FAIL
978    }
979}
980
981export default update;
982