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 16/** 17 * @file 18 * @kit AbilityKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22import { Callback } from './@ohos.base'; 23import Want from './@ohos.app.ability.Want'; 24import { StartAbilityParameter } from './ability/startAbilityParameter'; 25import { AbilityResult } from './ability/abilityResult'; 26import { AppVersionInfo as _AppVersionInfo } from './app/appVersionInfo'; 27import { Context as _Context } from './app/context'; 28import { DataAbilityHelper } from './ability/dataAbilityHelper'; 29import { ConnectOptions } from './ability/connectOptions'; 30import { ProcessInfo as _ProcessInfo } from './app/processInfo'; 31import window from './@ohos.window'; 32 33/** 34 * A Feature Ability represents an ability with a UI and is designed to interact with users. 35 * 36 * @namespace featureAbility 37 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 38 * @FAModelOnly 39 * @since 6 40 */ 41declare namespace featureAbility { 42 /** 43 * Obtain the want sent from the source ability. 44 * 45 * @param { AsyncCallback<Want> } callback - Indicates the ability to start. 46 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 47 * @FAModelOnly 48 * @since 6 49 */ 50 function getWant(callback: AsyncCallback<Want>): void; 51 52 /** 53 * Obtain the want sent from the source ability. 54 * 55 * @returns { Promise<Want> } The promise form returns the Want result 56 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 57 * @FAModelOnly 58 * @since 6 59 */ 60 function getWant(): Promise<Want>; 61 62 /** 63 * Starts a new ability. 64 * 65 * @param { StartAbilityParameter } parameter - Indicates the ability to start. 66 * @param { AsyncCallback<number> } callback - Returns the result of starting Ability in the form of callback. 67 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 68 * @FAModelOnly 69 * @since 6 70 */ 71 function startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>): void; 72 73 /** 74 * Starts a new ability. 75 * 76 * @param { StartAbilityParameter } parameter - Indicates the ability to start. 77 * @returns { Promise<number> } The promise form returns the Ability result 78 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 79 * @FAModelOnly 80 * @since 6 81 */ 82 function startAbility(parameter: StartAbilityParameter): Promise<number>; 83 84 /** 85 * Obtains the application context. 86 * 87 * @returns { Context } Returns the application context. 88 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 89 * @FAModelOnly 90 * @since 6 91 */ 92 function getContext(): Context; 93 94 /** 95 * Starts an ability and returns the execution result when the ability is destroyed. 96 * 97 * @param { StartAbilityParameter } parameter - Indicates the ability to start. 98 * @param { AsyncCallback<AbilityResult> } callback - Returns the result of starting Ability in the form of callback. 99 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 100 * @FAModelOnly 101 * @since 7 102 */ 103 function startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback<AbilityResult>): void; 104 105 /** 106 * Starts an ability and returns the execution result when the ability is destroyed. 107 * 108 * @param { StartAbilityParameter } parameter - Indicates the ability to start. 109 * @returns { Promise<AbilityResult> } Returns the {@link AbilityResult}. 110 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 111 * @FAModelOnly 112 * @since 7 113 */ 114 function startAbilityForResult(parameter: StartAbilityParameter): Promise<AbilityResult>; 115 116 /** 117 * Destroys the Page ability while returning the specified result code and data to the caller. 118 * 119 * @param { AbilityResult } parameter - Indicates the result to return. 120 * @param { AsyncCallback<void> } callback - Return the result of stopping Ability in the form of callback. 121 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 122 * @FAModelOnly 123 * @since 7 124 */ 125 function terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void; 126 127 /** 128 * Destroys the Page ability while returning the specified result code and data to the caller. 129 * 130 * @param { AbilityResult } parameter - Indicates the result to return. 131 * @returns { Promise<void> } the promise returned by the function. 132 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 133 * @FAModelOnly 134 * @since 7 135 */ 136 function terminateSelfWithResult(parameter: AbilityResult): Promise<void>; 137 138 /** 139 * Destroys this Page ability. 140 * 141 * @param { AsyncCallback<void> } callback - Returns the stop ability result in the form of a callback. 142 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 143 * @FAModelOnly 144 * @since 7 145 */ 146 function terminateSelf(callback: AsyncCallback<void>): void; 147 148 /** 149 * Destroys this Page ability. 150 * 151 * @returns { Promise<void> } the promise returned by the function. 152 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 153 * @FAModelOnly 154 * @since 7 155 */ 156 function terminateSelf(): Promise<void>; 157 158 /** 159 * Obtains the dataAbilityHelper. 160 * 161 * @param { string } uri - Indicates the path of the file to open. 162 * @returns { DataAbilityHelper } Returns the dataAbilityHelper. 163 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 164 * @FAModelOnly 165 * @since 7 166 */ 167 function acquireDataAbilityHelper(uri: string): DataAbilityHelper; 168 169 /** 170 * Checks whether the main window of this ability has window focus. 171 * 172 * @param { AsyncCallback<boolean> } callback - Returns the result in the form of callback.If this ability currently 173 * has window focus,return true otherwise,return false. 174 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 175 * @FAModelOnly 176 * @since 7 177 */ 178 function hasWindowFocus(callback: AsyncCallback<boolean>): void; 179 180 /** 181 * Checks whether the main window of this ability has window focus. 182 * 183 * @returns { Promise<boolean> } Returns {@code true} if this ability currently has window focus; 184 * returns {@code false} otherwise. 185 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 186 * @FAModelOnly 187 * @since 7 188 */ 189 function hasWindowFocus(): Promise<boolean>; 190 191 /** 192 * Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. 193 * 194 * @param { Want } request - The element name of the service ability 195 * @param { ConnectOptions } options - The remote object instance 196 * @returns { number } Returns the number code of the ability connected 197 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 198 * @FAModelOnly 199 * @since 7 200 */ 201 function connectAbility(request: Want, options: ConnectOptions): number; 202 203 /** 204 * Disconnects ability to a Service ability. 205 * 206 * @param { number } connection - The number code of the ability connected 207 * @param { AsyncCallback<void> } callback - Returns the disconnection result in the form of callback. 208 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 209 * @FAModelOnly 210 * @since 7 211 */ 212 function disconnectAbility(connection: number, callback: AsyncCallback<void>): void; 213 214 /** 215 * Disconnects ability to a Service ability. 216 * 217 * @param { number } connection - The number code of the ability connected 218 * @returns { Promise<void> } the promise returned by the function. 219 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 220 * @FAModelOnly 221 * @since 7 222 */ 223 function disconnectAbility(connection: number): Promise<void>; 224 225 /** 226 * Obtains the window corresponding to the current ability. 227 * 228 * @param { AsyncCallback<window.Window> } callback - Returns the window corresponding to the current ability 229 * in the form of callback. 230 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 231 * @FAModelOnly 232 * @since 7 233 */ 234 function getWindow(callback: AsyncCallback<window.Window>): void; 235 236 /** 237 * Obtains the window corresponding to the current ability. 238 * 239 * @returns { Promise<window.Window> } Returns the window corresponding to the current ability. 240 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 241 * @FAModelOnly 242 * @since 7 243 */ 244 function getWindow(): Promise<window.Window>; 245 246 /** 247 * Enum for the window configuration. 248 * 249 * @enum { number } 250 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 251 * @FAModelOnly 252 * @since 7 253 */ 254 export enum AbilityWindowConfiguration { 255 /** 256 * Undefined window format. 257 * 258 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 259 * @FAModelOnly 260 * @since 7 261 */ 262 WINDOW_MODE_UNDEFINED = 0, 263 264 /** 265 * Full screen. 266 * 267 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 268 * @FAModelOnly 269 * @since 7 270 */ 271 WINDOW_MODE_FULLSCREEN = 1, 272 273 /** 274 * If the screen is horizontally oriented, it indicates left split, and if the screen is vertically oriented, 275 * it indicates upper split. 276 * 277 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 278 * @FAModelOnly 279 * @since 7 280 */ 281 WINDOW_MODE_SPLIT_PRIMARY = 100, 282 283 /** 284 * If the screen is horizontally oriented, it indicates right split, and if the screen is vertically oriented, 285 * it indicates bottom split. 286 * 287 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 288 * @FAModelOnly 289 * @since 7 290 */ 291 WINDOW_MODE_SPLIT_SECONDARY = 101, 292 293 /** 294 * Suspended window. 295 * 296 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 297 * @FAModelOnly 298 * @since 7 299 */ 300 WINDOW_MODE_FLOATING = 102 301 } 302 303 /** 304 * Enum for the special start setting used in starting ability. 305 * 306 * @enum { string } 307 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 308 * @FAModelOnly 309 * @since 7 310 */ 311 export enum AbilityStartSetting { 312 /** 313 * The parameter name for the window display size attribute. 314 * 315 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 316 * @FAModelOnly 317 * @since 7 318 */ 319 BOUNDS_KEY = 'abilityBounds', 320 321 /** 322 * The parameter name of the window display mode attribute. 323 * 324 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 325 * @FAModelOnly 326 * @since 7 327 */ 328 WINDOW_MODE_KEY = 'windowMode', 329 330 /** 331 * The window displays the parameter name of the device ID attribute. 332 * 333 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 334 * @FAModelOnly 335 * @since 7 336 */ 337 DISPLAY_ID_KEY = 'displayId' 338 } 339 340 /** 341 * Enum for the error code. 342 * 343 * @enum { number } 344 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 345 * @FAModelOnly 346 * @since 7 347 */ 348 export enum ErrorCode { 349 /** 350 * There are no errors. 351 * 352 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 353 * @FAModelOnly 354 * @since 7 355 */ 356 NO_ERROR = 0, 357 358 /** 359 * Invalid parameter. 360 * 361 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 362 * @FAModelOnly 363 * @since 7 364 */ 365 INVALID_PARAMETER = -1, 366 367 /** 368 * Unable to find ABILITY. 369 * 370 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 371 * @FAModelOnly 372 * @since 7 373 */ 374 ABILITY_NOT_FOUND = -2, 375 376 /** 377 * Permission denied. 378 * 379 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 380 * @FAModelOnly 381 * @since 7 382 */ 383 PERMISSION_DENY = -3 384 } 385 386 /** 387 * Enum for the operation type of data. 388 * 389 * @enum { number } 390 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 391 * @FAModelOnly 392 * @since 7 393 */ 394 export enum DataAbilityOperationType { 395 /** 396 * Insert type. 397 * 398 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 399 * @FAModelOnly 400 * @since 7 401 */ 402 TYPE_INSERT = 1, 403 404 /** 405 * Modify the type. 406 * 407 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 408 * @FAModelOnly 409 * @since 7 410 */ 411 TYPE_UPDATE = 2, 412 413 /** 414 * Delete type. 415 * 416 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 417 * @FAModelOnly 418 * @since 7 419 */ 420 TYPE_DELETE = 3, 421 422 /** 423 * Declaration type. 424 * 425 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 426 * @FAModelOnly 427 * @since 7 428 */ 429 TYPE_ASSERT = 4 430 } 431 432 /** 433 * The context of an ability or an application. It allows access to 434 * application-specific resources, request and verification permissions. 435 * Can only be obtained through the ability. 436 * 437 * @syscap SystemCapability.Ability.AbilityRuntime.Core 438 * @FAModelOnly 439 * @since 9 440 */ 441 export type Context = _Context; 442 443 /** 444 * Defines an AppVersionInfo object. 445 * 446 * @syscap SystemCapability.Ability.AbilityRuntime.Core 447 * @FAModelOnly 448 * @since 9 449 */ 450 export type AppVersionInfo = _AppVersionInfo; 451 452 /** 453 * This process information about an application. 454 * 455 * @syscap SystemCapability.Ability.AbilityRuntime.Core 456 * @FAModelOnly 457 * @since 9 458 */ 459 export type ProcessInfo = _ProcessInfo; 460} 461export default featureAbility; 462