161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"), 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file 1861847f8eSopenharmony_ci * @kit AbilityKit 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport ExtensionContext from './ExtensionContext'; 2261847f8eSopenharmony_ciimport type Want from '../@ohos.app.ability.Want'; 2361847f8eSopenharmony_ciimport type StartOptions from '../@ohos.app.ability.StartOptions'; 2461847f8eSopenharmony_ciimport type AbilityStartCallback from './AbilityStartCallback'; 2561847f8eSopenharmony_ciimport { ConnectOptions } from '../ability/connectOptions'; 2661847f8eSopenharmony_ci 2761847f8eSopenharmony_ci/** 2861847f8eSopenharmony_ci * The context of UI service extension. It allows access to UIServiceExtension-specific resources. 2961847f8eSopenharmony_ci * 3061847f8eSopenharmony_ci * @extends ExtensionContext 3161847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 3261847f8eSopenharmony_ci * @systemapi 3361847f8eSopenharmony_ci * @stagemodelonly 3461847f8eSopenharmony_ci * @since 14 3561847f8eSopenharmony_ci */ 3661847f8eSopenharmony_ciexport default class UIServiceExtensionContext extends ExtensionContext { 3761847f8eSopenharmony_ci /** 3861847f8eSopenharmony_ci * UI service extension uses this method to start a specific ability.If the caller application is in foreground, 3961847f8eSopenharmony_ci * you can use this method to start ability; If the caller application is in the background, 4061847f8eSopenharmony_ci * you need to apply for permission:ohos.permission.START_ABILITIES_FROM_BACKGROUND. 4161847f8eSopenharmony_ci * If the target ability is visible, you can start the target ability; If the target ability is invisible, 4261847f8eSopenharmony_ci * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 4361847f8eSopenharmony_ci * If the target ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 4461847f8eSopenharmony_ci * 4561847f8eSopenharmony_ci * @param { Want } want - Indicates the ability to start. 4661847f8eSopenharmony_ci * @param { StartOptions } [options] - Indicates the start options. 4761847f8eSopenharmony_ci * @returns { Promise<void> } The promise returned by the function. 4861847f8eSopenharmony_ci * @throws { BusinessError } 201 - The application does not have permission to call the interface. 4961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 5061847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 5161847f8eSopenharmony_ci * @throws { BusinessError } 16000001 - The specified ability does not exist. 5261847f8eSopenharmony_ci * @throws { BusinessError } 16000002 - Incorrect ability type. 5361847f8eSopenharmony_ci * @throws { BusinessError } 16000004 - Failed to start the invisible ability. 5461847f8eSopenharmony_ci * @throws { BusinessError } 16000005 - The specified process does not have the permission. 5561847f8eSopenharmony_ci * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 5661847f8eSopenharmony_ci * @throws { BusinessError } 16000008 - The crowdtesting application expires. 5761847f8eSopenharmony_ci * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. 5861847f8eSopenharmony_ci * @throws { BusinessError } 16000010 - The call with the continuation and prepare continuation flag is forbidden. 5961847f8eSopenharmony_ci * @throws { BusinessError } 16000011 - The context does not exist. 6061847f8eSopenharmony_ci * @throws { BusinessError } 16000012 - The application is controlled. 6161847f8eSopenharmony_ci * @throws { BusinessError } 16000013 - The EDM prohibits the application from launching. 6261847f8eSopenharmony_ci * @throws { BusinessError } 16000019 - Can not match any component. 6361847f8eSopenharmony_ci * @throws { BusinessError } 16000050 - Internal error. 6461847f8eSopenharmony_ci * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 6561847f8eSopenharmony_ci * @throws { BusinessError } 16000055 - Installation-free timed out. 6661847f8eSopenharmony_ci * @throws { BusinessError } 16200001 - The caller has been released. 6761847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 6861847f8eSopenharmony_ci * @systemapi 6961847f8eSopenharmony_ci * @stagemodelonly 7061847f8eSopenharmony_ci * @since 14 7161847f8eSopenharmony_ci */ 7261847f8eSopenharmony_ci startAbility(want: Want, options?: StartOptions): Promise<void>; 7361847f8eSopenharmony_ci 7461847f8eSopenharmony_ci /** 7561847f8eSopenharmony_ci * Destroys the UI service extension. 7661847f8eSopenharmony_ci * 7761847f8eSopenharmony_ci * @returns { Promise<void> } The promise returned by the function. 7861847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 7961847f8eSopenharmony_ci * @systemapi 8061847f8eSopenharmony_ci * @stagemodelonly 8161847f8eSopenharmony_ci * @since 14 8261847f8eSopenharmony_ci */ 8361847f8eSopenharmony_ci terminateSelf(): Promise<void>; 8461847f8eSopenharmony_ci 8561847f8eSopenharmony_ci /** 8661847f8eSopenharmony_ci * Starts the UIAbility or UIExtensionAbility by type. 8761847f8eSopenharmony_ci * If the target ability is visible, you can start the target ability; If the target ability is invisible, 8861847f8eSopenharmony_ci * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. 8961847f8eSopenharmony_ci * If the caller application is in the background, it is not allowed to call this interface. 9061847f8eSopenharmony_ci * 9161847f8eSopenharmony_ci * @param { string } type - The type of target ability. 9261847f8eSopenharmony_ci * @param { Record<string, Object> } wantParam - Indicates the want parameter. 9361847f8eSopenharmony_ci * @param { AbilityStartCallback } abilityStartCallback - Indicates the abilityStartCallback. 9461847f8eSopenharmony_ci * @returns { Promise<void> } The promise returned by the function. 9561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 9661847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 9761847f8eSopenharmony_ci * @throws { BusinessError } 16000050 - Internal error. 9861847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 9961847f8eSopenharmony_ci * @systemapi 10061847f8eSopenharmony_ci * @stagemodelonly 10161847f8eSopenharmony_ci * @since 14 10261847f8eSopenharmony_ci */ 10361847f8eSopenharmony_ci startAbilityByType(type: string, wantParam: Record<string, Object>, 10461847f8eSopenharmony_ci abilityStartCallback: AbilityStartCallback): Promise<void>; 10561847f8eSopenharmony_ci 10661847f8eSopenharmony_ci /** 10761847f8eSopenharmony_ci * Connects to a service extension ability. 10861847f8eSopenharmony_ci * If the target service extension ability is visible, you can connect the target service extension ability; 10961847f8eSopenharmony_ci * If the target service extension ability is invisible, 11061847f8eSopenharmony_ci * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to connect target invisible service extension ability. 11161847f8eSopenharmony_ci * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 11261847f8eSopenharmony_ci * <p>This method can be called by an ability or service extension, but the destination of the connection must be a 11361847f8eSopenharmony_ci * service extension. You must implement the {@link ConnectOptions} interface to obtain the proxy of the target 11461847f8eSopenharmony_ci * service extension when the Service extension is connected.</p> 11561847f8eSopenharmony_ci * 11661847f8eSopenharmony_ci * @param { Want } want - Indicates the service extension to connect. 11761847f8eSopenharmony_ci * @param { ConnectOptions } options - Indicates the callback of connection. 11861847f8eSopenharmony_ci * @returns { number } Returns the connection id. 11961847f8eSopenharmony_ci * @throws { BusinessError } 201 - The application does not have permission to call the interface. 12061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 12161847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 12261847f8eSopenharmony_ci * @throws { BusinessError } 16000001 - The specified ability does not exist. 12361847f8eSopenharmony_ci * @throws { BusinessError } 16000002 - Incorrect ability type. 12461847f8eSopenharmony_ci * @throws { BusinessError } 16000004 - Failed to start the invisible ability. 12561847f8eSopenharmony_ci * @throws { BusinessError } 16000005 - The specified process does not have the permission. 12661847f8eSopenharmony_ci * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 12761847f8eSopenharmony_ci * @throws { BusinessError } 16000008 - The crowdtesting application expires. 12861847f8eSopenharmony_ci * @throws { BusinessError } 16000011 - The context does not exist. 12961847f8eSopenharmony_ci * @throws { BusinessError } 16000013 - The EDM prohibits the application from launching. 13061847f8eSopenharmony_ci * @throws { BusinessError } 16000050 - Internal error. 13161847f8eSopenharmony_ci * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 13261847f8eSopenharmony_ci * @throws { BusinessError } 16000055 - Installation-free timed out. 13361847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 13461847f8eSopenharmony_ci * @systemapi 13561847f8eSopenharmony_ci * @stagemodelonly 13661847f8eSopenharmony_ci * @since 14 13761847f8eSopenharmony_ci */ 13861847f8eSopenharmony_ci connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; 13961847f8eSopenharmony_ci 14061847f8eSopenharmony_ci /** 14161847f8eSopenharmony_ci * Disconnect an ability from a service extension, in contrast to {@link connectServiceExtensionAbility}. 14261847f8eSopenharmony_ci * 14361847f8eSopenharmony_ci * @param { number } connectionId - the connection id returned from connectServiceExtensionAbility api. 14461847f8eSopenharmony_ci * @returns { Promise<void> } The promise returned by the function. 14561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 14661847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 14761847f8eSopenharmony_ci * @throws { BusinessError } 16000011 - The context does not exist. 14861847f8eSopenharmony_ci * @throws { BusinessError } 16000050 - Internal error. 14961847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 15061847f8eSopenharmony_ci * @systemapi 15161847f8eSopenharmony_ci * @stagemodelonly 15261847f8eSopenharmony_ci * @since 14 15361847f8eSopenharmony_ci */ 15461847f8eSopenharmony_ci disconnectServiceExtensionAbility(connectionId: number): Promise<void>; 15561847f8eSopenharmony_ci} 156