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" 17import { Caller } from "../ohos_application_Ability"; 18import { ExtensionContextClass } from "./ExtensionContext" 19 20export const ServiceExtensionContextClass = class ServiceExtensionContext extends ExtensionContextClass { 21 constructor() { 22 super(); 23 console.warn("ServiceExtensionContext.constructor interface mocked in the Previewer. How this interface works on the Previewer" + 24 " may be different from that on a real device.") 25 this.startAbility = function (...args) { 26 console.warn("ServiceExtensionContext.startAbility interface mocked in the Previewer." + 27 " How this interface works on the Previewer may be different from that on a real device.") 28 const len = args.length 29 if (len > 0 && typeof args[len - 1] === 'function') { 30 args[len - 1].call(this, paramMock.businessErrorMock); 31 } else { 32 return new Promise((resolve, reject) => { 33 resolve(); 34 }) 35 } 36 }; 37 this.startAbilityWithAccount = function (...args) { 38 console.warn("ServiceExtensionContext.startAbilityWithAccount interface mocked in the Previewer." + 39 " How this interface works on the Previewer may be different from that on a real device.") 40 const len = args.length 41 if (len > 0 && typeof args[len - 1] === 'function') { 42 args[len - 1].call(this, paramMock.businessErrorMock); 43 } else { 44 return new Promise((resolve, reject) => { 45 resolve(); 46 }) 47 } 48 }; 49 this.startServiceExtensionAbility = function (...args) { 50 console.warn("ServiceExtensionContext.startServiceExtensionAbility interface mocked in the Previewer." + 51 " How this interface works on the Previewer may be different from that on a real device.") 52 const len = args.length 53 if (len > 0 && typeof args[len - 1] === 'function') { 54 args[len - 1].call(this, paramMock.businessErrorMock); 55 } else { 56 return new Promise((resolve, reject) => { 57 resolve(); 58 }) 59 } 60 }; 61 this.startServiceExtensionAbilityWithAccount = function (...args) { 62 console.warn("ServiceExtensionContext.startServiceExtensionAbilityWithAccount interface mocked in the Previewer." + 63 " How this interface works on the Previewer may be different from that on a real device.") 64 const len = args.length 65 if (len > 0 && typeof args[len - 1] === 'function') { 66 args[len - 1].call(this, paramMock.businessErrorMock); 67 } else { 68 return new Promise((resolve, reject) => { 69 resolve(); 70 }) 71 } 72 }; 73 this.stopServiceExtensionAbility = function (...args) { 74 console.warn("ServiceExtensionContext.stopServiceExtensionAbility interface mocked in the Previewer." + 75 " How this interface works on the Previewer may be different from that on a real device.") 76 const len = args.length 77 if (len > 0 && typeof args[len - 1] === 'function') { 78 args[len - 1].call(this, paramMock.businessErrorMock); 79 } else { 80 return new Promise((resolve, reject) => { 81 resolve(); 82 }) 83 } 84 }; 85 this.stopServiceExtensionAbilityWithAccount = function (...args) { 86 console.warn("ServiceExtensionContext.stopServiceExtensionAbilityWithAccount interface mocked in the Previewer." + 87 " How this interface works on the Previewer may be different from that on a real device.") 88 const len = args.length 89 if (len > 0 && typeof args[len - 1] === 'function') { 90 args[len - 1].call(this, paramMock.businessErrorMock); 91 } else { 92 return new Promise((resolve, reject) => { 93 resolve(); 94 }) 95 } 96 }; 97 this.terminateSelf = function (...args) { 98 console.warn("ServiceExtensionContext.terminateSelf interface mocked in the Previewer." + 99 " How this interface works on the Previewer may be different from that on a real device.") 100 const len = args.length 101 if (len > 0 && typeof args[len - 1] === 'function') { 102 args[len - 1].call(this, paramMock.businessErrorMock); 103 } else { 104 return new Promise((resolve, reject) => { 105 resolve(); 106 }) 107 } 108 }; 109 this.connectAbility = function (...args) { 110 console.warn("ServiceExtensionContext.connectAbility interface mocked in the Previewer." + 111 " How this interface works on the Previewer may be different from that on a real device.") 112 return paramMock.paramNumberMock 113 }; 114 this.connectAbilityWithAccount = function (...args) { 115 console.warn("ServiceExtensionContext.connectAbilityWithAccount interface mocked in the Previewer." + 116 " How this interface works on the Previewer may be different from that on a real device.") 117 return paramMock.paramNumberMock 118 }; 119 this.disconnectAbility = function (...args) { 120 console.warn("ServiceExtensionContext.disconnectAbility interface mocked in the Previewer." + 121 " How this interface works on the Previewer may be different from that on a real device.") 122 const len = args.length 123 if (len > 0 && typeof args[len - 1] === 'function') { 124 args[len - 1].call(this, paramMock.businessErrorMock); 125 } else { 126 return new Promise((resolve, reject) => { 127 resolve(); 128 }) 129 } 130 }; 131 this.startAbilityByCall = function (...args) { 132 console.warn("ServiceExtensionContext.startAbilityByCall interface mocked in the Previewer." + 133 " How this interface works on the Previewer may be different from that on a real device.") 134 return new Promise((resolve, reject) => { 135 resolve(Caller); 136 }) 137 }; 138 } 139};