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 16 #ifndef OHOS_DP_PERMISSION_MANAGER_H 17 #define OHOS_DP_PERMISSION_MANAGER_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_set> 22 #include <unordered_map> 23 #include "cJSON.h" 24 #include "single_instance.h" 25 26 namespace OHOS { 27 namespace DistributedDeviceProfile { 28 class PermissionManager { 29 DECLARE_SINGLE_INSTANCE(PermissionManager); 30 31 public: 32 int32_t Init(); 33 int32_t UnInit(); 34 bool IsCallerTrust(const std::string& interfaceName); 35 bool CheckCallerPermission(); 36 bool CheckCallerSyncPermission(); 37 std::string GetCallerProcName(); 38 39 private: 40 bool CheckInterfacePermission(const std::string& interfaceName); 41 int32_t LoadPermissionCfg(const std::string& filePath); 42 int32_t ParsePermissionJson(const cJSON* const permissionJson); 43 void SetRdbPermissionMap(const cJSON* const permissionJson); 44 void SetKVPermissionMap(const cJSON* const permissionJson); 45 void SetPermissionMap(const cJSON* const permissionJson, const std::string& interfaceName); 46 47 private: 48 std::mutex permissionMutex_; 49 std::unordered_map<std::string, std::unordered_set<std::string>> permissionMap_; 50 }; 51 } // namespace DeviceProfile 52 } // namespace OHOS 53 #endif // OHOS_DP_PERMISSION_MANAGER_H 54