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_ABILITY_RUNTIME_IAPPLICATION_STATE_OBSERVER_H
17 #define OHOS_ABILITY_RUNTIME_IAPPLICATION_STATE_OBSERVER_H
18 
19 #include "ability_state_data.h"
20 #include "app_state_data.h"
21 #include "page_state_data.h"
22 #include "process_data.h"
23 #include "iremote_broker.h"
24 #include "iremote_object.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 class IApplicationStateObserver : public IRemoteBroker {
29 public:
30     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IApplicationStateObserver");
31 
32     /**
33      * Application foreground state changed callback.
34      *
35      * @param appStateData Application state data.
36      */
37     virtual void OnForegroundApplicationChanged(const AppStateData &appStateData) = 0;
38 
39     /**
40      * Will be called when the ability state changes.
41      *
42      * @param abilityStateData Ability state data.
43      */
44     virtual void OnAbilityStateChanged(const AbilityStateData &abilityStateData) = 0;
45 
46     /**
47      * Will be called when the extension state changes.
48      *
49      * @param abilityStateData Extension state data.
50      */
51     virtual void OnExtensionStateChanged(const AbilityStateData &abilityStateData) = 0;
52 
53     /**
54      * Will be called when the process start.
55      *
56      * @param processData Process data.
57      */
58     virtual void OnProcessCreated(const ProcessData &processData) = 0;
59 
60     /**
61      * Will be called when the process state change.
62      *
63      * @param processData Process data.
64      */
OnProcessStateChanged(const ProcessData & processData)65     virtual void OnProcessStateChanged(const ProcessData &processData) {}
66 
67     /**
68      * Will be called when the process die.
69      *
70      * @param processData Process data.
71      */
72     virtual void OnProcessDied(const ProcessData &processData) = 0;
73 
74     /**
75      * Application state changed callback.
76      * Only observe APP_STATE_CREATE and APP_STATE_TERMINATED
77      *
78      * @param appStateData Application state data.
79      */
80     virtual void OnApplicationStateChanged(const AppStateData &appStateData) = 0;
81 
82     /**
83      * Application state changed callback.
84      * Only observe APP_STATE_FOREGROUND and APP_STATE_BACKGROUND
85      *
86      * @param appStateData Application state data.
87      */
OnAppStateChanged(const AppStateData & appStateData)88     virtual void OnAppStateChanged(const AppStateData &appStateData) {}
89 
OnProcessReused(const ProcessData & processData)90     virtual void OnProcessReused(const ProcessData &processData) {}
91 
92     /**
93      * Will be called when the application start.
94      *
95      * @param appStateData Application state data.
96      */
OnAppStarted(const AppStateData & appStateData)97     virtual void OnAppStarted(const AppStateData &appStateData) {};
98 
99     /**
100      * Will be called when the application stop.
101      *
102      * @param appStateData Application state data.
103      */
OnAppStopped(const AppStateData & appStateData)104     virtual void OnAppStopped(const AppStateData &appStateData) {};
105 
106     /**
107      * Will be called when page show.
108      *
109      * @param pageStateData Page state data.
110      */
OnPageShow(const PageStateData & pageStateData)111     virtual void OnPageShow(const PageStateData &pageStateData) {};
112 
113     /**
114      * Will be called whe page hide.
115      *
116      * @param pageStateData Page state data.
117      */
OnPageHide(const PageStateData & pageStateData)118     virtual void OnPageHide(const PageStateData &pageStateData) {};
119 
120     /**
121      * Will be called when application cache state change.
122      *
123      * @param appStateData Application state data.
124      */
OnAppCacheStateChanged(const AppStateData & appStateData)125     virtual void OnAppCacheStateChanged(const AppStateData &appStateData) {};
126 
127     enum class Message {
128         TRANSACT_ON_FOREGROUND_APPLICATION_CHANGED = 0,
129         TRANSACT_ON_ABILITY_STATE_CHANGED,
130         TRANSACT_ON_EXTENSION_STATE_CHANGED,
131         TRANSACT_ON_PROCESS_CREATED,
132         TRANSACT_ON_PROCESS_STATE_CHANGED,
133         TRANSACT_ON_PROCESS_DIED,
134         TRANSACT_ON_APPLICATION_STATE_CHANGED,
135         TRANSACT_ON_APP_STATE_CHANGED,
136         TRANSACT_ON_PROCESS_REUSED,
137         TRANSACT_ON_APP_STARTED,
138         TRANSACT_ON_APP_STOPPED,
139         TRANSACT_ON_PAGE_SHOW,
140         TRANSACT_ON_PAGE_HIDE,
141         TRANSACT_ON_APP_CACHE_STATE_CHANGED,
142     };
143 };
144 }  // namespace AppExecFwk
145 }  // namespace OHOS
146 #endif  // OHOS_ABILITY_RUNTIME_IAPPLICATION_STATE_OBSERVER_H
147