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 #include "app_lifecycle_deal.h"
17
18 #include "hilog_wrapper.h"
19 #include "hitrace_meter.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
AppLifeCycleDeal()23 AppLifeCycleDeal::AppLifeCycleDeal()
24 {}
25
~AppLifeCycleDeal()26 AppLifeCycleDeal::~AppLifeCycleDeal()
27 {
28 HILOG_INFO("AppLifeCycleDeal deconstructor");
29 }
30
LaunchApplication(const AppLaunchData & launchData,const Configuration & config)31 void AppLifeCycleDeal::LaunchApplication(const AppLaunchData &launchData, const Configuration &config)
32 {
33 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
34 HILOG_DEBUG("AppLifeCycleDeal ScheduleLaunchApplication");
35 if (appThread_) {
36 appThread_->ScheduleLaunchApplication(launchData, config);
37 }
38 }
39
UpdateApplicationInfoInstalled(const ApplicationInfo & appInfo)40 void AppLifeCycleDeal::UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo)
41 {
42 if (!appThread_) {
43 HILOG_ERROR("appThread_ is nullptr");
44 return;
45 }
46
47 appThread_->ScheduleUpdateApplicationInfoInstalled(appInfo);
48 }
49
AddAbilityStage(const HapModuleInfo & abilityStage)50 void AppLifeCycleDeal::AddAbilityStage(const HapModuleInfo &abilityStage)
51 {
52 if (!appThread_) {
53 HILOG_ERROR("appThread_ is nullptr");
54 return;
55 }
56
57 appThread_->ScheduleAbilityStage(abilityStage);
58 }
59
LaunchAbility(const std::shared_ptr<AbilityRunningRecord> & ability)60 void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability)
61 {
62 if (appThread_ && ability) {
63 appThread_->ScheduleLaunchAbility(*(ability->GetAbilityInfo()), ability->GetToken(),
64 ability->GetWant());
65 }
66 }
67
ScheduleTerminate()68 void AppLifeCycleDeal::ScheduleTerminate()
69 {
70 if (!appThread_) {
71 HILOG_ERROR("appThread_ is nullptr");
72 return;
73 }
74
75 appThread_->ScheduleTerminateApplication();
76 }
77
ScheduleForegroundRunning()78 void AppLifeCycleDeal::ScheduleForegroundRunning()
79 {
80 if (!appThread_) {
81 HILOG_ERROR("appThread_ is nullptr");
82 return;
83 }
84
85 appThread_->ScheduleForegroundApplication();
86 }
87
ScheduleBackgroundRunning()88 void AppLifeCycleDeal::ScheduleBackgroundRunning()
89 {
90 if (!appThread_) {
91 HILOG_ERROR("appThread_ is nullptr");
92 return;
93 }
94
95 appThread_->ScheduleBackgroundApplication();
96 }
97
ScheduleTrimMemory(int32_t timeLevel)98 void AppLifeCycleDeal::ScheduleTrimMemory(int32_t timeLevel)
99 {
100 if (!appThread_) {
101 HILOG_ERROR("appThread_ is nullptr");
102 return;
103 }
104
105 appThread_->ScheduleShrinkMemory(timeLevel);
106 }
107
ScheduleMemoryLevel(int32_t Level)108 void AppLifeCycleDeal::ScheduleMemoryLevel(int32_t Level)
109 {
110 if (!appThread_) {
111 HILOG_ERROR("appThread_ is nullptr");
112 return;
113 }
114
115 appThread_->ScheduleMemoryLevel(Level);
116 }
117
ScheduleHeapMemory(const int32_t pid,OHOS::AppExecFwk::MallocInfo & mallocInfo)118 void AppLifeCycleDeal::ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
119 {
120 if (!appThread_) {
121 HILOG_ERROR("appThread_ is nullptr");
122 return;
123 }
124
125 appThread_->ScheduleHeapMemory(pid, mallocInfo);
126 }
127
LowMemoryWarning()128 void AppLifeCycleDeal::LowMemoryWarning()
129 {
130 if (!appThread_) {
131 HILOG_ERROR("appThread_ is nullptr");
132 return;
133 }
134
135 appThread_->ScheduleLowMemory();
136 }
137
ScheduleCleanAbility(const sptr<IRemoteObject> & token)138 void AppLifeCycleDeal::ScheduleCleanAbility(const sptr<IRemoteObject> &token)
139 {
140 if (!appThread_) {
141 HILOG_ERROR("appThread_ is nullptr");
142 return;
143 }
144 appThread_->ScheduleCleanAbility(token);
145 }
146
ScheduleProcessSecurityExit()147 void AppLifeCycleDeal::ScheduleProcessSecurityExit()
148 {
149 if (!appThread_) {
150 HILOG_ERROR("appThread_ is nullptr");
151 return;
152 }
153
154 appThread_->ScheduleProcessSecurityExit();
155 }
156
SetApplicationClient(const sptr<IAppScheduler> & thread)157 void AppLifeCycleDeal::SetApplicationClient(const sptr<IAppScheduler> &thread)
158 {
159 appThread_ = thread;
160 }
161
GetApplicationClient() const162 sptr<IAppScheduler> AppLifeCycleDeal::GetApplicationClient() const
163 {
164 return appThread_;
165 }
166
ScheduleAcceptWant(const AAFwk::Want & want,const std::string & moduleName)167 void AppLifeCycleDeal::ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName)
168 {
169 if (!appThread_) {
170 HILOG_ERROR("appThread_ is nullptr");
171 return;
172 }
173
174 appThread_->ScheduleAcceptWant(want, moduleName);
175 }
176
UpdateConfiguration(const Configuration & config)177 int32_t AppLifeCycleDeal::UpdateConfiguration(const Configuration &config)
178 {
179 HILOG_DEBUG("call");
180 if (!appThread_) {
181 HILOG_ERROR("appThread_ is nullptr");
182 return ERR_INVALID_VALUE;
183 }
184 appThread_->ScheduleConfigurationUpdated(config);
185 return ERR_OK;
186 }
187
NotifyLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback,const int32_t recordId)188 int32_t AppLifeCycleDeal::NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback,
189 const int32_t recordId)
190 {
191 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
192 HILOG_DEBUG("call");
193 if (appThread_ == nullptr) {
194 HILOG_ERROR("appThread_ is nullptr.");
195 return ERR_INVALID_VALUE;
196 }
197 return appThread_->ScheduleNotifyLoadRepairPatch(bundleName, callback, recordId);
198 }
199
NotifyHotReloadPage(const sptr<IQuickFixCallback> & callback,const int32_t recordId)200 int32_t AppLifeCycleDeal::NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId)
201 {
202 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
203 HILOG_DEBUG("call");
204 if (appThread_ == nullptr) {
205 HILOG_ERROR("appThread_ is nullptr.");
206 return ERR_INVALID_VALUE;
207 }
208 return appThread_->ScheduleNotifyHotReloadPage(callback, recordId);
209 }
210
NotifyUnLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback,const int32_t recordId)211 int32_t AppLifeCycleDeal::NotifyUnLoadRepairPatch(const std::string &bundleName,
212 const sptr<IQuickFixCallback> &callback, const int32_t recordId)
213 {
214 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
215 HILOG_DEBUG("function called.");
216 if (appThread_ == nullptr) {
217 HILOG_ERROR("appThread_ is nullptr.");
218 return ERR_INVALID_VALUE;
219 }
220 return appThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback, recordId);
221 }
222
NotifyAppFault(const FaultData & faultData)223 int32_t AppLifeCycleDeal::NotifyAppFault(const FaultData &faultData)
224 {
225 HILOG_DEBUG("called.");
226 if (appThread_ == nullptr) {
227 HILOG_ERROR("appThread_ is nullptr.");
228 return ERR_INVALID_VALUE;
229 }
230 return appThread_->ScheduleNotifyAppFault(faultData);
231 }
232 } // namespace AppExecFwk
233 } // namespace OHOS
234