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