1 /*
2 * Copyright (c) 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 SANDBOXMANAGER_KIT_H
16 #define SANDBOXMANAGER_KIT_H
17 
18 #include <sys/types.h>
19 #include <map>
20 #include <mutex>
21 #include <unordered_set>
22 #include <vector>
23 
24 #include "ability_manager_errors.h"
25 #include "policy_info.h"
26 
27 namespace OHOS {
28 namespace AccessControl {
29 namespace SandboxManager {
30 
31 class SandboxManagerKit {
32 public:
33     static int32_t SetPolicy(uint32_t tokenid, const std::vector<PolicyInfo> &policys, uint64_t policyFlag,
34         std::vector<uint32_t> &results);
35 
36     static int32_t CheckPolicy(uint32_t tokenid, const std::vector<PolicyInfo> &policys, std::vector<bool> &results);
37 
38     static int32_t CheckPersistPolicy(uint32_t tokenid, const std::vector<PolicyInfo> &policys,
39         std::vector<bool> &results);
40 
41     static int32_t PersistPolicy(uint32_t tokenid, const std::vector<PolicyInfo> &policys,
42         std::vector<uint32_t> &results);
43 
44     static int32_t UnSetPolicy(uint32_t tokenid, const PolicyInfo &policy);
45 
46     static int32_t StartAccessingByTokenId(uint32_t tokenid);
47 
48     static void Init();
49 
50 public:
51     static std::mutex mutex_;
52     static std::mutex persistMutex_;
53     static std::map<std::string, int32_t> policyMap_;
54     static std::map<std::string, int32_t> persistPolicyMap_;
55 
56     static int32_t SetPolicyRet_;
57     static int32_t UnSetPolicyRet_;
58 };
59 
60 } // OHOS
61 } // AccessControl
62 } // SandboxManager
63 #endif // SANDBOXMANAGER_KIT_H