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 */ 15import { paramMock } from "../../utils" 16import { AbilityClass } from "../ohos_application_Ability" 17import { ContextClass } from "./Context" 18import { ShellCmdResult } from "./shellCmdResult" 19 20export const AbilityDelegator = { 21 addAbilityMonitor: function (...args) { 22 console.warn("AbilityDelegator.addAbilityMonitor interface mocked in the Previewer." + 23 " How this interface works on the Previewer may be different from that on a real device.") 24 const len = args.length 25 if (len > 0 && typeof args[len - 1] === 'function') { 26 args[len - 1].call(this, paramMock.businessErrorMock); 27 } else { 28 return new Promise((resolve, reject) => { 29 resolve(); 30 }) 31 } 32 }, 33 removeAbilityMonitor: function (...args) { 34 console.warn("AbilityDelegator.removeAbilityMonitor interface mocked in the Previewer." + 35 " How this interface works on the Previewer may be different from that on a real device.") 36 const len = args.length 37 if (len > 0 && typeof args[len - 1] === 'function') { 38 args[len - 1].call(this, paramMock.businessErrorMock); 39 } else { 40 return new Promise((resolve, reject) => { 41 resolve(); 42 }) 43 } 44 }, 45 waitAbilityMonitor: function (...args) { 46 console.warn("AbilityDelegator.waitAbilityMonitor interface mocked in the Previewer." + 47 " How this interface works on the Previewer may be different from that on a real device.") 48 const len = args.length 49 if (len > 0 && typeof args[len - 1] === 'function') { 50 args[len - 1].call(this, paramMock.businessErrorMock, new AbilityClass()); 51 } else { 52 return new Promise((resolve, reject) => { 53 resolve(new AbilityClass()); 54 }) 55 } 56 }, 57 getAppContext: function (...args) { 58 console.warn('AbilityDelegator.getAppContext interface mocked in the Previewer. How this interface works on the' + 59 ' Previewer may be different from that on a real device.'); 60 return new ContextClass(); 61 }, 62 getAbilityState: function (...args) { 63 console.warn('AbilityDelegator.getAbilityState interface mocked in the Previewer. How this interface works on the' + 64 ' Previewer may be different from that on a real device.'); 65 return paramMock.paramNumberMock; 66 }, 67 getCurrentTopAbility: function (...args) { 68 console.warn("AbilityDelegator.getCurrentTopAbility interface mocked in the Previewer." + 69 " How this interface works on the Previewer may be different from that on a real device.") 70 const len = args.length 71 if (len > 0 && typeof args[len - 1] === 'function') { 72 args[len - 1].call(this, paramMock.businessErrorMock, new AbilityClass()); 73 } else { 74 return new Promise((resolve, reject) => { 75 resolve(new AbilityClass()); 76 }) 77 } 78 }, 79 startAbility: function (...args) { 80 console.warn("AbilityDelegator.startAbility interface mocked in the Previewer." + 81 " How this interface works on the Previewer may be different from that on a real device.") 82 const len = args.length 83 if (len > 0 && typeof args[len - 1] === 'function') { 84 args[len - 1].call(this, paramMock.businessErrorMock); 85 } else { 86 return new Promise((resolve, reject) => { 87 resolve(); 88 }) 89 } 90 }, 91 doAbilityForeground: function (...args) { 92 console.warn("AbilityDelegator.doAbilityForeground interface mocked in the Previewer." + 93 " How this interface works on the Previewer may be different from that on a real device.") 94 const len = args.length 95 if (len > 0 && typeof args[len - 1] === 'function') { 96 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 97 } else { 98 return new Promise((resolve, reject) => { 99 resolve(paramMock.paramBooleanMock); 100 }) 101 } 102 }, 103 doAbilityBackground: function (...args) { 104 console.warn("AbilityDelegator.doAbilityBackground interface mocked in the Previewer." + 105 " How this interface works on the Previewer may be different from that on a real device.") 106 const len = args.length 107 if (len > 0 && typeof args[len - 1] === 'function') { 108 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 109 } else { 110 return new Promise((resolve, reject) => { 111 resolve(paramMock.paramBooleanMock); 112 }) 113 } 114 }, 115 print: function (...args) { 116 console.warn("AbilityDelegator.print interface mocked in the Previewer." + 117 " How this interface works on the Previewer may be different from that on a real device.") 118 const len = args.length 119 if (len > 0 && typeof args[len - 1] === 'function') { 120 args[len - 1].call(this, paramMock.businessErrorMock); 121 } else { 122 return new Promise((resolve, reject) => { 123 resolve(); 124 }) 125 } 126 }, 127 printSync: function (...args) { 128 console.warn('AbilityDelegator.printSync interface mocked in the Previewer. How this interface works on the' + 129 ' Previewer may be different from that on a real device.'); 130 }, 131 executeShellCommand: function (...args) { 132 console.warn("AbilityDelegator.executeShellCommand interface mocked in the Previewer." + 133 " How this interface works on the Previewer may be different from that on a real device.") 134 const len = args.length 135 if (len > 0 && typeof args[len - 1] === 'function') { 136 args[len - 1].call(this, paramMock.businessErrorMock, ShellCmdResult); 137 } else { 138 return new Promise((resolve, reject) => { 139 resolve(ShellCmdResult); 140 }) 141 } 142 }, 143 finishTest: function (...args) { 144 console.warn("AbilityDelegator.finishTest interface mocked in the Previewer." + 145 " How this interface works on the Previewer may be different from that on a real device.") 146 const len = args.length 147 if (len > 0 && typeof args[len - 1] === 'function') { 148 args[len - 1].call(this, paramMock.businessErrorMock); 149 } else { 150 return new Promise((resolve, reject) => { 151 resolve(); 152 }) 153 } 154 } 155}