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 #include "auth_center.h"
16 #include "stdbool.h"
17 #include "accesstoken_kit.h"
18 #include "permission_helper.h"
19
20
21 namespace OHOS {
22 namespace bluetooth {
23 #ifdef PERMISSION_ALWAYS_GRANT
24 bool g_permissionAlwaysGrant = true;
25 #else
26 bool g_permissionAlwaysGrant = false;
27 #endif
28
29 using namespace OHOS::Security::AccessToken;
30
GetInstance()31 AuthCenter &AuthCenter::GetInstance()
32 {
33 static AuthCenter authCenter;
34 return authCenter;
35 }
36
VerifyUseBluetoothPermission(const int & pid,const int & uid)37 int AuthCenter::VerifyUseBluetoothPermission(const int &pid, const int &uid)
38 {
39 if (g_permissionAlwaysGrant) {
40 return PERMISSION_GRANTED;
41 }
42
43 return PermissionHelper::VerifyUseBluetoothPermission(pid, uid);
44 }
45
VerifyDiscoverBluetoothPermission(const int & pid,const int & uid)46 int AuthCenter::VerifyDiscoverBluetoothPermission(const int &pid, const int &uid)
47 {
48 if (g_permissionAlwaysGrant) {
49 return PERMISSION_GRANTED;
50 }
51 return PermissionHelper::VerifyDiscoverBluetoothPermission(pid, uid);
52 }
53
VerifyManageBluetoothPermission(const int & pid,const int & uid)54 int AuthCenter::VerifyManageBluetoothPermission(const int &pid, const int &uid)
55 {
56 if (g_permissionAlwaysGrant) {
57 return PERMISSION_GRANTED;
58 }
59 return PermissionHelper::VerifyManageBluetoothPermission(pid, uid);
60 }
61
VerifyLocationPermission(const int & pid,const int & uid)62 int AuthCenter::VerifyLocationPermission(const int &pid, const int &uid)
63 {
64 if (g_permissionAlwaysGrant) {
65 return PERMISSION_GRANTED;
66 }
67 return PERMISSION_GRANTED;
68 }
69
VerifyApproximatelyPermission(const int & pid,const int & uid)70 int AuthCenter::VerifyApproximatelyPermission(const int &pid, const int &uid)
71 {
72 if (g_permissionAlwaysGrant) {
73 return PERMISSION_GRANTED;
74 }
75 return PERMISSION_GRANTED;
76 }
77
VerifyAccessBluetoothPermission(const int & pid,const int & uid)78 int AuthCenter::VerifyAccessBluetoothPermission(const int &pid, const int &uid)
79 {
80 if (g_permissionAlwaysGrant) {
81 return PERMISSION_GRANTED;
82 }
83 return PermissionHelper::VerifyAccessBluetoothPermission(pid, uid);
84 }
85
VerifyGetBluetoothLocalMacPermission(const int & pid,const int & uid)86 int AuthCenter::VerifyGetBluetoothLocalMacPermission(const int &pid, const int &uid)
87 {
88 if (g_permissionAlwaysGrant) {
89 return PERMISSION_GRANTED;
90 }
91 return PermissionHelper::VerifyGetBluetoothLocalMacPermission(pid, uid);
92 }
93
VerifyUseBluetoothPermission(const std::uint32_t & tokenID)94 int AuthCenter::VerifyUseBluetoothPermission(const std::uint32_t &tokenID)
95 {
96 if (g_permissionAlwaysGrant) {
97 return PERMISSION_GRANTED;
98 }
99 return PermissionHelper::VerifyUseBluetoothPermission(tokenID);
100 }
101
VerifyDiscoverBluetoothPermission(const std::uint32_t & tokenID)102 int AuthCenter::VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID)
103 {
104 if (g_permissionAlwaysGrant) {
105 return PERMISSION_GRANTED;
106 }
107 return PermissionHelper::VerifyDiscoverBluetoothPermission(tokenID);
108 }
109 } // namespace bluetooth
110 } // namespace OHOS