• 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 { paramMock } from "../utils"
17import { PixelMapMock } from "../multimedia"
18
19export function mockAppAbilityManager() {
20  global.ohosplugin.app = {}
21  const ActiveProcessInfoMock = {
22    pid: "[PC Preview] unknow pid",
23    uid: "[PC Preview] unknow uid",
24    processName: "[PC Preview] unknow processName",
25    bundleNames: ["[PC Preview] unknow bundleNames", "[PC Preview] unknow bundleNames"]
26  }
27  const ElementNameMock = {
28    deviceId: "[PC Preview] unknow deviceId",
29    bundleName: "[PC Preview] unknow bundleName",
30    abilityName: "[PC Preview] unknow abilityName",
31    uri: "[PC Preview] unknow uri",
32    shortName: "[PC Preview] unknow shortName",
33  }
34  const AbilityMissionInfoMock = {
35    missionId: "[PC Preview] unknow missionId",
36    bottomAbility: {
37      abilityName: ElementNameMock.abilityName,
38      bundleName: ElementNameMock.bundleName,
39      deviceId: ElementNameMock.deviceId
40    },
41    topAbility: {
42      abilityName: ElementNameMock.abilityName,
43      bundleName: ElementNameMock.bundleName,
44      deviceId: ElementNameMock.deviceId
45    },
46    windowMode: "[PC Preview] unknow windowMode"
47  }
48
49  const ActiveServiceAbilityInfoMock = {
50    pid: "[PC Preview] unknow pid",
51    uid: "[PC Preview] unknow uid",
52    processName: "[PC Preview] unknow processName",
53    serviceAbility: {
54      abilityName: ElementNameMock.abilityName,
55      bundleName: ElementNameMock.bundleName,
56      deviceId: ElementNameMock.deviceId
57    }
58  }
59
60  const ProcessErrorInfoMock = {
61    errStatus: "[PC Preview] unknow errStatus",
62    processName: "[PC Preview] unknow processName",
63    pid: "[PC Preview] unknow pid",
64    uid: "[PC Preview] unknow uid",
65    abilityName: "[PC Preview] unknow abilityName",
66    errMsg: "[PC Preview] unknow errMsg",
67    backTrace: "[PC Preview] unknow backTrace"
68  }
69  const SystemMemoryAttrMock = {
70    availSysMem: "[PC Preview] unknow availSysMem",
71    totalSysMem: "[PC Preview] unknow totalSysMem",
72    threshold: "[PC Preview] unknow threshold",
73    isSysInlowMem: "[PC Preview] unknow isSysInlowMem"
74  }
75  const MissionSnapshotMock = {
76    topAbility: {
77      abilityName: ElementNameMock.abilityName,
78      bundleName: ElementNameMock.bundleName,
79      deviceId: ElementNameMock.deviceId
80    },
81    snapshot: PixelMapMock
82  }
83  const MemoryMapInfoMock = {
84    vmPss: "[PC Preview] unknow vmPss",
85    vmPrivateDirty: "[PC Preview] unknow vmPrivateDirty",
86    vmSharedDirty: "[PC Preview] unknow vmSharedDirty",
87    nativePss: "[PC Preview] unknow nativePss",
88    nativePrivateDirty: "[PC Preview] unknow nativePrivateDirty",
89    nativeSharedDirty: "[PC Preview] unknow nativeSharedDirty",
90    otherPss: "[PC Preview] unknow otherPss",
91    otherPrivateDirty: "[PC Preview] unknow otherPrivateDirty",
92    otherSharedDirty: "[PC Preview] unknow otherSharedDirty"
93  }
94
95  global.ohosplugin.app.abilityManager = {
96    getCurrentUserId: function (...args) {
97      console.warn("app.abilityManager.getCurrentUserId interface mocked in the Previewer. How this interface works" +
98        " on the Previewer may be different from that on a real device.")
99      const len = args.length
100      if (typeof args[len - 1] === 'function') {
101        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
102      } else {
103        return new Promise((resolve) => {
104          resolve(paramMock.paramNumberMock)
105        })
106      }
107    },
108    getActiveProcessInfos: function (...args) {
109      console.warn("app.abilityManager.getActiveProcessInfos interface mocked in the Previewer. How this interface works" +
110        " on the Previewer may be different from that on a real device.")
111      const len = args.length
112      if (typeof args[len - 1] === 'function') {
113        args[len - 1].call(this, paramMock.businessErrorMock, [ActiveProcessInfoMock])
114      } else {
115        return new Promise((resolve) => {
116          resolve([ActiveProcessInfoMock])
117        })
118      }
119    },
120    getActiveAbilityMissionInfos: function (...args) {
121      console.warn("app.abilityManager.getActiveAbilityMissionInfos interface mocked in the Previewer. How this interface works" +
122        " on the Previewer may be different from that on a real device.")
123      const len = args.length
124      if (typeof args[len - 1] === 'function') {
125        args[len - 1].call(this, paramMock.businessErrorMock, [AbilityMissionInfoMock])
126      } else {
127        return new Promise((resolve) => {
128          resolve([AbilityMissionInfoMock])
129        })
130      }
131    },
132    getPreviousAbilityMissionInfos: function (...args) {
133      console.warn("app.abilityManager.getPreviousAbilityMissionInfos interface mocked in the Previewer. How this interface works" +
134        " on the Previewer may be different from that on a real device.")
135      const len = args.length
136      if (typeof args[len - 1] === 'function') {
137        args[len - 1].call(this, paramMock.businessErrorMock, [AbilityMissionInfoMock])
138      } else {
139        return new Promise((resolve) => {
140          resolve([AbilityMissionInfoMock])
141        })
142      }
143    },
144    deleteMissions: function (...args) {
145      console.warn("app.abilityManager.deleteMissions interface mocked in the Previewer. How this interface works" +
146        " on the Previewer may be different from that on a real device.")
147      const len = args.length
148      if (typeof args[len - 1] === 'function') {
149        args[len - 1].call(this, paramMock.businessErrorMock)
150      } else {
151        return new Promise((resolve) => {
152          resolve()
153        })
154      }
155    },
156    isUserATestUser: function (...args) {
157      console.warn("app.abilityManager.isUserATestUser interface mocked in the Previewer. How this interface works on" +
158        " the Previewer may be different from that on a real device.")
159      const len = args.length
160      if (typeof args[len - 1] === 'function') {
161        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
162      } else {
163        return new Promise((resolve) => {
164          resolve(paramMock.paramBooleanMock)
165        })
166      }
167    },
168    getActiveServiceAbilityInfos: function (...args) {
169      console.warn("app.abilityManager.getActiveServiceAbilityInfos interface mocked in the Previewer. How this interface works" +
170        " on the Previewer may be different from that on a real device.")
171      const len = args.length
172      if (typeof args[len - 1] === 'function') {
173        args[len - 1].call(this, paramMock.businessErrorMock, [ActiveServiceAbilityInfoMock])
174      } else {
175        return new Promise((resolve) => {
176          resolve([ActiveServiceAbilityInfoMock])
177        })
178      }
179    },
180    getHomeScreenIconDenseness: function (...args) {
181      console.warn("app.abilityManager.getHomeScreenIconDenseness interface mocked in the Previewer. How this interface works" +
182        " on the Previewer may be different from that on a real device.")
183      const len = args.length
184      if (typeof args[len - 1] === 'function') {
185        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
186      } else {
187        return new Promise((resolve) => {
188          resolve(paramMock.paramNumberMock)
189        })
190      }
191    },
192    getHomeScreenIconSize: function (...args) {
193      console.warn("app.abilityManager.getHomeScreenIconSize interface mocked in the Previewer. How this interface works" +
194        " on the Previewer may be different from that on a real device.")
195      const len = args.length
196      if (typeof args[len - 1] === 'function') {
197        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
198      } else {
199        return new Promise((resolve) => {
200          resolve(paramMock.paramNumberMock)
201        })
202      }
203    },
204    isMultiWindowAllowed: function (...args) {
205      console.warn("app.abilityManager.isMultiWindowAllowed interface mocked in the Previewer. How this interface works" +
206        " on the Previewer may be different from that on a real device.")
207      const len = args.length
208      if (typeof args[len - 1] === 'function') {
209        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
210      } else {
211        return new Promise((resolve) => {
212          resolve(paramMock.paramBooleanMock)
213        })
214      }
215    },
216    moveMissionToFirstSplitScreen: function (...args) {
217      console.warn("app.abilityManager.moveMissionToFirstSplitScreen interface mocked in the Previewer. How this interface works" +
218        " on the Previewer may be different from that on a real device.")
219      const len = args.length
220      if (typeof args[len - 1] === 'function') {
221        args[len - 1].call(this, paramMock.businessErrorMock)
222      } else {
223        return new Promise((resolve) => {
224          resolve()
225        })
226      }
227    },
228    isRamConstrainedDevice: function (...args) {
229      console.warn("app.abilityManager.isRamConstrainedDevice interface mocked in the Previewer. How this interface works" +
230        " on the Previewer may be different from that on a real device.")
231      const len = args.length
232      if (typeof args[len - 1] === 'function') {
233        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
234      } else {
235        return new Promise((resolve) => {
236          resolve(paramMock.paramBooleanMock)
237        })
238      }
239    },
240    getAppMemorySize: function (...args) {
241      console.warn("app.abilityManager.getAppMemorySize interface mocked in the Previewer. How this interface works" +
242        " on the Previewer may be different from that on a real device.")
243      const len = args.length
244      if (typeof args[len - 1] === 'function') {
245        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
246      } else {
247        return new Promise((resolve) => {
248          resolve(paramMock.paramNumberMock)
249        })
250      }
251    },
252    getProcessMemoryMapInfos: function (...args) {
253      console.warn("app.abilityManager.getProcessMemoryMapInfos interface mocked in the Previewer. How this interface works" +
254        " on the Previewer may be different from that on a real device.")
255      const len = args.length
256      if (typeof args[len - 1] === 'function') {
257        args[len - 1].call(this, paramMock.businessErrorMock, [MemoryMapInfoMock])
258      } else {
259        return new Promise((resolve) => {
260          resolve([MemoryMapInfoMock])
261        })
262      }
263    },
264
265    getSystemMemoryAttr: function (...args) {
266      console.warn("app.abilityManager.getSystemMemoryAttr interface mocked in the Previewer. How this interface works" +
267        " on the Previewer may be different from that on a real device.")
268      const len = args.length
269      if (typeof args[len - 1] === 'function') {
270        args[len - 1].call(this, paramMock.businessErrorMock, SystemMemoryAttrMock)
271      } else {
272        return new Promise((resolve) => {
273          resolve(SystemMemoryAttrMock)
274        })
275      }
276    },
277    getProcessErrorInfos: function (...args) {
278      console.warn("app.abilityManager.getProcessErrorInfos interface mocked in the Previewer. How this interface works" +
279        " on the Previewer may be different from that on a real device.")
280      const len = args.length
281      if (typeof args[len - 1] === 'function') {
282        args[len - 1].call(this, paramMock.businessErrorMock, [ProcessErrorInfoMock])
283      } else {
284        return new Promise((resolve) => {
285          resolve([ProcessErrorInfoMock])
286        })
287      }
288    },
289    getAbilityMissionSnapshot: function (...args) {
290      console.warn("app.abilityManager.getAbilityMissionSnapshot interface mocked in the Previewer. How this interface works" +
291        " on the Previewer may be different from that on a real device.")
292      const len = args.length
293      if (typeof args[len - 1] === 'function') {
294        args[len - 1].call(this, paramMock.businessErrorMock, MissionSnapshotMock)
295      } else {
296        return new Promise((resolve) => {
297          resolve(MissionSnapshotMock)
298        })
299      }
300    }
301  }
302}
303