1 /* 2 * Copyright (c) 2021-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 #ifndef OHOS_ABILITY_RUNTIME_APPLICATION_STATE_OBSERVER_PROXY_H 17 #define OHOS_ABILITY_RUNTIME_APPLICATION_STATE_OBSERVER_PROXY_H 18 19 #include "iremote_proxy.h" 20 21 #include "app_mgr_constants.h" 22 #include "iapplication_state_observer.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 class ApplicationStateObserverProxy : public IRemoteProxy<IApplicationStateObserver> { 27 public: 28 explicit ApplicationStateObserverProxy(const sptr<IRemoteObject> &impl); 29 virtual ~ApplicationStateObserverProxy() = default; 30 31 /** 32 * Application foreground state changed callback. 33 * 34 * @param appStateData Application Process data. 35 */ 36 virtual void OnForegroundApplicationChanged(const AppStateData &appStateData) override; 37 38 /** 39 * Will be called when the ability state changes. 40 * 41 * @param abilityStateData Ability state data. 42 */ 43 virtual void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override; 44 45 /** 46 * Will be called when the extension state changes. 47 * 48 * @param abilityStateData Extension state data. 49 */ 50 virtual void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override; 51 52 /** 53 * Will be called when the process start. 54 * 55 * @param processData Process data. 56 */ 57 virtual void OnProcessCreated(const ProcessData &processData) override; 58 59 /** 60 * Will be called when the process state change. 61 * 62 * @param processData Process data. 63 */ 64 virtual void OnProcessStateChanged(const ProcessData &processData) override; 65 66 /** 67 * Will be called when the process die. 68 * 69 * @param processData Process data. 70 */ 71 virtual void OnProcessDied(const ProcessData &processData) override; 72 73 /** 74 * Application state changed callback. 75 * Only observe APP_STATE_CREATE and APP_STATE_TERMINATED 76 * 77 * @param appStateData Application state data. 78 */ 79 virtual void OnApplicationStateChanged(const AppStateData &appStateData) override; 80 81 /** 82 * Application state changed callback. 83 * Only observe APP_STATE_FOREGROUND and APP_STATE_BACKGROUND 84 * 85 * @param appStateData Application state data. 86 */ 87 virtual void OnAppStateChanged(const AppStateData &appStateData) override; 88 89 virtual void OnProcessReused(const ProcessData &processData) override; 90 91 /** 92 * Will be called when the application start. 93 * 94 * @param appStateData Application state data. 95 */ 96 virtual void OnAppStarted(const AppStateData &appStateData) override; 97 98 /** 99 * Will be called when the application stop. 100 * 101 * @param appStateData Application state data. 102 */ 103 virtual void OnAppStopped(const AppStateData &appStateData) override; 104 105 /** 106 * Will be called when page show. 107 * 108 * @param pageStateData Page state data. 109 */ 110 virtual void OnPageShow(const PageStateData &pageStateData) override; 111 112 /** 113 * Will be called whe page hide. 114 * 115 * @param pageStateData Page state data. 116 */ 117 virtual void OnPageHide(const PageStateData &pageStateData) override; 118 119 /** 120 * Will be called when application cache state change. 121 * 122 * @param appStateData Application state data. 123 */ 124 virtual void OnAppCacheStateChanged(const AppStateData &appStateData) override; 125 126 private: 127 bool WriteInterfaceToken(MessageParcel &data); 128 static inline BrokerDelegator<ApplicationStateObserverProxy> delegator_; 129 int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 130 }; 131 } // namespace AppExecFwk 132 } // namespace OHOS 133 #endif 134