1 /* 2 * Copyright (c) 2022 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 PERMISSION_HELPER_H 17 #define PERMISSION_HELPER_H 18 19 #include "accesstoken_kit.h" 20 #include "singleton.h" 21 22 namespace OHOS { 23 namespace MMI { 24 class PermissionHelper final { 25 public: 26 static const uint32_t APL_NORMAL = 1 << OHOS::Security::AccessToken::APL_NORMAL; 27 static const uint32_t APL_SYSTEM_BASIC = 1 << OHOS::Security::AccessToken::APL_SYSTEM_BASIC; 28 static const uint32_t APL_SYSTEM_CORE = 1 << OHOS::Security::AccessToken::APL_SYSTEM_CORE; 29 static const uint32_t APL_SYSTEM_BASIC_CORE = APL_SYSTEM_BASIC + APL_SYSTEM_CORE; 30 31 public: GetInstance()32 static PermissionHelper* GetInstance() 33 { 34 static PermissionHelper instance; 35 return &instance; 36 } 37 PermissionHelper(const PermissionHelper&) = delete; 38 PermissionHelper& operator=(const PermissionHelper&) = delete; 39 40 bool CheckPermission(uint32_t required); 41 bool CheckMonitor(); 42 bool CheckInterceptor(); 43 int32_t GetTokenType(); 44 bool CheckDispatchControl(); 45 bool VerifySystemApp(); 46 bool CheckInfraredEmmit(); 47 bool CheckInjectPermission(); 48 bool RequestFromShell(); 49 bool CheckMouseCursor(); 50 bool CheckInputEventFilter(); 51 bool CheckAuthorize(); 52 53 private: PermissionHelper()54 PermissionHelper() {} 55 bool CheckHapPermission(uint32_t tokenId, uint32_t required); 56 bool CheckHapPermission(uint32_t tokenId, std::string permissionCode); 57 bool CheckHapPermission(std::string permissionCode); 58 }; 59 60 #define PER_HELPER PermissionHelper::GetInstance() 61 } // namespace MMI 62 } // namespace OHOS 63 #endif // PERMISSION_HELPER_H 64