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 16 #ifndef PERMISSION_MANAGER_H 17 #define PERMISSION_MANAGER_H 18 19 #include <unistd.h> 20 #include <string> 21 22 #include "message_parcel.h" 23 namespace OHOS { 24 namespace Location { 25 const std::string ACCESS_LOCATION = "ohos.permission.LOCATION"; 26 const std::string ACCESS_APPROXIMATELY_LOCATION = "ohos.permission.APPROXIMATELY_LOCATION"; 27 const std::string ACCESS_BACKGROUND_LOCATION = "ohos.permission.LOCATION_IN_BACKGROUND"; 28 const std::string ACCESS_MOCK_LOCATION = "ohos.permission.MOCK_LOCATION"; 29 const std::string MANAGE_SECURE_SETTINGS = "ohos.permission.MANAGE_SECURE_SETTINGS"; 30 const std::string RSS_PROCESS_NAME = "resource_schedule_service"; 31 const std::string ACCESS_CONTROL_LOCATION_SWITCH = "ohos.permission.CONTROL_LOCATION_SWITCH"; 32 const std::string ACCESS_LOCATION_SWITCH_IGNORED = "ohos.permission.LOCATION_SWITCH_IGNORED"; 33 34 static constexpr int PERMISSION_ACCURATE = 2; 35 static constexpr int PERMISSION_APPROXIMATELY = 1; 36 static constexpr int PERMISSION_INVALID = 0; 37 38 class PermissionManager { 39 public: 40 static bool CheckLocationPermission(uint32_t tokenId, uint32_t firstTokenId); 41 static bool CheckApproximatelyPermission(uint32_t tokenId, uint32_t firstTokenId); 42 static bool CheckBackgroundPermission(uint32_t tokenId, uint32_t firstTokenId); 43 static bool CheckMockLocationPermission(uint32_t tokenId, uint32_t firstTokenId); 44 static bool CheckPermission(const std::string &permission, uint32_t tokenId, uint32_t firstTokenId); 45 static bool CheckSecureSettings(uint32_t tokenId, uint32_t firstTokenId); 46 static bool CheckCallingPermission(pid_t callingUid, pid_t callingPid, MessageParcel &reply); 47 static bool CheckRssProcessName(uint32_t tokenId); 48 static bool CheckSystemPermission(uint32_t callerTokenId, uint64_t callerTokenIdEx); 49 static int GetPermissionLevel(uint32_t tokenId, uint32_t firstTokenId); 50 static bool CheckIsSystemSa(uint32_t tokenId); 51 static bool CheckLocationSwitchIgnoredPermission(uint32_t tokenId, uint32_t firstTokenId); 52 }; 53 } // namespace Location 54 } // namespace OHOS 55 #endif // PERMISSION_MANAGER_H 56