• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_scheduler.h"
17 
18 #include "ability_manager_service.h"
19 #include "ability_util.h"
20 #include "hitrace_meter.h"
21 #include "param.h"
22 #include "utils/state_utils.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
AppScheduler()26 AppScheduler::AppScheduler() : appMgrClient_(std::make_unique<AppExecFwk::AppMgrClient>())
27 {}
28 
~AppScheduler()29 AppScheduler::~AppScheduler()
30 {}
31 
Init(const std::weak_ptr<AppStateCallback> & callback)32 bool AppScheduler::Init(const std::weak_ptr<AppStateCallback> &callback)
33 {
34     CHECK_POINTER_RETURN_BOOL(callback.lock());
35     CHECK_POINTER_RETURN_BOOL(appMgrClient_);
36 
37     std::lock_guard<std::mutex> guard(lock_);
38     if (isInit_) {
39         return true;
40     }
41 
42     callback_ = callback;
43     /* because the errcode type of AppMgr Client API will be changed to int,
44      * so must to covert the return result  */
45     int result = static_cast<int>(appMgrClient_->ConnectAppMgrService());
46     if (result != ERR_OK) {
47         TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to ConnectAppMgrService");
48         return false;
49     }
50     this->IncStrongRef(this);
51     result = static_cast<int>(appMgrClient_->RegisterAppStateCallback(sptr<AppScheduler>(this)));
52     if (result != ERR_OK) {
53         TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to RegisterAppStateCallback");
54         return false;
55     }
56 
57     startSpecifiedAbilityResponse_ = new (std::nothrow) StartSpecifiedAbilityResponse();
58     if (startSpecifiedAbilityResponse_ == nullptr) {
59         TAG_LOGE(AAFwkTag::ABILITYMGR, "startSpecifiedAbilityResponse_ is nullptr.");
60         return false;
61     }
62     appMgrClient_->RegisterStartSpecifiedAbilityResponse(startSpecifiedAbilityResponse_);
63 
64     TAG_LOGI(AAFwkTag::ABILITYMGR, "success to ConnectAppMgrService");
65     isInit_ = true;
66     return true;
67 }
68 
LoadAbility(const AbilityRuntime::LoadParam & loadParam,const AppExecFwk::AbilityInfo & abilityInfo,const AppExecFwk::ApplicationInfo & applicationInfo,const Want & want)69 int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam &loadParam, const AppExecFwk::AbilityInfo &abilityInfo,
70     const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want)
71 {
72     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
73     TAG_LOGD(AAFwkTag::SERVICE_EXT, "called");
74     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
75     /* because the errcode type of AppMgr Client API will be changed to int,
76      * so must to covert the return result  */
77     int ret = static_cast<int>(IN_PROCESS_CALL(
78         appMgrClient_->LoadAbility(abilityInfo, applicationInfo, want, loadParam)));
79     if (ret != ERR_OK) {
80         TAG_LOGE(AAFwkTag::SERVICE_EXT, "AppScheduler fail to LoadAbility. ret %d", ret);
81         return INNER_ERR;
82     }
83     return ERR_OK;
84 }
85 
TerminateAbility(const sptr<IRemoteObject> & token,bool clearMissionFlag)86 int AppScheduler::TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag)
87 {
88     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
89     TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate ability.");
90     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
91     /* because the errcode type of AppMgr Client API will be changed to int,
92      * so must to covert the return result  */
93     int ret = static_cast<int>(IN_PROCESS_CALL(appMgrClient_->TerminateAbility(token, clearMissionFlag)));
94     if (ret != ERR_OK) {
95         TAG_LOGE(AAFwkTag::ABILITYMGR, "AppScheduler fail to TerminateAbility. ret %d", ret);
96         return INNER_ERR;
97     }
98     return ERR_OK;
99 }
100 
UpdateApplicationInfoInstalled(const std::string & bundleName,const int32_t uid)101 int AppScheduler::UpdateApplicationInfoInstalled(const std::string &bundleName, const int32_t uid)
102 {
103     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
104     TAG_LOGD(AAFwkTag::ABILITYMGR, "Start to update the application info after new module installed.");
105     int ret = (int)appMgrClient_->UpdateApplicationInfoInstalled(bundleName, uid);
106     if (ret != ERR_OK) {
107         TAG_LOGE(AAFwkTag::ABILITYMGR, "Fail to UpdateApplicationInfoInstalled.");
108         return INNER_ERR;
109     }
110 
111     return ERR_OK;
112 }
113 
MoveToForeground(const sptr<IRemoteObject> & token)114 void AppScheduler::MoveToForeground(const sptr<IRemoteObject> &token)
115 {
116     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
117     TAG_LOGD(AAFwkTag::ABILITYMGR, "Start to move the ability to foreground.");
118     CHECK_POINTER(appMgrClient_);
119     IN_PROCESS_CALL_WITHOUT_RET(
120         appMgrClient_->UpdateAbilityState(token, AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND));
121 }
122 
MoveToBackground(const sptr<IRemoteObject> & token)123 void AppScheduler::MoveToBackground(const sptr<IRemoteObject> &token)
124 {
125     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
126     TAG_LOGD(AAFwkTag::ABILITYMGR, "Move the app to background.");
127     CHECK_POINTER(appMgrClient_);
128     IN_PROCESS_CALL_WITHOUT_RET(
129         appMgrClient_->UpdateAbilityState(token, AppExecFwk::AbilityState::ABILITY_STATE_BACKGROUND));
130 }
131 
UpdateAbilityState(const sptr<IRemoteObject> & token,const AppExecFwk::AbilityState state)132 void AppScheduler::UpdateAbilityState(const sptr<IRemoteObject> &token, const AppExecFwk::AbilityState state)
133 {
134     TAG_LOGD(AAFwkTag::ABILITYMGR, "UpdateAbilityState.");
135     CHECK_POINTER(appMgrClient_);
136     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->UpdateAbilityState(token, state));
137 }
138 
UpdateExtensionState(const sptr<IRemoteObject> & token,const AppExecFwk::ExtensionState state)139 void AppScheduler::UpdateExtensionState(const sptr<IRemoteObject> &token, const AppExecFwk::ExtensionState state)
140 {
141     TAG_LOGD(AAFwkTag::ABILITYMGR, "UpdateExtensionState.");
142     CHECK_POINTER(appMgrClient_);
143     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->UpdateExtensionState(token, state));
144 }
145 
AbilityBehaviorAnalysis(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & preToken,const int32_t visibility,const int32_t perceptibility,const int32_t connectionState)146 void AppScheduler::AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
147     const int32_t visibility, const int32_t perceptibility, const int32_t connectionState)
148 {
149     TAG_LOGD(AAFwkTag::ABILITYMGR, "Ability behavior analysis.");
150     CHECK_POINTER(appMgrClient_);
151     IN_PROCESS_CALL_WITHOUT_RET(
152         appMgrClient_->AbilityBehaviorAnalysis(token, preToken, visibility, perceptibility, connectionState));
153 }
154 
KillProcessByAbilityToken(const sptr<IRemoteObject> & token)155 void AppScheduler::KillProcessByAbilityToken(const sptr<IRemoteObject> &token)
156 {
157     TAG_LOGI(AAFwkTag::ABILITYMGR, "Kill process by ability token.");
158     CHECK_POINTER(appMgrClient_);
159     appMgrClient_->KillProcessByAbilityToken(token);
160 }
161 
KillProcessesByUserId(int32_t userId)162 void AppScheduler::KillProcessesByUserId(int32_t userId)
163 {
164     TAG_LOGI(AAFwkTag::ABILITYMGR, "User id: %{public}d.", userId);
165     CHECK_POINTER(appMgrClient_);
166     appMgrClient_->KillProcessesByUserId(userId);
167 }
168 
KillProcessesByPids(std::vector<int32_t> & pids)169 void AppScheduler::KillProcessesByPids(std::vector<int32_t> &pids)
170 {
171     TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
172     CHECK_POINTER(appMgrClient_);
173     appMgrClient_->KillProcessesByPids(pids);
174 }
175 
AttachPidToParent(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callerToken)176 void AppScheduler::AttachPidToParent(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callerToken)
177 {
178     TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
179     CHECK_POINTER(appMgrClient_);
180     appMgrClient_->AttachPidToParent(token, callerToken);
181 }
182 
ConvertToAppAbilityState(const int32_t state)183 AppAbilityState AppScheduler::ConvertToAppAbilityState(const int32_t state)
184 {
185     AppExecFwk::AbilityState abilityState = static_cast<AppExecFwk::AbilityState>(state);
186     switch (abilityState) {
187         case AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND: {
188             return AppAbilityState::ABILITY_STATE_FOREGROUND;
189         }
190         case AppExecFwk::AbilityState::ABILITY_STATE_BACKGROUND: {
191             return AppAbilityState::ABILITY_STATE_BACKGROUND;
192         }
193         default:
194             return AppAbilityState::ABILITY_STATE_UNDEFINED;
195     }
196 }
197 
GetAbilityState() const198 AppAbilityState AppScheduler::GetAbilityState() const
199 {
200     return appAbilityState_;
201 }
202 
OnAbilityRequestDone(const sptr<IRemoteObject> & token,const AppExecFwk::AbilityState state)203 void AppScheduler::OnAbilityRequestDone(const sptr<IRemoteObject> &token, const AppExecFwk::AbilityState state)
204 {
205     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
206     TAG_LOGD(AAFwkTag::ABILITYMGR, "state:%{public}d", static_cast<int32_t>(state));
207     auto callback = callback_.lock();
208     CHECK_POINTER(callback);
209     appAbilityState_ = ConvertToAppAbilityState(static_cast<int32_t>(state));
210     callback->OnAbilityRequestDone(token, static_cast<int32_t>(state));
211 }
212 
NotifyConfigurationChange(const AppExecFwk::Configuration & config,int32_t userId)213 void AppScheduler::NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId)
214 {
215     auto callback = callback_.lock();
216     CHECK_POINTER(callback);
217     callback->NotifyConfigurationChange(config, userId);
218 }
219 
NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> & bundleInfos)220 void AppScheduler::NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
221 {
222     auto callback = callback_.lock();
223     CHECK_POINTER(callback);
224     callback->NotifyStartResidentProcess(bundleInfos);
225 }
226 
OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> & abilityTokens)227 void AppScheduler::OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens)
228 {
229     auto callback = callback_.lock();
230     CHECK_POINTER(callback);
231     callback->OnAppRemoteDied(abilityTokens);
232 }
233 
OnStartProcessFailed(sptr<IRemoteObject> token)234 void AppScheduler::OnStartProcessFailed(sptr<IRemoteObject> token)
235 {
236     auto callback = callback_.lock();
237     CHECK_POINTER(callback);
238     callback->OnStartProcessFailed(token);
239 }
240 
NotifyAppPreCache(int32_t pid,int32_t userId)241 void AppScheduler::NotifyAppPreCache(int32_t pid, int32_t userId)
242 {
243     auto callback = callback_.lock();
244     CHECK_POINTER(callback);
245     callback->NotifyAppPreCache(pid, userId);
246 }
247 
KillApplication(const std::string & bundleName,const bool clearPageStack)248 int AppScheduler::KillApplication(const std::string &bundleName, const bool clearPageStack)
249 {
250     TAG_LOGI(AAFwkTag::ABILITYMGR, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
251     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
252     int ret = (int)appMgrClient_->KillApplication(bundleName, clearPageStack);
253     if (ret != ERR_OK) {
254         TAG_LOGE(AAFwkTag::ABILITYMGR, "Fail to kill application.");
255         return INNER_ERR;
256     }
257 
258     return ERR_OK;
259 }
260 
ForceKillApplication(const std::string & bundleName,const int userId,const int appIndex)261 int AppScheduler::ForceKillApplication(const std::string &bundleName,
262     const int userId, const int appIndex)
263 {
264     TAG_LOGI(AAFwkTag::ABILITYMGR, "Called.");
265     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
266     int ret = (int)appMgrClient_->ForceKillApplication(bundleName, userId, appIndex);
267     if (ret != ERR_OK) {
268         TAG_LOGE(AAFwkTag::ABILITYMGR, "Fail to force kill application.");
269         return INNER_ERR;
270     }
271 
272     return ERR_OK;
273 }
274 
KillProcessesByAccessTokenId(const uint32_t accessTokenId)275 int AppScheduler::KillProcessesByAccessTokenId(const uint32_t accessTokenId)
276 {
277     TAG_LOGI(AAFwkTag::ABILITYMGR, "Called.");
278     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
279     int ret = (int)appMgrClient_->KillProcessesByAccessTokenId(accessTokenId);
280     if (ret != ERR_OK) {
281         TAG_LOGE(AAFwkTag::ABILITYMGR, "Fail to force kill application by accessTokenId.");
282         return INNER_ERR;
283     }
284 
285     return ERR_OK;
286 }
287 
KillApplicationByUid(const std::string & bundleName,int32_t uid,const std::string & reason)288 int AppScheduler::KillApplicationByUid(const std::string &bundleName, int32_t uid,
289     const std::string& reason)
290 {
291     TAG_LOGI(AAFwkTag::ABILITYMGR, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
292     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
293     int ret = (int)appMgrClient_->KillApplicationByUid(bundleName, uid, reason);
294     if (ret != ERR_OK) {
295         TAG_LOGE(AAFwkTag::ABILITYMGR, "Fail to kill application by uid.");
296         return INNER_ERR;
297     }
298 
299     return ERR_OK;
300 }
301 
AttachTimeOut(const sptr<IRemoteObject> & token)302 void AppScheduler::AttachTimeOut(const sptr<IRemoteObject> &token)
303 {
304     CHECK_POINTER(appMgrClient_);
305     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->AbilityAttachTimeOut(token));
306 }
307 
PrepareTerminate(const sptr<IRemoteObject> & token,bool clearMissionFlag)308 void AppScheduler::PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag)
309 {
310     CHECK_POINTER(appMgrClient_);
311     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->PrepareTerminate(token, clearMissionFlag));
312 }
313 
OnAppStateChanged(const AppExecFwk::AppProcessData & appData)314 void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData)
315 {
316     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
317     auto callback = callback_.lock();
318     CHECK_POINTER(callback);
319     AppInfo info;
320     for (const auto &list : appData.appDatas) {
321         AppData data;
322         data.appName = list.appName;
323         data.uid = list.uid;
324         info.appData.push_back(data);
325     }
326     info.processName = appData.processName;
327     info.state = static_cast<AppState>(appData.appState);
328     info.pid = appData.pid;
329     callback->OnAppStateChanged(info);
330 }
331 
GetRunningProcessInfoByToken(const sptr<IRemoteObject> & token,AppExecFwk::RunningProcessInfo & info)332 void AppScheduler::GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info)
333 {
334     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
335     CHECK_POINTER(appMgrClient_);
336     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->GetRunningProcessInfoByToken(token, info));
337 }
338 
GetRunningProcessInfoByPid(const pid_t pid,OHOS::AppExecFwk::RunningProcessInfo & info) const339 void AppScheduler::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const
340 {
341     CHECK_POINTER(appMgrClient_);
342     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->GetRunningProcessInfoByPid(pid, info));
343 }
344 
SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const345 void AppScheduler::SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const
346 {
347     CHECK_POINTER(appMgrClient_);
348     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetAbilityForegroundingFlagToAppRecord(pid));
349 }
350 
StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> & bundleInfos)351 void AppScheduler::StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos)
352 {
353     CHECK_POINTER(appMgrClient_);
354     appMgrClient_->StartupResidentProcess(bundleInfos);
355 }
356 
StartSpecifiedAbility(const AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,int32_t requestId)357 void AppScheduler::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
358     int32_t requestId)
359 {
360     CHECK_POINTER(appMgrClient_);
361     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->StartSpecifiedAbility(want, abilityInfo, requestId));
362 }
363 
OnAcceptWantResponse(const AAFwk::Want & want,const std::string & flag,int32_t requestId)364 void StartSpecifiedAbilityResponse::OnAcceptWantResponse(
365     const AAFwk::Want &want, const std::string &flag, int32_t requestId)
366 {
367     DelayedSingleton<AbilityManagerService>::GetInstance()->OnAcceptWantResponse(want, flag, requestId);
368 }
369 
OnTimeoutResponse(const AAFwk::Want & want,int32_t requestId)370 void StartSpecifiedAbilityResponse::OnTimeoutResponse(const AAFwk::Want &want, int32_t requestId)
371 {
372     DelayedSingleton<AbilityManagerService>::GetInstance()->OnStartSpecifiedAbilityTimeoutResponse(want, requestId);
373 }
374 
StartSpecifiedProcess(const AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,int32_t requestId)375 void AppScheduler::StartSpecifiedProcess(
376     const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId)
377 {
378     CHECK_POINTER(appMgrClient_);
379     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->StartSpecifiedProcess(want, abilityInfo, requestId));
380 }
381 
OnNewProcessRequestResponse(const AAFwk::Want & want,const std::string & flag,int32_t requestId)382 void StartSpecifiedAbilityResponse::OnNewProcessRequestResponse(
383     const AAFwk::Want &want, const std::string &flag, int32_t requestId)
384 {
385     DelayedSingleton<AbilityManagerService>::GetInstance()->OnStartSpecifiedProcessResponse(want, flag, requestId);
386 }
387 
OnNewProcessRequestTimeoutResponse(const AAFwk::Want & want,int32_t requestId)388 void StartSpecifiedAbilityResponse::OnNewProcessRequestTimeoutResponse(const AAFwk::Want &want, int32_t requestId)
389 {
390     DelayedSingleton<AbilityManagerService>::GetInstance()->OnStartSpecifiedProcessTimeoutResponse(want, requestId);
391 }
392 
GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> & info)393 int AppScheduler::GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info)
394 {
395     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
396     return static_cast<int>(appMgrClient_->GetAllRunningProcesses(info));
397 }
398 
GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> & info,int32_t userId)399 int AppScheduler::GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> &info, int32_t userId)
400 {
401     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
402     return static_cast<int>(appMgrClient_->GetProcessRunningInfosByUserId(info, userId));
403 }
404 
ConvertAppState(const AppState & state)405 std::string AppScheduler::ConvertAppState(const AppState &state)
406 {
407     return StateUtils::AppStateToStrMap(state);
408 }
409 
StartUserTest(const Want & want,const sptr<IRemoteObject> & observer,const AppExecFwk::BundleInfo & bundleInfo,int32_t userId)410 int AppScheduler::StartUserTest(
411     const Want &want, const sptr<IRemoteObject> &observer, const AppExecFwk::BundleInfo &bundleInfo, int32_t userId)
412 {
413     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
414     int ret = appMgrClient_->StartUserTestProcess(want, observer, bundleInfo, userId);
415     if (ret != ERR_OK) {
416         TAG_LOGE(AAFwkTag::ABILITYMGR, "Fail to start user test.");
417         return INNER_ERR;
418     }
419     return ERR_OK;
420 }
421 
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)422 int AppScheduler::FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName)
423 {
424     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
425     int ret = appMgrClient_->FinishUserTest(msg, resultCode, bundleName);
426     if (ret != ERR_OK) {
427         TAG_LOGE(AAFwkTag::ABILITYMGR, "Fail to start user test.");
428         return INNER_ERR;
429     }
430     return ERR_OK;
431 }
432 
UpdateConfiguration(const AppExecFwk::Configuration & config)433 int AppScheduler::UpdateConfiguration(const AppExecFwk::Configuration &config)
434 {
435     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
436     auto ret = static_cast<int>(appMgrClient_->UpdateConfiguration(config));
437     if (ret != ERR_OK) {
438         TAG_LOGE(AAFwkTag::ABILITYMGR, "UpdateConfiguration failed.");
439         return INNER_ERR;
440     }
441 
442     return ERR_OK;
443 }
444 
GetConfiguration(AppExecFwk::Configuration & config)445 int AppScheduler::GetConfiguration(AppExecFwk::Configuration &config)
446 {
447     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
448     auto ret = static_cast<int>(appMgrClient_->GetConfiguration(config));
449     if (ret != ERR_OK) {
450         TAG_LOGE(AAFwkTag::ABILITYMGR, "GetConfiguration failed.");
451         return INNER_ERR;
452     }
453 
454     return ERR_OK;
455 }
456 
GetAbilityRecordsByProcessID(const int pid,std::vector<sptr<IRemoteObject>> & tokens)457 int AppScheduler::GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens)
458 {
459     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
460     auto ret = static_cast<int>(appMgrClient_->GetAbilityRecordsByProcessID(pid, tokens));
461     if (ret != ERR_OK) {
462         TAG_LOGE(AAFwkTag::ABILITYMGR, "GetAbilityRecordsByProcessID failed.");
463         return INNER_ERR;
464     }
465 
466     return ERR_OK;
467 }
468 
GetApplicationInfoByProcessID(const int pid,AppExecFwk::ApplicationInfo & application,bool & debug)469 int AppScheduler::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug)
470 {
471     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
472     auto ret = static_cast<int>(appMgrClient_->GetApplicationInfoByProcessID(pid, application, debug));
473     if (ret != ERR_OK) {
474         TAG_LOGE(AAFwkTag::ABILITYMGR, "GetApplicationInfoByProcessID failed.");
475         return ret;
476     }
477 
478     return ERR_OK;
479 }
480 
NotifyAppMgrRecordExitReason(int32_t pid,int32_t reason,const std::string & exitMsg)481 int32_t AppScheduler::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg)
482 {
483     if (pid < 0) {
484         TAG_LOGW(AAFwkTag::ABILITYMGR, "NotifyAppMgrRecordExitReason failed, pid <= 0.");
485         return ERR_INVALID_VALUE;
486     }
487     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
488     auto ret = static_cast<int32_t>(IN_PROCESS_CALL(appMgrClient_->NotifyAppMgrRecordExitReason(pid, reason, exitMsg)));
489     if (ret != ERR_OK) {
490         TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyAppMgrRecordExitReason failed.");
491         return ret;
492     }
493     return ERR_OK;
494 }
495 
GetBundleNameByPid(const int pid,std::string & bundleName,int32_t & uid)496 int32_t AppScheduler::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid)
497 {
498     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
499     int32_t ret = static_cast<int32_t>(IN_PROCESS_CALL(appMgrClient_->GetBundleNameByPid(pid, bundleName, uid)));
500     if (ret != ERR_OK) {
501         TAG_LOGE(AAFwkTag::ABILITYMGR, "Get bundle name failed.");
502         return INNER_ERR;
503     }
504     return ERR_OK;
505 }
506 
SetCurrentUserId(const int32_t userId)507 void AppScheduler::SetCurrentUserId(const int32_t userId)
508 {
509     CHECK_POINTER(appMgrClient_);
510     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetCurrentUserId(userId));
511 }
512 
SetEnableStartProcessFlagByUserId(int32_t userId,bool enableStartProcess)513 void AppScheduler::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess)
514 {
515     CHECK_POINTER(appMgrClient_);
516     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetEnableStartProcessFlagByUserId(userId, enableStartProcess));
517 }
518 
NotifyFault(const AppExecFwk::FaultData & faultData)519 int32_t AppScheduler::NotifyFault(const AppExecFwk::FaultData &faultData)
520 {
521     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
522     auto ret = static_cast<int>(appMgrClient_->NotifyAppFault(faultData));
523     if (ret != ERR_OK) {
524         TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyAppFault failed.");
525         return INNER_ERR;
526     }
527 
528     return ERR_OK;
529 }
530 
RegisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> & listener)531 int32_t AppScheduler::RegisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> &listener)
532 {
533     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
534     auto ret = static_cast<int32_t>(appMgrClient_->RegisterAppDebugListener(listener));
535     if (ret != ERR_OK) {
536         TAG_LOGE(AAFwkTag::ABILITYMGR, "Register app debug listener failed.");
537         return INNER_ERR;
538     }
539     return ERR_OK;
540 }
541 
UnregisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> & listener)542 int32_t AppScheduler::UnregisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> &listener)
543 {
544     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
545     auto ret = static_cast<int32_t>(appMgrClient_->UnregisterAppDebugListener(listener));
546     if (ret != ERR_OK) {
547         TAG_LOGE(AAFwkTag::ABILITYMGR, "Unregister app debug listener failed.");
548         return INNER_ERR;
549     }
550     return ERR_OK;
551 }
552 
AttachAppDebug(const std::string & bundleName)553 int32_t AppScheduler::AttachAppDebug(const std::string &bundleName)
554 {
555     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
556     auto ret = static_cast<int32_t>(appMgrClient_->AttachAppDebug(bundleName));
557     if (ret != ERR_OK) {
558         TAG_LOGE(AAFwkTag::ABILITYMGR, "Attach app debug failed.");
559         return INNER_ERR;
560     }
561     return ERR_OK;
562 }
563 
DetachAppDebug(const std::string & bundleName)564 int32_t AppScheduler::DetachAppDebug(const std::string &bundleName)
565 {
566     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
567     auto ret = static_cast<int32_t>(appMgrClient_->DetachAppDebug(bundleName));
568     if (ret != ERR_OK) {
569         TAG_LOGE(AAFwkTag::ABILITYMGR, "Detach app debug failed.");
570         return INNER_ERR;
571     }
572     return ERR_OK;
573 }
574 
RegisterAbilityDebugResponse(const sptr<AppExecFwk::IAbilityDebugResponse> & response)575 int32_t AppScheduler::RegisterAbilityDebugResponse(const sptr<AppExecFwk::IAbilityDebugResponse> &response)
576 {
577     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
578     auto ret = static_cast<int32_t>(appMgrClient_->RegisterAbilityDebugResponse(response));
579     if (ret != ERR_OK) {
580         TAG_LOGE(AAFwkTag::ABILITYMGR, "Register ability debug response failed.");
581         return INNER_ERR;
582     }
583     return ERR_OK;
584 }
585 
IsAttachDebug(const std::string & bundleName)586 bool AppScheduler::IsAttachDebug(const std::string &bundleName)
587 {
588     CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
589     auto ret = static_cast<int32_t>(appMgrClient_->IsAttachDebug(bundleName));
590     if (ret != ERR_OK) {
591         TAG_LOGE(AAFwkTag::ABILITYMGR, "Call is attach debug failed.");
592         return INNER_ERR;
593     }
594     return ERR_OK;
595 }
596 
ClearProcessByToken(sptr<IRemoteObject> token) const597 void AppScheduler::ClearProcessByToken(sptr<IRemoteObject> token) const
598 {
599     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
600     CHECK_POINTER(appMgrClient_);
601     appMgrClient_->ClearProcessByToken(token);
602 }
603 
IsMemorySizeSufficent() const604 bool AppScheduler::IsMemorySizeSufficent() const
605 {
606     if (!appMgrClient_) {
607         TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
608         return true;
609     }
610     return appMgrClient_->IsMemorySizeSufficent();
611 }
612 
AttachedToStatusBar(const sptr<IRemoteObject> & token)613 void AppScheduler::AttachedToStatusBar(const sptr<IRemoteObject> &token)
614 {
615     TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
616     CHECK_POINTER(appMgrClient_);
617     appMgrClient_->AttachedToStatusBar(token);
618 }
619 
BlockProcessCacheByPids(const std::vector<int32_t> & pids)620 void AppScheduler::BlockProcessCacheByPids(const std::vector<int32_t> &pids)
621 {
622     TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
623     CHECK_POINTER(appMgrClient_);
624     appMgrClient_->BlockProcessCacheByPids(pids);
625 }
626 
IsKilledForUpgradeWeb(const std::string & bundleName)627 bool AppScheduler::IsKilledForUpgradeWeb(const std::string &bundleName)
628 {
629     if (!appMgrClient_) {
630         TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
631         return false;
632     }
633     return appMgrClient_->IsKilledForUpgradeWeb(bundleName);
634 }
635 
CleanAbilityByUserRequest(const sptr<IRemoteObject> & token)636 bool AppScheduler::CleanAbilityByUserRequest(const sptr<IRemoteObject> &token)
637 {
638     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
639     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
640     if (!appMgrClient_) {
641         TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
642         return false;
643     }
644     return IN_PROCESS_CALL(appMgrClient_->CleanAbilityByUserRequest(token));
645 }
646 
IsProcessContainsOnlyUIAbility(const pid_t pid)647 bool AppScheduler::IsProcessContainsOnlyUIAbility(const pid_t pid)
648 {
649     if (!appMgrClient_) {
650         TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
651         return false;
652     }
653     return appMgrClient_->IsProcessContainsOnlyUIAbility(pid);
654 }
IsProcessAttached(sptr<IRemoteObject> token) const655 bool AppScheduler::IsProcessAttached(sptr<IRemoteObject> token) const
656 {
657     if (!appMgrClient_) {
658         TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
659         return false;
660     }
661     return appMgrClient_->IsProcessAttached(token);
662 }
663 
SendAppSpawnUninstallDebugHapMsg(int32_t userId)664 void AppScheduler::SendAppSpawnUninstallDebugHapMsg(int32_t userId)
665 {
666     CHECK_POINTER(appMgrClient_);
667     IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SendAppSpawnUninstallDebugHapMsg(userId));
668 }
669 
SetProcessCacheStatus(int32_t pid,bool isSupport)670 void AppScheduler::SetProcessCacheStatus(int32_t pid, bool isSupport)
671 {
672     if (!appMgrClient_) {
673         TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
674         return;
675     }
676     appMgrClient_->SetSupportedProcessCache(pid, isSupport);
677 }
678 } // namespace AAFwk
679 }  // namespace OHOS
680