1/* 2 * Copyright (c) 2025 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 16/** 17 * @file 18 * @kit AbilityKit 19 */ 20 21import ExtensionContext from './ExtensionContext'; 22import { ConnectOptions } from '../ability/connectOptions'; 23import Want from '../@ohos.app.ability.Want'; 24import StartOptions from '../@ohos.app.ability.StartOptions'; 25 26/** 27 * The context of app service extension. It allows access to AppServiceExtension-specific resources. 28 * 29 * @extends ExtensionContext 30 * @syscap SystemCapability.Ability.AbilityRuntime.Core 31 * @stagemodelonly 32 * @since 20 33 */ 34export default class AppServiceExtensionContext extends ExtensionContext { 35 /** 36 * Connects the current ability to a service extension ability. 37 * If the target service extension ability is invisible, 38 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to connect target invisible service extension ability. 39 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 40 * 41 * @param { Want } want - The element name of the service ability 42 * @param { ConnectOptions } callback - The callback for obtaining the connection result 43 * @returns { number } Returns the number code of the ability connected 44 * @throws { BusinessError } 16000001 - The specified ability does not exist. 45 * @throws { BusinessError } 16000002 - Incorrect ability type. 46 * @throws { BusinessError } 16000004 - Cannot start an invisible component. 47 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 48 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 49 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 50 * @throws { BusinessError } 16000011 - The context does not exist. 51 * @throws { BusinessError } 16000050 - Internal error. 52 * @syscap SystemCapability.Ability.AbilityRuntime.Core 53 * @stagemodelonly 54 * @since 20 55 */ 56 connectServiceExtensionAbility(want: Want, callback: ConnectOptions): number; 57 58 /** 59 * Disconnect an ability from a service extension, in contrast to {@link connectServiceExtensionAbility}. 60 * 61 * @param { number } connection - The number code of the ability connected 62 * @returns { Promise<void> } The promise returned by the function. 63 * @throws { BusinessError } 16000011 - The context does not exist. 64 * @throws { BusinessError } 16000050 - Internal error. 65 * @syscap SystemCapability.Ability.AbilityRuntime.Core 66 * @stagemodelonly 67 * @since 20 68 */ 69 disconnectServiceExtensionAbility(connection: number): Promise<void>; 70 71 /** 72 * Start a UIAbility. 73 * If the target ability is visible, you can start the target ability: If the target ability is invisible, 74 * you need to apply for permission:ohos.pernission.START_INVISIBLE_ABILITY to start target invisible ability. 75 * If the target ability is in cross-device, you need to appply for permission:ohos.pernission.DISTRIBUTED_DATASYNC. 76 * 77 * @param { Want } want - Indicates the ability to start. 78 * @param { StartOptions } [options] - Indicates the start options. 79 * @returns { Promise<void> } The promise returned by the function. 80 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 81 * @throws { BusinessError } 16000001 - The specified ability does not exist. 82 * @throws { BusinessError } 16000002 - Incorrect ability type. 83 * @throws { BusinessError } 16000004 - Cannot start an invisible component. 84 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 85 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 86 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 87 * @throws { BusinessError } 16000010 - The call with the continuation and prepare continuation flag is forbidden. 88 * @throws { BusinessError } 16000011 - The context does not exist. 89 * @throws { BusinessError } 16000012 - The application is controlled. 90 * @throws { BusinessError } 16000013 - The application is controlled by EDM. 91 * @throws { BusinessError } 16000019 - No matching ability is found. 92 * @throws { BusinessError } 16000050 - Internal error. 93 * @throws { BusinessError } 16000055 - Installation-free timed out. 94 * @throws { BusinessError } 16000071 - App clone is not supported. 95 * @throws { BusinessError } 16000072 - App clone or multi-instance is not supported. 96 * @throws { BusinessError } 16000073 - The app clone index is invalid. 97 * @throws { BusinessError } 16000076 - The app instance key is invalid. 98 * @throws { BusinessError } 16000077 - The number of app instances reaches the limit. 99 * @throws { BusinessError } 16000078 - The multi-instance is not supported. 100 * @throws { BusinessError } 16000079 - The APP_INSTANCE_KEY cannot be specified. 101 * @throws { BusinessError } 16000080 - Creating a new instance is not supported. 102 * @syscap SystemCapability.Ability.AbilityRuntime.Core 103 * @stagemodelonly 104 * @since 20 105 */ 106 startAbility(want: Want, options?: StartOptions): Promise<void>; 107 108 /** 109 * Destroys this app service extension. 110 * 111 * @returns { Promise<void> } The promise returned by the function. 112 * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 113 * @throws { BusinessError } 16000011 - The context does not exist. 114 * @throws { BusinessError } 16000050 - Internal error. 115 * @syscap SystemCapability.Ability.AbilityRuntime.Core 116 * @stagemodelonly 117 * @since 20 118 */ 119 terminateSelf(): Promise<void>; 120} 121