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 { hasComplete } from "./utils" 17 18export function mockBrightness() { 19 global.systemplugin.brightness = { 20 argsV: { 21 value: 80 22 }, 23 argsM: { 24 mode: 0 25 }, 26 getValue: function (...args) { 27 console.warn("brightness.getValue interface mocked in the Previewer. How this interface works on the Previewer" + 28 " may be different from that on a real device.") 29 args[0].success(this.argsV) 30 hasComplete(args[0].complete) 31 }, 32 setValue: function (...args) { 33 console.warn("brightness.setValue interface mocked in the Previewer. How this interface works on the Previewer" + 34 " may be different from that on a real device.") 35 if (args[0].value) { 36 this.argsV.value = args[0].value 37 args[0].success() 38 hasComplete(args[0].complete) 39 } 40 }, 41 getMode: function (...args) { 42 console.warn("brightness.getMode interface mocked in the Previewer. How this interface works on the Previewer" + 43 " may be different from that on a real device.") 44 args[0].success(this.argsM) 45 hasComplete(args[0].complete) 46 }, 47 setMode: function (...args) { 48 console.warn("brightness.setMode interface mocked in the Previewer. How this interface works on the Previewer" + 49 " may be different from that on a real device.") 50 this.argsM.mode = args[0].mode 51 args[0].success() 52 hasComplete(args[0].complete) 53 }, 54 setKeepScreenOn: function (...args) { 55 console.warn("brightness.setKeepScreenOn interface mocked in the Previewer. How this interface works on the" + 56 " Previewer may be different from that on a real device.") 57 args[0].success() 58 hasComplete(args[0].complete) 59 } 60 } 61} 62