• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "reclaim_priority_config.h"
16 #include "memmgr_ptr_util.h"
17 #include "kernel_interface.h"
18 #include "reclaim_priority_manager.h"
19 #include "memmgr_config_manager.h"
20 #include "memmgr_log.h"
21 #include "xml_helper.h"
22 
23 namespace OHOS {
24 namespace Memory {
25 namespace {
26     const std::string TAG = "ReclaimPriorityConfig";
27 }
28 
ParseConfig(const xmlNodePtr & rootNodePtr)29 void ReclaimPriorityConfig::ParseConfig(const xmlNodePtr &rootNodePtr)
30 {
31     if (!XmlHelper::CheckNode(rootNodePtr) || !XmlHelper::HasChild(rootNodePtr)) {
32         HILOGD("Node exsist:%{public}d,has child node:%{public}d",
33                XmlHelper::CheckNode(rootNodePtr), XmlHelper::HasChild(rootNodePtr));
34         return;
35     }
36     for (xmlNodePtr currNode = rootNodePtr->xmlChildrenNode; currNode != nullptr; currNode = currNode->next) {
37         if (!XmlHelper::CheckNode(currNode)) {
38             return;
39         }
40         std::string name = std::string(reinterpret_cast<const char *>(currNode->name));
41         if (name.compare("killalbeSystemApps") == 0) {
42             ParseReclaimPriorityKillableSystemAppsConfig(currNode);
43             continue;
44         }
45         HILOGW("unknown node :<%{public}s>", name.c_str());
46         return;
47     }
48     return;
49 }
50 
ParseReclaimPriorityKillableSystemAppsConfig(const xmlNodePtr & rootNodePtr)51 void ReclaimPriorityConfig::ParseReclaimPriorityKillableSystemAppsConfig(const xmlNodePtr &rootNodePtr)
52 {
53     if (!XmlHelper::CheckNode(rootNodePtr) || !XmlHelper::HasChild(rootNodePtr)) {
54         HILOGD("Node exsist:%{public}d,has child node:%{public}d",
55                XmlHelper::CheckNode(rootNodePtr), XmlHelper::HasChild(rootNodePtr));
56         return;
57     }
58     for (xmlNodePtr currNode = rootNodePtr->xmlChildrenNode; currNode != nullptr; currNode = currNode->next) {
59         if (!XmlHelper::CheckNode(currNode)) {
60             return;
61         }
62         std::string name = std::string(reinterpret_cast<const char *>(currNode->name));
63         if (name.compare("killableSysApp") == 0) {
64             auto contentPtr = xmlNodeGetContent(currNode);
65             if (contentPtr == nullptr) {
66                 continue;
67             }
68             std::string value = std::string(reinterpret_cast<char *>(contentPtr));
69             HILOGW("read a killable app: %{public}s", value.c_str());
70             if (value.size() == 0) {
71                 HILOGE("read a empty killable app: %{public}s, ignore it!", value.c_str());
72                 continue;
73             }
74             killalbeSystemApps_.insert(value);
75             xmlFree(contentPtr);
76             continue;
77         }
78         HILOGW("unknown node :<%{public}s>", name.c_str());
79         return;
80     }
81     return;
82 }
83 
GetkillalbeSystemApps()84 std::set<std::string> ReclaimPriorityConfig::GetkillalbeSystemApps()
85 {
86     return killalbeSystemApps_;
87 }
88 } // namespace Memory
89 } // namespace OHOS
90