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 mockPower() { 19 const DevicePowerMode = { 20 MODE_PERFORMANCE: '[PC preview] unknow MODE_PERFORMANCE', 21 MODE_NORMAL: '[PC preview] unknow MODE_NORMAL', 22 MODE_POWER_SAVE: '[PC preview] unknow MODE_POWER_SAVE', 23 MODE_EXTREME_POWER_SAVE: '[PC preview] unknow MODE_EXTREME_POWER_SAVE', 24 } 25 const power = { 26 DevicePowerMode, 27 shutdownDevice: function (...args) { 28 console.warn("power.shutdownDevice interface mocked in the Previewer. How this interface works on the" + 29 " Previewer may be different from that on a real device.") 30 }, 31 rebootDevice: function (...args) { 32 console.warn("power.rebootDevice interface mocked in the Previewer. How this interface works on the" + 33 " Previewer may be different from that on a real device.") 34 }, 35 isScreenOn: function (...args) { 36 console.warn("power.isScreenOn interface mocked in the Previewer. How this interface works on the" + 37 " Previewer may be different from that on a real device.") 38 const len = args.length 39 if (typeof args[len - 1] === 'function') { 40 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 41 } else { 42 return new Promise((resolve, reject) => { 43 resolve(paramMock.paramBooleanMock); 44 }) 45 } 46 }, 47 wakeupDevice: function (...args) { 48 console.warn("power.wakeupDevice interface mocked in the Previewer. How this interface works on the" + 49 " Previewer may be different from that on a real device.") 50 }, 51 suspendDevice: function (...args) { 52 console.warn("power.suspendDevice interface mocked in the Previewer. How this interface works on the" + 53 " Previewer may be different from that on a real device.") 54 }, 55 getPowerMode: function (...args) { 56 console.warn("power.getPowerMode 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, DevicePowerMode); 61 } else { 62 return new Promise((resolve, reject) => { 63 resolve(DevicePowerMode); 64 }) 65 } 66 }, 67 setPowerMode: function (...args) { 68 console.warn("power.setPowerMode interface mocked in the Previewer. How this interface works on the" + 69 " Previewer may be different from that on a real device.") 70 const len = args.length 71 if (typeof args[len - 1] === 'function') { 72 args[len - 1].call(this, paramMock.businessErrorMock); 73 } else { 74 return new Promise((resolve, reject) => { 75 resolve(); 76 }) 77 } 78 }, 79 } 80 return power 81} 82