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 { WantClass } from "./ohos_application_Want" 18import { Context as _Context } from "./app/context" 19import { AbilityResult } from "./ability/abilityResult" 20import { windowMock } from "./ohos_window" 21import { DataAbilityHelper } from "./ability/dataAbilityHelper" 22import { AppVersionInfo as _AppVersionInfo } from "./app/appVersionInfo" 23import { ProcessInfo as _ProcessInfo } from "./app/processInfo" 24 25export function mockFeatureAbility() { 26 const featureAbility = { 27 getWant: function (...args) { 28 console.warn("featureAbility.getWant interface mocked in the Previewer." + 29 " How this interface works on the Previewer may be different from that on a real device.") 30 const len = args.length 31 if (len > 0 && typeof args[len - 1] === 'function') { 32 args[len - 1].call(this, paramMock.businessErrorMock, new WantClass()); 33 } else { 34 return new Promise((resolve, reject) => { 35 resolve(new WantClass()); 36 }) 37 } 38 }, 39 startAbility: function (...args) { 40 console.warn("featureAbility.startAbility interface mocked in the Previewer." + 41 " How this interface works on the Previewer may be different from that on a real device.") 42 const len = args.length 43 if (len > 0 && typeof args[len - 1] === 'function') { 44 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 45 } else { 46 return new Promise((resolve, reject) => { 47 resolve(paramMock.paramNumberMock); 48 }) 49 } 50 }, 51 getContext: function () { 52 console.warn("featureAbility.getContext interface mocked in the Previewer." + 53 " How this interface works on the Previewer may be different from that on a real device.") 54 return _Context; 55 }, 56 startAbilityForResult: function (...args) { 57 console.warn("featureAbility.startAbilityForResult interface mocked in the Previewer." + 58 " How this interface works on the Previewer may be different from that on a real device.") 59 const len = args.length 60 if (len > 0 && typeof args[len - 1] === 'function') { 61 args[len - 1].call(this, paramMock.businessErrorMock, AbilityResult); 62 } else { 63 return new Promise((resolve, reject) => { 64 resolve(AbilityResult); 65 }) 66 } 67 }, 68 terminateSelfWithResult: function (...args) { 69 console.warn("featureAbility.terminateSelfWithResult interface mocked in the Previewer." + 70 " How this interface works on the Previewer may be different from that on a real device.") 71 const len = args.length 72 if (len > 0 && typeof args[len - 1] === 'function') { 73 args[len - 1].call(this, paramMock.businessErrorMock); 74 } else { 75 return new Promise((resolve, reject) => { 76 resolve(); 77 }) 78 } 79 }, 80 terminateSelf: function () { 81 console.warn("featureAbility.terminateSelf interface mocked in the Previewer." + 82 " How this interface works on the Previewer may be different from that on a real device.") 83 const len = args.length 84 if (len > 0 && typeof args[len - 1] === 'function') { 85 args[len - 1].call(this, paramMock.businessErrorMock); 86 } else { 87 return new Promise((resolve, reject) => { 88 resolve(); 89 }) 90 } 91 }, 92 acquireDataAbilityHelper: function (...args) { 93 console.warn("featureAbility.acquireDataAbilityHelper interface mocked in the Previewer." + 94 " How this interface works on the Previewer may be different from that on a real device.") 95 return DataAbilityHelper; 96 }, 97 hasWindowFocus: function (...args) { 98 console.warn("featureAbility.hasWindowFocus 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, paramMock.paramBooleanMock); 103 } else { 104 return new Promise((resolve, reject) => { 105 resolve(paramMock.paramBooleanMock); 106 }) 107 } 108 }, 109 connectAbility: function (...args) { 110 console.warn("featureAbility.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 disconnectAbility: function (...args) { 115 console.warn("featureAbility.disconnectAbility interface mocked in the Previewer." + 116 " How this interface works on the Previewer may be different from that on a real device.") 117 const len = args.length 118 if (len > 0 && typeof args[len - 1] === 'function') { 119 args[len - 1].call(this, paramMock.businessErrorMock); 120 } else { 121 return new Promise((resolve, reject) => { 122 resolve(); 123 }) 124 } 125 }, 126 getWindow: function (...args) { 127 console.warn("featureAbility.getWindow interface mocked in the Previewer." + 128 " How this interface works on the Previewer may be different from that on a real device.") 129 const len = args.length 130 if (len > 0 && typeof args[len - 1] === 'function') { 131 args[len - 1].call(this, paramMock.businessErrorMock, windowMock); 132 } else { 133 return new Promise((resolve, reject) => { 134 resolve(windowMock); 135 }) 136 } 137 }, 138 AbilityWindowConfiguration, 139 AbilityStartSetting, 140 ErrorCode, 141 DataAbilityOperationType, 142 Context: _Context, 143 AppVersionInfo: _AppVersionInfo, 144 ProcessInfo: _ProcessInfo 145 } 146 return featureAbility; 147} 148export const AbilityWindowConfiguration = { 149 WINDOW_MODE_UNDEFINED: 0, 150 WINDOW_MODE_FULLSCREEN: 1, 151 WINDOW_MODE_SPLIT_PRIMARY: 100, 152 WINDOW_MODE_SPLIT_SECONDARY: 101, 153 WINDOW_MODE_FLOATING: 102 154} 155export const AbilityStartSetting = { 156 BOUNDS_KEY: "abilityBounds", 157 WINDOW_MODE_KEY: "windowMode", 158 DISPLAY_ID_KEY: "displayId" 159} 160export const ErrorCode = { 161 NO_ERROR: 0, 162 INVALID_PARAMETER: -1, 163 ABILITY_NOT_FOUND: -2, 164 PERMISSION_DENY: -3 165} 166export const DataAbilityOperationType = { 167 TYPE_INSERT: 1, 168 TYPE_UPDATE: 2, 169 TYPE_DELETE: 3, 170 TYPE_ASSERT: 4, 171}