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 #include "app_lifecycle_deal.h"
17 #include "bytrace.h"
18 #include "hilog_wrapper.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
AppLifeCycleDeal()22 AppLifeCycleDeal::AppLifeCycleDeal()
23 {}
24
~AppLifeCycleDeal()25 AppLifeCycleDeal::~AppLifeCycleDeal()
26 {}
27
LaunchApplication(const AppLaunchData & launchData_,const Configuration & config)28 void AppLifeCycleDeal::LaunchApplication(const AppLaunchData &launchData_, const Configuration &config)
29 {
30 BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
31 HILOG_INFO("AppLifeCycleDeal ScheduleLaunchApplication");
32 if (appThread_) {
33 appThread_->ScheduleLaunchApplication(launchData_, config);
34 }
35 }
36
AddAbilityStage(const HapModuleInfo & abilityStage)37 void AppLifeCycleDeal::AddAbilityStage(const HapModuleInfo &abilityStage)
38 {
39 if (!appThread_) {
40 HILOG_ERROR("appThread_ is nullptr");
41 return;
42 }
43
44 appThread_->ScheduleAbilityStage(abilityStage);
45 }
46
LaunchAbility(const std::shared_ptr<AbilityRunningRecord> & ability)47 void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability)
48 {
49 if (appThread_) {
50 appThread_->ScheduleLaunchAbility(*(ability->GetAbilityInfo()), ability->GetToken(),
51 ability->GetWant());
52 }
53 }
54
ScheduleTerminate()55 void AppLifeCycleDeal::ScheduleTerminate()
56 {
57 if (!appThread_) {
58 HILOG_ERROR("appThread_ is nullptr");
59 return;
60 }
61
62 appThread_->ScheduleTerminateApplication();
63 }
64
ScheduleForegroundRunning()65 void AppLifeCycleDeal::ScheduleForegroundRunning()
66 {
67 if (!appThread_) {
68 HILOG_ERROR("appThread_ is nullptr");
69 return;
70 }
71
72 appThread_->ScheduleForegroundApplication();
73 }
74
ScheduleBackgroundRunning()75 void AppLifeCycleDeal::ScheduleBackgroundRunning()
76 {
77 if (!appThread_) {
78 HILOG_ERROR("appThread_ is nullptr");
79 return;
80 }
81
82 appThread_->ScheduleBackgroundApplication();
83 }
84
ScheduleTrimMemory(int32_t timeLevel)85 void AppLifeCycleDeal::ScheduleTrimMemory(int32_t timeLevel)
86 {
87 if (!appThread_) {
88 HILOG_ERROR("appThread_ is nullptr");
89 return;
90 }
91
92 appThread_->ScheduleShrinkMemory(timeLevel);
93 }
94
LowMemoryWarning()95 void AppLifeCycleDeal::LowMemoryWarning()
96 {
97 if (!appThread_) {
98 HILOG_ERROR("appThread_ is nullptr");
99 return;
100 }
101
102 appThread_->ScheduleLowMemory();
103 }
104
ScheduleCleanAbility(const sptr<IRemoteObject> & token)105 void AppLifeCycleDeal::ScheduleCleanAbility(const sptr<IRemoteObject> &token)
106 {
107 if (!appThread_) {
108 HILOG_ERROR("appThread_ is nullptr");
109 return;
110 }
111 appThread_->ScheduleCleanAbility(token);
112 }
113
ScheduleProcessSecurityExit()114 void AppLifeCycleDeal::ScheduleProcessSecurityExit()
115 {
116 if (!appThread_) {
117 HILOG_ERROR("appThread_ is nullptr");
118 return;
119 }
120
121 appThread_->ScheduleProcessSecurityExit();
122 }
123
SetApplicationClient(const sptr<IAppScheduler> & thread)124 void AppLifeCycleDeal::SetApplicationClient(const sptr<IAppScheduler> &thread)
125 {
126 appThread_ = thread;
127 }
128
GetApplicationClient() const129 sptr<IAppScheduler> AppLifeCycleDeal::GetApplicationClient() const
130 {
131 return appThread_;
132 }
133
ScheduleAcceptWant(const AAFwk::Want & want,const std::string & moduleName)134 void AppLifeCycleDeal::ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName)
135 {
136 if (!appThread_) {
137 HILOG_ERROR("appThread_ is nullptr");
138 return;
139 }
140
141 appThread_->ScheduleAcceptWant(want, moduleName);
142 }
143
UpdateConfiguration(const Configuration & config)144 void AppLifeCycleDeal::UpdateConfiguration(const Configuration &config)
145 {
146 HILOG_INFO("call %{public}s", __func__);
147 if (!appThread_) {
148 HILOG_INFO("appThread_ is null");
149 return;
150 }
151 appThread_->ScheduleConfigurationUpdated(config);
152 }
153 } // namespace AppExecFwk
154 } // namespace OHOS