• 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_STATE_OBSERVER_H
17 #define OHOS_ABILITY_STATE_OBSERVER_H
18 
19 #include "application_state_observer_stub.h"
20 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
21 #include "background_task_mgr_helper.h"
22 #endif
23 
24 namespace OHOS {
25 namespace DistributedSchedule {
26 enum class SliteAbilityState {
27     STATE_UNKNOWN = 0,
28     /**
29      * Uninitialized state: An ability is in this state when it has not been initialized.
30      */
31     STATE_UNINITIALIZED = 1,
32 
33     /**
34      * Initial state: An ability is in this state after it is initialized.
35      */
36     STATE_INITIAL = 2,
37 
38     /**
39      * Foreground state: An ability is in this state when it is switched to the foreground.
40      */
41     STATE_FOREGROUND = 3,
42 
43     /**
44      * Background state: An ability is in this state after it returns to the background.
45      */
46     STATE_BACKGROUND = 4,
47 };
48 
49 class AbilityLifecycleObserver : public AppExecFwk::ApplicationStateObserverStub {
50 public:
51     /**
52      * Application foreground state changed callback.
53      *
54      * @param appStateData Application Process data.
55      */
56     void OnForegroundApplicationChanged(const AppExecFwk::AppStateData& appStateData) override;
57 
58     /**
59      * Will be called when the ability state changes.
60      *
61      * @param abilityStateData Ability state data.
62      */
63     void OnAbilityStateChanged(const AppExecFwk::AbilityStateData& abilityStateData) override;
64 
65     /**
66      * Will be called when the extension state changes.
67      *
68      * @param abilityStateData Extension state data.
69      */
70     void OnExtensionStateChanged(const AppExecFwk::AbilityStateData& abilityStateData) override;
71 
72     /**
73      * Will be called when the process start.
74      *
75      * @param processData Process data.
76      */
77     void OnProcessCreated(const AppExecFwk::ProcessData& processData) override;
78 
79     /**
80      * Will be called when the process die.
81      *
82      * @param processData Process data.
83      */
84     void OnProcessDied(const AppExecFwk::ProcessData& processData) override;
85 
86     void ReportDistributedComponentChange(const AppExecFwk::AbilityStateData& abilityStateData,
87     int32_t changeType);
88 private:
89     std::mutex countLock_;
90     std::map<sptr<IRemoteObject>, int32_t> connectAbilityMap_;
91 };
92 } // namespace DistributedSchedule
93 } // namespace OHOS
94 #endif // OHOS_ABILITY_STATE_OBSERVER_H
95