1 /*
2 * Copyright (c) 2023 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 #include "theme_pack_manager.h"
16
17 #include <dirent.h>
18 #include <cstdio>
19 #include <cstdlib>
20 #include <cstring>
21 #include "hilog_wrapper.h"
22 #include "theme_pack_resource.h"
23 #include <securec.h>
24 #include "utils/utils.h"
25
26 namespace OHOS {
27 namespace Global {
28 namespace Resource {
29 constexpr int FIRST_ELEMENT = 0;
30 constexpr int SECOND_ELEMENT = 1;
31 constexpr int THIRED_ELEMENT = 2;
32 static std::shared_ptr<ThemePackManager> themeMgr = nullptr;
33 static std::once_flag themeMgrFlag;
34 constexpr uint32_t SYSTEM_ID_BEGIN = 117440512; // 0x07000000
35 constexpr uint32_t SYSTEM_ID_END = 134217727; // 0x07FFFFFF
36 const std::string themeFlagA = "data/themes/a/app/flag";
37 const std::string themeFlagB = "data/themes/b/app/flag";
38 const std::string themeSkinA = "/data/themes/a/app/skin";
39 const std::string themeSkinB = "/data/themes/b/app/skin";
40 const std::string themeIconsA = "/data/themes/a/app/icons";
41 const std::string themeIconsB = "/data/themes/b/app/icons";
42 const std::string absoluteThemeFlagA = "data/service/el1/public/themes/<currentUserId>/a/app/flag";
43 const std::string absoluteThemeFlagB = "data/service/el1/public/themes/<currentUserId>/b/app/flag";
44 const std::string absoluteThemeSkinA = "/data/service/el1/public/themes/<currentUserId>/a/app/skin";
45 const std::string absoluteThemeSkinB = "/data/service/el1/public/themes/<currentUserId>/b/app/skin";
46 const std::string absoluteThemeIconsA = "/data/service/el1/public/themes/<currentUserId>/a/app/icons";
47 const std::string absoluteThemeIconsB = "/data/service/el1/public/themes/<currentUserId>/b/app/icons";
48 const std::string absoluteThemePath = "/data/service/el1/public/themes/";
ThemePackManager()49 ThemePackManager::ThemePackManager()
50 {}
51
~ThemePackManager()52 ThemePackManager::~ThemePackManager()
53 {
54 RESMGR_HILOGW_BY_FLAG(isLogFlag_, RESMGR_TAG, "~ThemePackManager");
55 skinResource_.clear();
56 iconResource_.clear();
57 iconMaskValues_.clear();
58 }
59
GetThemePackManager()60 std::shared_ptr<ThemePackManager> ThemePackManager::GetThemePackManager()
61 {
62 std::call_once(themeMgrFlag, [&] {
63 themeMgr = std::shared_ptr<ThemePackManager>(new ThemePackManager());
64 });
65 return themeMgr;
66 }
67
GetRootDir(const std::string & strCurrentDir)68 std::vector<std::string> ThemePackManager::GetRootDir(const std::string &strCurrentDir)
69 {
70 std::vector<std::string> vDir;
71 #if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
72 DIR *dir;
73 struct dirent *pDir;
74 if ((dir = opendir(strCurrentDir.c_str())) == nullptr) {
75 return vDir;
76 }
77 while ((pDir = readdir(dir)) != nullptr) {
78 if (strcmp(pDir->d_name, ".") == 0 || strcmp(pDir->d_name, "..") == 0) {
79 continue;
80 } else if (pDir->d_type == 4) { // 4 means dir
81 std::string strNextDir = strCurrentDir + "/" + pDir->d_name;
82 vDir.emplace_back(strNextDir);
83 } else if (pDir->d_type == 8) { // 8 means file
84 std::string filePath = strCurrentDir + "/" + pDir->d_name;
85 if (filePath.find("icon_mask") != std::string::npos) {
86 themeMask = filePath;
87 }
88 }
89 }
90 closedir(dir);
91 #endif
92 return vDir;
93 }
94
ClearSkinResource()95 void ThemePackManager::ClearSkinResource()
96 {
97 for (auto it = skinResource_.begin(); it != skinResource_.end();) {
98 if ((*it) == nullptr) {
99 continue;
100 }
101 // 1 means get the enable theme
102 if (!(*it)->IsNewResource()) {
103 it = skinResource_.erase(it);
104 } else {
105 ++it;
106 }
107 }
108 }
109
LoadThemeSkinResource(const std::string & bundleName,const std::string & moduleName,const std::vector<std::string> & rootDirs,int32_t userId)110 void ThemePackManager::LoadThemeSkinResource(const std::string &bundleName, const std::string &moduleName,
111 const std::vector<std::string> &rootDirs, int32_t userId)
112 {
113 std::lock_guard<std::mutex> lock(this->lockSkin_);
114 ChangeSkinResourceStatus(userId);
115 if (rootDirs.empty()) {
116 ClearSkinResource();
117 return;
118 }
119 for (const auto &dir : rootDirs) {
120 auto pos = dir.rfind('/');
121 if (pos == std::string::npos) {
122 RESMGR_HILOGE(RESMGR_TAG, "invalid dir = %{public}s in LoadThemeSkinResource", dir.c_str());
123 continue;
124 }
125 std::string tempBundleName = dir.substr(pos + 1);
126 if (tempBundleName != bundleName && tempBundleName != "systemRes") {
127 continue;
128 }
129 auto pThemeResource = ThemeResource::LoadThemeResource(dir);
130 if (pThemeResource != nullptr) {
131 this->skinResource_.emplace_back(pThemeResource);
132 }
133 }
134 ClearSkinResource();
135 }
136
LoadThemeRes(const std::string & bundleName,const std::string & moduleName,int32_t userId)137 void ThemePackManager::LoadThemeRes(const std::string &bundleName, const std::string &moduleName, int32_t userId)
138 {
139 UpdateUserId(userId);
140 std::vector<std::string> rootDirs;
141 std::vector<std::string> iconDirs;
142 if (Utils::IsFileExist(themeFlagA)) {
143 rootDirs = GetRootDir(themeSkinA);
144 iconDirs = GetRootDir(themeIconsA);
145 } else if (Utils::IsFileExist(themeFlagB)) {
146 rootDirs = GetRootDir(themeSkinB);
147 iconDirs = GetRootDir(themeIconsB);
148 } else {
149 isLogFlag_ = true;
150 LoadSAThemeRes(bundleName, moduleName, userId, rootDirs, iconDirs);
151 }
152 LoadThemeSkinResource(bundleName, moduleName, rootDirs, userId);
153 LoadThemeIconsResource(bundleName, moduleName, iconDirs, userId);
154 return;
155 }
156
LoadThemeIconRes(const std::string & bundleName,const std::string & moduleName,int32_t userId)157 void ThemePackManager::LoadThemeIconRes(const std::string &bundleName, const std::string &moduleName, int32_t userId)
158 {
159 UpdateUserId(userId);
160 std::vector<std::string> iconDirs;
161 if (Utils::IsFileExist(themeFlagA)) {
162 iconDirs = GetRootDir(themeIconsA);
163 } else if (Utils::IsFileExist(themeFlagB)) {
164 iconDirs = GetRootDir(themeIconsB);
165 } else {
166 if (Utils::IsFileExist(ReplaceUserIdInPath(absoluteThemeFlagA, userId))) {
167 iconDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeIconsA, userId));
168 } else if (Utils::IsFileExist(ReplaceUserIdInPath(absoluteThemeFlagB, userId))) {
169 iconDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeIconsB, userId));
170 } else {
171 RESMGR_HILOGE(RESMGR_TAG, "LoadThemesRes failed, userId = %{public}d, bundleName = %{public}s",
172 userId, bundleName.c_str());
173 }
174 }
175 LoadThemeIconsResource(bundleName, moduleName, iconDirs, userId);
176 }
177
LoadSAThemeRes(const std::string & bundleName,const std::string & moduleName,int32_t userId,std::vector<std::string> & rootDirs,std::vector<std::string> & iconDirs)178 void ThemePackManager::LoadSAThemeRes(const std::string &bundleName, const std::string &moduleName,
179 int32_t userId, std::vector<std::string> &rootDirs, std::vector<std::string> &iconDirs)
180 {
181 if (Utils::IsFileExist(ReplaceUserIdInPath(absoluteThemeFlagA, userId))) {
182 rootDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeSkinA, userId));
183 iconDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeIconsA, userId));
184 } else if (Utils::IsFileExist(ReplaceUserIdInPath(absoluteThemeFlagB, userId))) {
185 rootDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeSkinB, userId));
186 iconDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeIconsB, userId));
187 } else {
188 RESMGR_HILOGE(RESMGR_TAG, "LoadThemesRes failed, userId = %{public}d, bundleName = %{public}s",
189 userId, bundleName.c_str());
190 }
191 }
192
ReplaceUserIdInPath(const std::string & originalPath,int32_t userId)193 const std::string ThemePackManager::ReplaceUserIdInPath(const std::string &originalPath, int32_t userId)
194 {
195 std::string result = originalPath;
196 auto found = result.find("<currentUserId>");
197 if (found != std::string::npos) {
198 result.replace(found, 15, std::to_string(userId)); // 15 is the length of "<currentUserId>"
199 }
200 return result;
201 }
202
FindThemeResource(const std::pair<std::string,std::string> & bundleInfo,const std::vector<std::shared_ptr<IdItem>> & idItems,const ResConfigImpl & resConfig,int32_t userId,bool isThemeSystemResEnable)203 const std::string ThemePackManager::FindThemeResource(const std::pair<std::string, std::string> &bundleInfo,
204 const std::vector<std::shared_ptr<IdItem>> &idItems, const ResConfigImpl &resConfig, int32_t userId,
205 bool isThemeSystemResEnable)
206 {
207 std::string result;
208 for (size_t i = 0; i < idItems.size(); i++) {
209 std::string resName = idItems[i]->name_;
210 uint32_t id = idItems[i]->id_;
211 ResType resType = idItems[i]->resType_;
212 if (id >= SYSTEM_ID_BEGIN && id <= SYSTEM_ID_END) {
213 if (resType == ResType::COLOR && !isThemeSystemResEnable) {
214 break;
215 }
216 std::pair<std::string, std::string> tempInfo("systemRes", "entry");
217 result = GetThemeResource(tempInfo, resType, resName, resConfig, userId);
218 } else {
219 result = GetThemeResource(bundleInfo, resType, resName, resConfig, userId);
220 }
221 if (!result.empty()) {
222 break;
223 }
224 }
225 return result;
226 }
227
GetThemeResource(const std::pair<std::string,std::string> & bundInfo,const ResType & resType,const std::string & resName,const ResConfigImpl & resConfig,int32_t userId)228 const std::string ThemePackManager::GetThemeResource(const std::pair<std::string, std::string> &bundInfo,
229 const ResType &resType, const std::string &resName, const ResConfigImpl &resConfig, int32_t userId)
230 {
231 auto themeQualifierValue = GetThemeQualifierValue(bundInfo, resType, resName, resConfig, userId);
232 if (themeQualifierValue == nullptr) {
233 RESMGR_HILOGD(RESMGR_TAG, "themeQualifierValue == nullptr");
234 return std::string("");
235 }
236 return themeQualifierValue->GetResValue();
237 }
238
GetThemeResourceList(const std::pair<std::string,std::string> & bundInfo,const ResType & resType,const std::string & resName,int32_t userId)239 std::vector<std::shared_ptr<ThemeResource::ThemeValue> > ThemePackManager::GetThemeResourceList(
240 const std::pair<std::string, std::string> &bundInfo, const ResType &resType, const std::string &resName,
241 int32_t userId)
242 {
243 std::lock_guard<std::mutex> lock(this->lockSkin_);
244 std::vector<std::shared_ptr<ThemeResource::ThemeValue> > result;
245 for (size_t i = 0; i < skinResource_.size(); ++i) {
246 auto pThemeResource = skinResource_[i];
247 if (pThemeResource == nullptr) {
248 continue;
249 }
250 if (!IsSameResourceByUserId(pThemeResource->GetThemePath(), userId)) {
251 continue;
252 }
253 std::string bundleName = pThemeResource->GetThemeResBundleName(pThemeResource->themePath_);
254 if (bundleName != bundInfo.first) {
255 continue;
256 }
257 result = pThemeResource->GetThemeValues(bundInfo, resType, resName);
258 }
259 return result;
260 }
261
GetThemeQualifierValue(const std::pair<std::string,std::string> & bundInfo,const ResType & resType,const std::string & resName,const ResConfigImpl & resConfig,int32_t userId)262 const std::shared_ptr<ThemeResource::ThemeQualifierValue> ThemePackManager::GetThemeQualifierValue(
263 const std::pair<std::string, std::string> &bundInfo, const ResType &resType,
264 const std::string &resName, const ResConfigImpl &resConfig, int32_t userId)
265 {
266 auto candidates = this->GetThemeResourceList(bundInfo, resType, resName, userId);
267 if (candidates.size() == 0) {
268 return nullptr;
269 }
270 return GetBestMatchThemeResource(candidates, resConfig);
271 }
272
GetBestMatchThemeResource(const std::vector<std::shared_ptr<ThemeResource::ThemeValue>> & candidates,const ResConfigImpl & resConfig)273 const std::shared_ptr<ThemeResource::ThemeQualifierValue> ThemePackManager::GetBestMatchThemeResource(
274 const std::vector<std::shared_ptr<ThemeResource::ThemeValue> > &candidates, const ResConfigImpl &resConfig)
275 {
276 std::shared_ptr<ThemeResource::ThemeQualifierValue> result = nullptr;
277 std::shared_ptr<ThemeConfig> bestThemeConfig = nullptr;
278 for (auto iter = candidates.rbegin(); iter != candidates.rend(); iter++) {
279 const std::vector<std::shared_ptr<ThemeResource::ThemeQualifierValue> > ThemePaths =
280 (*iter)->GetThemeLimitPathsConst();
281 size_t len = ThemePaths.size();
282 for (size_t i = 0; i < len; i++) {
283 std::shared_ptr<ThemeResource::ThemeQualifierValue> path = ThemePaths[i];
284 auto themeConfig = path->GetThemeConfig();
285 if (!ThemeConfig::Match(themeConfig, resConfig)) {
286 continue;
287 }
288 if (bestThemeConfig == nullptr) {
289 bestThemeConfig = themeConfig;
290 result = path;
291 continue;
292 }
293 if (!bestThemeConfig->BestMatch(themeConfig, resConfig)) {
294 bestThemeConfig = themeConfig;
295 result = path;
296 }
297 }
298 }
299 return result;
300 }
301
ClearIconResource()302 void ThemePackManager::ClearIconResource()
303 {
304 for (auto it = iconResource_.begin(); it != iconResource_.end();) {
305 if ((*it) == nullptr) {
306 continue;
307 }
308 // 1 means get the enable theme
309 if (!(*it)->IsNewResource()) {
310 it = iconResource_.erase(it);
311 } else {
312 ++it;
313 }
314 }
315 iconMaskValues_.clear();
316 }
317
LoadThemeIconsResource(const std::string & bundleName,const std::string & moduleName,const std::vector<std::string> & rootDirs,int32_t userId)318 void ThemePackManager::LoadThemeIconsResource(const std::string &bundleName, const std::string &moduleName,
319 const std::vector<std::string> &rootDirs, int32_t userId)
320 {
321 std::lock_guard<std::mutex> lock(this->lockIcon_);
322 ChangeIconResourceStatus(userId);
323 if (rootDirs.empty()) {
324 ClearIconResource();
325 return;
326 }
327 for (const auto &dir : rootDirs) {
328 auto pos = dir.rfind('/');
329 if (pos == std::string::npos) {
330 RESMGR_HILOGE(RESMGR_TAG, "invalid dir = %{public}s in LoadThemeIconsResource", dir.c_str());
331 continue;
332 }
333 RESMGR_HILOGW_BY_FLAG(isLogFlag_, RESMGR_TAG, "load img, %{public}s", GetMaskString(dir).c_str());
334 auto pThemeResource = ThemeResource::LoadThemeIconResource(dir);
335 if (pThemeResource != nullptr) {
336 this->iconResource_.emplace_back(pThemeResource);
337 }
338 }
339 ClearIconResource();
340 RESMGR_HILOGW_BY_FLAG(isLogFlag_, RESMGR_TAG, "load img end, size is %{public}zu", iconResource_.size());
341 }
342
FindThemeIconResource(const std::pair<std::string,std::string> & bundleInfo,const std::string & iconName,int32_t userId,const std::string & abilityName)343 const std::string ThemePackManager::FindThemeIconResource(const std::pair<std::string, std::string> &bundleInfo,
344 const std::string &iconName, int32_t userId, const std::string &abilityName)
345 {
346 std::lock_guard<std::mutex> lock(this->lockIcon_);
347 std::string result;
348 for (size_t i = 0; i < iconResource_.size(); i++) {
349 auto pThemeResource = iconResource_[i];
350 if (pThemeResource == nullptr) {
351 continue;
352 }
353 if (!IsSameResourceByUserId(pThemeResource->GetThemePath(), userId)) {
354 continue;
355 }
356 result = pThemeResource->GetThemeAppIcon(bundleInfo, iconName, abilityName);
357 if (!result.empty()) {
358 RESMGR_HILOGW_BY_FLAG(isLogFlag_, RESMGR_TAG, "find img, %{public}s", GetMaskString(result).c_str());
359 break;
360 }
361 }
362 return result;
363 }
364
UpdateThemeId(uint32_t newThemeId)365 bool ThemePackManager::UpdateThemeId(uint32_t newThemeId)
366 {
367 std::lock_guard<std::mutex> lock(this->lockThemeId_);
368 if (newThemeId != 0 && newThemeId != themeId_) {
369 RESMGR_HILOGW(RESMGR_TAG, "update theme, themeId_= %{public}d, newThemeId= %{public}d", themeId_, newThemeId);
370 themeId_ = newThemeId;
371 return true;
372 }
373 return false;
374 }
375
IsFirstLoadResource()376 bool ThemePackManager::IsFirstLoadResource()
377 {
378 if (isFirstCreate) {
379 isFirstCreate = false;
380 return true;
381 }
382 return false;
383 }
384
HasIconInTheme(const std::string & bundleName,int32_t userId)385 bool ThemePackManager::HasIconInTheme(const std::string &bundleName, int32_t userId)
386 {
387 std::lock_guard<std::mutex> lock(this->lockIcon_);
388 bool result = false;
389 for (size_t i = 0; i < iconResource_.size(); i++) {
390 auto pThemeResource = iconResource_[i];
391 if (pThemeResource == nullptr) {
392 continue;
393 }
394 if (!IsSameResourceByUserId(pThemeResource->GetThemePath(), userId)) {
395 continue;
396 }
397 result = pThemeResource->HasIconInTheme(bundleName);
398 if (result) {
399 break;
400 }
401 }
402 return result;
403 }
404
GetOtherIconsInfo(const std::string & iconName,std::unique_ptr<uint8_t[]> & outValue,size_t & len,bool isGlobalMask,int32_t userId)405 RState ThemePackManager::GetOtherIconsInfo(const std::string &iconName,
406 std::unique_ptr<uint8_t[]> &outValue, size_t &len, bool isGlobalMask, int32_t userId)
407 {
408 std::lock_guard<std::mutex> lock(this->lockIconValue_);
409 std::string iconPath;
410 std::string iconTag;
411 if (iconName.find("icon_mask") != std::string::npos && isGlobalMask) {
412 iconPath = themeMask;
413 iconTag = "global_" + iconName;
414 } else {
415 std::pair<std::string, std::string> bundleInfo;
416 bundleInfo.first = "other_icons";
417 iconPath = FindThemeIconResource(bundleInfo, iconName, userId);
418 iconTag = "other_icons_" + iconName;
419 }
420
421 if (iconPath.empty()) {
422 RESMGR_HILOGD(RESMGR_TAG, "no found, iconTag = %{public}s", iconTag.c_str());
423 return ERROR_CODE_RES_NOT_FOUND_BY_NAME;
424 }
425
426 outValue = Utils::LoadResourceFile(iconPath, len);
427 if (outValue != nullptr && len != 0) {
428 auto tmpInfo = std::make_unique<uint8_t[]>(len);
429 errno_t ret = memcpy_s(tmpInfo.get(), len, outValue.get(), len);
430 if (ret != 0) {
431 RESMGR_HILOGE(RESMGR_TAG, "save fail, iconName = %{public}s, ret = %{public}d", iconName.c_str(), ret);
432 return SUCCESS;
433 }
434 iconMaskValues_.emplace_back(std::make_tuple(iconTag, std::move(tmpInfo), len));
435 return SUCCESS;
436 }
437 return ERROR_CODE_RES_NOT_FOUND_BY_NAME;
438 }
439
GetThemeIconFromCache(const std::string & iconTag,std::unique_ptr<uint8_t[]> & outValue,size_t & len)440 RState ThemePackManager::GetThemeIconFromCache(
441 const std::string &iconTag, std::unique_ptr<uint8_t[]> &outValue, size_t &len)
442 {
443 std::lock_guard<std::mutex> lock(this->lockIconValue_);
444 if (iconMaskValues_.empty()) {
445 return NOT_FOUND;
446 }
447
448 for (const auto &iconValue : iconMaskValues_) {
449 std::string tag = std::get<FIRST_ELEMENT>(iconValue);
450 if (iconTag != tag) {
451 continue;
452 }
453 size_t length = std::get<THIRED_ELEMENT>(iconValue);
454 auto iconInfo = std::make_unique<uint8_t[]>(length);
455 auto tmpInfo = std::get<SECOND_ELEMENT>(iconValue).get();
456 errno_t ret = memcpy_s(iconInfo.get(), length, tmpInfo, length);
457 if (ret != 0) {
458 RESMGR_HILOGE(RESMGR_TAG, "get icon info fail, ret = %{public}d", ret);
459 continue;
460 }
461 len = length;
462 outValue = std::move(iconInfo);
463 return SUCCESS;
464 }
465 return NOT_FOUND;
466 }
467
IsUpdateByUserId(int32_t userId)468 bool ThemePackManager::IsUpdateByUserId(int32_t userId)
469 {
470 std::lock_guard<std::mutex> lock(this->lockUserId_);
471 return userId != 0 && currentUserId_ != userId;
472 }
473
UpdateUserId(int32_t userId)474 void ThemePackManager::UpdateUserId(int32_t userId)
475 {
476 std::lock_guard<std::mutex> lock(this->lockUserId_);
477 if (userId != 0 && currentUserId_ != userId) {
478 RESMGR_HILOGW(RESMGR_TAG,
479 "update userId, currentUserId_= %{public}d, userId= %{public}d", currentUserId_, userId);
480 currentUserId_ = userId;
481 }
482 }
483
IsSameResourceByUserId(const std::string & path,int32_t userId)484 bool ThemePackManager::IsSameResourceByUserId(const std::string &path, int32_t userId)
485 {
486 std::string absolutePath("/data/service/el1/public/themes/");
487 if (path.empty() || path.find(absolutePath) == std::string::npos) {
488 return true;
489 }
490 auto pos = path.find("/", absolutePath.length());
491 if (pos == std::string::npos) {
492 return true;
493 }
494 auto subStr = path.substr(absolutePath.length(), pos - absolutePath.length());
495 int tmpId = -1;
496 if (!Utils::convertToInteger(subStr, tmpId)) {
497 return true;
498 }
499 return tmpId == userId;
500 }
501
ChangeSkinResourceStatus(int32_t userId)502 void ThemePackManager::ChangeSkinResourceStatus(int32_t userId)
503 {
504 for (size_t i = 0; i < skinResource_.size(); ++i) {
505 auto pThemeResource = skinResource_[i];
506 if (pThemeResource == nullptr) {
507 continue;
508 }
509 if (IsSameResourceByUserId(pThemeResource->GetThemePath(), userId)) {
510 pThemeResource->SetNewResource(false);
511 }
512 }
513 }
514
ChangeIconResourceStatus(int32_t userId)515 void ThemePackManager::ChangeIconResourceStatus(int32_t userId)
516 {
517 for (size_t i = 0; i < iconResource_.size(); ++i) {
518 auto pThemeResource = iconResource_[i];
519 if (pThemeResource == nullptr) {
520 continue;
521 }
522 if (IsSameResourceByUserId(pThemeResource->GetThemePath(), userId)) {
523 pThemeResource->SetNewResource(false);
524 }
525 }
526 }
527
GetMaskString(const std::string & path)528 const std::string ThemePackManager::GetMaskString(const std::string &path)
529 {
530 if (path.empty() || path.find(absoluteThemePath) == std::string::npos) {
531 return path;
532 }
533 return path.substr(absoluteThemePath.length(), path.length() - absoluteThemePath.length());
534 }
535 } // namespace Resource
536 } // namespace Global
537 } // namespace OHOS
538