!572 深色模式优化

Merge pull request !572 from 张婷/master
This commit is contained in:
openharmony_ci 2024-05-22 05:54:11 +00:00 committed by Gitee
commit 07924fac88
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 191 additions and 69 deletions

View File

@ -45,7 +45,7 @@ public:
* @return pResource if create pResource success, else nullptr
*/
static const std::shared_ptr<HapResource> LoadFromIndex(
const char *path, const std::shared_ptr<ResConfigImpl> defaultConfig,
const char *path, std::shared_ptr<ResConfigImpl> &defaultConfig,
bool isSystem = false, bool isOverlay = false, const uint32_t &selectedTypes = SELECT_ALL);
/**
@ -61,7 +61,7 @@ public:
* @return pResource if create pResource success, else nullptr
*/
static const std::shared_ptr<HapResource> LoadFromHap(
const char *path, const std::shared_ptr<ResConfigImpl> defaultConfig,
const char *path, std::shared_ptr<ResConfigImpl> &defaultConfig,
bool isSystem = false, bool isOverlay = false, const uint32_t &selectedTypes = SELECT_ALL);
/**
@ -77,7 +77,7 @@ public:
* @return pResource if create pResource success, else nullptr
*/
static const std::shared_ptr<HapResource> Load(
const char* path, const std::shared_ptr<ResConfigImpl> defaultConfig,
const char* path, std::shared_ptr<ResConfigImpl> &defaultConfig,
bool isSystem = false, bool isOverlay = false, const uint32_t &selectedTypes = SELECT_ALL);
/**
@ -90,7 +90,7 @@ public:
*/
static const std::unordered_map<std::string, std::shared_ptr<HapResource>> LoadOverlays(
const std::string &path, const std::vector<std::string> &overlayPath,
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem = false);
std::shared_ptr<ResConfigImpl> &defaultConfig, bool isSystem = false);
/**
* The destructor of HapResource
@ -305,12 +305,16 @@ private:
void GetKeyParamsLocales(const std::vector<std::shared_ptr<KeyParam>> keyParams, std::set<std::string> &outValue);
// must call Init() after constructor
bool Init();
bool Init(std::shared_ptr<ResConfigImpl> &defaultConfig);
bool InitMap(const std::shared_ptr<ResKey> &resKey, const std::pair<std::string, std::string> &resPath);
bool InitMap(const std::shared_ptr<ResKey> &resKey, const std::pair<std::string, std::string> &resPath,
std::shared_ptr<ResConfigImpl> &defaultConfig);
// step of Init(), called in Init()
bool InitIdList();
bool InitIdList(std::shared_ptr<ResConfigImpl> &defaultConfig);
void IsAppDarkRes(const std::shared_ptr<HapResource::ValueUnderQualifierDir> &limitPath,
std::shared_ptr<ResConfigImpl> &defaultConfig);
// resources.index file path
const std::string indexPath_;

View File

@ -141,9 +141,10 @@ public:
/**
* Copy other resConfig to this resConfig
* @param other the other resConfig
* @param isRead the isAppDarkRes_ is read-only
* @return true if copy other resConfig to this resConfig success, else false
*/
bool Copy(ResConfig &other);
bool Copy(ResConfig &other, bool isRead = false);
/**
* Complete the local script
@ -176,6 +177,30 @@ public:
virtual ~ResConfigImpl();
/**
* Set colorMode is setted by app
* @param isAppColorMode whether colorMode is setted by app
*/
void SetAppColorMode(bool isAppColorMode);
/**
* Get whether colorMode is setted by app
* @return True if colorMode is setted by app
*/
bool GetAppColorMode() const;
/**
* Set whether the app has dark resources
* @param isAppDarkRes whether the app has dark resources
*/
void SetAppDarkRes(bool isAppDarkRes);
/**
* Get whether the app has dark resources
* @return True if the app has dark resources
*/
bool GetAppDarkRes() const;
private:
bool IsMoreSpecificThan(const std::shared_ptr<ResConfigImpl> other, uint32_t density = 0) const;
@ -227,6 +252,8 @@ private:
Locale *localeInfo_;
#endif
bool isCompletedScript_;
bool isAppColorMode_;
bool isAppDarkRes_;
};
} // namespace Resource
} // namespace Global

