• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 { paramMock } from "../utils"
17import { BundleInfo, PixelMapFormat } from './bundle/bundleInfo'
18import { BundlePackInfo } from './bundle/packInfo'
19import { DispatchInfo } from './bundle/dispatchInfo'
20import { ApplicationInfo, Want } from './bundle/applicationInfo'
21import { AbilityInfo } from './bundle/abilityInfo'
22import { PermissionDef } from './bundle/PermissionDef'
23import { ExtensionAbilityInfo } from './bundle/extensionAbilityInfo'
24
25export const BundleFlag = {
26    GET_BUNDLE_DEFAULT: 0x00000000,
27    GET_BUNDLE_WITH_ABILITIES: 0x00000001,
28    GET_ABILITY_INFO_WITH_PERMISSION: 0x00000002,
29    GET_ABILITY_INFO_WITH_APPLICATION: 0x00000004,
30    GET_APPLICATION_INFO_WITH_PERMISSION: 0x00000008,
31    GET_BUNDLE_WITH_REQUESTED_PERMISSION: 0x00000010,
32    GET_ALL_APPLICATION_INFO: 0xFFFF0000,
33    GET_ABILITY_INFO_WITH_METADATA: 0x00000020,
34    GET_BUNDLE_WITH_EXTENSION_ABILITY: 0x00000020,
35    GET_BUNDLE_WITH_HASH_VALUE: 0x00000030,
36    GET_APPLICATION_INFO_WITH_METADATA: 0x00000040,
37    GET_ABILITY_INFO_SYSTEMAPP_ONLY: 0x00000080,
38    GET_ABILITY_INFO_WITH_DISABLE: 0x00000100,
39    GET_APPLICATION_INFO_WITH_DISABLE: 0x00000200,
40    GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT: 0x00000400,
41}
42
43export const ExtensionFlag = {
44    GET_EXTENSION_INFO_DEFAULT: 0x00000000,
45    GET_EXTENSION_INFO_WITH_PERMISSION: 0x00000002,
46    GET_EXTENSION_INFO_WITH_APPLICATION: 0x00000004,
47    GET_EXTENSION_INFO_WITH_METADATA: 0x00000020,
48}
49
50export const ColorMode = {
51    AUTO_MODE: -1,
52    DARK_MODE: 0,
53    LIGHT_MODE: 1,
54}
55
56export const GrantStatus = {
57    PERMISSION_DENIED: -1,
58    PERMISSION_GRANTED: 0,
59}
60
61export const AbilityType = {
62    UNKNOWN: 0,
63    PAGE: 1,
64    SERVICE: 2,
65    DATA: 3,
66}
67
68export const AbilitySubType = {
69    UNSPECIFIED: 0,
70    CA: 1,
71}
72
73export const DisplayOrientation = {
74    UNSPECIFIED: 0,
75    LANDSCAPE: 0,
76    PORTRAIT: 1,
77    FOLLOW_RECENT: 2,
78    LANDSCAPE_INVERTED: 3,
79    PORTRAIT_INVERTED: 4,
80    AUTO_ROTATION: 5,
81    AUTO_ROTATION_LANDSCAPE: 6,
82    AUTO_ROTATION_PORTRAIT: 7,
83    AUTO_ROTATION_RESTRICTED: 8,
84    AUTO_ROTATION_LANDSCAPE_RESTRICTED: 9,
85    AUTO_ROTATION_PORTRAIT_RESTRICTED: 10,
86    LOCKED: 11,
87}
88
89export const LaunchMode = {
90    SINGLETON: 0,
91    STANDARD: 1,
92}
93
94export const ExtensionAbilityType = {
95    FORM: 0,
96    WORK_SCHEDULER: 1,
97    INPUT_METHOD: 2,
98    SERVICE: 3,
99    ACCESSIBILITY: 4,
100    DATA_SHARE: 5,
101    FILE_SHARE: 6,
102    STATIC_SUBSCRIBER: 7,
103    WALLPAPER: 8,
104    BACKUP: 9,
105    WINDOW: 10,
106    ENTERPRISE_ADMIN: 11,
107    UNSPECIFIED: 20,
108}
109
110export const BundleOptions = {
111    userId: "[PC preview] unknown userId",
112}
113
114export const InstallErrorCode = {
115    SUCCESS: 0,
116    STATUS_INSTALL_FAILURE: 1,
117    STATUS_INSTALL_FAILURE_ABORTED: 2,
118    STATUS_INSTALL_FAILURE_INVALID: 3,
119    STATUS_INSTALL_FAILURE_CONFLICT: 4,
120    STATUS_INSTALL_FAILURE_STORAGE: 5,
121    STATUS_INSTALL_FAILURE_INCOMPATIBLE: 6,
122    STATUS_UNINSTALL_FAILURE: 7,
123    STATUS_UNINSTALL_FAILURE_BLOCKED: 8,
124    STATUS_UNINSTALL_FAILURE_ABORTED: 9,
125    STATUS_UNINSTALL_FAILURE_CONFLICT: 10,
126    STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT: 0x0B,
127    STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED: 0x0C,
128    STATUS_RECOVER_FAILURE_INVALID: 0x0D,
129    STATUS_ABILITY_NOT_FOUND: 0x40,
130    STATUS_BMS_SERVICE_ERROR: 0x41,
131    STATUS_FAILED_NO_SPACE_LEFT: 0x42,
132    STATUS_GRANT_REQUEST_PERMISSIONS_FAILED: 0x43,
133    STATUS_INSTALL_PERMISSION_DENIED: 0x44,
134    STATUS_UNINSTALL_PERMISSION_DENIED: 0x45,
135}
136
137export const UpgradeFlag = {
138    NOT_UPGRADE: 0,
139    SINGLE_UPGRADE: 1,
140    RELATION_UPGRADE: 2,
141}
142
143export const SupportWindowMode = {
144    FULL_SCREEN: 0,
145    SPLIT: 1,
146    FLOATING: 2,
147}
148
149export function mockBundle() {
150    const bundle = {
151        getBundleInfo: function(...args) {
152            console.warn("bundle.getBundleInfo interface mocked in the Previewer. How this interface works on the" +
153                " Previewer may be different from that on a real device.")
154            const len = args.length;
155            if (typeof args[len - 1] === 'function') {
156                args[len - 1].call(this, paramMock.businessErrorMock, BundleInfo);
157            } else {
158                return new Promise((resolve) => {
159                    resolve(BundleInfo);
160                })
161            }
162        },
163        getBundleInstaller: function(...args) {
164            console.warn("bundle.getBundleInstaller interface mocked in the Previewer. How this interface works on the" +
165                " Previewer may be different from that on a real device.")
166            const len = args.length;
167            if (typeof args[len - 1] === 'function') {
168                args[len - 1].call(this, paramMock.businessErrorMock);
169            } else {
170                return new Promise((resolve) => {
171                    resolve(paramMock.paramNumberMock);
172                })
173            }
174        },
175        getApplicationInfo: function(...args) {
176            console.warn("bundle.getApplicationInfo interface mocked in the Previewer. How this interface works on the" +
177                " Previewer may be different from that on a real device.")
178            const len = args.length;
179            if (typeof args[len - 1] === 'function') {
180                args[len - 1].call(this, paramMock.businessErrorMock, ApplicationInfo);
181            } else {
182                return new Promise((resolve) => {
183                    resolve(ApplicationInfo);
184                })
185            }
186        },
187        queryAbilityByWant: function(...args) {
188            console.warn("bundle.queryAbilityByWant interface mocked in the Previewer. How this interface works on the" +
189                " Previewer may be different from that on a real device.")
190            const len = args.length;
191            if (typeof args[len - 1] === 'function') {
192                args[len - 1].call(this, paramMock.businessErrorMock, Array(BundleInfo));
193            } else {
194                return new Promise((resolve) => {
195                    resolve(Array(BundleInfo));
196                })
197            }
198        },
199        getAllApplicationInfo: function(...args){
200            console.warn("bundle.getAllApplicationInfo interface mocked in the Previewer. How this interface works on the" +
201                " Previewer may be different from that on a real device.")
202            const len = args.length;
203            if (typeof args[len - 1] === 'function') {
204                args[len - 1].call(this, paramMock.businessErrorMock, Array(BundleInfo));
205            } else {
206                return new Promise((resolve) => {
207                    resolve(Array(BundleInfo));
208                })
209            }
210        },
211        getAllBundleInfo: function(...args) {
212            console.warn("bundle.getAllBundleInfo interface mocked in the Previewer. How this interface works on the" +
213                " Previewer may be different from that on a real device.")
214            const len = args.length;
215            if (typeof args[len - 1] === 'function') {
216                args[len - 1].call(this, paramMock.businessErrorMock, Array(ApplicationInfo));
217            } else {
218                return new Promise((resolve) => {
219                    resolve(Array(ApplicationInfo));
220                })
221            }
222        },
223        getBundleArchiveInfo:  function(...args) {
224            console.warn("bundle.getBundleArchiveInfo interface mocked in the Previewer. How this interface works on the" +
225                " Previewer may be different from that on a real device.")
226            const len = args.length;
227            if (typeof args[len - 1] === 'function') {
228                args[len - 1].call(this, paramMock.businessErrorMock, Array(BundleInfo));
229            } else {
230                return new Promise((resolve) => {
231                    resolve(Array(BundleInfo));
232                })
233            }
234        },
235        getLaunchWantForBundle: function(...args) {
236            console.warn("bundle.getBundleArchiveInfo interface mocked in the Previewer. How this interface works on the" +
237                " Previewer may be different from that on a real device.")
238            const len = args.length;
239            if (typeof args[len - 1] === 'function') {
240                args[len - 1].call(this, paramMock.businessErrorMock, Array(Want));
241            } else {
242                return new Promise((resolve) => {
243                    resolve(Array(Want));
244                })
245            }
246        },
247        cleanBundleCacheFiles: function(...args) {
248            console.warn("bundle.cleanBundleCacheFiles interface mocked in the Previewer. How this interface works on the" +
249                " Previewer may be different from that on a real device.")
250            const len = args.length;
251            if (typeof args[len - 1] === 'function') {
252                args[len - 1].call(this, paramMock.businessErrorMock);
253            } else {
254                return new Promise((resolve) => {
255                    resolve(paramMock.paramNumberMock);
256                })
257            }
258        },
259        setApplicationEnabled: function(...args) {
260            console.warn("bundle.setApplicationEnabled interface mocked in the Previewer. How this interface works on the" +
261                " Previewer may be different from that on a real device.")
262            const len = args.length;
263            if (typeof args[len - 1] === 'function') {
264                args[len - 1].call(this, paramMock.businessErrorMock);
265            } else {
266                return new Promise((resolve) => {
267                    resolve(paramMock.paramNumberMock);
268                })
269            }
270        },
271        setAbilityEnabled: function(...args) {
272            console.warn("bundle.setAbilityEnabled interface mocked in the Previewer. How this interface works on the" +
273                " Previewer may be different from that on a real device.")
274            const len = args.length;
275            if (typeof args[len - 1] === 'function') {
276                args[len - 1].call(this, paramMock.businessErrorMock);
277            } else {
278                return new Promise((resolve) => {
279                    resolve(paramMock.paramNumberMock);
280                })
281            }
282        },
283        setModuleUpgradeFlag: function (...args) {
284            console.warn("bundle.setModuleUpgradeFlag interface mocked in the Previewer. How this interface works on the" +
285                " Previewer may be different from that on a real device.")
286            const len = args.length
287            if (typeof args[len - 1] === 'function') {
288                args[len - 1].call(this, paramMock.businessErrorMock)
289            } else {
290                return new Promise((resolve) => {
291                    resolve()
292                });
293            }
294        },
295        isModuleRemovable: function (...args) {
296            console.warn("bundle.isModuleRemovable interface mocked in the Previewer. How this interface works on the" +
297                " Previewer may be different from that on a real device.")
298            const len = args.length
299            if (typeof args[len - 1] === 'function') {
300                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
301            } else {
302                return new Promise((resolve) => {
303                    resolve(paramMock.paramBooleanMock)
304                });
305            }
306        },
307        getProfileByAbility: function (...args) {
308            console.warn("bundle.getProfileByAbility interface mocked in the Previewer. How this interface works on the" +
309                " Previewer may be different from that on a real device.")
310            const len = args.length
311            if (typeof args[len - 1] === 'function') {
312                args[len - 1].call(this, paramMock.businessErrorMock, new Array(paramMock.paramStringMock))
313            } else {
314                return new Promise((resolve) => {
315                    resolve(new Array(paramMock.paramStringMock))
316                });
317            }
318        },
319        getProfileByExtensionAbility: function (...args) {
320            console.warn("bundle.getProfileByExtensionAbility interface mocked in the Previewer. How this interface works on the" +
321                " Previewer may be different from that on a real device.")
322            const len = args.length
323            if (typeof args[len - 1] === 'function') {
324                args[len - 1].call(this, paramMock.businessErrorMock, new Array(paramMock.paramStringMock))
325            } else {
326                return new Promise((resolve) => {
327                    resolve(new Array(paramMock.paramStringMock))
328                });
329            }
330        },
331        queryExtensionAbilityInfos: function (...args) {
332            console.warn("bundle.queryExtensionAbilityInfos interface mocked in the Previewer. How this interface works on the" +
333                " Previewer may be different from that on a real device.")
334            const len = args.length
335            if (typeof args[len - 1] === 'function') {
336                args[len - 1].call(this,paramMock.businessErrorMock, Array(ExtensionAbilityInfo))
337            } else {
338                return new Promise((resolve) => {
339                    resolve(Array(ExtensionAbilityInfo))
340                });
341            }
342        },
343        getBundlePackInfo: function(...args) {
344            console.warn("bundle.getBundlePackInfo interface mocked in the Previewer. How this interface works on the" +
345                " Previewer may be different from that on a real device.")
346            const len = args.length;
347            if (typeof args[len - 1] === 'function') {
348                args[len - 1].call(this, paramMock.businessErrorMock, BundlePackInfo);
349            } else {
350                return new Promise((resolve) => {
351                    resolve(BundlePackInfo);
352                })
353            }
354        },
355        getDispatcherVersion: function(...args) {
356            console.warn("bundle.getDispatcherVersion interface mocked in the Previewer. How this interface works on the" +
357                " Previewer may be different from that on a real device.")
358            const len = args.length;
359            if (typeof args[len - 1] === 'function') {
360                args[len - 1].call(this, paramMock.businessErrorMock, DispatchInfo);
361            } else {
362                return new Promise((resolve) => {
363                    resolve(DispatchInfo);
364                })
365            }
366        },
367        setDisposedStatus: function (...args) {
368            console.warn("bundle.setDisposedStatus interface mocked in the Previewer. How this interface works on the" +
369                " Previewer may be different from that on a real device.")
370            const len = args.length
371            if (typeof args[len - 1] === 'function') {
372                args[len - 1].call(this, paramMock.businessErrorMock)
373            } else {
374                return new Promise((resolve) => {
375                    resolve()
376                });
377            }
378        },
379        getDisposedStatus: function (...args) {
380            console.warn("bundle.getDisposedStatus interface mocked in the Previewer. How this interface works on the" +
381                " Previewer may be different from that on a real device.")
382            const len = args.length
383            if (typeof args[len - 1] === 'function') {
384                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
385            } else {
386                return new Promise((resolve) => {
387                    resolve(paramMock.paramNumberMock)
388                });
389            }
390        },
391        isAbilityEnabled: function(...args) {
392            console.warn("bundle.isAbilityEnabled interface mocked in the Previewer. How this interface works on the" +
393                " Previewer may be different from that on a real device.")
394            const len = args.length;
395            if (typeof args[len - 1] === 'function') {
396                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
397            } else {
398                return new Promise((resolve) => {
399                    resolve(paramMock.paramBooleanMock);
400                })
401            }
402        },
403        isApplicationEnabled: function(...args) {
404            console.warn("bundle.isApplicationEnabled interface mocked in the Previewer. How this interface works on the" +
405                " Previewer may be different from that on a real device.")
406            const len = args.length;
407            if (typeof args[len - 1] === 'function') {
408                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
409            } else {
410                return new Promise((resolve) => {
411                    resolve(paramMock.paramBooleanMock);
412                })
413            }
414        },
415        getAbilityIcon: function(...args) {
416            console.warn("bundle.getAbilityIcon interface mocked in the Previewer. How this interface works on the" +
417                " Previewer may be different from that on a real device.")
418            const len = args.length;
419            if (typeof args[len - 1] === 'function') {
420                args[len - 1].call(this, paramMock.businessErrorMock, PixelMapFormat);
421            } else {
422                return new Promise((resolve) => {
423                    resolve(PixelMapFormat);
424                })
425            }
426        },
427        getAbilityLabel: function(...args) {
428            console.warn("bundle.getAbilityLabel interface mocked in the Previewer. How this interface works on the" +
429                " Previewer may be different from that on a real device.")
430            const len = args.length;
431            if (typeof args[len - 1] === 'function') {
432                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
433            } else {
434                return new Promise((resolve) => {
435                    resolve(paramMock.paramStringMock);
436                })
437            }
438        },
439        getPermissionDef: function(...args) {
440            console.warn("bundle.getPermissionDef interface mocked in the Previewer. How this interface works on the" +
441                " Previewer may be different from that on a real device.")
442            const len = args.length;
443            if (typeof args[len - 1] === 'function') {
444                args[len - 1].call(this, paramMock.businessErrorMock, PermissionDef);
445            } else {
446                return new Promise((resolve) => {
447                    resolve(PermissionDef);
448                })
449            }
450        },
451        getNameForUid: function(...args) {
452            console.warn("bundle.getNameForUid interface mocked in the Previewer. How this interface works on the" +
453                " Previewer may be different from that on a real device.")
454            const len = args.length;
455            if (typeof args[len - 1] === 'function') {
456                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
457            } else {
458                return new Promise((resolve) => {
459                    resolve(paramMock.paramStringMock);
460                })
461            }
462        },
463        getAbilityInfo: function(...args) {
464            console.warn("bundle.getAbilityInfo interface mocked in the Previewer. How this interface works on the" +
465                " Previewer may be different from that on a real device.")
466            const len = args.length;
467            if (typeof args[len - 1] === 'function') {
468                args[len - 1].call(this, paramMock.businessErrorMock, AbilityInfo);
469            } else {
470                return new Promise((resolve) => {
471                    resolve(AbilityInfo);
472                })
473            }
474        },
475        getApplicationInfoSync: function(...args) {
476            console.warn("bundle.getApplicationInfoSync interface mocked in the Previewer. How this interface works on the" +
477                " Previewer may be different from that on a real device.")
478            return ApplicationInfo
479        },
480        getBundleInfoSync: function(...args) {
481            console.warn("bundle.getBundleInfoSync interface mocked in the Previewer. How this interface works on the" +
482                " Previewer may be different from that on a real device.")
483            return BundleInfo
484        },
485    };
486    return bundle;
487}