1 /* 2 * Copyright (c) 2021 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 FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MATCH_PERMISSION_H 17 #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MATCH_PERMISSION_H 18 19 #include <string> 20 #include <unordered_map> 21 #include <vector> 22 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace EventFwk { 27 enum class PermissionState { 28 DEFAULT, 29 AND, 30 OR, 31 }; 32 33 struct Permission { 34 PermissionState state; 35 std::vector<std::string> names; 36 bool isSensitive = false; PermissionPermission37 Permission() : state(PermissionState::DEFAULT) 38 {} 39 }; 40 41 class CommonEventPermissionManager : public DelayedSingleton<CommonEventPermissionManager> { 42 public: 43 CommonEventPermissionManager(); 44 45 ~CommonEventPermissionManager() = default; 46 47 /** 48 * Inits. 49 * 50 */ 51 void Init(); 52 53 /** 54 * Gets the permission of event. 55 * 56 * @param event Indicates the event name 57 */ 58 Permission GetEventPermission(const std::string &event); 59 60 private: 61 static bool IsSensitiveEvent(const std::string &event); 62 std::unordered_map<std::string, Permission> eventMap_; 63 }; 64 } // namespace EventFwk 65 } // namespace OHOS 66 67 #endif // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MATCH_PERMISSION_H