View File

@ -209,7 +209,7 @@ std::shared_ptr<ResConfigImpl> HapManager::getCompleteOverrideConfig(bool isGetO
return nullptr;
}
if (!completeOverrideConfig->Copy(*this->resConfig_)) {
if (!completeOverrideConfig->Copy(*this->resConfig_, true)) {
HILOG_ERROR("getCompleteOverrideConfig copy failed");
return nullptr;
}
@ -357,7 +357,7 @@ RState HapManager::UpdateOverrideResConfig(ResConfig &resConfig)
void HapManager::GetResConfig(ResConfig &resConfig)
{
AutoMutex mutex(this->lock_);
resConfig.Copy(*(this->resConfig_));
resConfig.Copy(*(this->resConfig_), true);
}
void HapManager::GetOverrideResConfig(ResConfig &resConfig)

View File

@ -84,7 +84,7 @@ HapResource::~HapResource()
}
const std::shared_ptr<HapResource> HapResource::Load(const char *path,
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem, bool isOverlay, const uint32_t &selectedTypes)
std::shared_ptr<ResConfigImpl> &defaultConfig, bool isSystem, bool isOverlay, const uint32_t &selectedTypes)
{
if (Utils::ContainsTail(path, Utils::tailSet)) {
return LoadFromHap(path, defaultConfig, isSystem, isOverlay, selectedTypes);
@ -94,7 +94,7 @@ const std::shared_ptr<HapResource> HapResource::Load(const char *path,
}
const std::shared_ptr<HapResource> HapResource::LoadFromIndex(const char *path,
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem, bool isOverlay, const uint32_t &selectedTypes)
std::shared_ptr<ResConfigImpl> &defaultConfig, bool isSystem, bool isOverlay, const uint32_t &selectedTypes)
{
char outPath[PATH_MAX + 1] = {0};
Utils::CanonicalizePath(path, outPath, PATH_MAX);
@ -141,7 +141,7 @@ const std::shared_ptr<HapResource> HapResource::LoadFromIndex(const char *path,
HILOG_ERROR("new HapResource failed when LoadFromIndex");
return nullptr;
}
if (!pResource->Init()) {
if (!pResource->Init(defaultConfig)) {
return nullptr;
}
return pResource;
@ -183,7 +183,7 @@ bool GetIndexData(const char *path, std::unique_ptr<uint8_t[]> &tmpBuf, size_t &
}
const std::shared_ptr<HapResource> HapResource::LoadFromHap(const char *path,
const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem, bool isOverlay, const uint32_t &selectedTypes)
std::shared_ptr<ResConfigImpl> &defaultConfig, bool isSystem, bool isOverlay, const uint32_t &selectedTypes)
{
std::unique_ptr<uint8_t[]> tmpBuf;
size_t tmpLen = 0;
@ -209,14 +209,14 @@ const std::shared_ptr<HapResource> HapResource::LoadFromHap(const char *path,
return nullptr;
}
if (!pResource->Init()) {
if (!pResource->Init(defaultConfig)) {
return nullptr;
}
return pResource;
}
const std::unordered_map<std::string, std::shared_ptr<HapResource>> HapResource::LoadOverlays(const std::string &path,
const std::vector<std::string> &overlayPaths, const std::shared_ptr<ResConfigImpl> defaultConfig, bool isSystem)
const std::vector<std::string> &overlayPaths, std::shared_ptr<ResConfigImpl> &defaultConfig, bool isSystem)
{
std::unordered_map<std::string, std::shared_ptr<HapResource>> result;
do {
@ -297,7 +297,7 @@ void HapResource::UpdateOverlayInfo(std::unordered_map<std::string, std::unorder
idValuesMap_.swap(newIdValuesMap);
}
bool HapResource::Init()
bool HapResource::Init(std::shared_ptr<ResConfigImpl> &defaultConfig)
{
#ifdef __WINNT__
char separator = '\\';
@ -330,10 +330,11 @@ bool HapResource::Init()
}
idValuesNameMap_.push_back(mptr);
}
return InitIdList();
return InitIdList(defaultConfig);
}
bool HapResource::InitMap(const std::shared_ptr<ResKey> &resKey, const std::pair<std::string, std::string> &resPath)
bool HapResource::InitMap(const std::shared_ptr<ResKey> &resKey, const std::pair<std::string, std::string> &resPath,
std::shared_ptr<ResConfigImpl> &defaultConfig)
{
for (size_t j = 0; j < resKey->resId_->idParams_.size(); ++j) {
std::shared_ptr<IdParam> idParam = resKey->resId_->idParams_[j];
@ -352,6 +353,7 @@ bool HapResource::InitMap(const std::shared_ptr<ResKey> &resKey, const std::pair
return false;
}
idValues->AddLimitPath(limitPath);
HapResource::IsAppDarkRes(limitPath, defaultConfig);
idValuesMap_.insert(std::make_pair(id, idValues));
std::string name = std::string(idParam->idItem_->name_);
idValuesNameMap_[idParam->idItem_->resType_]->insert(std::make_pair(name, idValues));
@ -367,12 +369,13 @@ bool HapResource::InitMap(const std::shared_ptr<ResKey> &resKey, const std::pair
return false;
}
idValues->AddLimitPath(limitPath);
HapResource::IsAppDarkRes(limitPath, defaultConfig);
}
}
return true;
}
bool HapResource::InitIdList()
bool HapResource::InitIdList(std::shared_ptr<ResConfigImpl> &defaultConfig)
{
if (resDesc_ == nullptr) {
HILOG_ERROR("resDesc_ is null ! InitIdList failed");
@ -381,7 +384,7 @@ bool HapResource::InitIdList()
const auto resPath = std::make_pair(indexPath_, resourcePath_);
for (size_t i = 0; i < resDesc_->keys_.size(); i++) {
const auto resKey = resDesc_->keys_[i];
if (!HapResource::InitMap(resKey, resPath)) {
if (!HapResource::InitMap(resKey, resPath, defaultConfig)) {
return false;
}
}
@ -528,6 +531,21 @@ bool HapResource::IsThemeSystemResEnable() const
{
return this->isThemeSystemResEnable_;
}
void HapResource::IsAppDarkRes(const std::shared_ptr<HapResource::ValueUnderQualifierDir> &limitPath,
std::shared_ptr<ResConfigImpl> &defaultConfig)
{
if (!defaultConfig) {
return;
}
if (isSystem_ || isOverlay_ || defaultConfig->GetAppDarkRes()) {
return;
}
std::string folder = limitPath->GetFolder();
if (folder.find("dark") != std::string::npos) {
defaultConfig->SetAppDarkRes(true);
}
}
} // namespace Resource
} // namespace Global
} // namespace OHOS

View File

@ -54,7 +54,9 @@ ResConfigImpl::ResConfigImpl()
preferredLocaleInfo_(nullptr),
localeInfo_(nullptr),
#endif
isCompletedScript_(false)
isCompletedScript_(false),
isAppColorMode_(false),
isAppDarkRes_(false)
{}
#ifdef SUPPORT_GRAPHICS
@ -360,7 +362,7 @@ bool ResConfigImpl::CopyLocaleAndPreferredLocale(ResConfig &other)
return true;
}
bool ResConfigImpl::Copy(ResConfig &other)
bool ResConfigImpl::Copy(ResConfig &other, bool isRead)
{
if (!this->CopyLocaleAndPreferredLocale(other)) {
return false;
@ -386,6 +388,12 @@ bool ResConfigImpl::Copy(ResConfig &other)
if (this->GetScreenDensity() != other.GetScreenDensity()) {
this->SetScreenDensity(other.GetScreenDensity());
}
if (this->GetAppColorMode() != other.GetAppColorMode()) {
this->SetAppColorMode(other.GetAppColorMode());
}
if (isRead) {
this->SetAppDarkRes(other.GetAppDarkRes());
}
return true;
}
@ -461,6 +469,9 @@ bool ResConfigImpl::IsDeviceTypeMatch(DeviceType deviceType) const
bool ResConfigImpl::IsColorModeMatch(ColorMode colorMode) const
{
if (this->colorMode_ == DARK && !this->GetAppColorMode() && !this->GetAppDarkRes()) {
return colorMode == COLOR_MODE_NOT_SET;
}
if (this->colorMode_ != COLOR_MODE_NOT_SET && colorMode != COLOR_MODE_NOT_SET) {
if (this->colorMode_ != colorMode) {
return false;
@ -765,6 +776,26 @@ ResConfig *CreateDefaultResConfig()
}
return temp;
}
void ResConfigImpl::SetAppColorMode(bool isAppColorMode)
{
this->isAppColorMode_ = isAppColorMode;
}
bool ResConfigImpl::GetAppColorMode() const
{
return this->isAppColorMode_;
}
void ResConfigImpl::SetAppDarkRes(bool isAppDarkRes)
{
this->isAppDarkRes_ = isAppDarkRes;
}
bool ResConfigImpl::GetAppDarkRes() const
{
return this->isAppDarkRes_;
}
} // namespace Resource
} // namespace Global
} // namespace OHOS

