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 #include "sec_comp_perm_manager.h"
23 
24 namespace OHOS {
25 namespace Security {
26 namespace SecurityComponent {
27 template<typename T>
ConstructComponent(const nlohmann::json & jsonComponent)28 T* ConstructComponent(const nlohmann::json& jsonComponent)
29 {
30     T *componentPtr = new (std::nothrow)T();
31     if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent)) {
32         delete componentPtr;
33         return nullptr;
34     }
35     return componentPtr;
36 }
37 
38 class __attribute__((visibility("default"))) SecCompInfoHelper {
39 public:
40     static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent);
41     static int32_t GrantTempPermission(AccessToken::AccessTokenID tokenId,
42         const std::shared_ptr<SecCompBase>& componentInfo);
43     static bool CheckComponentValid(SecCompBase* comp);
44     static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect);
45 
46 private:
47     static float GetWindowScale(int32_t windowId);
48     static void AdjustSecCompRect(SecCompBase* comp, float scale);
49     static bool IsDlpSandboxCalling(AccessToken::AccessTokenID tokenId);
50 };
51 }  // namespace SecurityComponent
52 }  // namespace Security
53 }  // namespace OHOS
54 #endif  // I_SECURITY_COMPONENT_INFO_HELPER_H
55