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_IAPP_STATE_CALLBACK_H
17 #define OHOS_ABILITY_RUNTIME_IAPP_STATE_CALLBACK_H
18 
19 #include "iremote_broker.h"
20 #include "iremote_object.h"
21 
22 #include "app_mgr_constants.h"
23 #include "app_process_data.h"
24 #include "bundle_info.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28     class Configuration;
29 }
30 }
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 class IAppStateCallback : public IRemoteBroker {
35 public:
36     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppStateCallback");
37 
38     /**
39      * Application state changed callback.
40      *
41      * @param appProcessData Process data
42      */
43     virtual void OnAppStateChanged(const AppProcessData &appProcessData) = 0;
44 
45     /**
46      * AbilityMgr's request is done.
47      *
48      * @param token Ability token.
49      * @param state Application state.
50      */
51     virtual void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const AbilityState state) = 0;
52 
53     /**
54      * @brief Notify application update system environment changes.
55      * @param config System environment change parameters.
56      * @param userId userId Designation User ID.
57      */
NotifyConfigurationChange(const AppExecFwk::Configuration & config,int32_t userId)58     virtual void NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) {}
59 
60     /**
61      * @brief Notify abilityms start resident process.
62      * @param bundleInfos resident process bundle infos.
63      */
NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> & bundleInfos)64     virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) {}
65 
66     /**
67      * @brief Notify abilityms app process OnRemoteDied
68      * @param abilityTokens abilities in died process.
69      */
OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> & abilityTokens)70     virtual void OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens) {}
71 
72     /**
73      * @brief Notify abilityms app process pre cache
74      * @param pid process pid.
75      * @param userId userId Designation User ID.
76      */
NotifyAppPreCache(int32_t pid,int32_t userId)77     virtual void NotifyAppPreCache(int32_t pid, int32_t userId) {}
78 
79     enum class Message {
80         TRANSACT_ON_APP_STATE_CHANGED = 0,
81         TRANSACT_ON_ABILITY_REQUEST_DONE,
82         TRANSACT_ON_NOTIFY_CONFIG_CHANGE,
83         TRANSACT_ON_NOTIFY_START_RESIDENT_PROCESS,
84         TRANSACT_ON_APP_REMOTE_DIED,
85         TRANSACT_ON_APP_PRE_CACHE
86     };
87 };
88 }  // namespace AppExecFwk
89 }  // namespace OHOS
90 #endif  // OHOS_ABILITY_RUNTIME_IAPP_STATE_CALLBACK_H
91