• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "drm_param_parse.h"
17 
18 namespace OHOS::Rosen {
19 constexpr const int LIST_SIZE_LIMIT = 100;
20 constexpr const int APP_WINDOW_NAME_LIMIT = 100;
21 
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)22 int32_t DRMParamParse::ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node)
23 {
24     RS_LOGI("DRMParamParse start");
25     xmlNode *currNode = &node;
26     if (currNode->xmlChildrenNode == nullptr) {
27         RS_LOGD("DRMParamParse stop parsing, no children nodes");
28         return PARSE_GET_CHILD_FAIL;
29     }
30 
31     currNode = currNode->xmlChildrenNode;
32     for (; currNode; currNode = currNode->next) {
33         if (currNode->type != XML_ELEMENT_NODE) {
34             continue;
35         }
36 
37         if (ParseDrmInternal(*currNode) != PARSE_EXEC_SUCCESS) {
38             RS_LOGD("DRMParamParse stop parsing, parse internal fail");
39             return PARSE_INTERNAL_FAIL;
40         }
41     }
42 
43     return PARSE_EXEC_SUCCESS;
44 }
45 
ParseDrmInternal(xmlNode & node)46 int32_t DRMParamParse::ParseDrmInternal(xmlNode &node)
47 {
48     xmlNode *currNode = &node;
49     // Start Parse Feature Params
50     int xmlParamType = GetXmlNodeAsInt(*currNode);
51     auto name = ExtractPropertyValue("name", *currNode);
52     auto val = ExtractPropertyValue("value", *currNode);
53     if (xmlParamType == PARSE_XML_FEATURE_SWITCH) {
54         bool isEnabled = ParseFeatureSwitch(val);
55         if (name == "DrmEnabled") {
56             DRMParam::SetDrmEnable(isEnabled);
57             RS_LOGI("DRMParamParse parse DrmEnabled %{public}d", DRMParam::IsDrmEnable());
58         } else if (name == "DrmMarkAllParentBlurEnabled") {
59             DRMParam::SetDrmMarkAllParentBlurEnable(isEnabled);
60             RS_LOGI("DRMParamParse parse DrmMaskBlurEnabled %{public}d", DRMParam::IsDrmMarkAllParentBlurEnable());
61         }
62     } else if (xmlParamType == PARSE_XML_FEATURE_MULTIPARAM) {
63         if (ParseFeatureMultiParam(*currNode) != PARSE_EXEC_SUCCESS) {
64             RS_LOGD("parse MultiParam fail");
65         }
66     }
67     return PARSE_EXEC_SUCCESS;
68 }
69 
ParseFeatureMultiParam(xmlNode & node)70 int32_t DRMParamParse::ParseFeatureMultiParam(xmlNode &node)
71 {
72     xmlNode *currNode = &node;
73     if (currNode->xmlChildrenNode == nullptr) {
74         RS_LOGE("DRMParamParse stop parsing, no children nodes");
75         return PARSE_GET_CHILD_FAIL;
76     }
77     currNode = currNode->xmlChildrenNode;
78     for (int i = 0; currNode && i < LIST_SIZE_LIMIT ; currNode = currNode->next, ++i) {
79         if (currNode->type != XML_ELEMENT_NODE) {
80             continue;
81         }
82         auto paramName = ExtractPropertyValue("name", *currNode);
83         if (paramName.size() > APP_WINDOW_NAME_LIMIT) {
84             continue;
85         }
86         auto val = ExtractPropertyValue("value", *currNode);
87         if (!IsNumber(val)) {
88             return PARSE_ERROR;
89         }
90         if (val == "1") {
91             DRMParam::AddWhiteList(paramName);
92         } else if (val == "0") {
93             DRMParam::AddBlackList(paramName);
94         }
95     }
96     return PARSE_EXEC_SUCCESS;
97 }
98 } // namespace OHOS::Rosen