/* * Copyright (c) 2024 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 type Want from '../@ohos.app.ability.Want'; import type StartOptions from '../@ohos.app.ability.StartOptions'; import type AbilityStartCallback from './AbilityStartCallback'; import { ConnectOptions } from '../ability/connectOptions'; /** * The context of UI service extension. It allows access to UIServiceExtension-specific resources. * * @extends ExtensionContext * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 14 */ export default class UIServiceExtensionContext extends ExtensionContext { /** * UI service extension uses this method to start a specific ability.If the caller application is in foreground, * you can use this method to start ability; If the caller application is in the background, * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. * 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.permission.START_INVISIBLE_ABILITY to start target invisible ability. * If the target ability is in cross-device, you need to apply for permission:ohos.permission.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 } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. * @throws { BusinessError } 16000001 - The specified ability does not exist. * @throws { BusinessError } 16000002 - Incorrect ability type. * @throws { BusinessError } 16000004 - Failed to start the invisible ability. * @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 } 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 EDM prohibits the application from launching. * @throws { BusinessError } 16000019 - Can not match any component. * @throws { BusinessError } 16000050 - Internal error. * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. * @throws { BusinessError } 16000055 - Installation-free timed out. * @throws { BusinessError } 16200001 - The caller has been released. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 14 */ startAbility(want: Want, options?: StartOptions): Promise; /** * Destroys the UI service extension. * * @returns { Promise } The promise returned by the function. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 14 */ terminateSelf(): Promise; /** * Starts the UIAbility or UIExtensionAbility by type. * 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.permission.START_INVISIBLE_ABILITY to start target invisible ability. * If the caller application is in the background, it is not allowed to call this interface. * * @param { string } type - The type of target ability. * @param { Record } wantParam - Indicates the want parameter. * @param { AbilityStartCallback } abilityStartCallback - Indicates the abilityStartCallback. * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. * @throws { BusinessError } 16000050 - Internal error. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 14 */ startAbilityByType(type: string, wantParam: Record, abilityStartCallback: AbilityStartCallback): Promise; /** * Connects to a service extension ability. * If the target service extension ability is visible, you can connect the target 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. *

This method can be called by an ability or service extension, but the destination of the connection must be a * service extension. You must implement the {@link ConnectOptions} interface to obtain the proxy of the target * service extension when the Service extension is connected.

* * @param { Want } want - Indicates the service extension to connect. * @param { ConnectOptions } options - Indicates the callback of connection. * @returns { number } Returns the connection id. * @throws { BusinessError } 201 - The application does not have permission to call the interface. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. * @throws { BusinessError } 16000001 - The specified ability does not exist. * @throws { BusinessError } 16000002 - Incorrect ability type. * @throws { BusinessError } 16000004 - Failed to start the invisible ability. * @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 } 16000013 - The EDM prohibits the application from launching. * @throws { BusinessError } 16000050 - Internal error. * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. * @throws { BusinessError } 16000055 - Installation-free timed out. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 14 */ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; /** * Disconnect an ability from a service extension, in contrast to {@link connectServiceExtensionAbility}. * * @param { number } connectionId - the connection id returned from connectServiceExtensionAbility api. * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. * @throws { BusinessError } 16000011 - The context does not exist. * @throws { BusinessError } 16000050 - Internal error. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 14 */ disconnectServiceExtensionAbility(connectionId: number): Promise; }