1/* 2 * Copyright (c) 2021-2023 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 '../@ohos.base'; 17import type { ConnectOptions } from '../ability/connectOptions'; 18import ExtensionContext from './ExtensionContext'; 19import Want from '../@ohos.app.ability.Want'; 20 21/** 22 * The context of form extension. It allows access to 23 * formExtension-specific resources. 24 * 25 * @extends ExtensionContext 26 * @syscap SystemCapability.Ability.Form 27 * @StageModelOnly 28 * @since 9 29 */ 30export default class FormExtensionContext extends ExtensionContext { 31 /** 32 * Start an ability within the same bundle. 33 * 34 * @param { Want } want - includes ability name, parameters and relative info sending to an ability. 35 * @param { AsyncCallback<void> } callback - The callback of startAbility. 36 * @throws { BusinessError } 202 - The application is not a system application. 37 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 38 * @throws { BusinessError } 16500050 - An IPC connection error happened. 39 * @throws { BusinessError } 16500100 - Failed to obtain the configuration information. 40 * @throws { BusinessError } 16500101 - The application is not a system application. 41 * @throws { BusinessError } 16501000 - An internal functional error occurred. 42 * @syscap SystemCapability.Ability.Form 43 * @systemapi 44 * @StageModelOnly 45 * @since 9 46 */ 47 startAbility(want: Want, callback: AsyncCallback<void>): void; 48 49 /** 50 * Start an ability within the same bundle. 51 * 52 * @param { Want } want - includes ability name, parameters and relative info sending to an ability. 53 * @returns { Promise<void> } The promise returned by the function. 54 * @throws { BusinessError } 202 - The application is not a system application. 55 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 56 * @throws { BusinessError } 16500050 - An IPC connection error happened. 57 * @throws { BusinessError } 16500100 - Failed to obtain the configuration information. 58 * @throws { BusinessError } 16500101 - The application is not a system application. 59 * @throws { BusinessError } 16501000 - An internal functional error occurred. 60 * @syscap SystemCapability.Ability.Form 61 * @systemapi 62 * @StageModelOnly 63 * @since 9 64 */ 65 startAbility(want: Want): Promise<void>; 66 67 /** 68 * Connect a service extension ability. 69 * If the target service extension ability is visible, you can connect the target service extension ability; 70 * If the target service extension ability is invisible, 71 * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to connect target invisible service extension ability. 72 * If the target service extension ability is in cross-device, you need to apply for permission:ohos.permission.DISTRIBUTED_DATASYNC. 73 * <p>This method can be called by an ability or service extension, but the destination of the connection must be a 74 * service extension. You must implement the {@link ConnectOptions} interface to obtain the proxy of the target 75 * service extension when the Service extension is connected.</p> 76 * 77 * @param { Want } want - Indicates the service extension to connect. 78 * @param { ConnectOptions } options - Indicates the callback of connection. 79 * @returns { number } Returns the connection id. 80 * @throws { BusinessError } 201 - The application does not have permission to call the interface. 81 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 82 * @throws { BusinessError } 16000001 - The specified ability does not exist. 83 * @throws { BusinessError } 16000002 - Incorrect ability type. 84 * @throws { BusinessError } 16000004 - Can not start invisible component. 85 * @throws { BusinessError } 16000005 - The specified process does not have the permission. 86 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 87 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 88 * @throws { BusinessError } 16000011 - The context does not exist. 89 * @throws { BusinessError } 16000050 - Internal error. 90 * @throws { BusinessError } 16000053 - The ability is not on the top of the UI. 91 * @throws { BusinessError } 16000055 - Installation-free timed out. 92 * @syscap SystemCapability.Ability.Form 93 * @systemapi 94 * @StageModelOnly 95 * @since 10 96 */ 97 connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; 98 99 /** 100 * Disconnect an ability to a service extension, in contrast to {@link connectServiceExtensionAbility}. 101 * 102 * @param { number } connection - the connection id returned from connectServiceExtensionAbility api. 103 * @param { AsyncCallback<void> } callback - The callback of disconnectServiceExtensionAbility. 104 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 105 * @throws { BusinessError } 16000011 - The context does not exist. 106 * @throws { BusinessError } 16000050 - Internal error. 107 * @syscap SystemCapability.Ability.Form 108 * @systemapi 109 * @StageModelOnly 110 * @since 10 111 */ 112 disconnectServiceExtensionAbility(connection: number, callback: AsyncCallback<void>): void; 113 114 /** 115 * Disconnect an ability to a service extension, in contrast to {@link connectServiceExtensionAbility}. 116 * 117 * @param { number } connection - the connection id returned from connectServiceExtensionAbility api. 118 * @returns { Promise<void> } The promise returned by the function. 119 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 120 * @throws { BusinessError } 16000011 - The context does not exist. 121 * @throws { BusinessError } 16000050 - Internal error. 122 * @syscap SystemCapability.Ability.Form 123 * @systemapi 124 * @StageModelOnly 125 * @since 10 126 */ 127 disconnectServiceExtensionAbility(connection: number): Promise<void>; 128} 129