From 31a66d0a7c6e9a8d781f4206555230a894061169 Mon Sep 17 00:00:00 2001 From: yangzk Date: Wed, 14 Jun 2023 17:04:47 +0800 Subject: [PATCH] =?UTF-8?q?Description:=20=E4=BF=AE=E5=A4=8D=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E6=84=8F=E8=A7=81=20IssueNo:=20#I7DHSG=20Sig:=20SIG?= =?UTF-8?q?=5FApplicationFramework=20Feature=20or=20Bugfix:=20Bugfix=20Bin?= =?UTF-8?q?ary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangzk Change-Id: I204b80c26dbc8bc4387b02653bbe33d60cd70261 --- .../include/slite/ability_list.h | 2 +- .../include/slite/native_ability_thread.h | 1 + .../src/slite/ability_list.cpp | 2 +- .../src/slite/ability_mgr_service_slite.cpp | 2 ++ .../src/slite/ability_record_manager.cpp | 21 +++++++++++++++--- .../slite/ability_record_observer_manager.cpp | 10 ++++++--- .../src/slite/native_ability_thread.cpp | 22 +++++++++++++++++++ 7 files changed, 52 insertions(+), 8 deletions(-) diff --git a/services/abilitymgr_lite/include/slite/ability_list.h b/services/abilitymgr_lite/include/slite/ability_list.h index dc5a616..dc8e011 100644 --- a/services/abilitymgr_lite/include/slite/ability_list.h +++ b/services/abilitymgr_lite/include/slite/ability_list.h @@ -23,7 +23,7 @@ namespace OHOS { namespace AbilitySlite { -constexpr char HOME_BUNDLE_NAME[] = "main"; +constexpr char MAIN_BUNDLE_NAME[] = "main"; class AbilityList { public: diff --git a/services/abilitymgr_lite/include/slite/native_ability_thread.h b/services/abilitymgr_lite/include/slite/native_ability_thread.h index 6032b16..14a0567 100644 --- a/services/abilitymgr_lite/include/slite/native_ability_thread.h +++ b/services/abilitymgr_lite/include/slite/native_ability_thread.h @@ -40,6 +40,7 @@ public: private: static osMessageQueueId_t nativeQueueId_; static UINT32 nativeTaskId_; + static SliteAbility *nativeAbility_; }; } } diff --git a/services/abilitymgr_lite/src/slite/ability_list.cpp b/services/abilitymgr_lite/src/slite/ability_list.cpp index 031e18f..d246362 100644 --- a/services/abilitymgr_lite/src/slite/ability_list.cpp +++ b/services/abilitymgr_lite/src/slite/ability_list.cpp @@ -191,7 +191,7 @@ void AbilityList::PopBottomAbility() abilityList_.PopBack(); return; } - if (lastRecord->appName == nullptr || strcmp(lastRecord->appName, HOME_BUNDLE_NAME) != 0) { + if (lastRecord->appName == nullptr || strcmp(lastRecord->appName, MAIN_BUNDLE_NAME) != 0) { abilityList_.PopBack(); delete lastRecord; return; diff --git a/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp b/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp index 8249473..4ba060d 100644 --- a/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp +++ b/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp @@ -17,6 +17,7 @@ #include "ability_errors.h" #include "ability_record_observer.h" +#include "ability_record_observer_manager.h" #include "ability_service_interface.h" #include "ability_thread_loader.h" #include "abilityms_slite_client.h" @@ -141,6 +142,7 @@ BOOL AbilityMgrServiceSlite::ServiceInitialize(Service *service, Identity identi abilityMgrService->serviceIdentity_ = identity; InitAbilityThreadLoad(); InitAbilityLoad(); + AbilityRecordObserverManager::GetInstance(); AbilityMsClient::GetInstance().SetServiceIdentity(&abilityMgrService->serviceIdentity_); return TRUE; } diff --git a/services/abilitymgr_lite/src/slite/ability_record_manager.cpp b/services/abilitymgr_lite/src/slite/ability_record_manager.cpp index c5cfd9c..8a8a0af 100644 --- a/services/abilitymgr_lite/src/slite/ability_record_manager.cpp +++ b/services/abilitymgr_lite/src/slite/ability_record_manager.cpp @@ -179,11 +179,13 @@ int32_t AbilityRecordManager::StartAbility(const Want *want) } isAppScheduling_ = true; if (want == nullptr || want->element == nullptr) { + isAppScheduling_ = false; HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability Service wanted element is null"); return PARAM_NULL_ERROR; } char *bundleName = want->element->bundleName; if (bundleName == nullptr) { + isAppScheduling_ = false; HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability Service wanted bundleName is null"); return PARAM_NULL_ERROR; } @@ -191,6 +193,7 @@ int32_t AbilityRecordManager::StartAbility(const Want *want) #ifdef OHOS_DMS_ENABLED if (want->element->deviceId != nullptr && *(want->element->deviceId) != '\0') { // deviceId is set + isAppScheduling_ = false; return StartRemoteAbility(want); } #endif @@ -222,11 +225,13 @@ int32_t AbilityRecordManager::StartAbility(const Want *want) auto *info = static_cast(AdapterMalloc(sizeof(AbilitySvcInfo))); if (info == nullptr) { + isAppScheduling_ = false; HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability Service AbilitySvcInfo is null"); return PARAM_NULL_ERROR; } uint8_t queryRet = BMSHelper::GetInstance().QueryAbilitySvcInfo(want, info); if (queryRet != ERR_OK) { + isAppScheduling_ = false; HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability BMS Helper return abilitySvcInfo failed"); AdapterFree(info); return PARAM_CHECK_ERROR; @@ -260,6 +265,7 @@ void AbilityRecordManager::UpdateRecord(AbilitySvcInfo *info) int32_t AbilityRecordManager::StartAbility(AbilitySvcInfo *info) { if ((info == nullptr) || (info->bundleName == nullptr) || (strlen(info->bundleName) == 0)) { + isAppScheduling_ = false; return PARAM_NULL_ERROR; } HILOG_INFO(HILOG_MODULE_AAFWK, "StartAbility"); @@ -267,6 +273,7 @@ int32_t AbilityRecordManager::StartAbility(AbilitySvcInfo *info) auto topRecord = abilityList_.GetTopAbility(); #ifndef _MINI_MULTI_TASKS_ if ((topRecord == nullptr) || (topRecord->appName == nullptr)) { + isAppScheduling_ = false; HILOG_ERROR(HILOG_MODULE_AAFWK, "StartAbility top null."); return PARAM_NULL_ERROR; } @@ -284,6 +291,7 @@ int32_t AbilityRecordManager::StartAbility(AbilitySvcInfo *info) } if ((info->isNativeApp == false) && !CheckResponse(info->bundleName)) { + isAppScheduling_ = false; return PARAM_CHECK_ERROR; } @@ -380,6 +388,7 @@ int32_t AbilityRecordManager::TerminateAbility(uint16_t token, const Want* want) HILOG_INFO(HILOG_MODULE_AAFWK, "TerminateAbility [%{public}u]", token); AbilityRecord *topRecord = const_cast(abilityList_.GetTopAbility()); if (topRecord == nullptr) { + isAppScheduling_ = false; APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_STOP_NO_ABILITY_RUNNING); return PARAM_NULL_ERROR; } @@ -387,6 +396,7 @@ int32_t AbilityRecordManager::TerminateAbility(uint16_t token, const Want* want) #ifndef _MINI_MULTI_TASKS_ if (token == LAUNCHER_TOKEN) { // if js is in background, the launcher goes back to background and js goes to active + isAppScheduling_ = false; if (topToken != token && topRecord->state == SCHEDULE_BACKGROUND) { HILOG_INFO(HILOG_MODULE_AAFWK, "Resume Js app [%{public}u]", topToken); return SchedulerLifecycle(LAUNCHER_TOKEN, SLITE_STATE_BACKGROUND); @@ -395,6 +405,7 @@ int32_t AbilityRecordManager::TerminateAbility(uint16_t token, const Want* want) } if (token != topToken) { + isAppScheduling_ = false; APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_STOP_UNKNOWN_ABILITY_TOKEN); DeleteRecordInfo(token); return -1; @@ -412,6 +423,7 @@ int32_t AbilityRecordManager::TerminateAbility(uint16_t token, const Want* want) if (token != topToken) { AbilityRecord* abilityRecord = abilityList_.Get(token); if ((abilityRecord == nullptr) || (abilityRecord->token == LAUNCHER_TOKEN)) { + isAppScheduling_ = false; return PARAM_CHECK_ERROR; } APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_STOP_UNKNOWN_ABILITY_TOKEN); @@ -423,6 +435,7 @@ int32_t AbilityRecordManager::TerminateAbility(uint16_t token, const Want* want) abilityList_.PopAbility(); AbilityRecord *newTopRecord = const_cast(abilityList_.GetTopAbility()); if (newTopRecord == nullptr) { + isAppScheduling_ = false; APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_STOP_NO_ABILITY_RUNNING); return PARAM_NULL_ERROR; } @@ -505,13 +518,13 @@ int32_t AbilityRecordManager::TerminateAll(const char *excludedBundleName) return AddAbilityOperation(TERMINATE_ALL, &want, 0); } isAppScheduling_ = true; - AbilityRecord *homeRecord = abilityList_.Get(HOME_BUNDLE_NAME); + AbilityRecord *homeRecord = abilityList_.Get(MAIN_BUNDLE_NAME); if (homeRecord == nullptr) { return PARAM_CHECK_ERROR; } AbilityRecord *topRecord = abilityList_.GetTopAbility(); abilityList_.PopAbility(); - if (excludedBundleName == nullptr || strcmp(excludedBundleName, HOME_BUNDLE_NAME) == 0 + if (excludedBundleName == nullptr || strcmp(excludedBundleName, MAIN_BUNDLE_NAME) == 0 || strcmp(excludedBundleName, topRecord->appName) == 0) { excludedBundleName = nullptr; } @@ -523,7 +536,7 @@ int32_t AbilityRecordManager::TerminateAll(const char *excludedBundleName) if (record == nullptr) { continue; } - if (strcmp(record->appName, HOME_BUNDLE_NAME) == 0) { + if (strcmp(record->appName, MAIN_BUNDLE_NAME) == 0) { continue; } if (excludedBundleName != nullptr && strcmp(record->appName, excludedBundleName) == 0) { @@ -552,6 +565,7 @@ int32_t AbilityRecordManager::ForceStop(const Want *want) if (want == nullptr || want->element == nullptr || want->element->bundleName == nullptr) { + isAppScheduling_ = false; return PARAM_NULL_ERROR; } @@ -564,6 +578,7 @@ int32_t AbilityRecordManager::ForceStop(const Want *want) // stop app AbilityRecord *terminateRecord = abilityList_.Get(want->element->bundleName); if (terminateRecord == nullptr) { + isAppScheduling_ = false; HILOG_ERROR(HILOG_MODULE_AAFWK, "ForceStop, The specified ability is not found."); return PARAM_CHECK_ERROR; } diff --git a/services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp b/services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp index 245df1f..6a52259 100644 --- a/services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp +++ b/services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp @@ -46,15 +46,19 @@ void AbilityRecordObserverManager::RemoveObserver(AbilityRecordObserver *observe void AbilityRecordObserverManager::NotifyAbilityRecordStateChanged(const AbilityRecordStateData &data) { for (auto it = observers_.Begin(); it != observers_.End(); it = it->next_) { - it->value_->OnAbilityRecordStateChanged(data); + if (it->value_ != nullptr) { + it->value_->OnAbilityRecordStateChanged(data); + } } } void AbilityRecordObserverManager::NotifyAbilityRecordCleanup(char *appName) { for (auto it = observers_.Begin(); it != observers_.End(); it = it->next_) { - it->value_->OnAbilityRecordCleanup(appName); + if (it->value_ != nullptr) { + it->value_->OnAbilityRecordCleanup(appName); + } } } } // namespace AbilitySlite -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr_lite/src/slite/native_ability_thread.cpp b/services/abilitymgr_lite/src/slite/native_ability_thread.cpp index 8b5cf4d..f92ff70 100644 --- a/services/abilitymgr_lite/src/slite/native_ability_thread.cpp +++ b/services/abilitymgr_lite/src/slite/native_ability_thread.cpp @@ -34,6 +34,7 @@ constexpr int32_t QUEUE_LENGTH = 32; osMessageQueueId_t NativeAbilityThread::nativeQueueId_ = nullptr; UINT32 NativeAbilityThread::nativeTaskId_ = UINT32_MAX; +SliteAbility *NativeAbilityThread::nativeAbility_ = nullptr; NativeAbilityThread::NativeAbilityThread() = default; @@ -42,8 +43,15 @@ NativeAbilityThread::~NativeAbilityThread() if (ability_ == nullptr) { return; } +#ifdef _MINI_MULTI_TASKS_ delete ability_; ability_ = nullptr; +#else + if ((ability_->bundleName_ == nullptr) || (strcmp(ability_->bundleName_, LAUNCHER_BUNDLE_NAME) != 0)) { + delete ability_; + ability_ = nullptr; + } +#endif } int32_t NativeAbilityThread::InitAbilityThread(const AbilityRecord *abilityRecord) @@ -89,8 +97,21 @@ int32_t NativeAbilityThread::InitAbilityThread(const AbilityRecord *abilityRecor } state_ = AbilityThreadState::ABILITY_THREAD_INITIALIZED; +#ifdef _MINI_MULTI_TASKS_ ability_ = SliteAbilityLoader::GetInstance().CreateAbility(SliteAbilityType::NATIVE_ABILITY, abilityRecord->appName); +#else + if (strcmp(abilityRecord->appName, LAUNCHER_BUNDLE_NAME) == 0) { + if (nativeAbility_ == nullptr) { + nativeAbility_ = SliteAbilityLoader::GetInstance().CreateAbility(SliteAbilityType::NATIVE_ABILITY, + abilityRecord->appName); + } + ability_ = nativeAbility_; + } else { + ability_ = SliteAbilityLoader::GetInstance().CreateAbility(SliteAbilityType::NATIVE_ABILITY, + abilityRecord->appName); + } +#endif if (ability_ == nullptr) { HILOG_INFO(HILOG_MODULE_AAFWK, "NativeAbility create fail"); LOS_TaskUnlock(); @@ -128,6 +149,7 @@ void NativeAbilityThread::Reset() } nativeQueueId_ = nullptr; nativeTaskId_ = 0; + nativeAbility_ = nullptr; } void NativeAbilityThread::NativeAppTaskHandler(UINT32 uwArg) -- Gitee