1/* 2 * Copyright (c) 2021-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 16var Context = requireNapi("application.Context") 17var Caller = requireNapi("application.Caller") 18 19const ERROR_CODE_INVALID_PARAM = 401; 20const ERROR_MSG_INVALID_PARAM = "Invalid input parameter."; 21class ParamError extends Error { 22 constructor() { 23 super(ERROR_MSG_INVALID_PARAM); 24 this.code = ERROR_CODE_INVALID_PARAM; 25 } 26} 27 28class AbilityContext extends Context { 29 constructor(obj) { 30 super(obj) 31 this.abilityInfo = obj.abilityInfo 32 this.currentHapModuleInfo = obj.currentHapModuleInfo 33 this.config = obj.config 34 } 35 36 onUpdateConfiguration(config) { 37 this.config = config 38 } 39 40 startAbility(want, options, callback) { 41 return this.__context_impl__.startAbility(want, options, callback) 42 } 43 44 startRecentAbility(want, options, callback) { 45 return this.__context_impl__.startRecentAbility(want, options, callback) 46 } 47 48 startAbilityWithAccount(want, accountId, options, callback) { 49 return this.__context_impl__.startAbilityWithAccount(want, accountId, options, callback) 50 } 51 52 startAbilityByCall(want) { 53 return new Promise(async (resolve, reject) => { 54 if (typeof want !== 'object' || want == null) { 55 console.log("AbilityContext::startAbilityByCall input param error"); 56 reject(new ParamError()); 57 return; 58 } 59 60 try{ 61 var callee = await this.__context_impl__.startAbilityByCall(want); 62 } catch(error) { 63 console.log("AbilityContext::startAbilityByCall Obtain remoteObject failed"); 64 reject(error); 65 return; 66 } 67 68 resolve(new Caller(callee)); 69 console.log("AbilityContext::startAbilityByCall success"); 70 return; 71 }); 72 } 73 74 startAbilityForResult(want, options, callback) { 75 return this.__context_impl__.startAbilityForResult(want, options, callback) 76 } 77 78 startAbilityForResultWithAccount(want, accountId, options, callback) { 79 return this.__context_impl__.startAbilityForResultWithAccount(want, accountId, options, callback) 80 } 81 82 startServiceExtensionAbility(want, callback) { 83 return this.__context_impl__.startServiceExtensionAbility(want, callback) 84 } 85 86 startServiceExtensionAbilityWithAccount(want, accountId, callback) { 87 return this.__context_impl__.startServiceExtensionAbilityWithAccount(want, accountId, callback) 88 } 89 90 stopServiceExtensionAbility(want, callback) { 91 return this.__context_impl__.stopServiceExtensionAbility(want, callback) 92 } 93 94 stopServiceExtensionAbilityWithAccount(want, accountId, callback) { 95 return this.__context_impl__.stopServiceExtensionAbilityWithAccount(want, accountId, callback) 96 } 97 98 connectAbility(want, options) { 99 return this.__context_impl__.connectAbility(want, options); 100 } 101 102 connectServiceExtensionAbility(want, options) { 103 return this.__context_impl__.connectServiceExtensionAbility(want, options); 104 } 105 106 connectAbilityWithAccount(want, accountId, options) { 107 return this.__context_impl__.connectAbilityWithAccount(want, accountId, options); 108 } 109 110 connectServiceExtensionAbilityWithAccount(want, accountId, options) { 111 return this.__context_impl__.connectServiceExtensionAbilityWithAccount(want, accountId, options); 112 } 113 114 disconnectAbility(connection, callback) { 115 return this.__context_impl__.disconnectAbility(connection, callback); 116 } 117 118 disconnectServiceExtensionAbility(connection, callback) { 119 return this.__context_impl__.disconnectServiceExtensionAbility(connection, callback); 120 } 121 122 terminateSelf(callback) { 123 return this.__context_impl__.terminateSelf(callback) 124 } 125 126 isTerminating() { 127 return this.__context_impl__.isTerminating() 128 } 129 130 terminateSelfWithResult(abilityResult, callback) { 131 return this.__context_impl__.terminateSelfWithResult(abilityResult, callback) 132 } 133 134 requestPermissionsFromUser(permissions, resultCallback) { 135 return this.__context_impl__.requestPermissionsFromUser(permissions, resultCallback) 136 } 137 138 restoreWindowStage(contentStorage) { 139 return this.__context_impl__.restoreWindowStage(contentStorage) 140 } 141 142 setMissionLabel(label, callback) { 143 return this.__context_impl__.setMissionLabel(label, callback) 144 } 145 146 setMissionIcon(icon, callback) { 147 return this.__context_impl__.setMissionIcon(icon, callback) 148 } 149 150 requestDialogService(want, resultCallback) { 151 return this.__context_impl__.requestDialogService(want, resultCallback) 152 } 153} 154 155export default AbilityContext 156