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. If the caller application is in foreground, 34 * you can use this method to start ability; If the caller application is in the background, 35 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 36 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 37 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 38 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 39 * @param { Want } want - Indicates the ability to start. 40 * @param { AsyncCallback<void> } callback - The callback of startAbility. 41 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 42 * @throws { BusinessError } 16000001 - The specified ability does not exist. 43 * @throws { BusinessError } 16000002 - Incorrect ability type. 44 * @throws { BusinessError } 16000004 - Can not start invisible component. 45 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 46 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 47 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 48 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 49 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 50 * @throws { BusinessError } 16000011 - The context does not exist. 51 * @throws { BusinessError } 16000050 - Internal error. 52 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 53 * @throws { BusinessError } 16000055 - Installation-free timed out. 54 * @throws { BusinessError } 16200001 - The caller has been released. 55 * @syscap SystemCapability.Ability.AbilityRuntime.Core 56 * @StageModelOnly 57 * @since 9 58 */ 59 startAbility(want: Want, callback: AsyncCallback<void>): void; 60 61 /** 62 * Service extension uses this method to start a specific ability. If the caller application is in foreground, 63 * you can use this method to start ability; If the caller application is in the background, 64 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 65 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 66 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 67 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 68 * @param { Want } want - Indicates the ability to start. 69 * @param { StartOptions } options - Indicates the start options. 70 * @param { AsyncCallback<void> } callback - The callback of startAbility. 71 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 72 * @throws { BusinessError } 16000001 - The specified ability does not exist. 73 * @throws { BusinessError } 16000002 - Incorrect ability type. 74 * @throws { BusinessError } 16000004 - Can not start invisible component. 75 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 76 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 77 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 78 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 79 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 80 * @throws { BusinessError } 16000011 - The context does not exist. 81 * @throws { BusinessError } 16000050 - Internal error. 82 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 83 * @throws { BusinessError } 16000055 - Installation-free timed out. 84 * @throws { BusinessError } 16200001 - The caller has been released. 85 * @syscap SystemCapability.Ability.AbilityRuntime.Core 86 * @StageModelOnly 87 * @since 9 88 */ 89 startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void; 90 91 /** 92 * Service extension uses this method to start a specific ability. If the caller application is in foreground, 93 * you can use this method to start ability; If the caller application is in the background, 94 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 95 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 96 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 97 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 98 * @param { Want } want - Indicates the ability to start. 99 * @param { StartOptions } options - Indicates the start options. 100 * @returns { Promise<void> } The promise returned by the function. 101 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 102 * @throws { BusinessError } 16000001 - The specified ability does not exist. 103 * @throws { BusinessError } 16000002 - Incorrect ability type. 104 * @throws { BusinessError } 16000004 - Can not start invisible component. 105 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 106 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 107 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 108 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 109 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 110 * @throws { BusinessError } 16000011 - The context does not exist. 111 * @throws { BusinessError } 16000050 - Internal error. 112 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 113 * @throws { BusinessError } 16000055 - Installation-free timed out. 114 * @throws { BusinessError } 16200001 - The caller has been released. 115 * @syscap SystemCapability.Ability.AbilityRuntime.Core 116 * @StageModelOnly 117 * @since 9 118 */ 119 startAbility(want: Want, options?: StartOptions): Promise<void>; 120 121 /** 122 * Service extension uses this method to start a specific ability with account. If the caller application is in foreground, 123 * you can use this method to start ability; If the caller application is in the background, 124 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 125 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 126 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 127 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 128 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 129 * @param { Want } want - Indicates the ability to start. 130 * @param { number } accountId - Indicates the accountId to start. 131 * @param { AsyncCallback<void> } callback - The callback of startAbilityWithAccount. 132 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 133 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 134 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 135 * @throws { BusinessError } 16000001 - The specified ability does not exist. 136 * @throws { BusinessError } 16000002 - Incorrect ability type. 137 * @throws { BusinessError } 16000004 - Can not start invisible component. 138 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 139 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 140 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 141 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 142 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 143 * @throws { BusinessError } 16000011 - The context does not exist. 144 * @throws { BusinessError } 16000050 - Internal error. 145 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 146 * @throws { BusinessError } 16000055 - Installation-free timed out. 147 * @throws { BusinessError } 16200001 - The caller has been released. 148 * @syscap SystemCapability.Ability.AbilityRuntime.Core 149 * @systemapi 150 * @StageModelOnly 151 * @since 9 152 */ 153 startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback<void>): void; 154 155 /** 156 * Service extension uses this method to start a specific ability with account. If the caller application is in foreground, 157 * you can use this method to start ability; If the caller application is in the background, 158 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 159 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 160 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 161 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 162 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 163 * @param { Want } want - Indicates the ability to start. 164 * @param { number } accountId - Indicates the accountId to start. 165 * @param { StartOptions } options - Indicates the start options. 166 * @param { AsyncCallback<void> } callback - The callback of startAbilityWithAccount. 167 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 168 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 169 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 170 * @throws { BusinessError } 16000001 - The specified ability does not exist. 171 * @throws { BusinessError } 16000002 - Incorrect ability type. 172 * @throws { BusinessError } 16000004 - Can not start invisible component. 173 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 174 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 175 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 176 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 177 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 178 * @throws { BusinessError } 16000011 - The context does not exist. 179 * @throws { BusinessError } 16000050 - Internal error. 180 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 181 * @throws { BusinessError } 16000055 - Installation-free timed out. 182 * @throws { BusinessError } 16200001 - The caller has been released. 183 * @syscap SystemCapability.Ability.AbilityRuntime.Core 184 * @systemapi 185 * @StageModelOnly 186 * @since 9 187 */ 188 startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback<void>): void; 189 190 /** 191 * Service extension uses this method to start a specific ability with account. If the caller application is in foreground, 192 * you can use this method to start ability; If the caller application is in the background, 193 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 194 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 195 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 196 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 197 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 198 * @param { Want } want - Indicates the ability to start. 199 * @param { number } accountId - Indicates the accountId to start. 200 * @param { StartOptions } options - Indicates the start options. 201 * @returns { Promise<void> } The promise returned by the function. 202 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 203 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 204 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 205 * @throws { BusinessError } 16000001 - The specified ability does not exist. 206 * @throws { BusinessError } 16000002 - Incorrect ability type. 207 * @throws { BusinessError } 16000004 - Can not start invisible component. 208 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 209 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 210 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 211 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 212 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 213 * @throws { BusinessError } 16000011 - The context does not exist. 214 * @throws { BusinessError } 16000050 - Internal error. 215 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 216 * @throws { BusinessError } 16000055 - Installation-free timed out. 217 * @throws { BusinessError } 16200001 - The caller has been released. 218 * @syscap SystemCapability.Ability.AbilityRuntime.Core 219 * @systemapi 220 * @StageModelOnly 221 * @since 9 222 */ 223 startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise<void>; 224 225 /** 226 * Starts a new service extension ability. If the caller application is in foreground, you can use this method to start service extension ability; 227 * If the caller application is in the background, you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 228 * If the target service extension ability is visible, you can start the target service extension ability; 229 * If the target service extension ability is invisible, 230 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible service extension ability. 231 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 232 * @param { Want } want - Indicates the want info to start. 233 * @param { AsyncCallback<void> } callback - The callback of startServiceExtensionAbility. 234 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 235 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 236 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 237 * @throws { BusinessError } 16000001 - The specified ability does not exist. 238 * @throws { BusinessError } 16000002 - Incorrect ability type. 239 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 240 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 241 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 242 * @throws { BusinessError } 16000011 - The context does not exist. 243 * @throws { BusinessError } 16000050 - Internal error. 244 * @throws { BusinessError } 16200001 - The caller has been released. 245 * @syscap SystemCapability.Ability.AbilityRuntime.Core 246 * @systemapi 247 * @StageModelOnly 248 * @since 9 249 */ 250 startServiceExtensionAbility(want: Want, callback: AsyncCallback<void>): void; 251 252 /** 253 * Starts a new service extension ability. If the caller application is in foreground, you can use this method to start service extension ability; 254 * If the caller application is in the background, you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 255 * If the target service extension ability is visible, you can start the target service extension ability; 256 * If the target service extension ability is invisible, 257 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible service extension ability. 258 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 259 * @param { Want } want - Indicates the want info to start. 260 * @returns { Promise<void> } The promise returned by the function. 261 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 262 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 263 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 264 * @throws { BusinessError } 16000001 - The specified ability does not exist. 265 * @throws { BusinessError } 16000002 - Incorrect ability type. 266 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 267 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 268 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 269 * @throws { BusinessError } 16000011 - The context does not exist. 270 * @throws { BusinessError } 16000050 - Internal error. 271 * @throws { BusinessError } 16200001 - The caller has been released. 272 * @syscap SystemCapability.Ability.AbilityRuntime.Core 273 * @systemapi 274 * @StageModelOnly 275 * @since 9 276 */ 277 startServiceExtensionAbility(want: Want): Promise<void>; 278 279 /** 280 * Starts a new service extension ability with account. If the caller application is in foreground, 281 * you can use this method to start service extension ability; If the caller application is in the background, 282 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 283 * If the target service extension ability is visible, you can start the target service extension ability; 284 * If the target service extension ability is invisible, 285 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible service extension ability. 286 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 287 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 288 * @param { Want } want - Indicates the want info to start. 289 * @param { number } accountId - Indicates the account to start. 290 * @param { AsyncCallback<void> } callback - The callback of startServiceExtensionAbilityWithAccount. 291 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 292 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 293 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 294 * @throws { BusinessError } 16000001 - The specified ability does not exist. 295 * @throws { BusinessError } 16000002 - Incorrect ability type. 296 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 297 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 298 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 299 * @throws { BusinessError } 16000011 - The context does not exist. 300 * @throws { BusinessError } 16000050 - Internal error. 301 * @throws { BusinessError } 16200001 - The caller has been released. 302 * @syscap SystemCapability.Ability.AbilityRuntime.Core 303 * @systemapi 304 * @StageModelOnly 305 * @since 9 306 */ 307 startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback<void>): void; 308 309 /** 310 * Starts a new service extension ability with account. If the caller application is in foreground, 311 * you can use this method to start service extension ability; If the caller application is in the background, 312 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 313 * If the target service extension ability is visible, you can start the target service extension ability; 314 * If the target service extension ability is invisible, 315 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible service extension ability. 316 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 317 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 318 * @param { Want } want - Indicates the want info to start. 319 * @param { number } accountId - Indicates the account to start. 320 * @returns { Promise<void> } The promise returned by the function. 321 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 322 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 323 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 324 * @throws { BusinessError } 16000001 - The specified ability does not exist. 325 * @throws { BusinessError } 16000002 - Incorrect ability type. 326 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 327 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 328 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 329 * @throws { BusinessError } 16000011 - The context does not exist. 330 * @throws { BusinessError } 16000050 - Internal error. 331 * @throws { BusinessError } 16200001 - The caller has been released. 332 * @syscap SystemCapability.Ability.AbilityRuntime.Core 333 * @systemapi 334 * @StageModelOnly 335 * @since 9 336 */ 337 startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise<void>; 338 339 /** 340 * Stops other service extension ability. If the caller application is in foreground, 341 * you can use this method to stop service extension ability; If the caller application is in the background, 342 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 343 * If the target service extension ability is visible, you can stop the target service extension ability; 344 * If the target service extension ability is invisible, 345 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to stop target invisible service extension ability. 346 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 347 * @param { Want } want - Indicates the want info to start. 348 * @param { AsyncCallback<void> } callback - The callback of stopServiceExtensionAbility. 349 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 350 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 351 * @throws { BusinessError } 16000001 - The specified ability does not exist. 352 * @throws { BusinessError } 16000002 - Incorrect ability type. 353 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 354 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 355 * @throws { BusinessError } 16000011 - The context does not exist. 356 * @throws { BusinessError } 16000050 - Internal error. 357 * @throws { BusinessError } 16200001 - The caller has been released. 358 * @syscap SystemCapability.Ability.AbilityRuntime.Core 359 * @systemapi 360 * @StageModelOnly 361 * @since 9 362 */ 363 stopServiceExtensionAbility(want: Want, callback: AsyncCallback<void>): void; 364 365 /** 366 * Stops other service extension ability. If the caller application is in foreground, 367 * you can use this method to stop service extension ability; If the caller application is in the background, 368 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 369 * If the target service extension ability is visible, you can stop the target service extension ability; 370 * If the target service extension ability is invisible, 371 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to stop target invisible service extension ability. 372 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 373 * @param { Want } want - Indicates the want info to start. 374 * @returns { Promise<void> } The promise returned by the function. 375 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 376 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 377 * @throws { BusinessError } 16000001 - The specified ability does not exist. 378 * @throws { BusinessError } 16000002 - Incorrect ability type. 379 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 380 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 381 * @throws { BusinessError } 16000011 - The context does not exist. 382 * @throws { BusinessError } 16000050 - Internal error. 383 * @throws { BusinessError } 16200001 - The caller has been released. 384 * @syscap SystemCapability.Ability.AbilityRuntime.Core 385 * @systemapi 386 * @StageModelOnly 387 * @since 9 388 */ 389 stopServiceExtensionAbility(want: Want): Promise<void>; 390 391 /** 392 * Stops other service extension ability with account. If the caller application is in foreground, 393 * you can use this method to stop service extension ability; If the caller application is in the background, 394 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 395 * If the target service extension ability is visible, you can stop the target service extension ability; 396 * If the target service extension ability is invisible, 397 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to stop target invisible service extension ability. 398 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 399 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 400 * @param { Want } want - Indicates the want info to start. 401 * @param { number } accountId - Indicates the accountId to start. 402 * @param { AsyncCallback<void> } callback - The callback of stopServiceExtensionAbilityWithAccount. 403 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 404 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 405 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 406 * @throws { BusinessError } 16000001 - The specified ability does not exist. 407 * @throws { BusinessError } 16000002 - Incorrect ability type. 408 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 409 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 410 * @throws { BusinessError } 16000011 - The context does not exist. 411 * @throws { BusinessError } 16000050 - Internal error. 412 * @throws { BusinessError } 16200001 - The caller has been released. 413 * @syscap SystemCapability.Ability.AbilityRuntime.Core 414 * @systemapi 415 * @StageModelOnly 416 * @since 9 417 */ 418 stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback<void>): void; 419 420 /** 421 * Stops other service extension ability with account. If the caller application is in foreground, 422 * you can use this method to stop service extension ability; If the caller application is in the background, 423 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 424 * If the target service extension ability is visible, you can stop the target service extension ability; 425 * If the target service extension ability is invisible, 426 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to stop target invisible service extension ability. 427 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 428 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 429 * @param { Want } want - Indicates the want info to start. 430 * @param { number } accountId - Indicates the accountId to start. 431 * @returns { Promise<void> } The promise returned by the function. 432 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 433 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 434 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 435 * @throws { BusinessError } 16000001 - The specified ability does not exist. 436 * @throws { BusinessError } 16000002 - Incorrect ability type. 437 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 438 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 439 * @throws { BusinessError } 16000011 - The context does not exist. 440 * @throws { BusinessError } 16000050 - Internal error. 441 * @throws { BusinessError } 16200001 - The caller has been released. 442 * @syscap SystemCapability.Ability.AbilityRuntime.Core 443 * @systemapi 444 * @StageModelOnly 445 * @since 9 446 */ 447 stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise<void>; 448 449 /** 450 * Destroys this service extension. 451 * @param { AsyncCallback<void> } callback - The callback of terminateSelf. 452 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 453 * @throws { BusinessError } 16000001 - The specified ability does not exist. 454 * @throws { BusinessError } 16000004 - Can not start invisible component. 455 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 456 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 457 * @throws { BusinessError } 16000011 - The context does not exist. 458 * @throws { BusinessError } 16000050 - Internal error. 459 * @syscap SystemCapability.Ability.AbilityRuntime.Core 460 * @StageModelOnly 461 * @since 9 462 */ 463 terminateSelf(callback: AsyncCallback<void>): void; 464 465 /** 466 * Destroys this service extension. 467 * @returns { Promise<void> } The promise returned by the function. 468 * @throws { BusinessError } 16000001 - The specified ability does not exist. 469 * @throws { BusinessError } 16000004 - Can not start invisible component. 470 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 471 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 472 * @throws { BusinessError } 16000011 - The context does not exist. 473 * @throws { BusinessError } 16000050 - Internal error. 474 * @syscap SystemCapability.Ability.AbilityRuntime.Core 475 * @StageModelOnly 476 * @since 9 477 */ 478 terminateSelf(): Promise<void>; 479 480 /** 481 * Connects an ability to a service extension ability. If the caller application is in foreground, 482 * you can use this method to connect service extension ability; If the caller application is in the background, 483 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 484 * If the target service extension ability is visible, you can connect the target service extension ability; 485 * If the target service extension ability is invisible, 486 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to connect target invisible service extension ability. 487 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 488 * <p>This method can be called by an ability or service extension, but the destination of the connection must be a 489 * service extension. You must implement the {@link ConnectOptions} interface to obtain the proxy of the target 490 * service extension when the Service extension is connected.</p> 491 * @param { Want } want - Indicates the service extension to connect. 492 * @param { ConnectOptions } options - Indicates the callback of connection. 493 * @returns { number } Returns the connection id. 494 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 495 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 496 * @throws { BusinessError } 16000001 - The specified ability does not exist. 497 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 498 * @throws { BusinessError } 16000011 - The context does not exist. 499 * @throws { BusinessError } 16000050 - Internal error. 500 * @syscap SystemCapability.Ability.AbilityRuntime.Core 501 * @StageModelOnly 502 * @since 9 503 */ 504 connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; 505 506 /** 507 * Connects an ability to a service extension ability with account. If the caller application is in foreground, 508 * you can use this method to connect service extension ability; If the caller application is in the background, 509 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 510 * If the target service extension ability is visible, you can connect the target service extension ability; 511 * If the target service extension ability is invisible, 512 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to connect target invisible service extension ability. 513 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 514 * <p>This method can be called by an ability or service extension, but the destination of the connection must be a 515 * service extension. You must implement the {@link ConnectOptions} interface to obtain the proxy of the target 516 * service extension when the Service extension is connected.</p> 517 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 518 * @param { Want } want - Indicates the service extension to connect. 519 * @param { number } accountId - Indicates the account to connect. 520 * @param { ConnectOptions } options - Indicates the callback of connection. 521 * @returns { number } Returns the connection id. 522 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 523 * @throws { BusinessError } 202 - The application is not system-app, can not use system-api. 524 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 525 * @throws { BusinessError } 16000001 - The specified ability does not exist. 526 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 527 * @throws { BusinessError } 16000011 - The context does not exist. 528 * @throws { BusinessError } 16000050 - Internal error. 529 * @syscap SystemCapability.Ability.AbilityRuntime.Core 530 * @systemapi 531 * @StageModelOnly 532 * @since 9 533 */ 534 connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number; 535 536 /** 537 * Disconnect an ability to a service extension, in contrast to {@link connectAbility}. 538 * @param { number } connection - the connection id returned from connectAbility api. 539 * @param { AsyncCallback<void> } callback - The callback of disconnectAbility. 540 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 541 * @throws { BusinessError } 16000011 - The context does not exist. 542 * @throws { BusinessError } 16000050 - Internal error. 543 * @syscap SystemCapability.Ability.AbilityRuntime.Core 544 * @StageModelOnly 545 * @since 9 546 */ 547 disconnectServiceExtensionAbility(connection: number, callback: AsyncCallback<void>): void; 548 549 /** 550 * Disconnect an ability to a service extension, in contrast to {@link connectAbility}. 551 * @param { number } connection - the connection id returned from connectAbility api. 552 * @returns { Promise<void> } The promise returned by the function. 553 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 554 * @throws { BusinessError } 16000011 - The context does not exist. 555 * @throws { BusinessError } 16000050 - Internal error. 556 * @syscap SystemCapability.Ability.AbilityRuntime.Core 557 * @StageModelOnly 558 * @since 9 559 */ 560 disconnectServiceExtensionAbility(connection: number): Promise<void>; 561 562 /** 563 * Get the caller object of the startup capability. 564 * If the local device starts a new ability, you need to apply for permission:ohos.permission.ABILITY_BACKGROUND_COMMUNICATION to use this method. 565 * If the caller application is in foreground, you can use this method to start ability; If the caller application is in the background, 566 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 567 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 568 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 569 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 570 * @permission ohos.permission.ABILITY_BACKGROUND_COMMUNICATION 571 * @param { Want } want - Indicates the ability to start. 572 * @returns { Promise<Caller> } Returns the Caller interface. 573 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 574 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 575 * @throws { BusinessError } 16000001 - The specified ability does not exist. 576 * @throws { BusinessError } 16000002 - Incorrect ability type. 577 * @throws { BusinessError } 16000004 - Can not start invisible component. 578 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 579 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 580 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 581 * @throws { BusinessError } 16000011 - The context does not exist. 582 * @throws { BusinessError } 16000050 - Internal error. 583 * @throws { BusinessError } 16200001 - The caller has been released. 584 * @syscap SystemCapability.Ability.AbilityRuntime.Core 585 * @systemapi 586 * @StageModelOnly 587 * @since 9 588 */ 589 startAbilityByCall(want: Want): Promise<Caller>; 590 591 /** 592 * Service extension uses this method to start a specific ability, if ability is multi instance, will start a recent instance. 593 * If the caller application is in foreground, you can use this method to start ability; If the caller application is in the background, 594 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 595 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 596 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 597 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 598 * @param { Want } want - Indicates the ability to start. 599 * @param { AsyncCallback<void> } callback - The callback of startAbility. 600 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 601 * @throws { BusinessError } 16000001 - The specified ability does not exist. 602 * @throws { BusinessError } 16000002 - Incorrect ability type. 603 * @throws { BusinessError } 16000004 - Can not start invisible component. 604 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 605 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 606 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 607 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 608 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 609 * @throws { BusinessError } 16000011 - The context does not exist. 610 * @throws { BusinessError } 16000050 - Internal error. 611 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 612 * @throws { BusinessError } 16000055 - Installation-free timed out. 613 * @throws { BusinessError } 16200001 - The caller has been released. 614 * @syscap SystemCapability.Ability.AbilityRuntime.Core 615 * @systemapi 616 * @StageModelOnly 617 * @since 9 618 */ 619 startRecentAbility(want: Want, callback: AsyncCallback<void>): void; 620 621 /** 622 * Service extension uses this method to start a specific ability, if ability is multi instance, will start a recent instance. 623 * If the caller application is in foreground, you can use this method to start ability; If the caller application is in the background, 624 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 625 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 626 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 627 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 628 * @param { Want } want - Indicates the ability to start. 629 * @param { StartOptions } options - Indicates the start options. 630 * @param { AsyncCallback<void> } callback - The callback of startAbility. 631 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 632 * @throws { BusinessError } 16000001 - The specified ability does not exist. 633 * @throws { BusinessError } 16000002 - Incorrect ability type. 634 * @throws { BusinessError } 16000004 - Can not start invisible component. 635 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 636 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 637 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 638 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 639 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 640 * @throws { BusinessError } 16000011 - The context does not exist. 641 * @throws { BusinessError } 16000050 - Internal error. 642 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 643 * @throws { BusinessError } 16000055 - Installation-free timed out. 644 * @throws { BusinessError } 16200001 - The caller has been released. 645 * @syscap SystemCapability.Ability.AbilityRuntime.Core 646 * @systemapi 647 * @StageModelOnly 648 * @since 9 649 */ 650 startRecentAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void; 651 652 /** 653 * Service extension uses this method to start a specific ability, if ability is multi instance, will start a recent instance. 654 * If the caller application is in foreground, you can use this method to start ability; If the caller application is in the background, 655 * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 656 * If the target ability is visible, you can start the target ability; If the target ability is invisible, 657 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 658 * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 659 * @param { Want } want - Indicates the ability to start. 660 * @param { StartOptions } options - Indicates the start options. 661 * @returns { Promise<void> } The promise returned by the function. 662 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 663 * @throws { BusinessError } 16000001 - The specified ability does not exist. 664 * @throws { BusinessError } 16000002 - Incorrect ability type. 665 * @throws { BusinessError } 16000004 - Can not start invisible component. 666 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 667 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 668 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 669 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 670 * @throws { BusinessError } 16000010 - The call with the continuation flag is forbidden. 671 * @throws { BusinessError } 16000011 - The context does not exist. 672 * @throws { BusinessError } 16000050 - Internal error. 673 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 674 * @throws { BusinessError } 16000055 - Installation-free timed out. 675 * @throws { BusinessError } 16200001 - The caller has been released. 676 * @syscap SystemCapability.Ability.AbilityRuntime.Core 677 * @systemapi 678 * @StageModelOnly 679 * @since 9 680 */ 681 startRecentAbility(want: Want, options?: StartOptions): Promise<void>; 682}