IssueNo:#I5Y0KN

Description:分支覆盖TDD补充及代码优化
Sig:SIG_ApplicationFramework
Feature or Bugfix:Bugfix
Binary Source: No

Signed-off-by: dy_study <dingyao5@huawei.com>
Change-Id: I6c4eab026ddc54ca80fb4e9239151c222b7a2f73
This commit is contained in:
dy_study
2022-10-27 14:28:23 +08:00
parent 421f8dcfd4
commit 52fbcfe040
6 changed files with 137 additions and 17 deletions
@@ -606,9 +606,6 @@ void ContextContainer::InitResourceManager(BundleInfo &bundleInfo, std::shared_p
"ContextContainer::InitResourceManager hapModuleInfos count: %{public}zu", bundleInfo.hapModuleInfos.size());
std::regex pattern(AbilityRuntime::Constants::ABS_CODE_PATH);
for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.resourcePath.empty() && hapModuleInfo.hapPath.empty()) {
continue;
}
std::string loadPath;
if (system::GetBoolParameter(AbilityRuntime::Constants::COMPRESS_PROPERTY, false) &&
!hapModuleInfo.hapPath.empty()) {
@@ -616,6 +613,9 @@ void ContextContainer::InitResourceManager(BundleInfo &bundleInfo, std::shared_p
} else {
loadPath = hapModuleInfo.resourcePath;
}
if (loadPath.empty()) {
continue;
}
loadPath = std::regex_replace(loadPath, pattern, AbilityRuntime::Constants::LOCAL_BUNDLES);
HILOG_DEBUG("ContextContainer::InitResourceManager loadPath: %{public}s", loadPath.c_str());
if (!resourceManager->AddResource(loadPath.c_str())) {
+3 -3
View File
@@ -770,11 +770,11 @@ bool MainThread::InitResourceManager(std::shared_ptr<Global::Resource::ResourceM
} else {
std::regex pattern(std::string(ABS_CODE_PATH) + std::string(FILE_SEPARATOR) + bundleInfo.name);
for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.resourcePath.empty() && hapModuleInfo.hapPath.empty()) {
continue;
}
std::string loadPath = (system::GetBoolParameter(AbilityRuntime::Constants::COMPRESS_PROPERTY, false) &&
!hapModuleInfo.hapPath.empty()) ? hapModuleInfo.hapPath : hapModuleInfo.resourcePath;
if (loadPath.empty()) {
continue;
}
loadPath = std::regex_replace(loadPath, pattern, std::string(LOCAL_CODE_PATH));
HILOG_DEBUG("ModuleResPath: %{public}s", loadPath.c_str());
if (!resourceManager->AddResource(loadPath.c_str())) {
+5 -5
View File
@@ -720,11 +720,6 @@ std::shared_ptr<Global::Resource::ResourceManager> AbilityRecord::CreateResource
std::shared_ptr<Global::Resource::ResourceManager> resourceMgr(Global::Resource::CreateResourceManager());
resourceMgr->UpdateResConfig(*resConfig);
if (abilityInfo_.resourcePath.empty() && abilityInfo_.hapPath.empty()) {
HILOG_WARN("Invalid app resource.");
return nullptr;
}
std::string loadPath;
if (system::GetBoolParameter(AbilityRuntime::Constants::COMPRESS_PROPERTY, false) &&
!abilityInfo_.hapPath.empty()) {
@@ -733,6 +728,11 @@ std::shared_ptr<Global::Resource::ResourceManager> AbilityRecord::CreateResource
loadPath = abilityInfo_.resourcePath;
}
if (loadPath.empty()) {
HILOG_WARN("Invalid app resource.");
return nullptr;
}
if (!resourceMgr->AddResource(loadPath.c_str())) {
HILOG_WARN("%{public}s AddResource failed.", __func__);
return nullptr;
@@ -330,9 +330,6 @@ void SystemDialogScheduler::GetAppNameFromResource(int32_t labelId,
std::regex pattern(std::string(AbilityRuntime::Constants::ABS_CODE_PATH) +
std::string(AbilityRuntime::Constants::FILE_SEPARATOR) + bundleInfo.name);
for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.resourcePath.empty() && hapModuleInfo.hapPath.empty()) {
continue;
}
std::string loadPath;
if (system::GetBoolParameter(AbilityRuntime::Constants::COMPRESS_PROPERTY, false) &&
!hapModuleInfo.hapPath.empty()) {
@@ -340,6 +337,9 @@ void SystemDialogScheduler::GetAppNameFromResource(int32_t labelId,
} else {
loadPath = hapModuleInfo.resourcePath;
}
if (loadPath.empty()) {
continue;
}
HILOG_DEBUG("GetAppNameFromResource loadPath: %{public}s", loadPath.c_str());
if (!resourceManager->AddResource(loadPath.c_str())) {
HILOG_ERROR("ResourceManager add %{public}s resource path failed!", bundleInfo.name.c_str());
@@ -16,13 +16,15 @@
#include <cstdlib>
#include <gtest/gtest.h>
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#define private public
#include "main_thread.h"
#undef private
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "mock_bundle_manager.h"
#include "process_info.h"
#include "quick_fix_callback_stub.h"
#include "system_ability_definition.h"
#include "sys_mgr_client.h"
@@ -160,5 +162,80 @@ HWTEST_F(MainThreadTest, ScheduleNotifyUnLoadRepairPatch_0100, TestSize.Level1)
EXPECT_EQ(ret, NO_ERROR);
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.name: InitResourceManager_0100
* @tc.desc: init resourceManager.
* @tc.type: FUNC
* @tc.require: issueI581VW
*/
HWTEST_F(MainThreadTest, InitResourceManager_0100, TestSize.Level1)
{
std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
EXPECT_TRUE(resourceManager != nullptr);
AppExecFwk::BundleInfo bundleInfo;
Configuration config;
bundleInfo.applicationInfo.multiProjects = true;
mainThread_->InitResourceManager(resourceManager, bundleInfo, config);
EXPECT_TRUE(resourceManager != nullptr);
bundleInfo.applicationInfo.multiProjects = false;
mainThread_->InitResourceManager(resourceManager, bundleInfo, config);
EXPECT_TRUE(resourceManager != nullptr);
HapModuleInfo info;
info.name = "com.ohos.contactsdataability";
info.moduleName = "entry";
info.description = "dataability_description";
info.iconPath = "$media:icon";
info.deviceTypes = {"smartVision"};
info.bundleName = "com.ohos.contactsdataability";
bundleInfo.hapModuleInfos.push_back(info);
bundleInfo.applicationInfo.multiProjects = true;
mainThread_->InitResourceManager(resourceManager, bundleInfo, config);
EXPECT_TRUE(resourceManager != nullptr);
bundleInfo.applicationInfo.multiProjects = false;
mainThread_->InitResourceManager(resourceManager, bundleInfo, config);
EXPECT_TRUE(resourceManager != nullptr);
info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\
"/com.ohos.contactsdataability/assets/entry/resources.index";
bundleInfo.hapModuleInfos.clear();
bundleInfo.hapModuleInfos.push_back(info);
mainThread_->InitResourceManager(resourceManager, bundleInfo, config);
EXPECT_TRUE(resourceManager != nullptr);
info.hapPath = "/system/app/com.ohos.contactsdataability/Contacts_DataAbility.hap";
bundleInfo.hapModuleInfos.clear();
bundleInfo.hapModuleInfos.push_back(info);
mainThread_->InitResourceManager(resourceManager, bundleInfo, config);
EXPECT_TRUE(resourceManager != nullptr);
info.resourcePath = "";
bundleInfo.hapModuleInfos.clear();
bundleInfo.hapModuleInfos.push_back(info);
mainThread_->InitResourceManager(resourceManager, bundleInfo, config);
EXPECT_TRUE(resourceManager != nullptr);
}
/**
* @tc.name: HandleLaunchApplication_0100
* @tc.desc: Handle launch application.
* @tc.type: FUNC
* @tc.require: issueI581VW
*/
HWTEST_F(MainThreadTest, HandleLaunchApplication_0100, TestSize.Level1)
{
Configuration config;
AppLaunchData lanchdate;
ProcessInfo processing("TestProcess", 9999);
ApplicationInfo appinf;
appinf.name = "MockTestApplication";
appinf.moduleSourceDirs.push_back("/hos/lib/libabilitydemo_native.z.so");
lanchdate.SetApplicationInfo(appinf);
lanchdate.SetProcessInfo(processing);
mainThread_->HandleLaunchApplication(lanchdate, config);
EXPECT_TRUE(mainThread_->application_ != nullptr);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -576,5 +576,48 @@ HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetProcessName_0200,
std::string name = context_->GetProcessName();
EXPECT_STREQ(empty.c_str(), name.c_str());
}
/**
* @tc.number: AppExecFwk_ContextContainer_InitResourceManager_0100
* @tc.name: GetProcessName
* @tc.desc: Test GetProcessName exception status.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_InitResourceManager_0100, Function | MediumTest | Level3)
{
std::shared_ptr<AppExecFwk::ContextDeal> appContext = std::make_shared<AppExecFwk::ContextDeal>(true);
AppExecFwk::BundleInfo bundleInfo;
context_->InitResourceManager(bundleInfo, appContext);
EXPECT_TRUE(appContext->GetResourceManager() != nullptr);
HapModuleInfo info;
info.name = "com.ohos.contactsdataability";
info.moduleName = "entry";
info.description = "dataability_description";
info.iconPath = "$media:icon";
info.deviceTypes = {"smartVision"};
info.bundleName = "com.ohos.contactsdataability";
bundleInfo.hapModuleInfos.push_back(info);
context_->InitResourceManager(bundleInfo, appContext);
EXPECT_TRUE(appContext->GetResourceManager() != nullptr);
info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\
"/com.ohos.contactsdataability/assets/entry/resources.index";
bundleInfo.hapModuleInfos.clear();
bundleInfo.hapModuleInfos.push_back(info);
context_->InitResourceManager(bundleInfo, appContext);
EXPECT_TRUE(appContext->GetResourceManager() != nullptr);
info.hapPath = "/system/app/com.ohos.contactsdataability/Contacts_DataAbility.hap";
bundleInfo.hapModuleInfos.clear();
bundleInfo.hapModuleInfos.push_back(info);
context_->InitResourceManager(bundleInfo, appContext);
EXPECT_TRUE(appContext->GetResourceManager() != nullptr);
info.resourcePath = "";
bundleInfo.hapModuleInfos.clear();
bundleInfo.hapModuleInfos.push_back(info);
context_->InitResourceManager(bundleInfo, appContext);
EXPECT_TRUE(appContext->GetResourceManager() != nullptr);
}
} // namespace AppExecFwk
} // namespace OHOS