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
16 #include "purgeablemem_config.h"
17 #include <set>
18 #include <string>
19 #include "memmgr_log.h"
20 #include "xml_helper.h"
21
22 namespace OHOS {
23 namespace Memory {
24 namespace {
25 const std::string TAG = "PurgeablememConfig";
26 }
27
ParseConfig(const xmlNodePtr & rootNodePtr)28 void PurgeablememConfig::ParseConfig(const xmlNodePtr &rootNodePtr)
29 {
30 if (!XmlHelper::CheckNode(rootNodePtr) || !XmlHelper::HasChild(rootNodePtr)) {
31 HILOGD("Node exsist:%{public}d,has child node:%{public}d",
32 XmlHelper::CheckNode(rootNodePtr), XmlHelper::HasChild(rootNodePtr));
33 return;
34 }
35 std::string nodeName;
36 std::string procName;
37 for (xmlNodePtr currNode = rootNodePtr->xmlChildrenNode; currNode != nullptr; currNode = currNode->next) {
38 if (!XmlHelper::CheckNode(currNode)) {
39 return;
40 }
41 std::map<std::string, std::string> param;
42 XmlHelper::GetModuleParam(currNode, param);
43 nodeName = std::string(reinterpret_cast<const char *>(currNode->name));
44 if (nodeName == "purgeWhiteAppList") {
45 XmlHelper::SetStringParam(param, "procName", procName, "");
46 purgeWhiteAppSet_.insert(procName);
47 }
48 }
49 }
50
GetPurgeWhiteAppSet()51 PurgeablememConfig::PurgeWhiteAppSet &PurgeablememConfig::GetPurgeWhiteAppSet()
52 {
53 return purgeWhiteAppSet_;
54 }
55
Dump(int fd)56 void PurgeablememConfig::Dump(int fd)
57 {
58 dprintf(fd, "purgeablememConfig: \n");
59 dprintf(fd, " purgeWhiteAppList: \n");
60 for (auto it = purgeWhiteAppSet_.begin(); it != purgeWhiteAppSet_.end(); it++) {
61 dprintf(fd, "%30s\n", (*it).c_str());
62 }
63 }
64 } // namespace Memory
65 } // namespace OHOS