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 "ability_window_configuration.h"
17 #include "app_running_record.h"
18 #include "render_record.h"
19 #include "app_mgr_service_inner.h"
20 #include "error_msg_util.h"
21 #include "event_report.h"
22 #include "exit_resident_process_manager.h"
23 #include "freeze_util.h"
24 #include "hitrace_meter.h"
25 #include "hilog_tag_wrapper.h"
26 #include "ui_extension_utils.h"
27 #include "app_mgr_service_const.h"
28 #include "app_mgr_service_dump_error_code.h"
29 #include "cache_process_manager.h"
30 #include "hisysevent.h"
31 #ifdef SUPPORT_SCREEN
32 #include "window_visibility_info.h"
33 #endif //SUPPORT_SCREEN
34 #ifdef SUPPORT_UPMS
35 #include "uri_permission_manager_client.h"
36 #endif // SUPPORT_UPMS
37 namespace OHOS {
38 namespace AppExecFwk {
39 namespace {
40 constexpr int64_t NANOSECONDS = 1000000000; // NANOSECONDS mean 10^9 nano second
41 constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 millias second
42 constexpr int32_t MAX_RESTART_COUNT = 3;
43 constexpr int32_t RESTART_INTERVAL_TIME = 120000;
44 constexpr int32_t HALF_TIMEOUT = 2;
45 constexpr const char* LAUNCHER_NAME = "com.ohos.sceneboard";
46 constexpr const char *EVENT_KEY_VERSION_NAME = "VERSION_NAME";
47 constexpr const char *EVENT_KEY_VERSION_CODE = "VERSION_CODE";
48 constexpr const char *EVENT_KEY_BUNDLE_NAME = "BUNDLE_NAME";
49 constexpr const char *EVENT_KEY_SUPPORT_STATE = "SUPPORT_STATE";
50 constexpr uint32_t PROCESS_MODE_RUN_WITH_MAIN_PROCESS =
51 1 << static_cast<uint32_t>(AppExecFwk::ExtensionProcessMode::RUN_WITH_MAIN_PROCESS);
52 }
53
54 int64_t AppRunningRecord::appEventId_ = 0;
55
56
AppRunningRecord(const std::shared_ptr<ApplicationInfo> & info,const int32_t recordId,const std::string & processName)57 AppRunningRecord::AppRunningRecord(
58 const std::shared_ptr<ApplicationInfo> &info, const int32_t recordId, const std::string &processName)
59 : appRecordId_(recordId), processName_(processName)
60 {
61 if (info) {
62 appInfo_ = info;
63 mainBundleName_ = info->bundleName;
64 isLauncherApp_ = info->isLauncherApp;
65 mainAppName_ = info->name;
66 }
67 priorityObject_ = std::make_shared<PriorityObject>();
68
69 struct timespec t;
70 t.tv_sec = 0;
71 t.tv_nsec = 0;
72 clock_gettime(CLOCK_MONOTONIC, &t);
73 startTimeMillis_ = static_cast<int64_t>(((t.tv_sec) * NANOSECONDS + t.tv_nsec) / MICROSECONDS);
74 }
75
SetApplicationClient(const sptr<IAppScheduler> & thread)76 void AppRunningRecord::SetApplicationClient(const sptr<IAppScheduler> &thread)
77 {
78 if (!appLifeCycleDeal_) {
79 appLifeCycleDeal_ = std::make_shared<AppLifeCycleDeal>();
80 }
81 appLifeCycleDeal_->SetApplicationClient(thread);
82
83 auto moduleRecordList = GetAllModuleRecord();
84 if (moduleRecordList.empty()) {
85 TAG_LOGD(AAFwkTag::APPMGR, "moduleRecordList is empty");
86 return;
87 }
88 for (const auto &moduleRecord : moduleRecordList) {
89 moduleRecord->SetApplicationClient(appLifeCycleDeal_);
90 }
91 }
92
GetBundleName() const93 const std::string &AppRunningRecord::GetBundleName() const
94 {
95 return mainBundleName_;
96 }
97
GetCallerPid() const98 int32_t AppRunningRecord::GetCallerPid() const
99 {
100 return callerPid_;
101 }
102
SetCallerPid(int32_t pid)103 void AppRunningRecord::SetCallerPid(int32_t pid)
104 {
105 callerPid_ = pid;
106 }
107
GetCallerUid() const108 int32_t AppRunningRecord::GetCallerUid() const
109 {
110 return callerUid_;
111 }
112
SetCallerUid(int32_t uid)113 void AppRunningRecord::SetCallerUid(int32_t uid)
114 {
115 callerUid_ = uid;
116 }
117
GetCallerTokenId() const118 int32_t AppRunningRecord::GetCallerTokenId() const
119 {
120 return callerTokenId_;
121 }
122
SetCallerTokenId(int32_t tokenId)123 void AppRunningRecord::SetCallerTokenId(int32_t tokenId)
124 {
125 callerTokenId_ = tokenId;
126 }
127
IsLauncherApp() const128 bool AppRunningRecord::IsLauncherApp() const
129 {
130 return isLauncherApp_;
131 }
132
GetRecordId() const133 int32_t AppRunningRecord::GetRecordId() const
134 {
135 return appRecordId_;
136 }
137
GetName() const138 const std::string &AppRunningRecord::GetName() const
139 {
140 return mainAppName_;
141 }
142
GetSignCode() const143 const std::string &AppRunningRecord::GetSignCode() const
144 {
145 return signCode_;
146 }
147
SetSignCode(const std::string & signCode)148 void AppRunningRecord::SetSignCode(const std::string &signCode)
149 {
150 signCode_ = signCode;
151 }
152
GetJointUserId() const153 const std::string &AppRunningRecord::GetJointUserId() const
154 {
155 return jointUserId_;
156 }
157
SetJointUserId(const std::string & jointUserId)158 void AppRunningRecord::SetJointUserId(const std::string &jointUserId)
159 {
160 jointUserId_ = jointUserId;
161 }
162
GetProcessName() const163 const std::string &AppRunningRecord::GetProcessName() const
164 {
165 return processName_;
166 }
167
SetSpecifiedProcessFlag(const std::string & flag)168 void AppRunningRecord::SetSpecifiedProcessFlag(const std::string &flag)
169 {
170 specifiedProcessFlag_ = flag;
171 }
172
GetSpecifiedProcessFlag() const173 const std::string &AppRunningRecord::GetSpecifiedProcessFlag() const
174 {
175 return specifiedProcessFlag_;
176 }
SetCustomProcessFlag(const std::string & flag)177 void AppRunningRecord::SetCustomProcessFlag(const std::string &flag)
178 {
179 customProcessFlag_ = flag;
180 }
181
GetCustomProcessFlag() const182 const std::string &AppRunningRecord::GetCustomProcessFlag() const
183 {
184 return customProcessFlag_;
185 }
186
GetUid() const187 int32_t AppRunningRecord::GetUid() const
188 {
189 return mainUid_;
190 }
191
SetUid(const int32_t uid)192 void AppRunningRecord::SetUid(const int32_t uid)
193 {
194 mainUid_ = uid;
195 }
196
GetUserId() const197 int32_t AppRunningRecord::GetUserId() const
198 {
199 return mainUid_ / BASE_USER_RANGE;
200 }
201
GetState() const202 ApplicationState AppRunningRecord::GetState() const
203 {
204 return curState_;
205 }
206
SetState(const ApplicationState state)207 void AppRunningRecord::SetState(const ApplicationState state)
208 {
209 if (state >= ApplicationState::APP_STATE_END && state != ApplicationState::APP_STATE_CACHED) {
210 TAG_LOGE(AAFwkTag::APPMGR, "Invalid application state");
211 return;
212 }
213 if (state == ApplicationState::APP_STATE_FOREGROUND || state == ApplicationState::APP_STATE_BACKGROUND) {
214 restartResidentProcCount_ = MAX_RESTART_COUNT;
215 }
216 std::string foreTag = "ForeApp:";
217 if (state == ApplicationState::APP_STATE_FOREGROUND) {
218 StartAsyncTrace(HITRACE_TAG_APP, foreTag + mainBundleName_, 0);
219 } else if (state == ApplicationState::APP_STATE_BACKGROUND) {
220 FinishAsyncTrace(HITRACE_TAG_APP, foreTag + mainBundleName_, 0);
221 }
222 curState_ = state;
223 }
224
SetRestartTimeMillis(const int64_t restartTimeMillis)225 void AppRunningRecord::SetRestartTimeMillis(const int64_t restartTimeMillis)
226 {
227 restartTimeMillis_ = restartTimeMillis;
228 }
229
GetAppInfoList()230 const std::list<std::shared_ptr<ApplicationInfo>> AppRunningRecord::GetAppInfoList()
231 {
232 std::list<std::shared_ptr<ApplicationInfo>> appInfoList;
233 std::lock_guard<ffrt::mutex> appInfosLock(appInfosLock_);
234 for (const auto &item : appInfos_) {
235 appInfoList.push_back(item.second);
236 }
237 return appInfoList;
238 }
239
SetAppIdentifier(const std::string & appIdentifier)240 void AppRunningRecord::SetAppIdentifier(const std::string &appIdentifier)
241 {
242 appIdentifier_ = appIdentifier;
243 }
244
GetAppIdentifier() const245 const std::string &AppRunningRecord::GetAppIdentifier() const
246 {
247 return appIdentifier_;
248 }
249
GetAbilities()250 const std::map<const sptr<IRemoteObject>, std::shared_ptr<AbilityRunningRecord>> AppRunningRecord::GetAbilities()
251 {
252 std::map<const sptr<IRemoteObject>, std::shared_ptr<AbilityRunningRecord>> abilitiesMap;
253 auto moduleRecordList = GetAllModuleRecord();
254 for (const auto &moduleRecord : moduleRecordList) {
255 auto abilities = moduleRecord->GetAbilities();
256 abilitiesMap.insert(abilities.begin(), abilities.end());
257 }
258 return abilitiesMap;
259 }
260
GetApplicationClient() const261 sptr<IAppScheduler> AppRunningRecord::GetApplicationClient() const
262 {
263 return (appLifeCycleDeal_ ? appLifeCycleDeal_->GetApplicationClient() : nullptr);
264 }
265
GetAbilityRunningRecord(const int64_t eventId) const266 std::shared_ptr<AbilityRunningRecord> AppRunningRecord::GetAbilityRunningRecord(const int64_t eventId) const
267 {
268 TAG_LOGD(AAFwkTag::APPMGR, "called");
269 auto moduleRecordList = GetAllModuleRecord();
270 for (const auto &moduleRecord : moduleRecordList) {
271 auto abilityRecord = moduleRecord->GetAbilityRunningRecord(eventId);
272 if (abilityRecord) {
273 return abilityRecord;
274 }
275 }
276
277 return nullptr;
278 }
279
RemoveModuleRecord(const std::shared_ptr<ModuleRunningRecord> & moduleRecord,bool isExtensionDebug)280 void AppRunningRecord::RemoveModuleRecord(
281 const std::shared_ptr<ModuleRunningRecord> &moduleRecord, bool isExtensionDebug)
282 {
283 TAG_LOGD(AAFwkTag::APPMGR, "called");
284
285 std::lock_guard<ffrt::mutex> hapModulesLock(hapModulesLock_);
286 for (auto &item : hapModules_) {
287 auto iter = std::find_if(item.second.begin(),
288 item.second.end(),
289 [&moduleRecord](const std::shared_ptr<ModuleRunningRecord> &record) { return moduleRecord == record; });
290 if (iter != item.second.end()) {
291 TAG_LOGD(AAFwkTag::APPMGR, "Removed a record.");
292 iter = item.second.erase(iter);
293 if (item.second.empty() && !isExtensionDebug) {
294 {
295 std::lock_guard<ffrt::mutex> appInfosLock(appInfosLock_);
296 TAG_LOGD(AAFwkTag::APPMGR, "Removed an appInfo.");
297 appInfos_.erase(item.first);
298 }
299 hapModules_.erase(item.first);
300 }
301 return;
302 }
303 }
304 }
305
LaunchApplication(const Configuration & config)306 void AppRunningRecord::LaunchApplication(const Configuration &config)
307 {
308 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
309 if (appLifeCycleDeal_ == nullptr) {
310 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
311 return;
312 }
313 auto scheduler = appLifeCycleDeal_->GetApplicationClient();
314 if (!scheduler) {
315 TAG_LOGE(AAFwkTag::APPMGR, "null appThread");
316 AddAppLifecycleEvent("AppRunningRecord::LaunchApplication; null scheduler");
317 return;
318 }
319 AppLaunchData launchData;
320 {
321 std::lock_guard<ffrt::mutex> appInfosLock(appInfosLock_);
322 auto moduleRecords = appInfos_.find(mainBundleName_);
323 if (moduleRecords != appInfos_.end()) {
324 launchData.SetApplicationInfo(*(moduleRecords->second));
325 }
326 }
327 ProcessInfo processInfo(processName_, GetPid());
328 processInfo.SetProcessType(processType_);
329 launchData.SetProcessInfo(processInfo);
330 launchData.SetRecordId(appRecordId_);
331 launchData.SetUId(mainUid_);
332 launchData.SetUserTestInfo(userTestRecord_);
333 launchData.SetAppIndex(appIndex_);
334 launchData.SetInstanceKey(instanceKey_);
335 launchData.SetDebugApp(isDebugApp_);
336 launchData.SetPerfCmd(perfCmd_);
337 launchData.SetErrorInfoEnhance(isErrorInfoEnhance_);
338 launchData.SetMultiThread(isMultiThread_);
339 launchData.SetJITEnabled(jitEnabled_);
340 launchData.SetNativeStart(isNativeStart_);
341 launchData.SetAppRunningUniqueId(std::to_string(startTimeMillis_));
342 launchData.SetIsNeedPreloadModule(isNeedPreloadModule_);
343 launchData.SetNWebPreload(isAllowedNWebPreload_);
344 launchData.SetPreloadModuleName(preloadModuleName_);
345 launchData.SetDebugFromLocal(isDebugFromLocal_);
346
347 TAG_LOGD(AAFwkTag::APPMGR, "%{public}s called,app is %{public}s.", __func__, GetName().c_str());
348 AddAppLifecycleEvent("AppRunningRecord::LaunchApplication");
349 AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast<uintptr_t>(scheduler.GetRefPtr()),
350 "LaunchApplication");
351 appLifeCycleDeal_->LaunchApplication(launchData, config);
352 }
353
UpdateApplicationInfoInstalled(const ApplicationInfo & appInfo,const std::string & moduleName)354 void AppRunningRecord::UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo, const std::string &moduleName)
355 {
356 if (!isStageBasedModel_) {
357 TAG_LOGI(AAFwkTag::APPMGR, "Current version than supports");
358 return;
359 }
360
361 if (appLifeCycleDeal_ == nullptr) {
362 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
363 return;
364 }
365 appLifeCycleDeal_->UpdateApplicationInfoInstalled(appInfo, moduleName);
366 }
367
AddAbilityStage()368 void AppRunningRecord::AddAbilityStage()
369 {
370 if (!isStageBasedModel_) {
371 TAG_LOGI(AAFwkTag::APPMGR, "Current version than supports");
372 return;
373 }
374 HapModuleInfo abilityStage;
375 if (GetTheModuleInfoNeedToUpdated(mainBundleName_, abilityStage)) {
376 auto timeout = GetAddStageTimeout();
377 SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_HALF_TIMEOUT_MSG, timeout / HALF_TIMEOUT);
378 SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG, timeout);
379 TAG_LOGI(AAFwkTag::APPMGR, "Current module : [%{public}s] | bundle : [%{public}s]",
380 abilityStage.moduleName.c_str(), mainBundleName_.c_str());
381 if (appLifeCycleDeal_ == nullptr) {
382 TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
383 return;
384 }
385 appLifeCycleDeal_->AddAbilityStage(abilityStage);
386 }
387 }
388
AddAbilityStageBySpecifiedAbility(const std::string & bundleName)389 bool AppRunningRecord::AddAbilityStageBySpecifiedAbility(const std::string &bundleName)
390 {
391 if (!eventHandler_) {
392 TAG_LOGE(AAFwkTag::APPMGR, "null eventHandler_");
393 return false;
394 }
395
396 HapModuleInfo hapModuleInfo;
397 if (GetTheModuleInfoNeedToUpdated(bundleName, hapModuleInfo)) {
398 if (!AppEventUtil::GetInstance().HasEvent(shared_from_this(),
399 AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG)) {
400 TAG_LOGI(
401 AAFwkTag::APPMGR, "ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG not exist");
402 auto timeout = GetAddStageTimeout();
403 SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_HALF_TIMEOUT_MSG, timeout / HALF_TIMEOUT);
404 SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG, timeout);
405 }
406 if (appLifeCycleDeal_ == nullptr) {
407 TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
408 return false;
409 }
410 appLifeCycleDeal_->AddAbilityStage(hapModuleInfo);
411 return true;
412 }
413 return false;
414 }
415
AddAbilityStageBySpecifiedProcess(const std::string & bundleName)416 void AppRunningRecord::AddAbilityStageBySpecifiedProcess(const std::string &bundleName)
417 {
418 TAG_LOGD(AAFwkTag::APPMGR, "call.");
419 if (!eventHandler_) {
420 TAG_LOGE(AAFwkTag::APPMGR, "null eventHandler_");
421 return;
422 }
423
424 HapModuleInfo hapModuleInfo;
425 if (GetTheModuleInfoNeedToUpdated(bundleName, hapModuleInfo)) {
426 auto timeout = GetAddStageTimeout();
427 SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_HALF_TIMEOUT_MSG, timeout / HALF_TIMEOUT);
428 SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG, timeout);
429 if (appLifeCycleDeal_ == nullptr) {
430 TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
431 return;
432 }
433 appLifeCycleDeal_->AddAbilityStage(hapModuleInfo);
434 }
435 }
436
AddAbilityStageDone()437 void AppRunningRecord::AddAbilityStageDone()
438 {
439 TAG_LOGI(AAFwkTag::APPMGR, "bundle %{public}s", mainBundleName_.c_str());
440 RemoveEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG);
441 RemoveEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_HALF_TIMEOUT_MSG);
442 RemoveEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG);
443 RemoveEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_HALF_TIMEOUT_MSG);
444 SetModuleLoaded(moduleName_);
445
446 // Should proceed to the next notification
447 if (IsStartSpecifiedAbility()) {
448 ScheduleAcceptWant(moduleName_);
449 return;
450 }
451
452 if (IsNewProcessRequest()) {
453 TAG_LOGD(AAFwkTag::APPMGR, "ScheduleNewProcessRequest.");
454 ScheduleNewProcessRequest(GetNewProcessRequestWant(), moduleName_);
455 return;
456 }
457
458 AddAbilityStage();
459 }
460
SetModuleLoaded(const std::string & moduleName) const461 void AppRunningRecord::SetModuleLoaded(const std::string &moduleName) const
462 {
463 auto moduleRecordList = GetAllModuleRecord();
464 for (const auto &item : moduleRecordList) {
465 if (item && item->GetModuleName() == moduleName) {
466 item->SetLoaded();
467 break;
468 }
469 }
470 }
471
LaunchAbility(const std::shared_ptr<AbilityRunningRecord> & ability)472 void AppRunningRecord::LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability)
473 {
474 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
475 if (appLifeCycleDeal_ == nullptr) {
476 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
477 return;
478 }
479 if (!ability || !ability->GetToken()) {
480 TAG_LOGE(AAFwkTag::APPMGR, "null abilityRecord or abilityToken");
481 return;
482 }
483
484 auto moduleRecord = GetModuleRunningRecordByToken(ability->GetToken());
485 if (!moduleRecord) {
486 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
487 return;
488 }
489
490 moduleRecord->LaunchAbility(ability);
491 }
492
ScheduleTerminate()493 void AppRunningRecord::ScheduleTerminate()
494 {
495 auto timeout = AMSEventHandler::TERMINATE_APPLICATION_TIMEOUT;
496 SendEvent(AMSEventHandler::TERMINATE_APPLICATION_HALF_TIMEOUT_MSG, timeout / HALF_TIMEOUT);
497 SendEvent(AMSEventHandler::TERMINATE_APPLICATION_TIMEOUT_MSG, timeout);
498 if (appLifeCycleDeal_ == nullptr) {
499 TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
500 return;
501 }
502 bool isLastProcess = false;
503 auto serviceInner = appMgrServiceInner_.lock();
504 if (serviceInner != nullptr) {
505 isLastProcess = serviceInner->IsFinalAppProcessByBundleName(GetBundleName());
506 }
507 appLifeCycleDeal_->ScheduleTerminate(isLastProcess);
508 }
509
LaunchPendingAbilities()510 void AppRunningRecord::LaunchPendingAbilities()
511 {
512 TAG_LOGI(AAFwkTag::APPMGR, "Launch pending abilities.");
513 AddAppLifecycleEvent("AppRunningRecord::LaunchPendingAbilities");
514 auto moduleRecordList = GetAllModuleRecord();
515 if (moduleRecordList.empty()) {
516 TAG_LOGE(AAFwkTag::APPMGR, "empty moduleRecordList");
517 return;
518 }
519 for (const auto &moduleRecord : moduleRecordList) {
520 moduleRecord->SetApplicationClient(appLifeCycleDeal_);
521 moduleRecord->LaunchPendingAbilities();
522 }
523 }
524
ScheduleForegroundRunning()525 bool AppRunningRecord::ScheduleForegroundRunning()
526 {
527 SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_FOREGROUNDING);
528 if (appLifeCycleDeal_) {
529 AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning");
530 auto scheduler = appLifeCycleDeal_->GetApplicationClient();
531 if (!scheduler) {
532 AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning; null scheduler");
533 return false;
534 }
535 AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast<uintptr_t>(scheduler.GetRefPtr()),
536 "ScheduleForegroundRunning");
537 return appLifeCycleDeal_->ScheduleForegroundRunning();
538 }
539 return false;
540 }
541
ScheduleBackgroundRunning()542 void AppRunningRecord::ScheduleBackgroundRunning()
543 {
544 SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_BACKGROUNDING);
545 int32_t recordId = GetRecordId();
546 auto serviceInner = appMgrServiceInner_;
547 auto appbackgroundtask = [recordId, serviceInner]() {
548 auto serviceInnerObj = serviceInner.lock();
549 if (serviceInnerObj == nullptr) {
550 TAG_LOGW(AAFwkTag::APPMGR, "APPManager is invalid");
551 return;
552 }
553 TAG_LOGE(AAFwkTag::APPMGR, "APPManager move timeout");
554 serviceInnerObj->ApplicationBackgrounded(recordId);
555 };
556 auto taskName = std::string("appbackground_") + std::to_string(recordId);
557 if (taskHandler_) {
558 taskHandler_->CancelTask(taskName);
559 }
560 PostTask(taskName, AMSEventHandler::BACKGROUND_APPLICATION_TIMEOUT, appbackgroundtask);
561 if (appLifeCycleDeal_) {
562 AddAppLifecycleEvent("AppRunningRecord::ScheduleBackgroundRunning");
563 appLifeCycleDeal_->ScheduleBackgroundRunning();
564 }
565 isAbilityForegrounding_.store(false);
566 }
567
ScheduleProcessSecurityExit()568 void AppRunningRecord::ScheduleProcessSecurityExit()
569 {
570 if (appLifeCycleDeal_) {
571 auto appRecord = shared_from_this();
572 DelayedSingleton<CacheProcessManager>::GetInstance()->PrepareActivateCache(appRecord);
573 appLifeCycleDeal_->ScheduleProcessSecurityExit();
574 }
575 }
576
ScheduleClearPageStack()577 void AppRunningRecord::ScheduleClearPageStack()
578 {
579 if (appLifeCycleDeal_) {
580 appLifeCycleDeal_->ScheduleClearPageStack();
581 }
582 }
583
ScheduleTrimMemory()584 void AppRunningRecord::ScheduleTrimMemory()
585 {
586 if (appLifeCycleDeal_ && priorityObject_) {
587 appLifeCycleDeal_->ScheduleTrimMemory(priorityObject_->GetTimeLevel());
588 }
589 }
590
ScheduleMemoryLevel(int32_t level)591 void AppRunningRecord::ScheduleMemoryLevel(int32_t level)
592 {
593 if (appLifeCycleDeal_) {
594 appLifeCycleDeal_->ScheduleMemoryLevel(level);
595 }
596 }
597
ScheduleHeapMemory(const int32_t pid,OHOS::AppExecFwk::MallocInfo & mallocInfo)598 void AppRunningRecord::ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
599 {
600 if (appLifeCycleDeal_) {
601 appLifeCycleDeal_->ScheduleHeapMemory(pid, mallocInfo);
602 }
603 }
604
ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo & info)605 void AppRunningRecord::ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info)
606 {
607 if (appLifeCycleDeal_) {
608 appLifeCycleDeal_->ScheduleJsHeapMemory(info);
609 }
610 }
611
LowMemoryWarning()612 void AppRunningRecord::LowMemoryWarning()
613 {
614 if (appLifeCycleDeal_) {
615 appLifeCycleDeal_->LowMemoryWarning();
616 }
617 }
618
AddModules(const std::shared_ptr<ApplicationInfo> & appInfo,const std::vector<HapModuleInfo> & moduleInfos)619 void AppRunningRecord::AddModules(
620 const std::shared_ptr<ApplicationInfo> &appInfo, const std::vector<HapModuleInfo> &moduleInfos)
621 {
622 TAG_LOGD(AAFwkTag::APPMGR, "Add modules");
623
624 if (moduleInfos.empty()) {
625 TAG_LOGI(AAFwkTag::APPMGR, "empty moduleInfos");
626 return;
627 }
628
629 for (auto &iter : moduleInfos) {
630 AddModule(appInfo, nullptr, nullptr, iter, nullptr, 0);
631 }
632 }
633
AddModule(std::shared_ptr<ApplicationInfo> appInfo,std::shared_ptr<AbilityInfo> abilityInfo,sptr<IRemoteObject> token,const HapModuleInfo & hapModuleInfo,std::shared_ptr<AAFwk::Want> want,int32_t abilityRecordId)634 void AppRunningRecord::AddModule(std::shared_ptr<ApplicationInfo> appInfo,
635 std::shared_ptr<AbilityInfo> abilityInfo, sptr<IRemoteObject> token,
636 const HapModuleInfo &hapModuleInfo, std::shared_ptr<AAFwk::Want> want, int32_t abilityRecordId)
637 {
638 TAG_LOGD(AAFwkTag::APPMGR, "called");
639
640 if (!appInfo) {
641 TAG_LOGE(AAFwkTag::APPMGR, "null appInfo");
642 return;
643 }
644
645 std::shared_ptr<ModuleRunningRecord> moduleRecord;
646 std::lock_guard<ffrt::mutex> hapModulesLock(hapModulesLock_);
647 const auto &iter = hapModules_.find(appInfo->bundleName);
648 if (iter != hapModules_.end()) {
649 moduleRecord = GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName);
650 if (!moduleRecord) {
651 moduleRecord = std::make_shared<ModuleRunningRecord>(appInfo, eventHandler_);
652 iter->second.push_back(moduleRecord);
653 moduleRecord->Init(hapModuleInfo, appIndex_, appMgrServiceInner_, appLifeCycleDeal_);
654 }
655 } else {
656 moduleRecord = std::make_shared<ModuleRunningRecord>(appInfo, eventHandler_);
657 std::vector<std::shared_ptr<ModuleRunningRecord>> moduleList;
658 moduleList.push_back(moduleRecord);
659 hapModules_.emplace(appInfo->bundleName, moduleList);
660 {
661 std::lock_guard<ffrt::mutex> appInfosLock(appInfosLock_);
662 appInfos_.emplace(appInfo->bundleName, appInfo);
663 }
664 moduleRecord->Init(hapModuleInfo, appIndex_, appMgrServiceInner_, appLifeCycleDeal_);
665 }
666
667 if (!abilityInfo || !token) {
668 TAG_LOGE(AAFwkTag::APPMGR, "null abilityInfo or token");
669 return;
670 }
671 moduleRecord->AddAbility(token, abilityInfo, want, abilityRecordId);
672
673 return;
674 }
675
GetModuleRecordByModuleName(const std::string & bundleName,const std::string & moduleName)676 std::shared_ptr<ModuleRunningRecord> AppRunningRecord::GetModuleRecordByModuleName(
677 const std::string &bundleName, const std::string &moduleName)
678 {
679 TAG_LOGD(AAFwkTag::APPMGR, "called");
680 auto moduleRecords = hapModules_.find(bundleName);
681 if (moduleRecords != hapModules_.end()) {
682 for (auto &iter : moduleRecords->second) {
683 if (iter->GetModuleName() == moduleName) {
684 return iter;
685 }
686 }
687 }
688
689 return nullptr;
690 }
691
StateChangedNotifyObserver(const std::shared_ptr<AbilityRunningRecord> & ability,int32_t state,bool isAbility,bool isFromWindowFocusChanged)692 void AppRunningRecord::StateChangedNotifyObserver(const std::shared_ptr<AbilityRunningRecord> &ability,
693 int32_t state, bool isAbility, bool isFromWindowFocusChanged)
694 {
695 if (ability == nullptr) {
696 TAG_LOGE(AAFwkTag::APPMGR, "null ability");
697 return;
698 }
699 auto abilityInfo = ability->GetAbilityInfo();
700 if (abilityInfo == nullptr) {
701 TAG_LOGE(AAFwkTag::APPMGR, "null abilityInfo");
702 return;
703 }
704 AbilityStateData abilityStateData;
705 abilityStateData.bundleName = abilityInfo->applicationInfo.bundleName;
706 abilityStateData.moduleName = abilityInfo->moduleName;
707 abilityStateData.abilityName = ability->GetName();
708 abilityStateData.pid = GetPid();
709 abilityStateData.abilityState = state;
710 abilityStateData.uid = abilityInfo->applicationInfo.uid;
711 abilityStateData.token = ability->GetToken();
712 abilityStateData.abilityType = static_cast<int32_t>(abilityInfo->type);
713 abilityStateData.isFocused = ability->GetFocusFlag();
714 abilityStateData.abilityRecordId = ability->GetAbilityRecordId();
715 auto applicationInfo = GetApplicationInfo();
716 if (applicationInfo && (static_cast<int32_t>(applicationInfo->multiAppMode.multiAppModeType) ==
717 static_cast<int32_t>(MultiAppModeType::APP_CLONE))) {
718 abilityStateData.appCloneIndex = appIndex_;
719 }
720 if (ability->GetWant() != nullptr) {
721 abilityStateData.callerAbilityName = ability->GetWant()->GetStringParam(Want::PARAM_RESV_CALLER_ABILITY_NAME);
722 abilityStateData.callerBundleName = ability->GetWant()->GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME);
723 abilityStateData.callerUid = ability->GetWant()->GetIntParam(Want::PARAM_RESV_CALLER_UID, -1);
724 }
725 if (applicationInfo && applicationInfo->bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) {
726 abilityStateData.isAtomicService = true;
727 }
728 bool isUIExtension = AAFwk::UIExtensionUtils::IsUIExtension(abilityInfo->extensionAbilityType);
729 if (isUIExtension) {
730 if (!isAbility) {
731 abilityStateData.extensionAbilityType = static_cast<int32_t>(abilityInfo->extensionAbilityType);
732 } else {
733 abilityStateData.isInnerNotify = true;
734 }
735 }
736 abilityStateData.processType = static_cast<int32_t>(processType_);
737 auto serviceInner = appMgrServiceInner_.lock();
738 if (serviceInner) {
739 serviceInner->StateChangedNotifyObserver(abilityStateData, isAbility, isFromWindowFocusChanged);
740 }
741 }
742
GetModuleRunningRecordByToken(const sptr<IRemoteObject> & token) const743 std::shared_ptr<ModuleRunningRecord> AppRunningRecord::GetModuleRunningRecordByToken(
744 const sptr<IRemoteObject> &token) const
745 {
746 if (!token) {
747 return nullptr;
748 }
749
750 auto moduleRecordList = GetAllModuleRecord();
751 for (const auto &moduleRecord : moduleRecordList) {
752 if (moduleRecord && moduleRecord->GetAbilityRunningRecordByToken(token)) {
753 return moduleRecord;
754 }
755 }
756
757 return nullptr;
758 }
759
GetModuleRunningRecordByTerminateLists(const sptr<IRemoteObject> & token) const760 std::shared_ptr<ModuleRunningRecord> AppRunningRecord::GetModuleRunningRecordByTerminateLists(
761 const sptr<IRemoteObject> &token) const
762 {
763 if (!token) {
764 TAG_LOGE(AAFwkTag::APPMGR, "null token");
765 return nullptr;
766 }
767
768 auto moduleRecordList = GetAllModuleRecord();
769 for (const auto &moduleRecord : moduleRecordList) {
770 if (moduleRecord && moduleRecord->GetAbilityByTerminateLists(token)) {
771 return moduleRecord;
772 }
773 }
774
775 return nullptr;
776 }
777
GetAbilityRunningRecordByToken(const sptr<IRemoteObject> & token) const778 std::shared_ptr<AbilityRunningRecord> AppRunningRecord::GetAbilityRunningRecordByToken(
779 const sptr<IRemoteObject> &token) const
780 {
781 auto moduleRecord = GetModuleRunningRecordByToken(token);
782 if (!moduleRecord) {
783 return nullptr;
784 }
785 return moduleRecord->GetAbilityRunningRecordByToken(token);
786 }
787
GetAbilityByTerminateLists(const sptr<IRemoteObject> & token) const788 std::shared_ptr<AbilityRunningRecord> AppRunningRecord::GetAbilityByTerminateLists(
789 const sptr<IRemoteObject> &token) const
790 {
791 auto moduleRecord = GetModuleRunningRecordByTerminateLists(token);
792 if (!moduleRecord) {
793 return nullptr;
794 }
795 return moduleRecord->GetAbilityByTerminateLists(token);
796 }
797
UpdateAbilityFocusState(const sptr<IRemoteObject> & token,bool isFocus)798 bool AppRunningRecord::UpdateAbilityFocusState(const sptr<IRemoteObject> &token, bool isFocus)
799 {
800 TAG_LOGD(AAFwkTag::APPMGR, "focus state is :%{public}d", isFocus);
801 auto abilityRecord = GetAbilityRunningRecordByToken(token);
802 if (!abilityRecord) {
803 TAG_LOGE(AAFwkTag::APPMGR, "can not find ability record");
804 return false;
805 }
806
807 bool lastFocusState = abilityRecord->GetFocusFlag();
808 if (lastFocusState == isFocus) {
809 TAG_LOGE(AAFwkTag::APPMGR, "no need update");
810 return false;
811 }
812
813 if (isFocus) {
814 return AbilityFocused(abilityRecord);
815 } else {
816 return AbilityUnfocused(abilityRecord);
817 }
818 }
819
UpdateAbilityState(const sptr<IRemoteObject> & token,const AbilityState state)820 void AppRunningRecord::UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state)
821 {
822 TAG_LOGD(AAFwkTag::APPMGR, "state is :%{public}d", static_cast<int32_t>(state));
823 auto abilityRecord = GetAbilityRunningRecordByToken(token);
824 if (!abilityRecord) {
825 TAG_LOGE(AAFwkTag::APPMGR, "can not find ability record");
826 return;
827 }
828 if (state == AbilityState::ABILITY_STATE_CREATE) {
829 StateChangedNotifyObserver(
830 abilityRecord, static_cast<int32_t>(AbilityState::ABILITY_STATE_CREATE), true, false);
831 return;
832 }
833 if (state == abilityRecord->GetState()) {
834 TAG_LOGE(AAFwkTag::APPMGR, "no need update");
835 return;
836 }
837
838 if (state == AbilityState::ABILITY_STATE_FOREGROUND) {
839 AbilityForeground(abilityRecord);
840 } else if (state == AbilityState::ABILITY_STATE_BACKGROUND) {
841 AbilityBackground(abilityRecord);
842 } else {
843 TAG_LOGW(AAFwkTag::APPMGR, "wrong state");
844 }
845 }
846
AbilityForeground(const std::shared_ptr<AbilityRunningRecord> & ability)847 void AppRunningRecord::AbilityForeground(const std::shared_ptr<AbilityRunningRecord> &ability)
848 {
849 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
850 if (!ability) {
851 TAG_LOGE(AAFwkTag::APPMGR, "null ability");
852 return;
853 }
854
855 AbilityState curAbilityState = ability->GetState();
856 if (curAbilityState != AbilityState::ABILITY_STATE_READY &&
857 curAbilityState != AbilityState::ABILITY_STATE_BACKGROUND) {
858 TAG_LOGE(AAFwkTag::APPMGR, "ability state(%{public}d) error", static_cast<int32_t>(curAbilityState));
859 return;
860 }
861
862 TAG_LOGI(AAFwkTag::APPMGR, "appState: %{public}d, pState: %{public}d, bundle: %{public}s, ability: %{public}s",
863 curState_, pendingState_, mainBundleName_.c_str(), ability->GetName().c_str());
864 // We need schedule application to foregrounded when current application state is ready or background running.
865 if (curState_ == ApplicationState::APP_STATE_FOREGROUND
866 && pendingState_ != ApplicationPendingState::BACKGROUNDING) {
867 // Just change ability to foreground if current application state is foreground or focus.
868 auto moduleRecord = GetModuleRunningRecordByToken(ability->GetToken());
869 if (moduleRecord == nullptr) {
870 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
871 return;
872 }
873
874 moduleRecord->OnAbilityStateChanged(ability, AbilityState::ABILITY_STATE_FOREGROUND);
875 StateChangedNotifyObserver(
876 ability, static_cast<int32_t>(AbilityState::ABILITY_STATE_FOREGROUND), true, false);
877
878 auto serviceInner = appMgrServiceInner_.lock();
879 if (serviceInner) {
880 serviceInner->OnAppStateChanged(shared_from_this(), curState_, false, false);
881 }
882 return;
883 }
884 if (curState_ == ApplicationState::APP_STATE_READY || curState_ == ApplicationState::APP_STATE_BACKGROUND
885 || curState_ == ApplicationState::APP_STATE_FOREGROUND) {
886 auto pendingState = pendingState_;
887 SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
888 if (pendingState == ApplicationPendingState::READY && !ScheduleForegroundRunning()) {
889 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(ability->GetToken(),
890 "ScheduleForegroundRunning fail");
891 }
892 foregroundingAbilityTokens_.insert(ability->GetToken());
893 TAG_LOGD(AAFwkTag::APPMGR, "foregroundingAbility size: %{public}d",
894 static_cast<int32_t>(foregroundingAbilityTokens_.size()));
895 if (curState_ == ApplicationState::APP_STATE_BACKGROUND) {
896 SendAppStartupTypeEvent(ability, AppStartType::HOT);
897 }
898 } else {
899 TAG_LOGW(AAFwkTag::APPMGR, "wrong state");
900 }
901 }
902
AbilityBackground(const std::shared_ptr<AbilityRunningRecord> & ability)903 void AppRunningRecord::AbilityBackground(const std::shared_ptr<AbilityRunningRecord> &ability)
904 {
905 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
906 if (!ability) {
907 TAG_LOGE(AAFwkTag::APPMGR, "null ability");
908 return;
909 }
910 TAG_LOGD(AAFwkTag::APPMGR, "ability is %{public}s", mainBundleName_.c_str());
911 if (ability->GetState() != AbilityState::ABILITY_STATE_FOREGROUND &&
912 ability->GetState() != AbilityState::ABILITY_STATE_READY) {
913 TAG_LOGE(AAFwkTag::APPMGR, "ability state is not foreground or focus");
914 return;
915 }
916
917 // First change ability to background.
918 auto moduleRecord = GetModuleRunningRecordByToken(ability->GetToken());
919 if (moduleRecord == nullptr) {
920 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
921 return;
922 }
923 moduleRecord->OnAbilityStateChanged(ability, AbilityState::ABILITY_STATE_BACKGROUND);
924 StateChangedNotifyObserver(
925 ability, static_cast<int32_t>(AbilityState::ABILITY_STATE_BACKGROUND), true, false);
926 if (curState_ != ApplicationState::APP_STATE_FOREGROUND && curState_ != ApplicationState::APP_STATE_CACHED) {
927 TAG_LOGW(AAFwkTag::APPMGR, "wrong state");
928 return;
929 }
930 int32_t foregroundSize = 0;
931 auto abilitiesMap = GetAbilities();
932 for (const auto &item : abilitiesMap) {
933 const auto &abilityRecord = item.second;
934 if (abilityRecord && abilityRecord->GetState() == AbilityState::ABILITY_STATE_FOREGROUND &&
935 abilityRecord->GetAbilityInfo() &&
936 (abilityRecord->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE
937 || AAFwk::UIExtensionUtils::IsUIExtension(abilityRecord->GetAbilityInfo()->extensionAbilityType))) {
938 foregroundSize++;
939 break;
940 }
941 }
942
943 // Then schedule application background when all ability is not foreground.
944 if (foregroundSize == 0 && mainBundleName_ != LAUNCHER_NAME && IsWindowIdsEmpty()) {
945 auto pendingState = pendingState_;
946 SetApplicationPendingState(ApplicationPendingState::BACKGROUNDING);
947 if (pendingState == ApplicationPendingState::READY) {
948 ScheduleBackgroundRunning();
949 }
950 }
951 }
952
AbilityFocused(const std::shared_ptr<AbilityRunningRecord> & ability)953 bool AppRunningRecord::AbilityFocused(const std::shared_ptr<AbilityRunningRecord> &ability)
954 {
955 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
956 if (!ability) {
957 TAG_LOGE(AAFwkTag::APPMGR, "null ability");
958 return false;
959 }
960 ability->UpdateFocusState(true);
961
962 // update ability state
963 int32_t abilityState = static_cast<int32_t>(ability->GetState());
964 bool isAbility = true;
965 if (ability->GetAbilityInfo() != nullptr && ability->GetAbilityInfo()->type == AbilityType::EXTENSION) {
966 isAbility = false;
967 }
968 StateChangedNotifyObserver(ability, abilityState, isAbility, true);
969
970 if (isFocused_) {
971 // process state is already focused, no need update process state.
972 return false;
973 }
974
975 // update process focus state to true.
976 isFocused_ = true;
977 return true;
978 }
979
AbilityUnfocused(const std::shared_ptr<AbilityRunningRecord> & ability)980 bool AppRunningRecord::AbilityUnfocused(const std::shared_ptr<AbilityRunningRecord> &ability)
981 {
982 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
983 if (!ability) {
984 TAG_LOGE(AAFwkTag::APPMGR, "null ability");
985 return false;
986 }
987 ability->UpdateFocusState(false);
988
989 // update ability state to unfocused.
990 int32_t abilityState = static_cast<int32_t>(ability->GetState());
991 bool isAbility = true;
992 if (ability->GetAbilityInfo() != nullptr && ability->GetAbilityInfo()->type == AbilityType::EXTENSION) {
993 isAbility = false;
994 }
995 StateChangedNotifyObserver(ability, abilityState, isAbility, true);
996
997 if (!isFocused_) {
998 return false; // invalid process focus state, already unfocused, process state not change.
999 }
1000
1001 bool changeProcessToUnfocused = true;
1002 auto abilitysMap = GetAbilities();
1003 for (const auto &item : abilitysMap) {
1004 const auto &abilityRecord = item.second;
1005 if (abilityRecord && abilityRecord->GetFocusFlag()) {
1006 changeProcessToUnfocused = false;
1007 break;
1008 }
1009 }
1010
1011 if (changeProcessToUnfocused) {
1012 isFocused_ = false; // process focus state : from focus to unfocus.
1013 }
1014 return changeProcessToUnfocused;
1015 }
1016
PopForegroundingAbilityTokens()1017 void AppRunningRecord::PopForegroundingAbilityTokens()
1018 {
1019 TAG_LOGI(AAFwkTag::APPMGR, "ability size: %{public}d",
1020 static_cast<int32_t>(foregroundingAbilityTokens_.size()));
1021 for (auto iter = foregroundingAbilityTokens_.begin(); iter != foregroundingAbilityTokens_.end();) {
1022 auto ability = GetAbilityRunningRecordByToken(*iter);
1023 auto moduleRecord = GetModuleRunningRecordByToken(*iter);
1024 if (moduleRecord != nullptr) {
1025 moduleRecord->OnAbilityStateChanged(ability, AbilityState::ABILITY_STATE_FOREGROUND);
1026 StateChangedNotifyObserver(
1027 ability, static_cast<int32_t>(AbilityState::ABILITY_STATE_FOREGROUND), true, false);
1028 } else {
1029 TAG_LOGW(AAFwkTag::APPMGR, "null moduleRecord");
1030 }
1031 // The token should be removed even though the module record didn't exist.
1032 iter = foregroundingAbilityTokens_.erase(iter);
1033 }
1034 }
1035
TerminateAbility(const sptr<IRemoteObject> & token,const bool isForce,bool isTimeout)1036 void AppRunningRecord::TerminateAbility(const sptr<IRemoteObject> &token, const bool isForce, bool isTimeout)
1037 {
1038 TAG_LOGD(AAFwkTag::APPMGR, "isForce: %{public}d", static_cast<int>(isForce));
1039
1040 auto moduleRecord = GetModuleRunningRecordByToken(token);
1041 if (!moduleRecord) {
1042 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
1043 return;
1044 }
1045
1046 auto abilityRecord = GetAbilityRunningRecordByToken(token);
1047 if (abilityRecord) {
1048 TAG_LOGI(AAFwkTag::APPMGR, "TerminateAbility:%{public}s", abilityRecord->GetName().c_str());
1049 }
1050 if (!isTimeout) {
1051 StateChangedNotifyObserver(
1052 abilityRecord, static_cast<int32_t>(AbilityState::ABILITY_STATE_TERMINATED), true, false);
1053 }
1054 moduleRecord->TerminateAbility(shared_from_this(), token, isForce);
1055 }
1056
AbilityTerminated(const sptr<IRemoteObject> & token)1057 void AppRunningRecord::AbilityTerminated(const sptr<IRemoteObject> &token)
1058 {
1059 TAG_LOGD(AAFwkTag::APPMGR, "called");
1060 auto moduleRecord = GetModuleRunningRecordByTerminateLists(token);
1061 if (!moduleRecord) {
1062 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
1063 return;
1064 }
1065
1066 bool isExtensionDebug = false;
1067 auto abilityRecord = moduleRecord->GetAbilityByTerminateLists(token);
1068 if (abilityRecord != nullptr && abilityRecord->GetAbilityInfo() != nullptr) {
1069 isExtensionDebug = (abilityRecord->GetAbilityInfo()->type == AppExecFwk::AbilityType::EXTENSION) &&
1070 (isAttachDebug_ || isDebugApp_);
1071 }
1072 TAG_LOGD(AAFwkTag::APPMGR, "Extension debug is [%{public}s]", isExtensionDebug ? "true" : "false");
1073
1074 moduleRecord->AbilityTerminated(token);
1075
1076 auto appRecord = shared_from_this();
1077 auto cacheProcMgr = DelayedSingleton<CacheProcessManager>::GetInstance();
1078 bool needCache = false;
1079 if (cacheProcMgr != nullptr && cacheProcMgr->IsAppShouldCache(appRecord)) {
1080 cacheProcMgr->CheckAndCacheProcess(appRecord);
1081 TAG_LOGI(AAFwkTag::APPMGR, "App %{public}s should not remove module and terminate app",
1082 appRecord->GetBundleName().c_str());
1083 needCache = true;
1084 }
1085 auto state = static_cast<int>(GetSupportProcessCacheState());
1086 auto appInfo = appRecord->GetApplicationInfo();
1087 HiSysEventWrite(HiSysEvent::Domain::AAFWK, "CACHE_SUPPORT_STATE", HiSysEvent::EventType::BEHAVIOR,
1088 EVENT_KEY_VERSION_CODE, appInfo->versionCode, EVENT_KEY_VERSION_NAME, appInfo->versionName,
1089 EVENT_KEY_BUNDLE_NAME, appInfo->bundleName, EVENT_KEY_SUPPORT_STATE, state);
1090 if (moduleRecord->GetAbilities().empty() && (!IsKeepAliveApp()
1091 || AAFwk::UIExtensionUtils::IsUIExtension(GetExtensionType())
1092 || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient()) && !needCache) {
1093 RemoveModuleRecord(moduleRecord, isExtensionDebug);
1094 }
1095
1096 auto moduleRecordList = GetAllModuleRecord();
1097 if (moduleRecordList.empty() && (!IsKeepAliveApp()
1098 || AAFwk::UIExtensionUtils::IsUIExtension(GetExtensionType())
1099 || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient()) && !isExtensionDebug
1100 && !needCache) {
1101 ScheduleTerminate();
1102 }
1103 }
1104
GetAllModuleRecord() const1105 std::list<std::shared_ptr<ModuleRunningRecord>> AppRunningRecord::GetAllModuleRecord() const
1106 {
1107 std::list<std::shared_ptr<ModuleRunningRecord>> moduleRecordList;
1108 std::lock_guard<ffrt::mutex> hapModulesLock(hapModulesLock_);
1109 for (const auto &item : hapModules_) {
1110 for (const auto &list : item.second) {
1111 moduleRecordList.push_back(list);
1112 }
1113 }
1114 return moduleRecordList;
1115 }
1116
RemoveAppDeathRecipient() const1117 void AppRunningRecord::RemoveAppDeathRecipient() const
1118 {
1119 if (appLifeCycleDeal_ == nullptr) {
1120 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1121 return;
1122 }
1123 if (!appLifeCycleDeal_->GetApplicationClient()) {
1124 TAG_LOGE(AAFwkTag::APPMGR, "null appThread");
1125 return;
1126 }
1127 auto object = appLifeCycleDeal_->GetApplicationClient()->AsObject();
1128 if (object) {
1129 if (!object->RemoveDeathRecipient(appDeathRecipient_)) {
1130 TAG_LOGD(AAFwkTag::APPMGR, "Failed to remove deathRecipient.");
1131 }
1132 }
1133 }
1134
SetAppMgrServiceInner(const std::weak_ptr<AppMgrServiceInner> & inner)1135 void AppRunningRecord::SetAppMgrServiceInner(const std::weak_ptr<AppMgrServiceInner> &inner)
1136 {
1137 appMgrServiceInner_ = inner;
1138
1139 auto moduleRecordList = GetAllModuleRecord();
1140 if (moduleRecordList.empty()) {
1141 TAG_LOGE(AAFwkTag::APPMGR, "empty moduleRecordList");
1142 return;
1143 }
1144
1145 for (const auto &moduleRecord : moduleRecordList) {
1146 moduleRecord->SetAppMgrServiceInner(appMgrServiceInner_);
1147 }
1148 }
1149
SetAppDeathRecipient(const sptr<AppDeathRecipient> & appDeathRecipient)1150 void AppRunningRecord::SetAppDeathRecipient(const sptr<AppDeathRecipient> &appDeathRecipient)
1151 {
1152 appDeathRecipient_ = appDeathRecipient;
1153 }
1154
GetPriorityObject()1155 std::shared_ptr<PriorityObject> AppRunningRecord::GetPriorityObject()
1156 {
1157 return priorityObject_;
1158 }
1159
SendEventForSpecifiedAbility()1160 void AppRunningRecord::SendEventForSpecifiedAbility()
1161 {
1162 auto timeOUt = AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT;
1163 SendEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_HALF_TIMEOUT_MSG, timeOUt / HALF_TIMEOUT);
1164 SendEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG, timeOUt);
1165 }
1166
SendAppStartupTypeEvent(const std::shared_ptr<AbilityRunningRecord> & ability,const AppStartType startType)1167 void AppRunningRecord::SendAppStartupTypeEvent(const std::shared_ptr<AbilityRunningRecord> &ability,
1168 const AppStartType startType)
1169 {
1170 if (!ability) {
1171 TAG_LOGE(AAFwkTag::APPMGR, "null ability");
1172 return;
1173 }
1174 AAFwk::EventInfo eventInfo;
1175 auto applicationInfo = GetApplicationInfo();
1176 if (!applicationInfo) {
1177 TAG_LOGE(AAFwkTag::APPMGR, "null applicationInfo");
1178 } else {
1179 eventInfo.bundleName = applicationInfo->name;
1180 eventInfo.versionName = applicationInfo->versionName;
1181 eventInfo.versionCode = applicationInfo->versionCode;
1182 }
1183
1184 auto abilityInfo = ability->GetAbilityInfo();
1185 if (!abilityInfo) {
1186 TAG_LOGE(AAFwkTag::APPMGR, "null abilityInfo");
1187 } else {
1188 eventInfo.abilityName = abilityInfo->name;
1189 }
1190 if (GetPriorityObject() == nullptr) {
1191 TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject");
1192 } else {
1193 eventInfo.pid = GetPid();
1194 }
1195 eventInfo.startType = static_cast<int32_t>(startType);
1196 AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_STARTUP_TYPE, HiSysEventType::BEHAVIOR, eventInfo);
1197 }
1198
SendEvent(uint32_t msg,int64_t timeOut)1199 void AppRunningRecord::SendEvent(uint32_t msg, int64_t timeOut)
1200 {
1201 if (!eventHandler_) {
1202 TAG_LOGE(AAFwkTag::APPMGR, "null eventHandler_");
1203 return;
1204 }
1205
1206 if (isDebugApp_ || isNativeDebug_ || isAttachDebug_) {
1207 TAG_LOGI(AAFwkTag::APPMGR, "no need to handle time out");
1208 return;
1209 }
1210
1211 appEventId_++;
1212 auto param = appEventId_;
1213
1214 TAG_LOGI(AAFwkTag::APPMGR, "eventId %{public}d", static_cast<int>(param));
1215 eventHandler_->SendEvent(AAFwk::EventWrap(msg, param), timeOut, false);
1216 AppEventUtil::GetInstance().AddEvent(shared_from_this(), msg, param);
1217 }
1218
RemoveEvent(uint32_t msg)1219 void AppRunningRecord::RemoveEvent(uint32_t msg)
1220 {
1221 if (!eventHandler_) {
1222 TAG_LOGE(AAFwkTag::APPMGR, "null eventHandler_");
1223 return;
1224 }
1225 auto eventList = AppEventUtil::GetInstance().RemoveEvent(shared_from_this(), msg);
1226 for (const auto &eventData : eventList) {
1227 eventHandler_->RemoveEvent(msg, eventData.param);
1228 }
1229 }
1230
PostTask(std::string msg,int64_t timeOut,const Closure & task)1231 void AppRunningRecord::PostTask(std::string msg, int64_t timeOut, const Closure &task)
1232 {
1233 if (!taskHandler_) {
1234 TAG_LOGE(AAFwkTag::APPMGR, "null taskHandler_");
1235 return;
1236 }
1237 taskHandler_->SubmitTask(task, msg, timeOut);
1238 }
1239
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)1240 void AppRunningRecord::SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)
1241 {
1242 taskHandler_ = taskHandler;
1243 }
1244
SetEventHandler(const std::shared_ptr<AMSEventHandler> & handler)1245 void AppRunningRecord::SetEventHandler(const std::shared_ptr<AMSEventHandler> &handler)
1246 {
1247 eventHandler_ = handler;
1248 }
1249
IsLastAbilityRecord(const sptr<IRemoteObject> & token)1250 bool AppRunningRecord::IsLastAbilityRecord(const sptr<IRemoteObject> &token)
1251 {
1252 auto moduleRecord = GetModuleRunningRecordByToken(token);
1253 if (!moduleRecord) {
1254 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
1255 return false;
1256 }
1257
1258 auto moduleRecordList = GetAllModuleRecord();
1259 if (moduleRecordList.size() == 1) {
1260 return moduleRecord->IsLastAbilityRecord(token);
1261 }
1262
1263 return false;
1264 }
1265
ExtensionAbilityRecordExists()1266 bool AppRunningRecord::ExtensionAbilityRecordExists()
1267 {
1268 auto moduleRecordList = GetAllModuleRecord();
1269 for (auto moduleRecord : moduleRecordList) {
1270 if (moduleRecord && moduleRecord->ExtensionAbilityRecordExists()) {
1271 return true;
1272 }
1273 }
1274 TAG_LOGD(AAFwkTag::APPMGR, "can not find extension record");
1275 return false;
1276 }
1277
IsLastPageAbilityRecord(const sptr<IRemoteObject> & token)1278 bool AppRunningRecord::IsLastPageAbilityRecord(const sptr<IRemoteObject> &token)
1279 {
1280 auto moduleRecord = GetModuleRunningRecordByToken(token);
1281 if (!moduleRecord) {
1282 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
1283 return false;
1284 }
1285
1286 int32_t pageAbilitySize = 0;
1287 auto moduleRecordList = GetAllModuleRecord();
1288 for (auto moduleRecord : moduleRecordList) {
1289 if (moduleRecord) {
1290 pageAbilitySize += moduleRecord->GetPageAbilitySize();
1291 }
1292 if (pageAbilitySize > 1) {
1293 return false;
1294 }
1295 }
1296
1297 return pageAbilitySize == 1;
1298 }
1299
SetTerminating()1300 void AppRunningRecord::SetTerminating()
1301 {
1302 isTerminating = true;
1303 auto prioObject = GetPriorityObject();
1304 if (prioObject) {
1305 AbilityRuntime::FreezeUtil::GetInstance().DeleteAppLifecycleEvent(prioObject->GetPid());
1306 }
1307 }
1308
IsTerminating()1309 bool AppRunningRecord::IsTerminating()
1310 {
1311 return isTerminating;
1312 }
1313
IsKeepAliveApp() const1314 bool AppRunningRecord::IsKeepAliveApp() const
1315 {
1316 if (!isMainProcess_ || !isKeepAliveBundle_ || !isKeepAliveRdb_) {
1317 return false;
1318 }
1319 auto userId = GetUid() / BASE_USER_RANGE;
1320 if (userId == 0) {
1321 return isSingleton_;
1322 }
1323 return true;
1324 }
1325
IsKeepAliveDkv() const1326 bool AppRunningRecord::IsKeepAliveDkv() const
1327 {
1328 return isKeepAliveDkv_;
1329 }
1330
SetKeepAliveEnableState(bool isKeepAliveEnable)1331 void AppRunningRecord::SetKeepAliveEnableState(bool isKeepAliveEnable)
1332 {
1333 isKeepAliveRdb_ = isKeepAliveEnable;
1334 }
1335
SetKeepAliveDkv(bool isKeepAliveDkv)1336 void AppRunningRecord::SetKeepAliveDkv(bool isKeepAliveDkv)
1337 {
1338 isKeepAliveDkv_ = isKeepAliveDkv;
1339 }
1340
SetKeepAliveBundle(bool isKeepAliveBundle)1341 void AppRunningRecord::SetKeepAliveBundle(bool isKeepAliveBundle)
1342 {
1343 isKeepAliveBundle_ = isKeepAliveBundle;
1344 }
1345
IsEmptyKeepAliveApp() const1346 bool AppRunningRecord::IsEmptyKeepAliveApp() const
1347 {
1348 return isEmptyKeepAliveApp_;
1349 }
1350
SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp)1351 void AppRunningRecord::SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp)
1352 {
1353 isEmptyKeepAliveApp_ = isEmptyKeepAliveApp;
1354 }
1355
IsMainProcess() const1356 bool AppRunningRecord::IsMainProcess() const
1357 {
1358 return isMainProcess_;
1359 }
1360
SetMainProcess(bool isMainProcess)1361 void AppRunningRecord::SetMainProcess(bool isMainProcess)
1362 {
1363 isMainProcess_ = isMainProcess;
1364 }
1365
SetSingleton(bool isSingleton)1366 void AppRunningRecord::SetSingleton(bool isSingleton)
1367 {
1368 isSingleton_ = isSingleton;
1369 }
1370
SetStageModelState(bool isStageBasedModel)1371 void AppRunningRecord::SetStageModelState(bool isStageBasedModel)
1372 {
1373 isStageBasedModel_ = isStageBasedModel;
1374 }
1375
GetTheModuleInfoNeedToUpdated(const std::string bundleName,HapModuleInfo & info)1376 bool AppRunningRecord::GetTheModuleInfoNeedToUpdated(const std::string bundleName, HapModuleInfo &info)
1377 {
1378 bool result = false;
1379 std::lock_guard<ffrt::mutex> hapModulesLock(hapModulesLock_);
1380 auto moduleInfoVectorIter = hapModules_.find(bundleName);
1381 if (moduleInfoVectorIter == hapModules_.end() || moduleInfoVectorIter->second.empty()) {
1382 return result;
1383 }
1384 std::string moduleName = moduleName_;
1385 auto findCondition = [moduleName](const std::shared_ptr<ModuleRunningRecord> &record) {
1386 if (record) {
1387 return (moduleName.empty() || (moduleName == record->GetModuleName())) &&
1388 (record->GetModuleRecordState() == ModuleRecordState::INITIALIZED_STATE);
1389 }
1390 return false;
1391 };
1392 auto moduleRecordIter =
1393 std::find_if(moduleInfoVectorIter->second.begin(), moduleInfoVectorIter->second.end(), findCondition);
1394 if (moduleRecordIter != moduleInfoVectorIter->second.end()) {
1395 (*moduleRecordIter)->GetHapModuleInfo(info);
1396 (*moduleRecordIter)->SetModuleRecordState(ModuleRecordState::RUNNING_STATE);
1397 result = true;
1398 }
1399
1400 return result;
1401 }
1402
SetRestartResidentProcCount(int count)1403 void AppRunningRecord::SetRestartResidentProcCount(int count)
1404 {
1405 restartResidentProcCount_ = count;
1406 }
1407
DecRestartResidentProcCount()1408 void AppRunningRecord::DecRestartResidentProcCount()
1409 {
1410 restartResidentProcCount_--;
1411 }
1412
GetRestartResidentProcCount() const1413 int AppRunningRecord::GetRestartResidentProcCount() const
1414 {
1415 return restartResidentProcCount_;
1416 }
1417
CanRestartResidentProc()1418 bool AppRunningRecord::CanRestartResidentProc()
1419 {
1420 struct timespec t;
1421 t.tv_sec = 0;
1422 t.tv_nsec = 0;
1423 clock_gettime(CLOCK_MONOTONIC, &t);
1424 int64_t systemTimeMillis = static_cast<int64_t>(((t.tv_sec) * NANOSECONDS + t.tv_nsec) / MICROSECONDS);
1425 if ((restartResidentProcCount_ >= 0) || ((systemTimeMillis - restartTimeMillis_) > RESTART_INTERVAL_TIME)) {
1426 return true;
1427 }
1428 return false;
1429 }
1430
GetBundleNames(std::vector<std::string> & bundleNames)1431 void AppRunningRecord::GetBundleNames(std::vector<std::string> &bundleNames)
1432 {
1433 std::lock_guard<ffrt::mutex> appInfosLock(appInfosLock_);
1434 for (auto &app : appInfos_) {
1435 bundleNames.emplace_back(app.first);
1436 }
1437 }
1438
SetUserTestInfo(const std::shared_ptr<UserTestRecord> & record)1439 void AppRunningRecord::SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record)
1440 {
1441 userTestRecord_ = record;
1442 }
1443
GetUserTestInfo()1444 std::shared_ptr<UserTestRecord> AppRunningRecord::GetUserTestInfo()
1445 {
1446 return userTestRecord_;
1447 }
1448
SetProcessAndExtensionType(const std::shared_ptr<AbilityInfo> & abilityInfo,uint32_t extensionProcessMode)1449 void AppRunningRecord::SetProcessAndExtensionType(
1450 const std::shared_ptr<AbilityInfo> &abilityInfo, uint32_t extensionProcessMode)
1451 {
1452 if (abilityInfo == nullptr) {
1453 TAG_LOGE(AAFwkTag::APPMGR, "null abilityInfo");
1454 return;
1455 }
1456 extensionType_ = abilityInfo->extensionAbilityType;
1457 preloadModuleName_ = abilityInfo->moduleName;
1458 if (extensionType_ == ExtensionAbilityType::UNSPECIFIED) {
1459 //record Service Ability in FA model as Service Extension
1460 if (abilityInfo->type == AbilityType::SERVICE) {
1461 processType_ = ProcessType::EXTENSION;
1462 extensionType_ = ExtensionAbilityType::SERVICE;
1463 return;
1464 }
1465 //record Data Ability in FA model as Datashare Extension
1466 if (abilityInfo->type == AbilityType::DATA) {
1467 processType_ = ProcessType::EXTENSION;
1468 extensionType_ = ExtensionAbilityType::DATASHARE;
1469 return;
1470 }
1471 processType_ = ProcessType::NORMAL;
1472 return;
1473 }
1474
1475 if (AAFwk::UIExtensionUtils::IsUIExtension(extensionType_) &&
1476 extensionProcessMode == PROCESS_MODE_RUN_WITH_MAIN_PROCESS) {
1477 processType_ = ProcessType::NORMAL;
1478 } else {
1479 processType_ = ProcessType::EXTENSION;
1480 }
1481 return;
1482 }
1483
SetSpecifiedAbilityFlagAndWant(int requestId,const AAFwk::Want & want,const std::string & moduleName)1484 void AppRunningRecord::SetSpecifiedAbilityFlagAndWant(
1485 int requestId, const AAFwk::Want &want, const std::string &moduleName)
1486 {
1487 std::lock_guard lock(specifiedMutex_);
1488 if (specifiedAbilityRequest_ != nullptr) {
1489 TAG_LOGW(AAFwkTag::APPMGR, "specifiedRequestId: %{public}d", specifiedAbilityRequest_->requestId);
1490 }
1491 specifiedAbilityRequest_ = std::make_shared<SpecifiedRequest>();
1492 specifiedAbilityRequest_->requestId = requestId;
1493 specifiedAbilityRequest_->want = want;
1494 moduleName_ = moduleName;
1495 }
1496
GetSpecifiedRequestId() const1497 int32_t AppRunningRecord::GetSpecifiedRequestId() const
1498 {
1499 std::lock_guard lock(specifiedMutex_);
1500 if (specifiedAbilityRequest_ != nullptr) {
1501 return specifiedAbilityRequest_->requestId;
1502 }
1503 return -1;
1504 }
1505
ResetSpecifiedRequest()1506 void AppRunningRecord::ResetSpecifiedRequest()
1507 {
1508 std::lock_guard lock(specifiedMutex_);
1509 specifiedAbilityRequest_.reset();
1510 }
1511
SetScheduleNewProcessRequestState(int32_t requestId,const AAFwk::Want & want,const std::string & moduleName)1512 void AppRunningRecord::SetScheduleNewProcessRequestState(int32_t requestId,
1513 const AAFwk::Want &want, const std::string &moduleName)
1514 {
1515 std::lock_guard lock(specifiedMutex_);
1516 if (specifiedProcessRequest_ != nullptr) {
1517 TAG_LOGW(AAFwkTag::APPMGR, "newProcessRequestId: %{public}d", specifiedProcessRequest_->requestId);
1518 }
1519 specifiedProcessRequest_ = std::make_shared<SpecifiedRequest>();
1520 specifiedProcessRequest_->requestId = requestId;
1521 specifiedProcessRequest_->want = want;
1522 moduleName_ = moduleName;
1523 }
1524
IsNewProcessRequest() const1525 bool AppRunningRecord::IsNewProcessRequest() const
1526 {
1527 std::lock_guard lock(specifiedMutex_);
1528 return specifiedProcessRequest_ != nullptr;
1529 }
1530
IsStartSpecifiedAbility() const1531 bool AppRunningRecord::IsStartSpecifiedAbility() const
1532 {
1533 std::lock_guard lock(specifiedMutex_);
1534 return specifiedAbilityRequest_ != nullptr;
1535 }
1536
SchedulePrepareTerminate(const std::string & moduleName)1537 void AppRunningRecord::SchedulePrepareTerminate(const std::string &moduleName)
1538 {
1539 TAG_LOGD(AAFwkTag::APPMGR, "called");
1540 if (appLifeCycleDeal_ == nullptr) {
1541 TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1542 return;
1543 }
1544 bool found = false;
1545 {
1546 std::lock_guard<ffrt::mutex> hapModulesLock(hapModulesLock_);
1547 for (const auto &iter : hapModules_) {
1548 for (const auto &moduleRecord : iter.second) {
1549 if (moduleRecord != nullptr && moduleName == moduleRecord->GetModuleName()) {
1550 found = true;
1551 break;
1552 }
1553 }
1554 }
1555 }
1556 if (!found) {
1557 TAG_LOGE(AAFwkTag::APPMGR, "moduleName not exist");
1558 return;
1559 }
1560 appLifeCycleDeal_->SchedulePrepareTerminate(moduleName);
1561 }
1562
ScheduleAcceptWant(const std::string & moduleName)1563 void AppRunningRecord::ScheduleAcceptWant(const std::string &moduleName)
1564 {
1565 auto timeOUt = AMSEventHandler::START_SPECIFIED_ABILITY_TIMEOUT;
1566 SendEvent(AMSEventHandler::START_SPECIFIED_ABILITY_HALF_TIMEOUT_MSG, timeOUt / HALF_TIMEOUT);
1567 SendEvent(AMSEventHandler::START_SPECIFIED_ABILITY_TIMEOUT_MSG, timeOUt);
1568 if (appLifeCycleDeal_ == nullptr) {
1569 TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1570 return;
1571 }
1572 appLifeCycleDeal_->ScheduleAcceptWant(GetSpecifiedWant(), moduleName);
1573 }
1574
ScheduleAcceptWantDone()1575 void AppRunningRecord::ScheduleAcceptWantDone()
1576 {
1577 TAG_LOGI(AAFwkTag::APPMGR, "ScheduleAcceptWantDone, bundle %{public}s", mainBundleName_.c_str());
1578 RemoveEvent(AMSEventHandler::START_SPECIFIED_ABILITY_HALF_TIMEOUT_MSG);
1579 RemoveEvent(AMSEventHandler::START_SPECIFIED_ABILITY_TIMEOUT_MSG);
1580 SetModuleLoaded(moduleName_);
1581 }
1582
ScheduleNewProcessRequest(const AAFwk::Want & want,const std::string & moduleName)1583 void AppRunningRecord::ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName)
1584 {
1585 auto timeOUt = AMSEventHandler::START_SPECIFIED_PROCESS_TIMEOUT;
1586 SendEvent(AMSEventHandler::START_SPECIFIED_PROCESS_HALF_TIMEOUT_MSG, timeOUt / HALF_TIMEOUT);
1587 SendEvent(AMSEventHandler::START_SPECIFIED_PROCESS_TIMEOUT_MSG, timeOUt);
1588 if (appLifeCycleDeal_ == nullptr) {
1589 TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1590 return;
1591 }
1592 appLifeCycleDeal_->ScheduleNewProcessRequest(want, moduleName);
1593 }
1594
ScheduleNewProcessRequestDone()1595 void AppRunningRecord::ScheduleNewProcessRequestDone()
1596 {
1597 TAG_LOGI(AAFwkTag::APPMGR, "bundle %{public}s", mainBundleName_.c_str());
1598 RemoveEvent(AMSEventHandler::START_SPECIFIED_PROCESS_HALF_TIMEOUT_MSG);
1599 RemoveEvent(AMSEventHandler::START_SPECIFIED_PROCESS_TIMEOUT_MSG);
1600 SetModuleLoaded(moduleName_);
1601 }
1602
ApplicationTerminated()1603 void AppRunningRecord::ApplicationTerminated()
1604 {
1605 TAG_LOGD(AAFwkTag::APPMGR, "Application terminated bundle %{public}s", mainBundleName_.c_str());
1606
1607 RemoveEvent(AMSEventHandler::TERMINATE_APPLICATION_HALF_TIMEOUT_MSG);
1608 RemoveEvent(AMSEventHandler::TERMINATE_APPLICATION_TIMEOUT_MSG);
1609 }
1610
GetSpecifiedWant() const1611 AAFwk::Want AppRunningRecord::GetSpecifiedWant() const
1612 {
1613 std::lock_guard lock(specifiedMutex_);
1614 if (specifiedAbilityRequest_ != nullptr) {
1615 return specifiedAbilityRequest_->want;
1616 }
1617 return AAFwk::Want();
1618 }
1619
GetNewProcessRequestWant() const1620 AAFwk::Want AppRunningRecord::GetNewProcessRequestWant() const
1621 {
1622 std::lock_guard lock(specifiedMutex_);
1623 if (specifiedProcessRequest_ != nullptr) {
1624 return specifiedProcessRequest_->want;
1625 }
1626 return AAFwk::Want();
1627 }
1628
GetNewProcessRequestId() const1629 int32_t AppRunningRecord::GetNewProcessRequestId() const
1630 {
1631 std::lock_guard lock(specifiedMutex_);
1632 if (specifiedProcessRequest_ != nullptr) {
1633 return specifiedProcessRequest_->requestId;
1634 }
1635 return -1;
1636 }
1637
ResetNewProcessRequest()1638 void AppRunningRecord::ResetNewProcessRequest()
1639 {
1640 std::lock_guard lock(specifiedMutex_);
1641 specifiedProcessRequest_.reset();
1642 }
1643
UpdateConfiguration(const Configuration & config)1644 int32_t AppRunningRecord::UpdateConfiguration(const Configuration &config)
1645 {
1646 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1647 TAG_LOGD(AAFwkTag::APPMGR, "called");
1648 if (!appLifeCycleDeal_) {
1649 TAG_LOGI(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1650 return ERR_INVALID_VALUE;
1651 }
1652 return appLifeCycleDeal_->UpdateConfiguration(config);
1653 }
1654
AddRenderRecord(const std::shared_ptr<RenderRecord> & record)1655 void AppRunningRecord::AddRenderRecord(const std::shared_ptr<RenderRecord> &record)
1656 {
1657 if (!record) {
1658 TAG_LOGD(AAFwkTag::APPMGR, "AddRenderRecord: record is null");
1659 return;
1660 }
1661 {
1662 std::lock_guard renderPidSetLock(renderPidSetLock_);
1663 renderPidSet_.insert(record->GetPid());
1664 }
1665 std::lock_guard renderRecordMapLock(renderRecordMapLock_);
1666 renderRecordMap_.emplace(record->GetUid(), record);
1667 }
1668
RemoveRenderRecord(const std::shared_ptr<RenderRecord> & record)1669 void AppRunningRecord::RemoveRenderRecord(const std::shared_ptr<RenderRecord> &record)
1670 {
1671 if (!record) {
1672 TAG_LOGD(AAFwkTag::APPMGR, "RemoveRenderRecord: record null");
1673 return;
1674 }
1675 std::lock_guard renderRecordMapLock(renderRecordMapLock_);
1676 renderRecordMap_.erase(record->GetUid());
1677 }
1678
RemoveRenderPid(pid_t renderPid)1679 void AppRunningRecord::RemoveRenderPid(pid_t renderPid)
1680 {
1681 std::lock_guard renderPidSetLock(renderPidSetLock_);
1682 renderPidSet_.erase(renderPid);
1683 }
1684
GetRenderProcessInfos(std::list<SimpleProcessInfo> & processInfos)1685 void AppRunningRecord::GetRenderProcessInfos(std::list<SimpleProcessInfo> &processInfos)
1686 {
1687 std::lock_guard renderRecordMapLock(renderRecordMapLock_);
1688 for (auto &item : renderRecordMap_) {
1689 auto renderRecord = item.second;
1690 if (renderRecord && renderRecord->GetPid() > 0) {
1691 auto processInfo = SimpleProcessInfo(renderRecord->GetPid(), renderRecord->GetProcessName());
1692 processInfos.emplace_back(processInfo);
1693 }
1694 }
1695 }
1696
ConstainsRenderPid(pid_t renderPid)1697 bool AppRunningRecord::ConstainsRenderPid(pid_t renderPid)
1698 {
1699 std::lock_guard renderPidSetLock(renderPidSetLock_);
1700 return renderPidSet_.find(renderPid) != renderPidSet_.end();
1701 }
1702
GetRenderRecordByPid(const pid_t pid)1703 std::shared_ptr<RenderRecord> AppRunningRecord::GetRenderRecordByPid(const pid_t pid)
1704 {
1705 std::lock_guard renderRecordMapLock(renderRecordMapLock_);
1706 if (renderRecordMap_.empty()) {
1707 return nullptr;
1708 }
1709 for (auto iter : renderRecordMap_) {
1710 auto renderRecord = iter.second;
1711 if (renderRecord && renderRecord->GetPid() == pid) {
1712 return renderRecord;
1713 }
1714 }
1715 return nullptr;
1716 }
1717
GetRenderRecordMap()1718 std::map<int32_t, std::shared_ptr<RenderRecord>> AppRunningRecord::GetRenderRecordMap()
1719 {
1720 std::lock_guard renderRecordMapLock(renderRecordMapLock_);
1721 return renderRecordMap_;
1722 }
1723
SetStartMsg(const AppSpawnStartMsg & msg)1724 void AppRunningRecord::SetStartMsg(const AppSpawnStartMsg &msg)
1725 {
1726 startMsg_ = msg;
1727 }
1728
GetStartMsg()1729 AppSpawnStartMsg AppRunningRecord::GetStartMsg()
1730 {
1731 return startMsg_;
1732 }
1733
IsDebug()1734 bool AppRunningRecord::IsDebug()
1735 {
1736 if (IsDebugApp() || isNativeDebug_ || !perfCmd_.empty() || IsAttachDebug() || IsAssertionPause()) {
1737 TAG_LOGI(AAFwkTag::ABILITYMGR, "debugApp, no need to handle");
1738 return true;
1739 }
1740 return false;
1741 }
1742
SetDebugApp(bool isDebugApp)1743 void AppRunningRecord::SetDebugApp(bool isDebugApp)
1744 {
1745 TAG_LOGD(AAFwkTag::APPMGR, "value is %{public}d", isDebugApp);
1746 isDebugApp_ = isDebugApp;
1747 }
1748
IsDebugApp()1749 bool AppRunningRecord::IsDebugApp()
1750 {
1751 return isDebugApp_;
1752 }
1753
SetNativeDebug(bool isNativeDebug)1754 void AppRunningRecord::SetNativeDebug(bool isNativeDebug)
1755 {
1756 TAG_LOGD(AAFwkTag::APPMGR, "SetNativeDebug, value is %{public}d", isNativeDebug);
1757 isNativeDebug_ = isNativeDebug;
1758 }
1759
SetPerfCmd(const std::string & perfCmd)1760 void AppRunningRecord::SetPerfCmd(const std::string &perfCmd)
1761 {
1762 perfCmd_ = perfCmd;
1763 }
1764
SetErrorInfoEnhance(bool errorInfoEnhance)1765 void AppRunningRecord::SetErrorInfoEnhance(bool errorInfoEnhance)
1766 {
1767 isErrorInfoEnhance_ = errorInfoEnhance;
1768 }
1769
SetMultiThread(bool multiThread)1770 void AppRunningRecord::SetMultiThread(bool multiThread)
1771 {
1772 isMultiThread_ = multiThread;
1773 }
1774
SetAppIndex(const int32_t appIndex)1775 void AppRunningRecord::SetAppIndex(const int32_t appIndex)
1776 {
1777 appIndex_ = appIndex;
1778 }
1779
SetInstanceKey(const std::string & instanceKey)1780 void AppRunningRecord::SetInstanceKey(const std::string& instanceKey)
1781 {
1782 instanceKey_ = instanceKey;
1783 }
1784
GetSplitModeAndFloatingMode(bool & isSplitScreenMode,bool & isFloatingWindowMode)1785 void AppRunningRecord::GetSplitModeAndFloatingMode(bool &isSplitScreenMode, bool &isFloatingWindowMode)
1786 {
1787 auto abilitiesMap = GetAbilities();
1788 isSplitScreenMode = false;
1789 isFloatingWindowMode = false;
1790 for (const auto &item : abilitiesMap) {
1791 const auto &abilityRecord = item.second;
1792 if (abilityRecord == nullptr) {
1793 continue;
1794 }
1795 const auto &abilityWant = abilityRecord->GetWant();
1796 if (abilityWant != nullptr) {
1797 int windowMode = abilityWant->GetIntParam(Want::PARAM_RESV_WINDOW_MODE, -1);
1798 if (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING) {
1799 isFloatingWindowMode = true;
1800 }
1801 if (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY ||
1802 windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) {
1803 isSplitScreenMode = true;
1804 }
1805 }
1806 if (isFloatingWindowMode && isSplitScreenMode) {
1807 break;
1808 }
1809 }
1810 }
1811
GetAppIndex() const1812 int32_t AppRunningRecord::GetAppIndex() const
1813 {
1814 return appIndex_;
1815 }
1816
GetInstanceKey() const1817 std::string AppRunningRecord::GetInstanceKey() const
1818 {
1819 return instanceKey_;
1820 }
1821
SetSecurityFlag(bool securityFlag)1822 void AppRunningRecord::SetSecurityFlag(bool securityFlag)
1823 {
1824 securityFlag_ = securityFlag;
1825 }
1826
GetSecurityFlag() const1827 bool AppRunningRecord::GetSecurityFlag() const
1828 {
1829 return securityFlag_;
1830 }
1831
SetKilling()1832 void AppRunningRecord::SetKilling()
1833 {
1834 isKilling_.store(true);
1835 }
1836
IsKilling() const1837 bool AppRunningRecord::IsKilling() const
1838 {
1839 return isKilling_.load();
1840 }
1841
NeedUpdateConfigurationBackground()1842 bool AppRunningRecord::NeedUpdateConfigurationBackground()
1843 {
1844 bool needUpdate = false;
1845 auto abilitiesMap = GetAbilities();
1846 for (const auto &item : abilitiesMap) {
1847 const auto &abilityRecord = item.second;
1848 if (!abilityRecord || !abilityRecord->GetAbilityInfo()) {
1849 continue;
1850 }
1851 if (abilityRecord->GetAbilityInfo()->type != AppExecFwk::AbilityType::PAGE &&
1852 !(AAFwk::UIExtensionUtils::IsUIExtension(abilityRecord->GetAbilityInfo()->extensionAbilityType))) {
1853 needUpdate = true;
1854 break;
1855 }
1856 }
1857 return needUpdate;
1858 }
1859
RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject> & token) const1860 void AppRunningRecord::RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const
1861 {
1862 auto moduleRecord = GetModuleRunningRecordByToken(token);
1863 if (!moduleRecord) {
1864 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
1865 return;
1866 }
1867 (void)moduleRecord->RemoveTerminateAbilityTimeoutTask(token);
1868 }
1869
NotifyLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback,const int32_t recordId)1870 int32_t AppRunningRecord::NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback,
1871 const int32_t recordId)
1872 {
1873 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1874 TAG_LOGD(AAFwkTag::APPMGR, "called");
1875 if (!appLifeCycleDeal_) {
1876 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1877 return ERR_INVALID_VALUE;
1878 }
1879 return appLifeCycleDeal_->NotifyLoadRepairPatch(bundleName, callback, recordId);
1880 }
1881
NotifyHotReloadPage(const sptr<IQuickFixCallback> & callback,const int32_t recordId)1882 int32_t AppRunningRecord::NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId)
1883 {
1884 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1885 TAG_LOGD(AAFwkTag::APPMGR, "called");
1886 if (!appLifeCycleDeal_) {
1887 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1888 return ERR_INVALID_VALUE;
1889 }
1890 return appLifeCycleDeal_->NotifyHotReloadPage(callback, recordId);
1891 }
1892
NotifyUnLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback,const int32_t recordId)1893 int32_t AppRunningRecord::NotifyUnLoadRepairPatch(const std::string &bundleName,
1894 const sptr<IQuickFixCallback> &callback, const int32_t recordId)
1895 {
1896 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1897 TAG_LOGD(AAFwkTag::APPMGR, "called");
1898 if (!appLifeCycleDeal_) {
1899 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1900 return ERR_INVALID_VALUE;
1901 }
1902 return appLifeCycleDeal_->NotifyUnLoadRepairPatch(bundleName, callback, recordId);
1903 }
1904
NotifyAppFault(const FaultData & faultData)1905 int32_t AppRunningRecord::NotifyAppFault(const FaultData &faultData)
1906 {
1907 TAG_LOGD(AAFwkTag::APPMGR, "called");
1908 if (!appLifeCycleDeal_) {
1909 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
1910 return ERR_INVALID_VALUE;
1911 }
1912 return appLifeCycleDeal_->NotifyAppFault(faultData);
1913 }
1914
IsAbilitiesBackground()1915 bool AppRunningRecord::IsAbilitiesBackground()
1916 {
1917 std::lock_guard<ffrt::mutex> hapModulesLock(hapModulesLock_);
1918 for (const auto &iter : hapModules_) {
1919 for (const auto &moduleRecord : iter.second) {
1920 if (moduleRecord == nullptr) {
1921 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
1922 continue;
1923 }
1924 if (!moduleRecord->IsAbilitiesBackgrounded()) {
1925 return false;
1926 }
1927 }
1928 }
1929 return true;
1930 }
1931 #ifdef SUPPORT_SCREEN
1932
ChangeWindowVisibility(const sptr<OHOS::Rosen::WindowVisibilityInfo> & info)1933 void AppRunningRecord::ChangeWindowVisibility(const sptr<OHOS::Rosen::WindowVisibilityInfo> &info)
1934 {
1935 if (info == nullptr) {
1936 TAG_LOGE(AAFwkTag::APPMGR, "null info");
1937 return;
1938 }
1939
1940 if (GetPriorityObject() == nullptr) {
1941 TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject");
1942 return;
1943 }
1944
1945 if (info->pid_ != GetPid()) {
1946 return;
1947 }
1948
1949 std::lock_guard windowIdsLock(windowIdsLock_);
1950 auto iter = windowIds_.find(info->windowId_);
1951 if (iter != windowIds_.end() &&
1952 info->visibilityState_ == OHOS::Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) {
1953 windowIds_.erase(iter);
1954 return;
1955 }
1956 if (iter == windowIds_.end() &&
1957 info->visibilityState_ < OHOS::Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) {
1958 windowIds_.emplace(info->windowId_);
1959 }
1960 }
1961
OnWindowVisibilityChanged(const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> & windowVisibilityInfos)1962 void AppRunningRecord::OnWindowVisibilityChanged(
1963 const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos)
1964 {
1965 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1966 TAG_LOGD(AAFwkTag::APPMGR, "called");
1967 AddAppLifecycleEvent("AppRunningRecord::OnWindowVisibilityChanged");
1968 if (windowVisibilityInfos.empty()) {
1969 TAG_LOGW(AAFwkTag::APPMGR, "empty info");
1970 return;
1971 }
1972
1973 for (const auto &info : windowVisibilityInfos) {
1974 if (info == nullptr || info->pid_ != GetPid()) {
1975 TAG_LOGE(AAFwkTag::APPMGR, "null info or info pid is not matched");
1976 continue;
1977 }
1978 std::lock_guard windowIdsLock(windowIdsLock_);
1979 auto iter = windowIds_.find(info->windowId_);
1980 if (iter != windowIds_.end() &&
1981 info->visibilityState_ == OHOS::Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) {
1982 windowIds_.erase(iter);
1983 continue;
1984 }
1985 if (iter == windowIds_.end() &&
1986 info->visibilityState_ < OHOS::Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) {
1987 windowIds_.emplace(info->windowId_);
1988 }
1989 }
1990 OnWindowVisibilityChangedWithPendingState();
1991 }
1992
OnWindowVisibilityChangedWithPendingState()1993 void AppRunningRecord::OnWindowVisibilityChangedWithPendingState()
1994 {
1995 TAG_LOGI(AAFwkTag::APPMGR, "wnd call, %{public}s_%{public}d, isEmpty_%{public}d, c_%{public}d -> p_%{public}d",
1996 GetBundleName().c_str(), GetPid(), IsWindowIdsEmpty(), curState_, pendingState_);
1997 if (pendingState_ == ApplicationPendingState::READY) {
1998 if (!IsWindowIdsEmpty()) {
1999 if (curState_ != ApplicationState::APP_STATE_FOREGROUND) {
2000 SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
2001 ScheduleForegroundRunning();
2002 }
2003 if (watchdogVisibilityState_ != WatchdogVisibilityState::WATCHDOG_STATE_VISIBILITY) {
2004 watchdogVisibilityState_ = WatchdogVisibilityState::WATCHDOG_STATE_VISIBILITY;
2005 SetWatchdogBackgroundStatusRunning(false);
2006 }
2007 } else {
2008 if (IsAbilitiesBackground() && curState_ == ApplicationState::APP_STATE_FOREGROUND) {
2009 SetApplicationPendingState(ApplicationPendingState::BACKGROUNDING);
2010 ScheduleBackgroundRunning();
2011 }
2012 if (watchdogVisibilityState_ != WatchdogVisibilityState::WATCHDOG_STATE_UNVISIBILITY) {
2013 watchdogVisibilityState_ = WatchdogVisibilityState::WATCHDOG_STATE_UNVISIBILITY;
2014 SetWatchdogBackgroundStatusRunning(true);
2015 }
2016 }
2017 } else {
2018 if (!IsWindowIdsEmpty()) {
2019 SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
2020 }
2021 if (IsWindowIdsEmpty() && IsAbilitiesBackground() && foregroundingAbilityTokens_.empty()) {
2022 SetApplicationPendingState(ApplicationPendingState::BACKGROUNDING);
2023 }
2024 }
2025 }
2026 #endif //SUPPORT_SCREEN
2027
IsWindowIdsEmpty()2028 bool AppRunningRecord::IsWindowIdsEmpty()
2029 {
2030 std::lock_guard windowIdsLock(windowIdsLock_);
2031 return windowIds_.empty();
2032 }
2033
IsContinuousTask()2034 bool AppRunningRecord::IsContinuousTask()
2035 {
2036 return isContinuousTask_;
2037 }
2038
SetContinuousTaskAppState(bool isContinuousTask)2039 void AppRunningRecord::SetContinuousTaskAppState(bool isContinuousTask)
2040 {
2041 isContinuousTask_ = isContinuousTask;
2042 }
2043
GetFocusFlag() const2044 bool AppRunningRecord::GetFocusFlag() const
2045 {
2046 return isFocused_;
2047 }
2048
GetAppStartTime() const2049 int64_t AppRunningRecord::GetAppStartTime() const
2050 {
2051 return startTimeMillis_;
2052 }
2053
SetRequestProcCode(int32_t requestProcCode)2054 void AppRunningRecord::SetRequestProcCode(int32_t requestProcCode)
2055 {
2056 requestProcCode_ = requestProcCode;
2057 }
2058
GetRequestProcCode() const2059 int32_t AppRunningRecord::GetRequestProcCode() const
2060 {
2061 return requestProcCode_;
2062 }
2063
SetProcessChangeReason(ProcessChangeReason reason)2064 void AppRunningRecord::SetProcessChangeReason(ProcessChangeReason reason)
2065 {
2066 processChangeReason_ = reason;
2067 }
2068
GetProcessChangeReason() const2069 ProcessChangeReason AppRunningRecord::GetProcessChangeReason() const
2070 {
2071 return processChangeReason_;
2072 }
2073
GetExtensionType() const2074 ExtensionAbilityType AppRunningRecord::GetExtensionType() const
2075 {
2076 return extensionType_;
2077 }
2078
GetProcessType() const2079 ProcessType AppRunningRecord::GetProcessType() const
2080 {
2081 return processType_;
2082 }
2083
GetChildAppRecordMap() const2084 std::map<pid_t, std::weak_ptr<AppRunningRecord>> AppRunningRecord::GetChildAppRecordMap() const
2085 {
2086 return childAppRecordMap_;
2087 }
2088
AddChildAppRecord(pid_t pid,std::shared_ptr<AppRunningRecord> appRecord)2089 void AppRunningRecord::AddChildAppRecord(pid_t pid, std::shared_ptr<AppRunningRecord> appRecord)
2090 {
2091 childAppRecordMap_[pid] = appRecord;
2092 }
2093
RemoveChildAppRecord(pid_t pid)2094 void AppRunningRecord::RemoveChildAppRecord(pid_t pid)
2095 {
2096 childAppRecordMap_.erase(pid);
2097 }
2098
ClearChildAppRecordMap()2099 void AppRunningRecord::ClearChildAppRecordMap()
2100 {
2101 childAppRecordMap_.clear();
2102 }
2103
SetParentAppRecord(std::shared_ptr<AppRunningRecord> appRecord)2104 void AppRunningRecord::SetParentAppRecord(std::shared_ptr<AppRunningRecord> appRecord)
2105 {
2106 parentAppRecord_ = appRecord;
2107 }
2108
GetParentAppRecord()2109 std::shared_ptr<AppRunningRecord> AppRunningRecord::GetParentAppRecord()
2110 {
2111 return parentAppRecord_.lock();
2112 }
2113
ChangeAppGcState(int32_t state)2114 int32_t AppRunningRecord::ChangeAppGcState(int32_t state)
2115 {
2116 TAG_LOGD(AAFwkTag::APPMGR, "called");
2117 if (appLifeCycleDeal_ == nullptr) {
2118 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
2119 return ERR_INVALID_VALUE;
2120 }
2121 return appLifeCycleDeal_->ChangeAppGcState(state);
2122 }
2123
SetAttachDebug(bool isAttachDebug,bool isDebugFromLocal)2124 void AppRunningRecord::SetAttachDebug(bool isAttachDebug, bool isDebugFromLocal)
2125 {
2126 TAG_LOGD(AAFwkTag::APPMGR, "called");
2127 isAttachDebug_ = isAttachDebug;
2128 isDebugFromLocal_ = isDebugFromLocal;
2129
2130 if (appLifeCycleDeal_ == nullptr) {
2131 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
2132 return;
2133 }
2134 isAttachDebug_ ? appLifeCycleDeal_->AttachAppDebug(isDebugFromLocal_) : appLifeCycleDeal_->DetachAppDebug();
2135 }
2136
IsAttachDebug() const2137 bool AppRunningRecord::IsAttachDebug() const
2138 {
2139 return isAttachDebug_;
2140 }
2141
SetApplicationPendingState(ApplicationPendingState pendingState)2142 void AppRunningRecord::SetApplicationPendingState(ApplicationPendingState pendingState)
2143 {
2144 pendingState_ = pendingState;
2145 }
2146
GetApplicationPendingState() const2147 ApplicationPendingState AppRunningRecord::GetApplicationPendingState() const
2148 {
2149 return pendingState_;
2150 }
2151
SetApplicationScheduleState(ApplicationScheduleState scheduleState)2152 void AppRunningRecord::SetApplicationScheduleState(ApplicationScheduleState scheduleState)
2153 {
2154 scheduleState_ = scheduleState;
2155 }
2156
GetApplicationScheduleState() const2157 ApplicationScheduleState AppRunningRecord::GetApplicationScheduleState() const
2158 {
2159 return scheduleState_;
2160 }
2161
2162 #ifdef SUPPORT_CHILD_PROCESS
AddChildProcessRecord(pid_t pid,std::shared_ptr<ChildProcessRecord> record)2163 void AppRunningRecord::AddChildProcessRecord(pid_t pid, std::shared_ptr<ChildProcessRecord> record)
2164 {
2165 if (!record) {
2166 TAG_LOGE(AAFwkTag::APPMGR, "null record");
2167 return;
2168 }
2169 if (pid <= 0) {
2170 TAG_LOGE(AAFwkTag::APPMGR, "pid <= 0");
2171 return;
2172 }
2173 std::lock_guard lock(childProcessRecordMapLock_);
2174 childProcessRecordMap_.emplace(pid, record);
2175 }
2176
RemoveChildProcessRecord(std::shared_ptr<ChildProcessRecord> record)2177 void AppRunningRecord::RemoveChildProcessRecord(std::shared_ptr<ChildProcessRecord> record)
2178 {
2179 if (!record) {
2180 TAG_LOGE(AAFwkTag::APPMGR, "null record");
2181 return;
2182 }
2183 TAG_LOGI(AAFwkTag::APPMGR, "pid: %{public}d", record->GetPid());
2184 auto pid = record->GetPid();
2185 if (pid <= 0) {
2186 TAG_LOGE(AAFwkTag::APPMGR, "pid <= 0");
2187 return;
2188 }
2189 std::lock_guard lock(childProcessRecordMapLock_);
2190 childProcessRecordMap_.erase(pid);
2191 }
2192
GetChildProcessRecordByPid(pid_t pid)2193 std::shared_ptr<ChildProcessRecord> AppRunningRecord::GetChildProcessRecordByPid(pid_t pid)
2194 {
2195 std::lock_guard lock(childProcessRecordMapLock_);
2196 auto iter = childProcessRecordMap_.find(pid);
2197 if (iter == childProcessRecordMap_.end()) {
2198 return nullptr;
2199 }
2200 return iter->second;
2201 }
2202
GetChildProcessRecordMap()2203 std::map<int32_t, std::shared_ptr<ChildProcessRecord>> AppRunningRecord::GetChildProcessRecordMap()
2204 {
2205 std::lock_guard lock(childProcessRecordMapLock_);
2206 return childProcessRecordMap_;
2207 }
2208
GetChildProcessCount()2209 int32_t AppRunningRecord::GetChildProcessCount()
2210 {
2211 std::lock_guard lock(childProcessRecordMapLock_);
2212 return childProcessRecordMap_.size();
2213 }
2214
GetChildProcessInfos(std::list<SimpleProcessInfo> & processInfos)2215 void AppRunningRecord::GetChildProcessInfos(std::list<SimpleProcessInfo> &processInfos)
2216 {
2217 std::lock_guard lock(childProcessRecordMapLock_);
2218 for (auto &iter : childProcessRecordMap_) {
2219 auto childRecord = iter.second;
2220 if (childRecord && childRecord->GetPid() > 0) {
2221 auto processInfo = SimpleProcessInfo(childRecord->GetPid(), childRecord->GetProcessName());
2222 processInfos.emplace_back(processInfo);
2223 }
2224 }
2225 }
2226 #endif //SUPPORT_CHILD_PROCESS
2227
SetJITEnabled(const bool jitEnabled)2228 void AppRunningRecord::SetJITEnabled(const bool jitEnabled)
2229 {
2230 jitEnabled_ = jitEnabled;
2231 }
2232
IsJITEnabled() const2233 bool AppRunningRecord::IsJITEnabled() const
2234 {
2235 return jitEnabled_;
2236 }
2237
SetPreloadMode(PreloadMode mode)2238 void AppRunningRecord::SetPreloadMode(PreloadMode mode)
2239 {
2240 preloadMode_ = mode;
2241 }
2242
GetPreloadMode()2243 PreloadMode AppRunningRecord::GetPreloadMode()
2244 {
2245 return preloadMode_;
2246 }
2247
SetPreloadModuleName(const std::string & preloadModuleName)2248 void AppRunningRecord::SetPreloadModuleName(const std::string& preloadModuleName)
2249 {
2250 preloadModuleName_ = preloadModuleName;
2251 }
2252
GetPreloadModuleName() const2253 std::string AppRunningRecord::GetPreloadModuleName() const
2254 {
2255 return preloadModuleName_;
2256 }
2257
SetPreloadState(PreloadState state)2258 void AppRunningRecord::SetPreloadState(PreloadState state)
2259 {
2260 preloadState_ = state;
2261 }
2262
IsPreloading() const2263 bool AppRunningRecord::IsPreloading() const
2264 {
2265 return preloadState_ == PreloadState::PRELOADING;
2266 }
2267
IsPreloaded() const2268 bool AppRunningRecord::IsPreloaded() const
2269 {
2270 return preloadState_ == PreloadState::PRELOADED;
2271 }
2272
GetAssignTokenId() const2273 int32_t AppRunningRecord::GetAssignTokenId() const
2274 {
2275 return assignTokenId_;
2276 }
2277
SetAssignTokenId(int32_t assignTokenId)2278 void AppRunningRecord::SetAssignTokenId(int32_t assignTokenId)
2279 {
2280 assignTokenId_ = assignTokenId;
2281 }
2282
SetRestartAppFlag(bool isRestartApp)2283 void AppRunningRecord::SetRestartAppFlag(bool isRestartApp)
2284 {
2285 isRestartApp_ = isRestartApp;
2286 }
2287
GetRestartAppFlag() const2288 bool AppRunningRecord::GetRestartAppFlag() const
2289 {
2290 return isRestartApp_;
2291 }
2292
SetAssertionPauseFlag(bool flag)2293 void AppRunningRecord::SetAssertionPauseFlag(bool flag)
2294 {
2295 isAssertPause_ = flag;
2296 }
2297
IsAssertionPause() const2298 bool AppRunningRecord::IsAssertionPause() const
2299 {
2300 return isAssertPause_;
2301 }
2302
IsDebugging() const2303 bool AppRunningRecord::IsDebugging() const
2304 {
2305 return isDebugApp_ || isAssertPause_;
2306 }
2307
SetNativeStart(bool isNativeStart)2308 void AppRunningRecord::SetNativeStart(bool isNativeStart)
2309 {
2310 isNativeStart_ = isNativeStart;
2311 }
2312
isNativeStart() const2313 bool AppRunningRecord::isNativeStart() const
2314 {
2315 return isNativeStart_;
2316 }
2317
SetExitReason(int32_t reason)2318 void AppRunningRecord::SetExitReason(int32_t reason)
2319 {
2320 exitReason_ = reason;
2321 }
2322
GetExitReason() const2323 int32_t AppRunningRecord::GetExitReason() const
2324 {
2325 return exitReason_;
2326 }
2327
SetExitMsg(const std::string & exitMsg)2328 void AppRunningRecord::SetExitMsg(const std::string &exitMsg)
2329 {
2330 exitMsg_ = exitMsg;
2331 }
2332
GetExitMsg() const2333 std::string AppRunningRecord::GetExitMsg() const
2334 {
2335 return exitMsg_;
2336 }
2337
DumpIpcStart(std::string & result)2338 int AppRunningRecord::DumpIpcStart(std::string& result)
2339 {
2340 TAG_LOGD(AAFwkTag::APPMGR, "called");
2341 if (appLifeCycleDeal_ == nullptr) {
2342 result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT))
2343 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
2344 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
2345 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
2346 return DumpErrorCode::ERR_INTERNAL_ERROR;
2347 }
2348 return appLifeCycleDeal_->DumpIpcStart(result);
2349 }
2350
DumpIpcStop(std::string & result)2351 int AppRunningRecord::DumpIpcStop(std::string& result)
2352 {
2353 TAG_LOGD(AAFwkTag::APPMGR, "called");
2354 if (appLifeCycleDeal_ == nullptr) {
2355 result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT))
2356 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
2357 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
2358 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
2359 return DumpErrorCode::ERR_INTERNAL_ERROR;
2360 }
2361 return appLifeCycleDeal_->DumpIpcStop(result);
2362 }
2363
DumpIpcStat(std::string & result)2364 int AppRunningRecord::DumpIpcStat(std::string& result)
2365 {
2366 TAG_LOGD(AAFwkTag::APPMGR, "called");
2367 if (appLifeCycleDeal_ == nullptr) {
2368 result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT))
2369 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
2370 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
2371 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
2372 return DumpErrorCode::ERR_INTERNAL_ERROR;
2373 }
2374 return appLifeCycleDeal_->DumpIpcStat(result);
2375 }
2376
DumpFfrt(std::string & result)2377 int AppRunningRecord::DumpFfrt(std::string& result)
2378 {
2379 TAG_LOGD(AAFwkTag::APPMGR, "called");
2380 if (appLifeCycleDeal_ == nullptr) {
2381 result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
2382 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
2383 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
2384 return DumpErrorCode::ERR_INTERNAL_ERROR;
2385 }
2386 return appLifeCycleDeal_->DumpFfrt(result);
2387 }
2388
SetWatchdogBackgroundStatusRunning(bool status)2389 void AppRunningRecord::SetWatchdogBackgroundStatusRunning(bool status)
2390 {
2391 if (appLifeCycleDeal_) {
2392 appLifeCycleDeal_->SetWatchdogBackgroundStatusRunning(status);
2393 }
2394 }
2395
SetSupportedProcessCache(bool isSupport)2396 bool AppRunningRecord::SetSupportedProcessCache(bool isSupport)
2397 {
2398 TAG_LOGI(AAFwkTag::APPMGR, "call");
2399 procCacheSupportState_ = isSupport ? SupportProcessCacheState::SUPPORT : SupportProcessCacheState::NOT_SUPPORT;
2400 return true;
2401 }
2402
SetEnableProcessCache(bool enable)2403 bool AppRunningRecord::SetEnableProcessCache(bool enable)
2404 {
2405 TAG_LOGI(AAFwkTag::APPMGR, "call");
2406 enableProcessCache_ = enable;
2407 return true;
2408 }
2409
GetEnableProcessCache()2410 bool AppRunningRecord::GetEnableProcessCache()
2411 {
2412 return enableProcessCache_;
2413 }
2414
GetSupportProcessCacheState()2415 SupportProcessCacheState AppRunningRecord::GetSupportProcessCacheState()
2416 {
2417 return procCacheSupportState_;
2418 }
2419
ScheduleCacheProcess()2420 void AppRunningRecord::ScheduleCacheProcess()
2421 {
2422 if (appLifeCycleDeal_ == nullptr) {
2423 TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
2424 return;
2425 }
2426 appLifeCycleDeal_->ScheduleCacheProcess();
2427 }
2428
CancelTask(std::string msg)2429 bool AppRunningRecord::CancelTask(std::string msg)
2430 {
2431 if (!taskHandler_) {
2432 TAG_LOGE(AAFwkTag::APPMGR, "null taskHandler_");
2433 return false;
2434 }
2435 return taskHandler_->CancelTask(msg);
2436 }
2437
SetBrowserHost(sptr<IRemoteObject> browser)2438 void AppRunningRecord::SetBrowserHost(sptr<IRemoteObject> browser)
2439 {
2440 browserHost_ = browser;
2441 }
2442
GetBrowserHost()2443 sptr<IRemoteObject> AppRunningRecord::GetBrowserHost()
2444 {
2445 return browserHost_;
2446 }
2447
SetHasGPU(bool gpu)2448 void AppRunningRecord::SetHasGPU(bool gpu)
2449 {
2450 if (gpu) {
2451 hasGPU_ = gpu;
2452 }
2453 }
2454
HasGPU()2455 bool AppRunningRecord::HasGPU()
2456 {
2457 return hasGPU_;
2458 }
2459
SetGPUPid(pid_t gpuPid)2460 void AppRunningRecord::SetGPUPid(pid_t gpuPid)
2461 {
2462 gpuPid_ = gpuPid;
2463 }
2464
GetGPUPid()2465 pid_t AppRunningRecord::GetGPUPid()
2466 {
2467 return gpuPid_;
2468 }
2469
GetPid()2470 pid_t AppRunningRecord::GetPid()
2471 {
2472 auto prioObj = GetPriorityObject();
2473 if (prioObj) {
2474 return prioObj->GetPid();
2475 }
2476 return 0;
2477 }
2478
SetAttachedToStatusBar(bool isAttached)2479 void AppRunningRecord::SetAttachedToStatusBar(bool isAttached)
2480 {
2481 isAttachedToStatusBar = isAttached;
2482 }
2483
IsAttachedToStatusBar()2484 bool AppRunningRecord::IsAttachedToStatusBar()
2485 {
2486 return isAttachedToStatusBar;
2487 }
2488
SetProcessCacheBlocked(bool isBlocked)2489 void AppRunningRecord::SetProcessCacheBlocked(bool isBlocked)
2490 {
2491 processCacheBlocked = isBlocked;
2492 }
2493
GetProcessCacheBlocked()2494 bool AppRunningRecord::GetProcessCacheBlocked()
2495 {
2496 return processCacheBlocked;
2497 }
2498
IsAllAbilityReadyToCleanedByUserRequest()2499 bool AppRunningRecord::IsAllAbilityReadyToCleanedByUserRequest()
2500 {
2501 std::lock_guard<ffrt::mutex> lock(hapModulesLock_);
2502 for (const auto &iter : hapModules_) {
2503 for (const auto &moduleRecord : iter.second) {
2504 if (moduleRecord == nullptr) {
2505 TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord");
2506 continue;
2507 }
2508 if (!moduleRecord->IsAllAbilityReadyToCleanedByUserRequest()) {
2509 return false;
2510 }
2511 }
2512 }
2513 return true;
2514 }
2515
SetUserRequestCleaning()2516 void AppRunningRecord::SetUserRequestCleaning()
2517 {
2518 isUserRequestCleaning_ = true;
2519 }
2520
IsUserRequestCleaning() const2521 bool AppRunningRecord::IsUserRequestCleaning() const
2522 {
2523 return isUserRequestCleaning_;
2524 }
2525
IsProcessAttached() const2526 bool AppRunningRecord::IsProcessAttached() const
2527 {
2528 if (appLifeCycleDeal_ == nullptr) {
2529 return false;
2530 }
2531 return appLifeCycleDeal_->GetApplicationClient() != nullptr;
2532 }
2533
SetUIAbilityLaunched(bool hasLaunched)2534 void AppRunningRecord::SetUIAbilityLaunched(bool hasLaunched)
2535 {
2536 hasUIAbilityLaunched_ = hasLaunched;
2537 }
2538
HasUIAbilityLaunched()2539 bool AppRunningRecord::HasUIAbilityLaunched()
2540 {
2541 return hasUIAbilityLaunched_;
2542 }
2543
SetProcessCaching(bool isCaching)2544 void AppRunningRecord::SetProcessCaching(bool isCaching)
2545 {
2546 isCaching_ = isCaching;
2547 }
2548
IsCaching()2549 bool AppRunningRecord::IsCaching()
2550 {
2551 return isCaching_;
2552 }
2553
AddAppLifecycleEvent(const std::string & msg)2554 void AppRunningRecord::AddAppLifecycleEvent(const std::string &msg)
2555 {
2556 pid_t pid = GetPid();
2557 if (pid != 0) {
2558 AbilityRuntime::FreezeUtil::GetInstance().AddAppLifecycleEvent(pid, msg);
2559 }
2560 }
2561
SetNeedPreloadModule(bool isNeedPreloadModule)2562 void AppRunningRecord::SetNeedPreloadModule(bool isNeedPreloadModule)
2563 {
2564 isNeedPreloadModule_ = isNeedPreloadModule;
2565 }
2566
GetNeedPreloadModule()2567 bool AppRunningRecord::GetNeedPreloadModule()
2568 {
2569 return isNeedPreloadModule_;
2570 }
2571
SetNWebPreload(const bool isAllowedNWebPreload)2572 void AppRunningRecord::SetNWebPreload(const bool isAllowedNWebPreload)
2573 {
2574 isAllowedNWebPreload_ = isAllowedNWebPreload;
2575 }
2576
IsNWebPreload() const2577 bool AppRunningRecord::IsNWebPreload() const
2578 {
2579 return isAllowedNWebPreload_;
2580 }
2581
SetIsUnSetPermission(bool isUnSetPermission)2582 void AppRunningRecord::SetIsUnSetPermission(bool isUnSetPermission)
2583 {
2584 isUnSetPermission_ = isUnSetPermission;
2585 }
2586
IsUnSetPermission()2587 bool AppRunningRecord::IsUnSetPermission()
2588 {
2589 return isUnSetPermission_;
2590 }
2591
GetNeedLimitPrio()2592 bool AppRunningRecord::GetNeedLimitPrio()
2593 {
2594 return isNeedLimitPrio_;
2595 }
2596
SetNeedLimitPrio(bool isNeedLimitPrio)2597 void AppRunningRecord::SetNeedLimitPrio(bool isNeedLimitPrio)
2598 {
2599 isNeedLimitPrio_ = isNeedLimitPrio;
2600 }
2601
UnSetPolicy()2602 void AppRunningRecord::UnSetPolicy()
2603 {
2604 TAG_LOGD(AAFwkTag::APPMGR, "UnSetPolicy call");
2605 auto appInfo = GetApplicationInfo();
2606 if (appInfo == nullptr) {
2607 TAG_LOGE(AAFwkTag::APPMGR, "appInfo null");
2608 return;
2609 }
2610 if (IsUnSetPermission()) {
2611 TAG_LOGI(AAFwkTag::APPMGR, "app is unset permission");
2612 return;
2613 }
2614 SetIsUnSetPermission(true);
2615 #ifdef SUPPORT_UPMS
2616 AAFwk::UriPermissionManagerClient::GetInstance().ClearPermissionTokenByMap(appInfo->accessTokenId);
2617 #endif // SUPPORT_UPMS
2618 }
2619
GetAddStageTimeout() const2620 uint32_t AppRunningRecord::GetAddStageTimeout() const
2621 {
2622 if (IsEmptyKeepAliveApp()) {
2623 return AMSEventHandler::ADD_ABILITY_STAGE_EMPTY_RESIDENT_TIMEOUT;
2624 }
2625 return AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT;
2626 }
2627
SetDebugFromLocal(bool isDebugFromLocal)2628 void AppRunningRecord::SetDebugFromLocal(bool isDebugFromLocal)
2629 {
2630 isDebugFromLocal_ = isDebugFromLocal;
2631 }
2632 } // namespace AppExecFwk
2633 } // namespace OHOS
2634