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 #include <string> 19 20 namespace OHOS { 21 namespace bluetooth { 22 class PermissionHelper { 23 public: 24 /** 25 * @Description Verify where the app has the permission. 26 * 27 * @param permissionName Permission name. 28 * @param pid The app's process id. 29 * @param uid The app id. 30 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 31 */ 32 static int VerifyPermission(const std::string &permissionName, const int &pid, const int &uid); 33 34 /** 35 * @Description Verify where the app has the permission. 36 * 37 * @param permissionName Permission name. 38 * @param callerToken The app's token id. 39 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 40 */ 41 static int VerifyPermission(const std::string &permissionName, const std::uint32_t &callerToken); 42 43 /** 44 * @Description Verify where the app has the permission to use bluetooth 45 * 46 * @param pid The app's process id. 47 * @param uid The app id. 48 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 49 */ 50 static int VerifyUseBluetoothPermission(const int &pid, const int &uid); 51 52 /** 53 * @Description Verify where the app has the permission to discover bluetooth 54 * 55 * @param pid The app's process id. 56 * @param uid The app id. 57 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 58 */ 59 static int VerifyDiscoverBluetoothPermission(const int &pid, const int &uid); 60 61 /** 62 * @Description Verify where the app has the permission to manager bluetooth 63 * 64 * @param pid The app's process id. 65 * @param uid The app id. 66 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 67 */ 68 static int VerifyManageBluetoothPermission(const int &pid, const int &uid); 69 70 /** 71 * @Description Verify where the app has the permission to location 72 * 73 * @param pid The app's process id. 74 * @param uid The app id. 75 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 76 */ 77 static int VerifyLocationPermission(const int &pid, const int &uid); 78 79 /** 80 * @Description Verify where the app has the permission to approximately location 81 * 82 * @param pid The app's process id. 83 * @param uid The app id. 84 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 85 */ 86 static int VerifyApproximatelyPermission(const int &pid, const int &uid); 87 88 /** 89 * @Description Verify where the app has the permission to access bluetooth 90 * 91 * @param pid the app's process id. 92 * @param uid the app id. 93 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 94 */ 95 static int VerifyAccessBluetoothPermission(const int &pid, const int &uid); 96 97 /** 98 * @Description Verify where the app has the permission to get bluetooth local mac 99 * 100 * @param pid the app's process id. 101 * @param uid the app id. 102 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 103 */ 104 static int VerifyGetBluetoothLocalMacPermission(const int &pid, const int &uid); 105 106 /** 107 * @Description Verify where the app has the permission to use bluetooth 108 * 109 * @param tokenID The app's token id. 110 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 111 */ 112 static int VerifyUseBluetoothPermission(const std::uint32_t &tokenID); 113 114 /** 115 * @Description Verify where the app has the permission to discover bluetooth 116 * 117 * @param tokenID The app's token id. 118 * @return int PERMISSION_DENIED or PERMISSION_GRANTED 119 */ 120 static int VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID); 121 }; 122 } // namespace bluetooth 123 } // namespace OHOS 124 #endif