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