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 */ 15 16import { paramMock } from "../utils" 17 18export function mockRunninglock() { 19 const RunningLockType = { 20 BACKGROUND: 1, 21 PROXIMITY_SCREEN_CONTROL: '[PC Preview] unknow PROXIMITY_SCREEN_CONTROL', 22 } 23 const RunningLockClass = class RunningLock { 24 constructor() { 25 this.lock = function (...args) { 26 console.warn("RunningLock.lock interface mocked in the Previewer. How this interface works on the Previewer" + 27 " may be different from that on a real device.") 28 }; 29 this.isUsed = function (...args) { 30 console.warn("RunningLock.isUsed interface mocked in the Previewer. How this interface works on the" + 31 " Previewer may be different from that on a real device.") 32 return paramMock.paramBooleanMock 33 }; 34 this.unlock = function (...args) { 35 console.warn("RunningLock.unlock interface mocked in the Previewer. How this interface works on the Previewer" + 36 " may be different from that on a real device.") 37 }; 38 } 39 } 40 const runninglock = { 41 RunningLock:RunningLockClass, 42 RunningLockType, 43 isRunningLockTypeSupported: function (...args) { 44 console.warn("runningLock.isRunningLockTypeSupported interface mocked in the Previewer. How this interface works on the" + 45 " Previewer may be different from that on a real device.") 46 const len = args.length 47 if (typeof args[len - 1] === 'function') { 48 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 49 } else { 50 return new Promise((resolve, reject) => { 51 resolve(paramMock.paramBooleanMock); 52 }) 53 } 54 }, 55 createRunningLock: function (...args) { 56 console.warn("runningLock.createRunningLock interface mocked in the Previewer. How this interface works on the" + 57 " Previewer may be different from that on a real device.") 58 const len = args.length 59 if (typeof args[len - 1] === 'function') { 60 args[len - 1].call(this, paramMock.businessErrorMock, new RunningLockClass()); 61 } else { 62 return new Promise((resolve, reject) => { 63 resolve(new RunningLockClass()); 64 }) 65 } 66 } 67 } 68 return runninglock 69} 70