1/* 2 * Copyright (c) 2021 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 */ 15import { AsyncCallback } from './basic'; 16import { Callback } from './basic'; 17import { Want } from './ability/want'; 18import { StartAbilityParameter } from './ability/startAbilityParameter'; 19import { AbilityResult } from './ability/abilityResult'; 20import { Context } from './app/context'; 21import { DataAbilityHelper } from './ability/dataAbilityHelper'; 22import { ConnectOptions } from './ability/connectOptions'; 23import window from './@ohos.window'; 24 25/** 26 * A Feature Ability represents an ability with a UI and is designed to interact with users. 27 * @name featureAbility 28 * @since 6 29 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 30 * @permission N/A 31 * @FAModelOnly 32 */ 33declare namespace featureAbility { 34 /** 35 * Obtain the want sended from the source ability. 36 * 37 * @since 6 38 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 39 * @param parameter Indicates the ability to start. 40 * @return - 41 * @FAModelOnly 42 */ 43 function getWant(callback: AsyncCallback<Want>): void; 44 function getWant(): Promise<Want>; 45 46 /** 47 * Starts a new ability. 48 * 49 * @since 6 50 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 51 * @param parameter Indicates the ability to start. 52 * @return - 53 * @FAModelOnly 54 */ 55 function startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>): void; 56 function startAbility(parameter: StartAbilityParameter): Promise<number>; 57 58 /** 59 * Obtains the application context. 60 * 61 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 62 * @return Returns the application context. 63 * @since 6 64 * @FAModelOnly 65 */ 66 function getContext(): Context; 67 68 /** 69 * Starts an ability and returns the execution result when the ability is destroyed. 70 * 71 * @since 7 72 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 73 * @param parameter Indicates the ability to start. 74 * @return Returns the {@link AbilityResult}. 75 * @FAModelOnly 76 */ 77 function startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback<AbilityResult>): void; 78 function startAbilityForResult(parameter: StartAbilityParameter): Promise<AbilityResult>; 79 80 /** 81 * Sets the result code and data to be returned by this Page ability to the caller 82 * and destroys this Page ability. 83 * 84 * @since 7 85 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 86 * @param parameter Indicates the result to return. 87 * @return - 88 * @FAModelOnly 89 */ 90 function terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void; 91 function terminateSelfWithResult(parameter: AbilityResult): Promise<void>; 92 93 /** 94 * Destroys this Page ability. 95 * 96 * @since 7 97 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 98 * @return - 99 * @FAModelOnly 100 */ 101 function terminateSelf(callback: AsyncCallback<void>): void; 102 function terminateSelf(): Promise<void>; 103 104 /** 105 * Obtains the dataAbilityHelper. 106 * 107 * @since 7 108 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 109 * @param uri Indicates the path of the file to open. 110 * @return Returns the dataAbilityHelper. 111 * @FAModelOnly 112 */ 113 function acquireDataAbilityHelper(uri: string): DataAbilityHelper; 114 115 /** 116 * Checks whether the main window of this ability has window focus. 117 * 118 * @since 7 119 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 120 * @return Returns {@code true} if this ability currently has window focus; returns {@code false} otherwise. 121 * @FAModelOnly 122 */ 123 function hasWindowFocus(callback: AsyncCallback<boolean>): void; 124 function hasWindowFocus(): Promise<boolean>; 125 126 /** 127 * Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. 128 * @default - 129 * @since 7 130 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 131 * @param request The element name of the service ability 132 * @param options The remote object instance 133 * @return Returns the number code of the ability connected 134 * @FAModelOnly 135 */ 136 function connectAbility(request: Want, options:ConnectOptions ): number; 137 138 /** 139 * The callback interface was connect successfully. 140 * @default - 141 * @since 7 142 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 143 * @param connection The number code of the ability connected 144 * @FAModelOnly 145 */ 146 function disconnectAbility(connection: number, callback:AsyncCallback<void>): void; 147 function disconnectAbility(connection: number): Promise<void>; 148 149 /** 150 * Obtains the window corresponding to the current ability. 151 * 152 * @since 7 153 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 154 * @return Returns the window corresponding to the current ability. 155 * @FAModelOnly 156 */ 157 function getWindow(callback: AsyncCallback<window.Window>): void; 158 function getWindow(): Promise<window.Window>; 159 160 /** 161 * Obtain the window configuration. 162 * 163 * @since 7 164 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 165 * @FAModelOnly 166 */ 167 export enum AbilityWindowConfiguration { 168 WINDOW_MODE_UNDEFINED = 0, 169 WINDOW_MODE_FULLSCREEN = 1, 170 WINDOW_MODE_SPLIT_PRIMARY = 100, 171 WINDOW_MODE_SPLIT_SECONDARY = 101, 172 WINDOW_MODE_FLOATING = 102 173 } 174 175 /** 176 * Obtain the window properties. 177 * 178 * @since 7 179 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 180 * @FAModelOnly 181 */ 182 export enum AbilityStartSetting { 183 BOUNDS_KEY = "abilityBounds", 184 WINDOW_MODE_KEY = "windowMode", 185 DISPLAY_ID_KEY = "displayId" 186 } 187 188 /** 189 * Obtain the errorCode. 190 * 191 * @since 7 192 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 193 * @FAModelOnly 194 */ 195 export enum ErrorCode { 196 NO_ERROR = 0, 197 INVALID_PARAMETER = -1, 198 ABILITY_NOT_FOUND = -2, 199 PERMISSION_DENY = -3 200 } 201 202 /** 203 * Indicates the operation type of data. 204 * 205 * @since 7 206 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 207 * @FAModelOnly 208 */ 209 export enum DataAbilityOperationType { 210 TYPE_INSERT = 1, 211 TYPE_UPDATE = 2, 212 TYPE_DELETE = 3, 213 TYPE_ASSERT = 4, 214 } 215} 216export default featureAbility; 217