• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include <string>
17 #include <set>
18 #include "telephony_permission.h"
19 #include "telephony_permission_test_helper.h"
20 namespace OHOS {
21 namespace Telephony {
22 namespace {
23 std::set<std::string> g_permissionNames;
24 bool g_isSystemApp = false;
25 }
26 
TelephonyPermissionTestHelper(bool isSystem)27 TelephonyPermissionTestHelper::TelephonyPermissionTestHelper(bool isSystem)
28 {
29     g_isSystemApp = isSystem;
30     g_permissionNames.clear();
31 }
GrantPermission(const std::string & permissionName)32 TelephonyPermissionTestHelper &TelephonyPermissionTestHelper::GrantPermission(const std::string &permissionName)
33 {
34     g_permissionNames.insert(permissionName);
35     return *this;
36 }
~TelephonyPermissionTestHelper()37 TelephonyPermissionTestHelper::~TelephonyPermissionTestHelper()
38 {
39     g_isSystemApp = false;
40     g_permissionNames.clear();
41 }
42 
CheckPermission(const std::string & permissionName)43 bool TelephonyPermission::CheckPermission(const std::string &permissionName)
44 {
45     return g_permissionNames.count(permissionName) != 0;
46 }
47 
CheckCallerIsSystemApp()48 bool TelephonyPermission::CheckCallerIsSystemApp()
49 {
50     return g_isSystemApp;
51 }
52 } // namespace Telephony
53 } // namespace OHOS