• 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"
17
18export function mockScreenLock() {
19  const screenLock = {
20    isScreenLocked: function (...args) {
21      console.warn("screenLock.isScreenLocked interface mocked in the Previewer. How this interface works on the" +
22        " Previewer may be different from that on a real device.")
23      const len = args.length
24      if (typeof args[len - 1] === 'function') {
25        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
26      } else {
27        return new Promise((resolve) => {
28          resolve(paramMock.paramBooleanMock);
29        })
30      }
31    },
32    isLocked: function (...args) {
33      console.warn("wallpaper.isLocked interface mocked in the Previewer. How this interface works on the" +
34        " Previewer may be different from that on a real device.")
35      return paramMock.paramBooleanMock;
36    },
37    isSecureMode: function (...args) {
38      console.warn("screenLock.isSecureMode interface mocked in the Previewer. How this interface works on the" +
39        " Previewer may be different from that on a real device.")
40      const len = args.length
41      if (typeof args[len - 1] === 'function') {
42        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
43      } else {
44        return new Promise((resolve) => {
45          resolve(paramMock.paramBooleanMock);
46        })
47      }
48    },
49    isSecure: function (...args) {
50      console.warn("wallpaper.isSecure interface mocked in the Previewer. How this interface works on the" +
51        " Previewer may be different from that on a real device.")
52      return paramMock.paramBooleanMock;
53    },
54    unlockScreen: function (...args) {
55      console.warn("screenLock.unlockScreen interface mocked in the Previewer. How this interface works on the" +
56        " Previewer may be different from that on a real device.")
57      const len = args.length
58      if (typeof args[len - 1] === 'function') {
59        args[len - 1].call(this, paramMock.businessErrorMock)
60      } else {
61        return new Promise((resolve) => {
62          resolve();
63        })
64      }
65    },
66    unlock: function (...args) {
67      console.warn("screenLock.unlock interface mocked in the Previewer. How this interface works on the" +
68        " Previewer may be different from that on a real device.")
69      const len = args.length
70      if (typeof args[len - 1] === 'function') {
71        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
72      } else {
73        return new Promise((resolve) => {
74          resolve(paramMock.paramBooleanMock);
75        })
76      }
77    },
78    lock: function (...args) {
79      console.warn("screenLock.lockScreen interface mocked in the Previewer. How this interface works on the" +
80        " Previewer may be different from that on a real device.")
81      const len = args.length
82      if (typeof args[len - 1] === 'function') {
83        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
84      } else {
85        return new Promise((resolve) => {
86          resolve(paramMock.paramBooleanMock);
87        })
88      }
89    },
90    onSystemEvent: function (...args) {
91      console.warn("screenLock.onSystemEvent interface mocked in the Previewer. How this interface works on the" +
92        " Previewer may be different from that on a real device.")
93      const len = args.length
94      if (typeof args[len - 1] === 'function') {
95        args[len - 1].call(this, screenLock.SystemEvent)
96      }
97      return paramMock.paramBooleanMock
98    },
99    SystemEvent: {
100      eventType: '[PC Preview] unknow eventType',
101      params: paramMock.paramStringMock
102    },
103    sendScreenLockEvent: function (...args) {
104      console.warn("screenLock.sendScreenLockEvent interface mocked in the Previewer. How this interface works on the" +
105        " Previewer may be different from that on a real device.")
106      const len = args.length
107      if (typeof args[len - 1] === 'function') {
108        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
109      } else {
110        return new Promise((resolve) => {
111          resolve(paramMock.paramBooleanMock);
112        })
113      }
114    }
115  }
116  return screenLock
117}