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