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