1 /*
2 * Copyright (c) 2023-2024 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 #ifndef I_SECURITY_COMPONENT_INFO_HELPER_H
16 #define I_SECURITY_COMPONENT_INFO_HELPER_H
17
18 #include "accesstoken_kit.h"
19 #include "nlohmann/json.hpp"
20 #include "sec_comp_base.h"
21 #include "sec_comp_info.h"
22
23 namespace OHOS {
24 namespace Security {
25 namespace SecurityComponent {
26 template<typename T>
ConstructComponent(const nlohmann::json & jsonComponent)27 T* ConstructComponent(const nlohmann::json& jsonComponent)
28 {
29 T *componentPtr = new (std::nothrow)T();
30 if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent)) {
31 delete componentPtr;
32 return nullptr;
33 }
34 return componentPtr;
35 }
36
37 class __attribute__((visibility("default"))) SecCompInfoHelper {
38 public:
39 static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent);
40 static bool CheckComponentValid(SecCompBase* comp);
41 static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, const uint64_t displayId,
42 const CrossAxisState crossAxisState);
43
44 private:
45 static float GetWindowScale(int32_t windowId);
46 static void AdjustSecCompRect(SecCompBase* comp, float scale);
47 static bool IsDlpSandboxCalling(AccessToken::AccessTokenID tokenId);
48 };
49 } // namespace SecurityComponent
50 } // namespace Security
51 } // namespace OHOS
52 #endif // I_SECURITY_COMPONENT_INFO_HELPER_H
53