• 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 */
15import { paramMock } from "../../utils"
16import { ProcessInfo } from "./processInfo"
17import { AppVersionInfo } from "./appVersionInfo"
18import { AbilityInfo } from "../bundle/abilityInfo"
19import { ApplicationInfo } from "../bundle/applicationInfo"
20import { ElementName } from "../bundle/elementName"
21import { HapModuleInfo } from "../bundle/hapModuleInfo"
22
23const DisplayOrientation = {
24    UNSPECIFIED: "[PC preview] unknown is UNSPECIFIED",
25    LANDSCAPE: "[PC preview] unknown is LANDSCAPE",
26    PORTRAIT: "[PC preview] unknown is PORTRAIT",
27    FOLLOW_RECENT: "[PC preview] unknown is FOLLOW_RECENT",
28    LANDSCAPE_INVERTED: "[PC preview] unknown is LANDSCAPE_INVERTED",
29    PORTRAIT_INVERTED: "[PC preview] unknown is PORTRAIT_INVERTED",
30    AUTO_ROTATION: "[PC preview] unknown is AUTO_ROTATION",
31    AUTO_ROTATION_LANDSCAPE: "[PC preview] unknown is AUTO_ROTATION_LANDSCAPE",
32    AUTO_ROTATION_PORTRAIT: "[PC preview] unknown is AUTO_ROTATION_PORTRAIT",
33    AUTO_ROTATION_RESTRICTED: "[PC preview] unknown is AUTO_ROTATION_RESTRICTED",
34    AUTO_ROTATION_LANDSCAPE_RESTRICTED: "[PC preview] unknown is AUTO_ROTATION_LANDSCAPE_RESTRICTED",
35    AUTO_ROTATION_PORTRAIT_RESTRICTED: "[PC preview] unknown is AUTO_ROTATION_PORTRAIT_RESTRICTED",
36    LOCKED: "[PC preview] unknown is LOCKED",
37}
38export const Context = {
39    getOrCreateLocalDir: function (...args) {
40        console.warn("Context.getOrCreateLocalDir interface mocked in the Previewer." +
41            " How this interface works on the Previewer may be different from that on a real device.")
42        const len = args.length
43        if (len > 0 && typeof args[len - 1] === 'function') {
44            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
45        } else {
46            return new Promise((resolve, reject) => {
47                resolve(paramMock.paramStringMock);
48            })
49        }
50    },
51    verifyPermission: function (...args) {
52        console.warn("Context.verifyPermission interface mocked in the Previewer." +
53            " How this interface works on the Previewer may be different from that on a real device.")
54        const len = args.length
55        if (len > 0 && typeof args[len - 1] === 'function') {
56            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
57        } else {
58            return new Promise((resolve, reject) => {
59                resolve(paramMock.paramNumberMock);
60            })
61        }
62    },
63    requestPermissionsFromUser: function (...args) {
64        console.warn("Context.requestPermissionsFromUser interface mocked in the Previewer." +
65            " How this interface works on the Previewer may be different from that on a real device.")
66        const len = args.length
67        if (len > 0 && typeof args[len - 1] === 'function') {
68            args[len - 1].call(this, paramMock.businessErrorMock, PermissionRequestResult);
69        } else {
70            return new Promise((resolve, reject) => {
71                resolve(PermissionRequestResult);
72            })
73        }
74    },
75    getApplicationInfo: function (...args) {
76        console.warn("Context.getApplicationInfo interface mocked in the Previewer." +
77            " How this interface works on the Previewer may be different from that on a real device.")
78        const len = args.length
79        if (len > 0 && typeof args[len - 1] === 'function') {
80            args[len - 1].call(this, paramMock.businessErrorMock, ApplicationInfo);
81        } else {
82            return new Promise((resolve, reject) => {
83                resolve(ApplicationInfo);
84            })
85        }
86    },
87    getBundleName: function (...args) {
88        console.warn("Context.getBundleName interface mocked in the Previewer." +
89            " How this interface works on the Previewer may be different from that on a real device.")
90        const len = args.length
91        if (len > 0 && typeof args[len - 1] === 'function') {
92            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
93        } else {
94            return new Promise((resolve, reject) => {
95                resolve(paramMock.paramStringMock);
96            })
97        }
98    },
99    getDisplayOrientation: function (...args) {
100        console.warn("Context.getDisplayOrientation interface mocked in the Previewer." +
101            " How this interface works on the Previewer may be different from that on a real device.")
102        const len = args.length
103        if (len > 0 && typeof args[len - 1] === 'function') {
104            args[len - 1].call(this, paramMock.businessErrorMock, DisplayOrientation);
105        } else {
106            return new Promise((resolve, reject) => {
107                resolve(DisplayOrientation);
108            })
109        }
110    },
111    setDisplayOrientation: function (...args) {
112        console.warn("Context.setDisplayOrientation interface mocked in the Previewer." +
113            " How this interface works on the Previewer may be different from that on a real device.")
114        const len = args.length
115        if (len > 0 && typeof args[len - 1] === 'function') {
116            args[len - 1].call(this, paramMock.businessErrorMock);
117        } else {
118            return new Promise((resolve, reject) => {
119                resolve();
120            })
121        }
122    },
123    setShowOnLockScreen: function (...args) {
124        console.warn("Context.setShowOnLockScreen interface mocked in the Previewer." +
125            " How this interface works on the Previewer may be different from that on a real device.")
126        const len = args.length
127        if (len > 0 && typeof args[len - 1] === 'function') {
128            args[len - 1].call(this, paramMock.businessErrorMock);
129        } else {
130            return new Promise((resolve, reject) => {
131                resolve();
132            })
133        }
134    },
135    setWakeUpScreen: function (...args) {
136        console.warn("Context.setWakeUpScreen interface mocked in the Previewer." +
137            " How this interface works on the Previewer may be different from that on a real device.")
138        const len = args.length
139        if (len > 0 && typeof args[len - 1] === 'function') {
140            args[len - 1].call(this, paramMock.businessErrorMock);
141        } else {
142            return new Promise((resolve, reject) => {
143                resolve();
144            })
145        }
146    },
147    getProcessInfo: function (...args) {
148        console.warn("Context.getProcessInfo interface mocked in the Previewer." +
149            " How this interface works on the Previewer may be different from that on a real device.")
150        const len = args.length
151        if (len > 0 && typeof args[len - 1] === 'function') {
152            args[len - 1].call(this, paramMock.businessErrorMock, ProcessInfo);
153        } else {
154            return new Promise((resolve, reject) => {
155                resolve(ProcessInfo);
156            })
157        }
158    },
159    getElementName: function (...args) {
160        console.warn("Context.getElementName interface mocked in the Previewer." +
161            " How this interface works on the Previewer may be different from that on a real device.")
162        const len = args.length
163        if (len > 0 && typeof args[len - 1] === 'function') {
164            args[len - 1].call(this, paramMock.businessErrorMock, ElementName);
165        } else {
166            return new Promise((resolve, reject) => {
167                resolve(ElementName);
168            })
169        }
170    },
171    getProcessName: function (...args) {
172        console.warn("Context.getProcessName interface mocked in the Previewer." +
173            " How this interface works on the Previewer may be different from that on a real device.")
174        const len = args.length
175        if (len > 0 && typeof args[len - 1] === 'function') {
176            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
177        } else {
178            return new Promise((resolve, reject) => {
179                resolve(paramMock.paramStringMock);
180            })
181        }
182    },
183    getCallingBundle: function (...args) {
184        console.warn("Context.getCallingBundle interface mocked in the Previewer." +
185            " How this interface works on the Previewer may be different from that on a real device.")
186        const len = args.length
187        if (len > 0 && typeof args[len - 1] === 'function') {
188            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
189        } else {
190            return new Promise((resolve, reject) => {
191                resolve(paramMock.paramStringMock);
192            })
193        }
194    },
195    getFilesDir: function (...args) {
196        console.warn("Context.getFilesDir interface mocked in the Previewer." +
197            " How this interface works on the Previewer may be different from that on a real device.")
198        const len = args.length
199        if (len > 0 && typeof args[len - 1] === 'function') {
200            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
201        } else {
202            return new Promise((resolve, reject) => {
203                resolve(paramMock.paramStringMock);
204            })
205        }
206    },
207    getCacheDir: function (...args) {
208        console.warn("Context.getCacheDir interface mocked in the Previewer." +
209            " How this interface works on the Previewer may be different from that on a real device.")
210        const len = args.length
211        if (len > 0 && typeof args[len - 1] === 'function') {
212            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
213        } else {
214            return new Promise((resolve, reject) => {
215                resolve(paramMock.paramStringMock);
216            })
217        }
218    },
219    getOrCreateDistributedDir: function (...args) {
220        console.warn("Context.getOrCreateDistributedDir interface mocked in the Previewer." +
221            " How this interface works on the Previewer may be different from that on a real device.")
222        const len = args.length
223        if (len > 0 && typeof args[len - 1] === 'function') {
224            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
225        } else {
226            return new Promise((resolve, reject) => {
227                resolve(paramMock.paramStringMock);
228            })
229        }
230    },
231    getAppType: function (...args) {
232        console.warn("Context.getAppType interface mocked in the Previewer." +
233            " How this interface works on the Previewer may be different from that on a real device.")
234        const len = args.length
235        if (len > 0 && typeof args[len - 1] === 'function') {
236            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
237        } else {
238            return new Promise((resolve, reject) => {
239                resolve(paramMock.paramStringMock);
240            })
241        }
242    },
243    getHapModuleInfo: function (...args) {
244        console.warn("Context.getHapModuleInfo interface mocked in the Previewer." +
245            " How this interface works on the Previewer may be different from that on a real device.")
246        const len = args.length
247        if (len > 0 && typeof args[len - 1] === 'function') {
248            args[len - 1].call(this, paramMock.businessErrorMock, HapModuleInfo);
249        } else {
250            return new Promise((resolve, reject) => {
251                resolve(HapModuleInfo);
252            })
253        }
254    },
255    getAppVersionInfo: function (...args) {
256        console.warn("Context.getAppVersionInfo interface mocked in the Previewer." +
257            " How this interface works on the Previewer may be different from that on a real device.")
258        const len = args.length
259        if (len > 0 && typeof args[len - 1] === 'function') {
260            args[len - 1].call(this, paramMock.businessErrorMock, AppVersionInfo);
261        } else {
262            return new Promise((resolve, reject) => {
263                resolve(AppVersionInfo);
264            })
265        }
266    },
267    getApplicationContext: function () {
268        console.warn("Context.getApplicationContext interface mocked in the Previewer." +
269            " How this interface works on the Previewer may be different from that on a real device.")
270        return Context;
271    },
272    getAbilityInfo: function (...args) {
273        console.warn("Context.getAbilityInfo interface mocked in the Previewer." +
274            " How this interface works on the Previewer may be different from that on a real device.")
275        const len = args.length
276        if (len > 0 && typeof args[len - 1] === 'function') {
277            args[len - 1].call(this, paramMock.businessErrorMock, AbilityInfo);
278        } else {
279            return new Promise((resolve, reject) => {
280                resolve(AbilityInfo);
281            })
282        }
283    },
284    isUpdatingConfigurations: function (...args) {
285        console.warn("Context.isUpdatingConfigurations interface mocked in the Previewer." +
286            " How this interface works on the Previewer may be different from that on a real device.")
287        const len = args.length
288        if (len > 0 && typeof args[len - 1] === 'function') {
289            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
290        } else {
291            return new Promise((resolve, reject) => {
292                resolve(paramMock.paramBooleanMock);
293            })
294        }
295    },
296    printDrawnCompleted: function (...args) {
297        console.warn("Context.printDrawnCompleted interface mocked in the Previewer." +
298            " How this interface works on the Previewer may be different from that on a real device.")
299        const len = args.length
300        if (len > 0 && typeof args[len - 1] === 'function') {
301            args[len - 1].call(this, paramMock.businessErrorMock);
302        } else {
303            return new Promise((resolve, reject) => {
304                resolve();
305            })
306        }
307    }
308}
309export const PermissionRequestResult = {
310    requestCode: "[PC Preview] unknow requestCode",
311    permissions: [paramMock.paramStringMock],
312    authResults: [paramMock.paramNumberMock],
313}
314export const PermissionOptions = {
315    pid: "[PC Preview] unknow pid",
316    uid: "[PC Preview] unknow uid",
317}