• 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"
17
18export function mockOsAccount() {
19  const osAccountInfoMock = {
20    localId: "[PC Preview] unknown id",
21    localName: "[PC Preview] unknown name",
22    type: "[PC Preview] unknown type",
23    constraints: "[PC Preview] unknown constraints",
24    distributedInfo: "[PC Preview] unknown distributedInfo"
25  };
26  const osAccountTypeMock = "[PC Preview] unknown type";
27  const accountManagerMock = {
28    activateOsAccount: function (...args) {
29      console.warn("AccountManager.activateOsAccount interface mocked in the Previewer. " +
30        "How this interface works on the Previewer may be different from that on a real device.")
31      const len = args.length
32      if (len > 0 && typeof args[len - 1] === 'function') {
33        args[len - 1].call(this, paramMock.businessErrorMock);
34      } else {
35        return new Promise((resolve, reject) => {
36          resolve();
37        })
38      }
39    },
40    isMultiOsAccountEnable: function (...args) {
41      console.warn("AccountManager.isMultiOsAccountEnable interface mocked in the Previewer. " +
42        "How this interface works on the Previewer may be different from that on a real device.")
43      const len = args.length
44      if (len > 0 && typeof args[len - 1] === 'function') {
45        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
46      } else {
47        return new Promise((resolve, reject) => {
48          resolve(paramMock.paramBooleanMock);
49        })
50      }
51    },
52    isOsAccountActived: function (...args) {
53      console.warn("AccountManager.isOsAccountActived interface mocked in the Previewer. " +
54        "How this interface works on the Previewer may be different from that on a real device.")
55      const len = args.length
56      if (len > 0 && typeof args[len - 1] === 'function') {
57        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
58      } else {
59        return new Promise((resolve, reject) => {
60          resolve(paramMock.paramBooleanMock);
61        })
62      }
63    },
64    isOsAccountConstraintEnable: function (...args) {
65      console.warn("AccountManager.isOsAccountConstraintEnable interface mocked in the Previewer. " +
66        "How this interface works on the Previewer may be different from that on a real device.")
67      const len = args.length
68      if (len > 0 && typeof args[len - 1] === 'function') {
69        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
70      } else {
71        return new Promise((resolve, reject) => {
72          resolve(paramMock.paramBooleanMock);
73        })
74      }
75    },
76    isTestOsAccount: function (...args) {
77      console.warn("AccountManager.isTestOsAccount interface mocked in the Previewer. " +
78        "How this interface works on the Previewer may be different from that on a real device.")
79      const len = args.length
80      if (len > 0 && typeof args[len - 1] === 'function') {
81        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
82      } else {
83        return new Promise((resolve, reject) => {
84          resolve(paramMock.paramBooleanMock);
85        })
86      }
87    },
88    isOsAccountVerified: function (...args) {
89      console.warn("AccountManager.isOsAccountVerified interface mocked in the Previewer. " +
90        "How this interface works on the Previewer may be different from that on a real device.")
91      const len = args.length
92      if (len > 0 && typeof args[len - 1] === 'function') {
93        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
94      } else {
95        return new Promise((resolve, reject) => {
96          resolve(paramMock.paramBooleanMock);
97        })
98      }
99    },
100    removeOsAccount: function (...args) {
101      console.warn("AccountManager.removeOsAccount interface mocked in the Previewer. " +
102        "How this interface works on the Previewer may be different from that on a real device.")
103      const len = args.length
104      if (len > 0 && typeof args[len - 1] === 'function') {
105        args[len - 1].call(this, paramMock.businessErrorMock);
106      } else {
107        return new Promise((resolve, reject) => {
108          resolve();
109        })
110      }
111    },
112    setOsAccountConstraints: function (...args) {
113      console.warn("AccountManager.setOsAccountConstraints interface mocked in the Previewer. " +
114        "How this interface works on the Previewer may be different from that on a real device.")
115      const len = args.length
116      if (len > 0 && typeof args[len - 1] === 'function') {
117        args[len - 1].call(this, paramMock.businessErrorMock);
118      } else {
119        return new Promise((resolve, reject) => {
120          resolve();
121        })
122      }
123    },
124    setOsAccountName: function (...args) {
125      console.warn("AccountManager.setOsAccountName interface mocked in the Previewer. " +
126        "How this interface works on the Previewer may be different from that on a real device.")
127      const len = args.length
128      if (len > 0 && typeof args[len - 1] === 'function') {
129        args[len - 1].call(this, paramMock.businessErrorMock);
130      } else {
131        return new Promise((resolve, reject) => {
132          resolve();
133        })
134      }
135    },
136    getCreatedOsAccountsCount: function (...args) {
137      console.warn("AccountManager.getCreatedOsAccountsCount interface mocked in the Previewer. " +
138        "How this interface works on the Previewer may be different from that on a real device.")
139      const len = args.length
140      if (len > 0 && typeof args[len - 1] === 'function') {
141        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
142      } else {
143        return new Promise((resolve, reject) => {
144          resolve(paramMock.paramNumberMock);
145        })
146      }
147    },
148    getOsAccountLocalIdFromProcess: function (...args) {
149      console.warn("AccountManager.getOsAccountLocalIdFromProcess interface mocked in the Previewer. " +
150        "How this interface works on the Previewer may be different from that on a real device.")
151      const len = args.length
152      if (len > 0 && typeof args[len - 1] === 'function') {
153        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
154      } else {
155        return new Promise((resolve, reject) => {
156          resolve(paramMock.paramNumberMock);
157        })
158      }
159    },
160    getOsAccountLocalIdFromUid: function (...args) {
161      console.warn("AccountManager.getOsAccountLocalIdFromUid interface mocked in the Previewer. " +
162        "How this interface works on the Previewer may be different from that on a real device.")
163      const len = args.length
164      if (len > 0 && typeof args[len - 1] === 'function') {
165        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
166      } else {
167        return new Promise((resolve, reject) => {
168          resolve(paramMock.paramNumberMock);
169        })
170      }
171    },
172    getOsAccountLocalIdFromDomain: function (...args) {
173      console.warn("AccountManager.getOsAccountLocalIdFromDomain interface mocked in the Previewer. " +
174        "How this interface works on the Previewer may be different from that on a real device.")
175      const len = args.length
176      if (len > 0 && typeof args[len - 1] === 'function') {
177        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
178      } else {
179        return new Promise((resolve, reject) => {
180          resolve(paramMock.paramNumberMock);
181        })
182      }
183    },
184    queryMaxOsAccountNumber: function (...args) {
185      console.warn("AccountManager.queryMaxOsAccountNumber interface mocked in the Previewer. " +
186        "How this interface works on the Previewer may be different from that on a real device.")
187      const len = args.length
188      if (len > 0 && typeof args[len - 1] === 'function') {
189        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
190      } else {
191        return new Promise((resolve, reject) => {
192          resolve(paramMock.paramNumberMock);
193        })
194      }
195    },
196    getOsAccountAllConstraints: function (...args) {
197      console.warn("AccountManager.getOsAccountAllConstraints interface mocked in the Previewer. " +
198        "How this interface works on the Previewer may be different from that on a real device.")
199      const len = args.length
200      if (len > 0 && typeof args[len - 1] === 'function') {
201        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
202      } else {
203        return new Promise((resolve, reject) => {
204          resolve(paramMock.paramStringMock);
205        })
206      }
207    },
208    queryAllCreatedOsAccounts: function (...args) {
209      console.warn("AccountManager.queryAllCreatedOsAccounts interface mocked in the Previewer. " +
210        "How this interface works on the Previewer may be different from that on a real device.")
211      var osAccountInfoArrayMock = new Array();
212      osAccountInfoArrayMock.push(osAccountInfoMock);
213      const len = args.length
214      if (len > 0 && typeof args[len - 1] === 'function') {
215        args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoArrayMock);
216      } else {
217        return new Promise((resolve, reject) => {
218          resolve(osAccountInfoArrayMock);
219        })
220      }
221    },
222    queryActivatedOsAccountIds: function (...args) {
223      console.warn("AccountManager.queryActivatedOsAccountIds interface mocked in the Previewer. " +
224        "How this interface works on the Previewer may be different from that on a real device.")
225      var osAccountIdsArrayMock = new Array();
226      osAccountIdsArrayMock.push(osAccountInfoMock);
227      const len = args.length
228      if (len > 0 && typeof args[len - 1] === 'function') {
229        args[len - 1].call(this, paramMock.businessErrorMock, osAccountIdsArrayMock);
230      } else {
231        return new Promise((resolve, reject) => {
232          resolve(osAccountIdsArrayMock);
233        })
234      }
235    },
236    createOsAccount: function (...args) {
237      console.warn("AccountManager.createOsAccount interface mocked in the Previewer. " +
238        "How this interface works on the Previewer may be different from that on a real device.")
239      const len = args.length
240      if (len > 0 && typeof args[len - 1] === 'function') {
241        args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock);
242      } else {
243        return new Promise((resolve, reject) => {
244          resolve(osAccountInfoMock);
245        })
246      }
247    },
248    createOsAccountForDomain: function (...args) {
249      console.warn("AccountManager.createOsAccountForDomain interface mocked in the Previewer. " +
250        "How this interface works on the Previewer may be different from that on a real device.")
251      const len = args.length
252      if (len > 0 && typeof args[len - 1] === 'function') {
253        args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock);
254      } else {
255        return new Promise((resolve, reject) => {
256          resolve(osAccountInfoMock);
257        })
258      }
259    },
260    queryCurrentOsAccount: function (...args) {
261      console.warn("AccountManager.queryCurrentOsAccount interface mocked in the Previewer. " +
262        "How this interface works on the Previewer may be different from that on a real device.")
263      const len = args.length
264      if (len > 0 && typeof args[len - 1] === 'function') {
265        args[len - 1].call(this, paramMock.businessErrorMock, osAccountInfoMock);
266      } else {
267        return new Promise((resolve, reject) => {
268          resolve(osAccountInfoMock);
269        })
270      }
271    },
272    queryOsAccountById: function (...args) {
273      console.warn("AccountManager.queryOsAccountById 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, osAccountInfoMock);
278      } else {
279        return new Promise((resolve, reject) => {
280          resolve(osAccountInfoMock);
281        })
282      }
283    },
284    getOsAccountTypeFromProcess: function (...args) {
285      console.warn("AccountManager.getOsAccountTypeFromProcess 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, osAccountTypeMock);
290      } else {
291        return new Promise((resolve, reject) => {
292          resolve(osAccountTypeMock);
293        })
294      }
295    },
296    getDistributedVirtualDeviceId: function (...args) {
297      console.warn("AccountManager.getDistributedVirtualDeviceId 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, paramMock.paramStringMock);
302      } else {
303        return new Promise((resolve, reject) => {
304          resolve(paramMock.paramStringMock);
305        })
306      }
307    },
308    getOsAccountProfilePhoto: function (...args) {
309      console.warn("AccountManager.getOsAccountProfilePhoto interface mocked in the Previewer. " +
310        "How this interface works on the Previewer may be different from that on a real device.")
311      const len = args.length
312      if (len > 0 && typeof args[len - 1] === 'function') {
313        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
314      } else {
315        return new Promise((resolve, reject) => {
316          resolve(paramMock.paramStringMock);
317        })
318      }
319    },
320    setOsAccountProfilePhoto: function (...args) {
321      console.warn("AccountManager.setOsAccountProfilePhoto interface mocked in the Previewer. " +
322        "How this interface works on the Previewer may be different from that on a real device.")
323      const len = args.length
324      if (len > 0 && typeof args[len - 1] === 'function') {
325        args[len - 1].call(this, paramMock.businessErrorMock);
326      } else {
327        return new Promise((resolve, reject) => {
328          resolve();
329        })
330      }
331    },
332    getOsAccountLocalIdBySerialNumber: function (...args) {
333      console.warn("AccountManager.getOsAccountLocalIdBySerialNumber interface mocked in the Previewer. " +
334        "How this interface works on the Previewer may be different from that on a real device.")
335      const len = args.length
336      if (len > 0 && typeof args[len - 1] === 'function') {
337        args[len - 1].call(this, paramMock.businessErrorMock);
338      } else {
339        return new Promise((resolve, reject) => {
340          resolve();
341        })
342      }
343    },
344    getSerialNumberByOsAccountLocalId: function (...args) {
345      console.warn("AccountManager.getSerialNumberByOsAccountLocalId interface mocked in the Previewer. " +
346        "How this interface works on the Previewer may be different from that on a real device.")
347      const len = args.length
348      if (len > 0 && typeof args[len - 1] === 'function') {
349        args[len - 1].call(this, paramMock.businessErrorMock);
350      } else {
351        return new Promise((resolve, reject) => {
352          resolve();
353        })
354      }
355    },
356    on: function (...args) {
357      console.warn("AccountManager.on interface mocked in the Previewer. " +
358        "How this interface works on the Previewer may be different from that on a real device.")
359      const len = args.length
360      if (len > 0 && typeof args[len - 1] === 'function') {
361        args[len - 1].call(this, paramMock.paramNumberMock);
362      } else {
363        return new Promise((resolve, reject) => {
364          resolve(paramMock.paramNumberMock);
365        })
366      }
367    },
368    off: function (...args) {
369      console.warn("AccountManager.off interface mocked in the Previewer. " +
370        "How this interface works on the Previewer may be different from that on a real device.")
371      const len = args.length
372      if (len > 0 && typeof args[len - 1] === 'function') {
373        args[len - 1].call(this, paramMock.paramNumberMock);
374      } else {
375        return new Promise((resolve, reject) => {
376          resolve(paramMock.paramNumberMock);
377        })
378      }
379    }
380  };
381  const osAccount = {
382    getAccountManager: function (...args) {
383      console.warn("osAccount.getAccountManager interface mocked in the Previewer. " +
384        "How this interface works on the Previewer may be different from that on a real device.")
385      return accountManagerMock;
386    },
387    OsAccountType: {
388      ADMIN: "[PC Preview] unknown ADMIN",
389      NORMAL: "[PC Preview] unknown NORMAL",
390      GUEST: "[PC Preview] unknown GUEST"
391    }
392  }
393  return osAccount
394}