• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef OHOS_ABILITY_RUNTIME_CJ_CONTEXT_ABILITY_LIFECYCLE_CALLBACK_H
17 #define OHOS_ABILITY_RUNTIME_CJ_CONTEXT_ABILITY_LIFECYCLE_CALLBACK_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <memory>
22 #include "cj_common_ffi.h"
23 
24 using WindowStagePtr = void*;
25 
26 namespace OHOS {
27 namespace AbilityRuntime {
28 
29 class CjAbilityLifecycleCallback {
30 public:
~CjAbilityLifecycleCallback()31     virtual ~CjAbilityLifecycleCallback() {}
32     /**
33      * Called back when the ability is started for initialization.
34      *
35      * @since 9
36      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
37      * @param ability: Indicates the ability to register for listening.
38      * @StageModelOnly
39      */
40     virtual void OnAbilityCreate(const int64_t &ability) = 0;
41 
42     /**
43      * Called back when the window stage is created.
44      *
45      * @since 9
46      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
47      * @param ability: Indicates the ability to register for listening.
48      * @param windowStage: Indicates the window stage to create.
49      * @StageModelOnly
50      */
51     virtual void OnWindowStageCreate(const int64_t &ability, WindowStagePtr windowStage) = 0;
52 
53     /**
54      * Called back when the window stage is destroy.
55      *
56      * @since 9
57      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
58      * @param ability: Indicates the ability to register for listening.
59      * @param windowStage: Indicates the window stage to destroy.
60      * @StageModelOnly
61      */
62     virtual void OnWindowStageDestroy(const int64_t &ability,
63         WindowStagePtr windowStage) = 0;
64 
65     /**
66      * Called back when the window stage is active.
67      *
68      * @since 9
69      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
70      * @param ability: Indicates the ability to register for listening.
71      * @param windowStage: Indicates the window stage to active.
72      * @StageModelOnly
73      */
74     virtual void OnWindowStageActive(const int64_t &ability, WindowStagePtr windowStage) = 0;
75 
76     /**
77      * Called back when the window stage is inactive.
78      *
79      * @since 9
80      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
81      * @param ability: Indicates the ability to register for listening.
82      * @param windowStage: Indicates the window stage to inactive.
83      * @StageModelOnly
84      */
85     virtual void OnWindowStageInactive(const int64_t &ability, WindowStagePtr windowStage) = 0;
86 
87     /**
88      * Called back when the ability is destroy.
89      *
90      * @since 9
91      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
92      * @param ability: Indicates the ability to register for listening.
93      * @StageModelOnly
94      */
95     virtual void OnAbilityDestroy(const int64_t &ability) = 0;
96 
97     /**
98      * Called back after the UIAbility called onNewWant.
99      *
100      * @since 12
101      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
102      * @param ability: Indicates the ability to register for listening.
103      * @StageModelOnly
104      */
OnNewWant(const int64_t & ability)105     virtual void OnNewWant(const int64_t &ability)
106     {}
107 
108     /**
109      * Called back before the UIAbility will called onNewWant.
110      *
111      * @since 12
112      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
113      * @param ability: Indicates the ability to register for listening.
114      * @StageModelOnly
115      */
OnWillNewWant(const int64_t & ability)116     virtual void OnWillNewWant(const int64_t &ability)
117     {}
118 
119     /**
120      * Called back before an ability is started for initialization.
121      *
122      * @since 12
123      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
124      * @param ability: Indicates the ability to register for listening.
125      * @StageModelOnly
126      */
OnAbilityWillCreate(const int64_t & ability)127     virtual void OnAbilityWillCreate(const int64_t &ability)
128     {}
129 
130     /**
131      * Called back before a window stage is created.
132      *
133      * @since 12
134      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
135      * @param ability: Indicates the ability to register for listening.
136      * @param windowStage: Indicates the window stage to active.
137      * @StageModelOnly
138      */
OnWindowStageWillCreate(const int64_t & ability,WindowStagePtr windowStage)139     virtual void OnWindowStageWillCreate(const int64_t &ability,
140         WindowStagePtr windowStage) {}
141 
142     /**
143      * Called back before a window stage is destroyed.
144      *
145      * @since 12
146      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
147      * @param ability: Indicates the ability to register for listening.
148      * @param windowStage: Indicates the window stage to active.
149      * @StageModelOnly
150      */
OnWindowStageWillDestroy(const int64_t & ability,WindowStagePtr windowStage)151     virtual void OnWindowStageWillDestroy(const int64_t &ability,
152         WindowStagePtr windowStage) {}
153 
154     /**
155      * Called back before an ability is destroyed.
156      *
157      * @since 12
158      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
159      * @param ability: Indicates the ability to register for listening.
160      * @StageModelOnly
161      */
OnAbilityWillDestroy(const int64_t & ability)162     virtual void OnAbilityWillDestroy(const int64_t &ability) {}
163 
164     /**
165      * Called back before the state of an ability changes to foreground.
166      *
167      * @since 12
168      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
169      * @param ability: Indicates the ability to register for listening.
170      * @StageModelOnly
171      */
OnAbilityWillForeground(const int64_t & ability)172     virtual void OnAbilityWillForeground(const int64_t &ability) {}
173 
174     /**
175      * Called back before the state of an ability changes to background.
176      *
177      * @since 12
178      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
179      * @param ability: Indicates the ability to register for listening.
180      * @StageModelOnly
181      */
OnAbilityWillBackground(const int64_t & ability)182     virtual void OnAbilityWillBackground(const int64_t &ability) {}
183 
184     /**
185      * Called back when the ability is foreground.
186      *
187      * @since 9
188      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
189      * @param ability: Indicates the ability to register for listening.
190      * @StageModelOnly
191      */
192     virtual void OnAbilityForeground(const int64_t &ability) = 0;
193 
194     /**
195      * Called back when the ability is background.
196      *
197      * @since 9
198      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
199      * @param ability: Indicates the ability to register for listening.
200      * @StageModelOnly
201      */
202     virtual void OnAbilityBackground(const int64_t &ability) = 0;
203 
204     /**
205      * Called back when the ability is continue.
206      *
207      * @since 9
208      * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
209      * @param ability: Indicates the ability to register for listening.
210      * @StageModelOnly
211      */
212     virtual void OnAbilityContinue(const int64_t &ability) = 0;
213 
OnAbilityWillContinue(const int64_t & ability)214     virtual void OnAbilityWillContinue(const int64_t &ability) {}
OnWindowStageWillRestore(const int64_t & ability,WindowStagePtr windowStage)215     virtual void OnWindowStageWillRestore(const int64_t &ability,
216         WindowStagePtr windowStage) {}
OnWindowStageRestore(const int64_t & ability,WindowStagePtr windowStage)217     virtual void OnWindowStageRestore(const int64_t &ability,
218         WindowStagePtr windowStage) {}
OnAbilityWillSaveState(const int64_t & ability)219     virtual void OnAbilityWillSaveState(const int64_t &ability) {}
OnAbilitySaveState(const int64_t & ability)220     virtual void OnAbilitySaveState(const int64_t &ability) {}
221 };
222 }  // namespace AbilityRuntime
223 }  // namespace OHOS
224 #endif  // OHOS_ABILITY_RUNTIME_CJ_CONTEXT_ABILITY_LIFECYCLE_CALLBACK_H