View File

@ -42,7 +42,9 @@ bool ThemeConfig::Match(const std::shared_ptr<ThemeConfig> &themeConfig, const R
return false;
}
}
if (colorMode == DARK && !resConfig.GetAppColorMode() && !resConfig.GetAppDarkRes()) {
return themeColorMode_ == COLOR_MODE_NOT_SET;
}
if (colorMode != COLOR_MODE_NOT_SET && themeColorMode_ != COLOR_MODE_NOT_SET) {
if (colorMode != themeColorMode_) {
return false;

View File

@ -102,7 +102,8 @@ void TestGetIdValuesByName(const std::shared_ptr<HapResource> pResource)
HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level0)
{
auto start = CurrentTimeUsec();
auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
std::shared_ptr<ResConfigImpl> rc = nullptr;
auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), rc);
auto cost = CurrentTimeUsec() - start;
HILOG_DEBUG("load cost: %ld us.", cost);
@ -220,7 +221,8 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1)
HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1)
{
auto start = CurrentTimeUsec();
auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
std::shared_ptr<ResConfigImpl> rc = nullptr;
auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), rc);
auto cost = CurrentTimeUsec() - start;
HILOG_DEBUG("load cost: %ld us.", cost);

View File

@ -55,8 +55,9 @@ void ResConfigImplTest::TearDown()
std::shared_ptr<ResConfigImpl> CreateResConfigImpl(const char *language, const char *script, const char *region)
{
auto resConfigImpl = std::make_shared<ResConfigImpl>() ;
auto resConfigImpl = std::make_shared<ResConfigImpl>();
resConfigImpl->SetLocaleInfo(language, script, region);
resConfigImpl->SetAppDarkRes(true);
return resConfigImpl;
}
@ -576,6 +577,21 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest036, TestSize.Level1)
EXPECT_TRUE(current->Match(other));
};
/*
* @tc.name: ResConfigImplMatchTest037
* @tc.desc: Test ResConfig Match
* @tc.type: FUNC
*/
HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest037, TestSize.Level1)
{
auto other = CreateResConfigImpl("en", nullptr, nullptr);
auto current = CreateResConfigImpl("en", nullptr, nullptr);
current->SetColorMode(ColorMode::DARK);
current->SetAppDarkRes(false);
other->SetColorMode(ColorMode::DARK);
EXPECT_FALSE(current->Match(other));
};
/*
* @tc.name: ResConfigImplIsMoreSuitableTest001
* @tc.desc: Test ResConfig IsMoreSuitable

View File

@ -55,6 +55,7 @@ int ResConfigImplMatchTest033(void);
int ResConfigImplMatchTest034(void);
int ResConfigImplMatchTest035(void);
int ResConfigImplMatchTest036(void);
int ResConfigImplMatchTest037(void);
int ResConfigImplIsMoreSuitableTest001(void);
int ResConfigImplIsMoreSuitableTest002(void);
int ResConfigImplIsMoreSuitableTest003(void);

View File

@ -113,6 +113,7 @@ void ResourceManagerPerformanceTest::TearDown(void)
int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen)
{
long long total = 0;
auto defaultResConfig = InitDefaultResConfig();
for (int k = 0; k < 1000; ++k) {
auto t1 = std::chrono::high_resolution_clock::now();
auto resDesc = std::make_shared<ResDesc>();
@ -136,7 +137,7 @@ int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen)
free(buf);
return -1;
}
if (!pResource->Init()) {
if (!pResource->Init(defaultResConfig)) {
free(buf);
return -1;
}

View File

@ -174,7 +174,7 @@ void ResourceManagerTestCommon::TestGetRawFilePathByName(const std::string &name
void ResourceManagerTestCommon::TestGetProfileById(HapResource *tmp)
{
tmp->Init();
tmp->Init(this->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/profile/test_profile.json");
@ -189,7 +189,7 @@ void ResourceManagerTestCommon::TestGetProfileById(HapResource *tmp)
void ResourceManagerTestCommon::TestGetProfileByName(HapResource *tmp)
{
tmp->Init();
tmp->Init(this->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/profile/test_profile.json");
@ -201,7 +201,7 @@ void ResourceManagerTestCommon::TestGetProfileByName(HapResource *tmp)
void ResourceManagerTestCommon::TestGetMediaById(HapResource *tmp)
{
tmp->Init();
tmp->Init(this->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/media/icon1.png");
@ -215,7 +215,7 @@ void ResourceManagerTestCommon::TestGetMediaById(HapResource *tmp)
void ResourceManagerTestCommon::TestGetMediaWithDensityById(HapResource *tmp)
{
tmp->Init();
tmp->Init(this->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/sdpi/media/icon.png");
@ -241,7 +241,7 @@ void ResourceManagerTestCommon::TestGetMediaWithDensityById(HapResource *tmp)
void ResourceManagerTestCommon::TestGetMediaByName(HapResource *tmp)
{
tmp->Init();
tmp->Init(this->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/media/icon1.png");
@ -253,7 +253,7 @@ void ResourceManagerTestCommon::TestGetMediaByName(HapResource *tmp)
void ResourceManagerTestCommon::TestGetMediaWithDensityByName(HapResource *tmp)
{
tmp->Init();
tmp->Init(this->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/sdpi/media/icon.png");

View File

@ -50,6 +50,8 @@ public:
public:
ResourceManager *rm;
std::shared_ptr<ResConfigImpl> defaultResConfig = InitDefaultResConfig();
int GetResId(const std::string &name, ResType resType);
void TestStringByName(const char *name, const char *cmp);

View File

@ -116,7 +116,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest004, TestSize.
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mdpi/media/icon.png");
@ -152,7 +152,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest005, TestSize.
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/ldpi/media/icon.png");
@ -188,7 +188,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest006, TestSize.
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/xldpi/media/icon.png");
@ -224,7 +224,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest007, TestSize.
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/xxldpi/media/icon.png");
@ -260,7 +260,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest008, TestSize.
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/xxxldpi/media/icon.png");
@ -344,7 +344,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest011, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-sdpi/media/icon.png");
@ -380,7 +380,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest012, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-mdpi/media/icon.png");
@ -416,7 +416,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest013, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-ldpi/media/icon.png");
@ -452,7 +452,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest014, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-xldpi/media/icon.png");
@ -488,7 +488,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest015, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-xxldpi/media/icon.png");
@ -524,7 +524,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest016, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-xxxldpi/media/icon.png");
@ -560,7 +560,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest017, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-sdpi/media/icon.png");
@ -599,7 +599,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest018, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-mdpi/media/icon.png");
@ -638,7 +638,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest019, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-ldpi/media/icon.png");
@ -677,7 +677,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest020, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-xldpi/media/icon.png");
@ -716,7 +716,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest021, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-xxldpi/media/icon.png");
@ -755,7 +755,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByIdTest022, TestSize.
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-xxxldpi/media/icon.png");
@ -853,7 +853,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest004, TestSiz
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mdpi/media/icon.png");
@ -887,7 +887,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest005, TestSiz
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/ldpi/media/icon.png");
@ -921,7 +921,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest006, TestSiz
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/xldpi/media/icon.png");
@ -955,7 +955,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest007, TestSiz
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/xxldpi/media/icon.png");
@ -989,7 +989,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest008, TestSiz
rmc->AddResource("en", nullptr, "US");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/xxxldpi/media/icon.png");
@ -1068,7 +1068,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest011, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-sdpi/media/icon.png");
@ -1102,7 +1102,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest012, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-mdpi/media/icon.png");
@ -1136,7 +1136,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest013, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-ldpi/media/icon.png");
@ -1170,7 +1170,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest014, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-xldpi/media/icon.png");
@ -1204,7 +1204,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest015, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-xxldpi/media/icon.png");
@ -1238,7 +1238,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest016, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/zh_CN-xxxldpi/media/icon.png");
@ -1272,7 +1272,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest017, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-sdpi/media/icon.png");
@ -1309,7 +1309,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest018, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-mdpi/media/icon.png");
@ -1346,7 +1346,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest019, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-ldpi/media/icon.png");
@ -1383,7 +1383,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest020, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-xldpi/media/icon.png");
@ -1420,7 +1420,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest021, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-xxldpi/media/icon.png");
@ -1457,7 +1457,7 @@ HWTEST_F(ResourceManagerTestMedia, ResourceManagerGetMediaByNameTest022, TestSiz
rmc->AddResource("zh", nullptr, "CN");
HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr);
tmp->Init();
tmp->Init(rmc->defaultResConfig);
std::string res = tmp->GetResourcePath();
res.append("entry/resources/mcc460_mnc101-zh_CN-phone-dark-xxxldpi/media/icon.png");

View File

@ -86,6 +86,16 @@ Locale GetLocale(const char *language, const char *script, const char *region)
.setRegion(region).setScript(script).build(errCode);
return locale;
}
std::shared_ptr<ResConfigImpl> InitDefaultResConfig()
{
std::shared_ptr<ResConfigImpl> resConfig = std::make_shared<ResConfigImpl>();
if (resConfig == nullptr) {
return nullptr;
}
resConfig->SetAppDarkRes(true);
return resConfig;
}
} // namespace Resource
} // namespace Global
} // namespace OHOS

View File

@ -47,6 +47,8 @@ void PrintVectorString(const std::vector<std::string> &value);
ResConfig *CreateResConfig(const char *language, const char *script, const char *region);
Locale GetLocale(const char *language, const char *script, const char *region);
std::shared_ptr<ResConfigImpl> InitDefaultResConfig();
} // namespace Resource
} // namespace Global
} // namespace OHOS

View File

@ -63,7 +63,7 @@ public:
virtual uint32_t GetMnc() const = 0;
virtual bool Copy(ResConfig &other) = 0;
virtual bool Copy(ResConfig &other, bool isRead = false) = 0;
virtual void SetInputDevice(InputDevice inputDevice) = 0;
@ -84,6 +84,12 @@ public:
virtual RState SetLocaleInfo(const char *localeStr) = 0;
virtual ScreenDensity GetScreenDensityDpi() const = 0;
virtual void SetAppColorMode(bool isAppColorMode) = 0;
virtual bool GetAppColorMode() const = 0;
virtual bool GetAppDarkRes() const = 0;
};
EXPORT_FUNC ResConfig *CreateResConfig();