/* * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"), * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file * @kit AbilityKit */ import ExtensionContext from './ExtensionContext'; import { ConnectOptions } from '../ability/connectOptions'; import Want from '../@ohos.app.ability.Want'; import StartOptions from '../@ohos.app.ability.StartOptions'; /** * The context of app service extension. It allows access to AppServiceExtension-specific resources. * * @extends ExtensionContext * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 20 */ export default class AppServiceExtensionContext extends ExtensionContext { /** * Connects the current ability to a service extension ability. * If the target service extension ability is invisible, * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to connect target invisible service extension ability. * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. * * @param { Want } want - The element name of the service ability * @param { ConnectOptions } callback - The callback for obtaining the connection result * @returns { number } Returns the number code of the ability connected * @throws { BusinessError } 16000001 - The specified ability does not exist. * @throws { BusinessError } 16000002 - Incorrect ability type. * @throws { BusinessError } 16000004 - Cannot start an invisible component. * @throws { BusinessError } 16000005 - The specified process does not have the permission. * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. * @throws { BusinessError } 16000008 - The crowdtesting application expires. * @throws { BusinessError } 16000011 - The context does not exist. * @throws { BusinessError } 16000050 - Internal error. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 20 */ connectServiceExtensionAbility(want: Want, callback: ConnectOptions): number; /** * Disconnect an ability from a service extension, in contrast to {@link connectServiceExtensionAbility}. * * @param { number } connection - The number code of the ability connected * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 16000011 - The context does not exist. * @throws { BusinessError } 16000050 - Internal error. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 20 */ disconnectServiceExtensionAbility(connection: number): Promise; /** * Start a UIAbility. * If the target ability is visible, you can start the target ability: If the target ability is invisible, * you need to apply for permission:ohos.pernission.START_INVISIBLE_ABILITY to start target invisible ability. * If the target ability is in cross-device, you need to appply for permission:ohos.pernission.DISTRIBUTED_DATASYNC. * * @param { Want } want - Indicates the ability to start. * @param { StartOptions } [options] - Indicates the start options. * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 201 - The application does not have permission to call the interface. * @throws { BusinessError } 16000001 - The specified ability does not exist. * @throws { BusinessError } 16000002 - Incorrect ability type. * @throws { BusinessError } 16000004 - Cannot start an invisible component. * @throws { BusinessError } 16000005 - The specified process does not have the permission. * @throws { BusinessError } 16000008 - The crowdtesting application expires. * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. * @throws { BusinessError } 16000010 - The call with the continuation and prepare continuation flag is forbidden. * @throws { BusinessError } 16000011 - The context does not exist. * @throws { BusinessError } 16000012 - The application is controlled. * @throws { BusinessError } 16000013 - The application is controlled by EDM. * @throws { BusinessError } 16000019 - No matching ability is found. * @throws { BusinessError } 16000050 - Internal error. * @throws { BusinessError } 16000055 - Installation-free timed out. * @throws { BusinessError } 16000071 - App clone is not supported. * @throws { BusinessError } 16000072 - App clone or multi-instance is not supported. * @throws { BusinessError } 16000073 - The app clone index is invalid. * @throws { BusinessError } 16000076 - The app instance key is invalid. * @throws { BusinessError } 16000077 - The number of app instances reaches the limit. * @throws { BusinessError } 16000078 - The multi-instance is not supported. * @throws { BusinessError } 16000079 - The APP_INSTANCE_KEY cannot be specified. * @throws { BusinessError } 16000080 - Creating a new instance is not supported. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 20 */ startAbility(want: Want, options?: StartOptions): Promise; /** * Destroys this app service extension. * * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. * @throws { BusinessError } 16000011 - The context does not exist. * @throws { BusinessError } 16000050 - Internal error. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 20 */ terminateSelf(): Promise; }