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