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 { AsyncCallback } from "../basic"; 17import { ConnectOptions } from "../ability/connectOptions"; 18import { Caller } from '../@ohos.app.ability.UIAbility'; 19import ExtensionContext from "./ExtensionContext"; 20import Want from "../@ohos.app.ability.Want"; 21import StartOptions from "../@ohos.app.ability.StartOptions"; 22 23/** 24 * The context of service extension. It allows access to 25 * serviceExtension-specific resources. 26 * @syscap SystemCapability.Ability.AbilityRuntime.Core 27 * @systemapi 28 * @StageModelOnly 29 * @since 9 30 */ 31export default class ServiceExtensionContext extends ExtensionContext { 32 /** 33 * Service extension uses this method to start a specific ability. 34 * @param { Want } want - Indicates the ability to start. 35 * @param { AsyncCallback<void> } callback - The callback of startAbility. 36 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 37 * @syscap SystemCapability.Ability.AbilityRuntime.Core 38 * @StageModelOnly 39 * @since 9 40 */ 41 startAbility(want: Want, callback: AsyncCallback<void>): void; 42 43 /** 44 * Service extension uses this method to start a specific ability. 45 * @param { Want } want - Indicates the ability to start. 46 * @param { StartOptions } options - Indicates the start options. 47 * @param { AsyncCallback<void> } callback - The callback of startAbility. 48 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 49 * @syscap SystemCapability.Ability.AbilityRuntime.Core 50 * @StageModelOnly 51 * @since 9 52 */ 53 startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void; 54 55 /** 56 * Service extension uses this method to start a specific ability. 57 * @param { Want } want - Indicates the ability to start. 58 * @param { StartOptions } options - Indicates the start options. 59 * @returns { Promise<void> } The promise returned by the function. 60 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 61 * @syscap SystemCapability.Ability.AbilityRuntime.Core 62 * @StageModelOnly 63 * @since 9 64 */ 65 startAbility(want: Want, options?: StartOptions): Promise<void>; 66 67 /** 68 * Service extension uses this method to start a specific ability with account. 69 * @param { Want } want - Indicates the ability to start. 70 * @param { number } accountId - Indicates the accountId to start. 71 * @param { AsyncCallback<void> } callback - The callback of startAbilityWithAccount. 72 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 73 * @syscap SystemCapability.Ability.AbilityRuntime.Core 74 * @systemapi 75 * @StageModelOnly 76 * @since 9 77 */ 78 startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback<void>): void; 79 80 /** 81 * Service extension uses this method to start a specific ability with account. 82 * @param { Want } want - Indicates the ability to start. 83 * @param { number } accountId - Indicates the accountId to start. 84 * @param { StartOptions } options - Indicates the start options. 85 * @param { AsyncCallback<void> } callback - The callback of startAbilityWithAccount. 86 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 87 * @syscap SystemCapability.Ability.AbilityRuntime.Core 88 * @systemapi 89 * @StageModelOnly 90 * @since 9 91 */ 92 startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback<void>): void; 93 94 /** 95 * Service extension uses this method to start a specific ability with account. 96 * @param { Want } want - Indicates the ability to start. 97 * @param { number } accountId - Indicates the accountId to start. 98 * @param { StartOptions } options - Indicates the start options. 99 * @returns { Promise<void> } The promise returned by the function. 100 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 101 * @syscap SystemCapability.Ability.AbilityRuntime.Core 102 * @systemapi 103 * @StageModelOnly 104 * @since 9 105 */ 106 startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise<void>; 107 108 /** 109 * Starts a new service extension ability. 110 * @param { Want } want - Indicates the want info to start. 111 * @param { AsyncCallback<void> } callback - The callback of startServiceExtensionAbility. 112 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 113 * @syscap SystemCapability.Ability.AbilityRuntime.Core 114 * @systemapi 115 * @StageModelOnly 116 * @since 9 117 */ 118 startServiceExtensionAbility(want: Want, callback: AsyncCallback<void>): void; 119 120 /** 121 * Starts a new service extension ability. 122 * @param { Want } want - Indicates the want info to start. 123 * @returns { Promise<void> } The promise returned by the function. 124 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 125 * @syscap SystemCapability.Ability.AbilityRuntime.Core 126 * @systemapi 127 * @StageModelOnly 128 * @since 9 129 */ 130 startServiceExtensionAbility(want: Want): Promise<void>; 131 132 /** 133 * Starts a new service extension ability with account. 134 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 135 * @param { Want } want - Indicates the want info to start. 136 * @param { number } accountId - Indicates the account to start. 137 * @param { AsyncCallback<void> } callback - The callback of startServiceExtensionAbilityWithAccount. 138 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 139 * @syscap SystemCapability.Ability.AbilityRuntime.Core 140 * @systemapi 141 * @StageModelOnly 142 * @since 9 143 */ 144 startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback<void>): void; 145 146 /** 147 * Starts a new service extension ability with account. 148 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 149 * @param { Want } want - Indicates the want info to start. 150 * @param { number } accountId - Indicates the account to start. 151 * @returns { Promise<void> } The promise returned by the function. 152 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 153 * @syscap SystemCapability.Ability.AbilityRuntime.Core 154 * @systemapi 155 * @StageModelOnly 156 * @since 9 157 */ 158 startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise<void>; 159 160 /** 161 * Stops a service within the same application. 162 * @param { Want } want - Indicates the want info to start. 163 * @param { AsyncCallback<void> } callback - The callback of stopServiceExtensionAbility. 164 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 165 * @syscap SystemCapability.Ability.AbilityRuntime.Core 166 * @systemapi 167 * @StageModelOnly 168 * @since 9 169 */ 170 stopServiceExtensionAbility(want: Want, callback: AsyncCallback<void>): void; 171 172 /** 173 * Stops a service within the same application. 174 * @param { Want } want - Indicates the want info to start. 175 * @returns { Promise<void> } The promise returned by the function. 176 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 177 * @syscap SystemCapability.Ability.AbilityRuntime.Core 178 * @systemapi 179 * @StageModelOnly 180 * @since 9 181 */ 182 stopServiceExtensionAbility(want: Want): Promise<void>; 183 184 /** 185 * Stops a service within the same application with account. 186 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 187 * @param { Want } want - Indicates the want info to start. 188 * @param { number } accountId - Indicates the accountId to start. 189 * @param { AsyncCallback<void> } callback - The callback of stopServiceExtensionAbilityWithAccount. 190 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 191 * @syscap SystemCapability.Ability.AbilityRuntime.Core 192 * @systemapi 193 * @StageModelOnly 194 * @since 9 195 */ 196 stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback<void>): void; 197 198 /** 199 * Stops a service within the same application with account. 200 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 201 * @param { Want } want - Indicates the want info to start. 202 * @param { number } accountId - Indicates the accountId to start. 203 * @returns { Promise<void> } The promise returned by the function. 204 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 205 * @syscap SystemCapability.Ability.AbilityRuntime.Core 206 * @systemapi 207 * @StageModelOnly 208 * @since 9 209 */ 210 stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise<void>; 211 212 /** 213 * Destroys this service extension. 214 * @param { AsyncCallback<void> } callback - The callback of terminateSelf. 215 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 216 * @syscap SystemCapability.Ability.AbilityRuntime.Core 217 * @StageModelOnly 218 * @since 9 219 */ 220 terminateSelf(callback: AsyncCallback<void>): void; 221 222 /** 223 * Destroys this service extension. 224 * @returns { Promise<void> } The promise returned by the function. 225 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 226 * @syscap SystemCapability.Ability.AbilityRuntime.Core 227 * @StageModelOnly 228 * @since 9 229 */ 230 terminateSelf(): Promise<void>; 231 232 /** 233 * Connects an ability to a Service extension. 234 * <p>This method can be called by an ability or service extension, but the destination of the connection must be a 235 * service extension. You must implement the {@link ConnectOptions} interface to obtain the proxy of the target 236 * service extension when the Service extension is connected.</p> 237 * @param { Want } want - Indicates the service extension to connect. 238 * @param { ConnectOptions } options - Indicates the callback of connection. 239 * @returns { number } Returns the connection id. 240 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 241 * @syscap SystemCapability.Ability.AbilityRuntime.Core 242 * @StageModelOnly 243 * @since 9 244 */ 245 connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; 246 247 /** 248 * Connects an ability to a Service extension with account. 249 * <p>This method can be called by an ability or service extension, but the destination of the connection must be a 250 * service extension. You must implement the {@link ConnectOptions} interface to obtain the proxy of the target 251 * service extension when the Service extension is connected.</p> 252 * @param { Want } want - Indicates the service extension to connect. 253 * @param { number } accountId - Indicates the account to connect. 254 * @param { ConnectOptions } options - Indicates the callback of connection. 255 * @returns { number } Returns the connection id. 256 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 257 * @syscap SystemCapability.Ability.AbilityRuntime.Core 258 * @systemapi 259 * @StageModelOnly 260 * @since 9 261 */ 262 connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number; 263 264 /** 265 * Disconnect an ability to a service extension, in contrast to {@link connectAbility}. 266 * @param { number } connection - the connection id returned from connectAbility api. 267 * @param { AsyncCallback<void> } callback - The callback of disconnectAbility. 268 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 269 * @syscap SystemCapability.Ability.AbilityRuntime.Core 270 * @StageModelOnly 271 * @since 9 272 */ 273 disconnectServiceExtensionAbility(connection: number, callback: AsyncCallback<void>): void; 274 275 /** 276 * Disconnect an ability to a service extension, in contrast to {@link connectAbility}. 277 * @param { number } connection - the connection id returned from connectAbility api. 278 * @returns { Promise<void> } The promise returned by the function. 279 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 280 * @syscap SystemCapability.Ability.AbilityRuntime.Core 281 * @StageModelOnly 282 * @since 9 283 */ 284 disconnectServiceExtensionAbility(connection: number): Promise<void>; 285 286 /** 287 * Get the caller object of the startup capability 288 * @permission ohos.permission.ABILITY_BACKGROUND_COMMUNICATION 289 * @param { Want } want - Indicates the ability to start. 290 * @returns { Promise<Caller> } Returns the Caller interface. 291 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 292 * @syscap SystemCapability.Ability.AbilityRuntime.Core 293 * @systemapi 294 * @StageModelOnly 295 * @since 9 296 */ 297 startAbilityByCall(want: Want): Promise<Caller>; 298 299 /** 300 * Service extension uses this method to start a specific ability, 301 * if ability is multi instance, will start a recent instance. 302 * @param { Want } want - Indicates the ability to start. 303 * @param { AsyncCallback<void> } callback - The callback of startAbility. 304 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 305 * @syscap SystemCapability.Ability.AbilityRuntime.Core 306 * @systemapi 307 * @StageModelOnly 308 * @since 9 309 */ 310 startRecentAbility(want: Want, callback: AsyncCallback<void>): void; 311 312 /** 313 * Service extension uses this method to start a specific ability, 314 * if ability is multi instance, will start a recent instance. 315 * @param { Want } want - Indicates the ability to start. 316 * @param { StartOptions } options - Indicates the start options. 317 * @param { AsyncCallback<void> } callback - The callback of startAbility. 318 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 319 * @syscap SystemCapability.Ability.AbilityRuntime.Core 320 * @systemapi 321 * @StageModelOnly 322 * @since 9 323 */ 324 startRecentAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void; 325 326 /** 327 * Service extension uses this method to start a specific ability, 328 * if ability is multi instance, will start a recent instance. 329 * @param { Want } want - Indicates the ability to start. 330 * @param { StartOptions } options - Indicates the start options. 331 * @returns { Promise<void> } The promise returned by the function. 332 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 333 * @syscap SystemCapability.Ability.AbilityRuntime.Core 334 * @systemapi 335 * @StageModelOnly 336 * @since 9 337 */ 338 startRecentAbility(want: Want, options?: StartOptions): Promise<void>; 339}