From 1123d69bb436cab3860234f0e8263a51aa11734a Mon Sep 17 00:00:00 2001 From: songjindian Date: Tue, 18 Apr 2023 10:14:01 +0800 Subject: [PATCH] =?UTF-8?q?bms=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songjindian --- .../include/slite/ability_record_manager.h | 10 +-- .../include/slite/bms_helper.h | 18 ++++- .../include/slite/slite_ability_loader.h | 3 + .../src/slite/ability_list.cpp | 1 - .../src/slite/ability_record_manager.cpp | 32 ++------- .../abilitymgr_lite/src/slite/bms_helper.cpp | 67 ++++++++++++++++--- .../src/slite/slite_ability_loader.cpp | 14 ++++ 7 files changed, 101 insertions(+), 44 deletions(-) diff --git a/services/abilitymgr_lite/include/slite/ability_record_manager.h b/services/abilitymgr_lite/include/slite/ability_record_manager.h index 51dd354..976c544 100644 --- a/services/abilitymgr_lite/include/slite/ability_record_manager.h +++ b/services/abilitymgr_lite/include/slite/ability_record_manager.h @@ -22,6 +22,7 @@ #include "ability_record.h" #include "ability_stack.h" #include "adapter.h" +#include "bms_helper.h" #include "js_ability_thread.h" #include "nocopyable.h" #include "want.h" @@ -30,12 +31,6 @@ namespace OHOS { namespace AbilitySlite { -struct AbilitySvcInfo { - char *bundleName; - char *path; - void *data; - uint16_t dataLength; -}; class AbilityRecordManager : public NoCopyable { public: @@ -110,8 +105,7 @@ private: void UpdateRecord(AbilitySvcInfo *info); int32_t ForceStopBundleInner(uint16_t token); - - bool IsValidAbility(AbilityInfo *abilityInfo); + bool IsLauncher(const char *bundleName); Want *CreateWant(const AbilityRecord *record); diff --git a/services/abilitymgr_lite/include/slite/bms_helper.h b/services/abilitymgr_lite/include/slite/bms_helper.h index 017a861..8cceeda 100644 --- a/services/abilitymgr_lite/include/slite/bms_helper.h +++ b/services/abilitymgr_lite/include/slite/bms_helper.h @@ -17,10 +17,20 @@ #define ABILITYLITE_BMS_HELPER_H #include +#include "bundle_manager.h" #include "utils_list.h" +#include "want.h" namespace OHOS { namespace AbilitySlite { +struct AbilitySvcInfo { + char *bundleName; + char *path; + void *data; + bool isNativeApp; + uint16_t dataLength; +}; + class BMSHelper final { public: static BMSHelper &GetInstance() @@ -33,13 +43,17 @@ public: ~BMSHelper(); - void RegisterBundleNames(List &names); + void RegisterBundleNames(const List &names); void Erase(); bool IsNativeApp(const char *bundleName); + + uint8_t QueryAbilitySvcInfo(const Want *want, AbilitySvcInfo *svcInfo); + + bool IsValidAbility(const AbilityInfo *abilityInfo); private: - List bundleNames {}; + List bundleNames_ {}; }; } // namespace AbilitySlite } // namespace OHOS diff --git a/services/abilitymgr_lite/include/slite/slite_ability_loader.h b/services/abilitymgr_lite/include/slite/slite_ability_loader.h index 230919f..66cce10 100644 --- a/services/abilitymgr_lite/include/slite/slite_ability_loader.h +++ b/services/abilitymgr_lite/include/slite/slite_ability_loader.h @@ -43,6 +43,9 @@ public: void SetAbilityCreatorFunc(SliteAbilityType type, SliteAbilityCreatorFunc creator); SliteAbility *CreateAbility(SliteAbilityType type, const char *bundleName); + + void UnsetAbilityCreatorFunc(SliteAbilityType type); + private: SliteAbilityCreatorFunc jsAbilityCreatorFunc_ = nullptr; SliteAbilityCreatorFunc nativeAbilityCreatorFunc_ = nullptr; diff --git a/services/abilitymgr_lite/src/slite/ability_list.cpp b/services/abilitymgr_lite/src/slite/ability_list.cpp index d2ae4d2..121eb60 100644 --- a/services/abilitymgr_lite/src/slite/ability_list.cpp +++ b/services/abilitymgr_lite/src/slite/ability_list.cpp @@ -80,7 +80,6 @@ AbilityRecord *AbilityList::GetByTaskId(uint32_t taskId) const return record; } } - return nullptr; } diff --git a/services/abilitymgr_lite/src/slite/ability_record_manager.cpp b/services/abilitymgr_lite/src/slite/ability_record_manager.cpp index 1c406e0..bdf8fad 100644 --- a/services/abilitymgr_lite/src/slite/ability_record_manager.cpp +++ b/services/abilitymgr_lite/src/slite/ability_record_manager.cpp @@ -72,20 +72,6 @@ void AbilityRecordManager::StartLauncher() (void) SchedulerLifecycleInner(record, SLITE_STATE_FOREGROUND); } -bool AbilityRecordManager::IsValidAbility(AbilityInfo *abilityInfo) -{ - if (abilityInfo == nullptr) { - return false; - } - if (abilityInfo->bundleName == nullptr || abilityInfo->srcPath == nullptr) { - return false; - } - if (strlen(abilityInfo->bundleName) == 0 || strlen(abilityInfo->srcPath) == 0) { - return false; - } - return true; -} - bool AbilityRecordManager::IsLauncher(const char *bundleName) { size_t len = strlen(bundleName); @@ -160,7 +146,6 @@ int32_t AbilityRecordManager::StartAbility(const Want *want) HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability Service AbilitySvcInfo is null"); return PARAM_NULL_ERROR; } - if (IsLauncher(bundleName)) { // Launcher info->bundleName = Utils::Strdup(bundleName); @@ -168,18 +153,15 @@ int32_t AbilityRecordManager::StartAbility(const Want *want) } else { // JS APP #ifdef _MINI_BMS_ - AbilityInfo abilityInfo = { nullptr, nullptr }; - QueryAbilityInfo(want, &abilityInfo); - if (!(BMSHelper::GetInstance().IsNativeApp(bundleName) || IsValidAbility(&abilityInfo))) { - APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_START_UNKNOWN_BUNDLE_INFO); - ClearAbilityInfo(&abilityInfo); + uint8_t queryRet = BMSHelper::GetInstance().QueryAbilitySvcInfo(want, info); + if (queryRet != ERR_OK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability BMS Helper return abilitySvcInfo failed"); + AdapterFree(info->bundleName); + AdapterFree(info->path); + AdapterFree(info->data); AdapterFree(info); - HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability Service returned bundleInfo is not valid"); - return PARAM_NULL_ERROR; + return PARAM_CHECK_ERROR; } - info->bundleName = OHOS::Utils::Strdup(abilityInfo.bundleName); - info->path = OHOS::Utils::Strdup(abilityInfo.srcPath); - ClearAbilityInfo(&abilityInfo); #else info->bundleName = Utils::Strdup(bundleName); // Here users assign want->data with js app path. diff --git a/services/abilitymgr_lite/src/slite/bms_helper.cpp b/services/abilitymgr_lite/src/slite/bms_helper.cpp index a3f24a0..1ba7c79 100644 --- a/services/abilitymgr_lite/src/slite/bms_helper.cpp +++ b/services/abilitymgr_lite/src/slite/bms_helper.cpp @@ -14,31 +14,36 @@ */ #include "bms_helper.h" +#include "aafwk_event_error_code.h" +#include "ability_errors.h" +#include "abilityms_log.h" #include "utils.h" +using namespace OHOS::ACELite; + namespace OHOS::AbilitySlite { BMSHelper::~BMSHelper() { Erase(); } -void BMSHelper::RegisterBundleNames(List &names) +void BMSHelper::RegisterBundleNames(const List &names) { for (auto node = names.Begin(); node != names.End(); node = node->next_) { char *bundleName = node->value_; if (bundleName != nullptr) { char *name = Utils::Strdup(bundleName); - bundleNames.PushBack(name); + bundleNames_.PushBack(name); } } } void BMSHelper::Erase() { - while (bundleNames.Front() != nullptr) { - char *name = bundleNames.Front(); + while (bundleNames_.Front() != nullptr) { + char *name = bundleNames_.Front(); AdapterFree(name); - bundleNames.PopFront(); + bundleNames_.PopFront(); } } @@ -47,14 +52,60 @@ bool BMSHelper::IsNativeApp(const char *bundleName) if (bundleName == nullptr) { return false; } - auto next = bundleNames.Begin(); - for (auto node = next; node != bundleNames.End(); node = next) { + for (auto node = bundleNames_.Begin(); node != bundleNames_.End(); node = node->next_) { char *bundleName_ = node->value_; - next = node->next_; if (strcmp(bundleName, bundleName_) == 0) { return true; } } return false; } + +uint8_t BMSHelper::QueryAbilitySvcInfo(const Want *want, AbilitySvcInfo *svcInfo) +{ +#ifdef _MINI_BMS_ + if (want == nullptr || want->element == nullptr || want->element->bundleName == nullptr) { + return PARAM_NULL_ERROR; + } + if (IsNativeApp(want->element->bundleName)) { + svcInfo->bundleName = OHOS::Utils::Strdup(want->element->bundleName); + svcInfo->path = nullptr; + svcInfo->isNativeApp = true; + return ERR_OK; + } + + AbilityInfo abilityInfo = { nullptr, nullptr }; + QueryAbilityInfo(want, &abilityInfo); + if (!IsValidAbility(&abilityInfo)) { + APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_START_UNKNOWN_BUNDLE_INFO); + HILOG_ERROR(HILOG_MODULE_AAFWK, "Invalid AbilityInfo"); + ClearAbilityInfo(&abilityInfo); + return PARAM_CHECK_ERROR; + } + svcInfo->bundleName = OHOS::Utils::Strdup(abilityInfo.bundleName); + svcInfo->path = OHOS::Utils::Strdup(abilityInfo.srcPath); + svcInfo->isNativeApp = false; + ClearAbilityInfo(&abilityInfo); + return ERR_OK; +#else + svcInfo->bundleName = Utils::Strdup(want->element->bundleName); + // Here users assign want->data with js app path. + svcInfo->path = Utils::Strdup((const char *)want->data); + return ERR_OK; +#endif +} + +bool BMSHelper::IsValidAbility(const AbilityInfo *abilityInfo) +{ + if (abilityInfo == nullptr) { + return false; + } + if (abilityInfo->bundleName == nullptr || abilityInfo->srcPath == nullptr) { + return false; + } + if (strlen(abilityInfo->bundleName) == 0 || strlen(abilityInfo->srcPath) == 0) { + return false; + } + return true; +} } \ No newline at end of file diff --git a/services/abilitymgr_lite/src/slite/slite_ability_loader.cpp b/services/abilitymgr_lite/src/slite/slite_ability_loader.cpp index 7c4c001..0c0a712 100644 --- a/services/abilitymgr_lite/src/slite/slite_ability_loader.cpp +++ b/services/abilitymgr_lite/src/slite/slite_ability_loader.cpp @@ -51,4 +51,18 @@ SliteAbility *SliteAbilityLoader::CreateAbility(SliteAbilityType type, const cha } return nullptr; } + +void SliteAbilityLoader::UnsetAbilityCreatorFunc(SliteAbilityType type) +{ + switch (type) { + case SliteAbilityType::JS_ABILITY: + jsAbilityCreatorFunc_ = nullptr; + break; + case SliteAbilityType::NATIVE_ABILITY: + nativeAbilityCreatorFunc_ = nullptr; + break; + default: + break; + } +} } \ No newline at end of file -- Gitee