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