• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
15 
16 #ifndef OHOS_SLITE_ABILITY_H
17 #define OHOS_SLITE_ABILITY_H
18 
19 #include "lite_context.h"
20 #include "want.h"
21 
22 namespace OHOS {
23 /**
24  * @brief Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to or
25  *        disconnecting from Particle Abilities.
26  *
27  * As the fundamental unit of OpenHarmony applications, abilities are classified into Feature Abilities and Particle
28  * Abilities. Feature Abilities support the Page template, and Particle Abilities support the Service template.
29  * An ability using the Page template is called Page ability for short and that using the Service template
30  * is called Service ability.
31  *
32  * @since 1.0
33  * @version 1.0
34  */
35 class SliteAbility : public LiteContext {
36 public:
37     SliteAbility() = default;
38     virtual ~SliteAbility() = default;
39 
40     /**
41      * @brief Called when this ability is started. You must override this function if you want to perform some
42      *        initialization operations during ability startup.
43      *
44      * This function can be called only once in the entire lifecycle of an ability.
45      * @param want Indicates the {@link Want} structure containing startup information about the ability.
46      */
47     virtual void OnStart(const Want &want);
48 
49     /**
50      * @brief Called when this ability enters the <b>STATE_INACTIVE</b> state.
51      *
52      * <b>STATE_INACTIVE</b> is an instantaneous state. The ability in this state may be visible but does not have
53      * focus. You can override this function to implement your own processing logic.
54      */
55     virtual void OnInactive();
56 
57     /**
58      * @brief Called when this ability enters the <b>STATE_ACTIVE</b> state.
59      *
60      * The ability in the <b>STATE_ACTIVE</b> state is visible and has focus.
61      * You can override this function to implement your own processing logic.
62      *
63      * @param want Indicates the {@link Want} structure containing activation information about the ability.
64      */
65     virtual void OnActive(const Want &want);
66 
67     /**
68      * @brief Called when this ability enters the <b>STATE_BACKGROUND</b> state.
69      *
70      *
71      * The ability in the <b>STATE_BACKGROUND</b> state is invisible.
72      * You can override this function to implement your own processing logic.
73      */
74     virtual void OnBackground();
75 
76     /**
77      * @brief Called when this ability enters the <b>STATE_STOP</b> state.
78      *
79      * The ability in the <b>STATE_STOP</b> is being destroyed.
80      * You can override this function to implement your own processing logic.
81      */
82     virtual void OnStop();
83 
84     int GetState() const;
85 private:
86     int abilityState_ = 0;
87 };
88 } // namespace OHOS
89 #endif // OHOS_SLITE_ABILITY_H
90