• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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 AbilityConstant from './@ohos.app.ability.AbilityConstant';
22import AbilityStageContext from './application/AbilityStageContext';
23import Want from './@ohos.app.ability.Want';
24import { Configuration } from './@ohos.app.ability.Configuration';
25
26/**
27 * The class of an ability stage.
28 *
29 * @syscap SystemCapability.Ability.AbilityRuntime.Core
30 * @stagemodelonly
31 * @since 9
32 */
33/**
34 * The class of an ability stage.
35 *
36 * @syscap SystemCapability.Ability.AbilityRuntime.Core
37 * @stagemodelonly
38 * @crossplatform
39 * @since 10
40 */
41/**
42 * The class of an ability stage.
43 *
44 * @syscap SystemCapability.Ability.AbilityRuntime.Core
45 * @stagemodelonly
46 * @crossplatform
47 * @atomicservice
48 * @since 11
49 */
50export default class AbilityStage {
51  /**
52   * Indicates configuration information about context.
53   *
54   * @type { AbilityStageContext }
55   * @syscap SystemCapability.Ability.AbilityRuntime.Core
56   * @stagemodelonly
57   * @since 9
58   */
59  /**
60   * Indicates configuration information about context.
61   *
62   * @type { AbilityStageContext }
63   * @syscap SystemCapability.Ability.AbilityRuntime.Core
64   * @stagemodelonly
65   * @crossplatform
66   * @since 10
67   */
68  /**
69   * Indicates configuration information about context.
70   *
71   * @type { AbilityStageContext }
72   * @syscap SystemCapability.Ability.AbilityRuntime.Core
73   * @stagemodelonly
74   * @crossplatform
75   * @atomicservice
76   * @since 11
77   */
78  context: AbilityStageContext;
79
80  /**
81   * Called back when an ability stage is started for initialization.
82   *
83   * @syscap SystemCapability.Ability.AbilityRuntime.Core
84   * @stagemodelonly
85   * @since 9
86   */
87  /**
88   * Called back when an ability stage is started for initialization.
89   *
90   * @syscap SystemCapability.Ability.AbilityRuntime.Core
91   * @stagemodelonly
92   * @crossplatform
93   * @since 10
94   */
95  /**
96   * Called back when an ability stage is started for initialization.
97   *
98   * @syscap SystemCapability.Ability.AbilityRuntime.Core
99   * @stagemodelonly
100   * @crossplatform
101   * @atomicservice
102   * @since 11
103   */
104  onCreate(): void;
105
106  /**
107   * Called back when start specified ability.
108   *
109   * @param { Want } want - Indicates the want info of started ability.
110   * @returns { string } The user returns an ability string ID. If the ability of this ID has been started before,
111   *         do not create a new instance and pull it back to the top of the stack.
112   *         Otherwise, create a new instance and start it.
113   * @syscap SystemCapability.Ability.AbilityRuntime.Core
114   * @stagemodelonly
115   * @since 9
116   */
117  /**
118   * Called back when start specified ability.
119   *
120   * @param { Want } want - Indicates the want info of started ability.
121   * @returns { string } The user returns an ability string ID. If the ability of this ID has been started before,
122   *         do not create a new instance and pull it back to the top of the stack.
123   *         Otherwise, create a new instance and start it.
124   * @syscap SystemCapability.Ability.AbilityRuntime.Core
125   * @stagemodelonly
126   * @atomicservice
127   * @since 11
128   */
129  onAcceptWant(want: Want): string;
130
131  /**
132   * Called back when start UIAbility in specified process.
133   *
134   * @param { Want } want - Indicates the want info of started ability.
135   * @returns { string } The user returns an process string ID. If the process of this ID has been created before,
136   *         let the ability run in this process. Otherwise, create a new process.
137   * @syscap SystemCapability.Ability.AbilityRuntime.Core
138   * @stagemodelonly
139   * @since 11
140   */
141  onNewProcessRequest(want: Want): string;
142
143  /**
144   * Called when the system configuration is updated.
145   *
146   * @param { Configuration } newConfig - Indicates the updated configuration.
147   * @syscap SystemCapability.Ability.AbilityRuntime.Core
148   * @stagemodelonly
149   * @since 9
150   */
151  /**
152   * Called when the system configuration is updated.
153   *
154   * @param { Configuration } newConfig - Indicates the updated configuration.
155   * @syscap SystemCapability.Ability.AbilityRuntime.Core
156   * @stagemodelonly
157   * @crossplatform
158   * @since 10
159   */
160  /**
161   * Called when the system configuration is updated.
162   *
163   * @param { Configuration } newConfig - Indicates the updated configuration.
164   * @syscap SystemCapability.Ability.AbilityRuntime.Core
165   * @stagemodelonly
166   * @crossplatform
167   * @atomicservice
168   * @since 11
169   */
170  onConfigurationUpdate(newConfig: Configuration): void;
171
172  /**
173   * Called when the system has determined to trim the memory, for example, when the ability is running in the
174   * background and there is no enough memory for running as many background processes as possible.
175   *
176   * @param { AbilityConstant.MemoryLevel } level - Indicates the memory trim level, which shows the current memory usage status.
177   * @syscap SystemCapability.Ability.AbilityRuntime.Core
178   * @stagemodelonly
179   * @since 9
180   */
181  /**
182   * Called when the system has determined to trim the memory, for example, when the ability is running in the
183   * background and there is no enough memory for running as many background processes as possible.
184   *
185   * @param { AbilityConstant.MemoryLevel } level - Indicates the memory trim level, which shows the current memory usage status.
186   * @syscap SystemCapability.Ability.AbilityRuntime.Core
187   * @stagemodelonly
188   * @atomicservice
189   * @since 11
190   */
191  onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
192
193  /**
194   * Called back when an ability stage is Destroyed.
195   * Will not call the onDestroy function when killing a process or crashing abnormally.
196   *
197   * @syscap SystemCapability.Ability.AbilityRuntime.Core
198   * @stagemodelonly
199   * @atomicservice
200   * @since 12
201   */
202  onDestroy(): void;
203
204  /**
205   * Called back before an ability stage is terminated.
206   *
207   * @permission ohos.permission.PREPARE_APP_TERMINATE
208   * @returns { AbilityConstant.PrepareTermination } The user returns an action indicating
209   *                                                 what the process should do prior to terminating.
210   * @syscap SystemCapability.Ability.AbilityRuntime.Core
211   * @stagemodelonly
212   * @atomicservice
213   * @since 15
214   */
215  onPrepareTermination(): AbilityConstant.PrepareTermination;
216
217  /**
218   * Called back asynchronously before an ability stage is terminated.
219   * If onPrepareTerminationAsync has been implemented then onPrepareTermination won't take effect
220   *
221   * @permission ohos.permission.PREPARE_APP_TERMINATE
222   * @returns { Promise<AbilityConstant.PrepareTermination> } The user returns a promise of the action indicating
223   *                                                          what the process should do prior to terminating.
224   * @syscap SystemCapability.Ability.AbilityRuntime.Core
225   * @stagemodelonly
226   * @atomicservice
227   * @since 15
228   */
229  onPrepareTerminationAsync(): Promise<AbilityConstant.PrepareTermination>;
230}
231