• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "SoftBus_Test_Permission.h"
17 #include "permission/permission.h"
18 #include "permission/permission_kit.h"
19 
20 using namespace std;
21 using namespace OHOS::Security::Permission;
22 
23 const static std::string SYSTEM_APP_PERMISSION = "com.permission.MANAGE_DISTRIBUTED_PERMISSION";
24 const static std::string DANGER_APP_PERMISSION = "ohos.permission.DISTRIBUTED_DATASYNC";
25 const static std::string BIND_DISCOVER_SERVICE = "com.hwddmp.permission.BIND_DISCOVER_SERVICE";
26 const static std::string TEST_LABEL = "test label";
27 const static std::string TEST_DESCRIPTION = "test description";
28 const static int TEST_LABEL_ID = 9527;
29 const static int TEST_DESCRIPTION_ID = 9528;
30 
AddPermission(const string & pkgName)31 void SoftBus_Test_Permission::AddPermission(const string& pkgName)
32 {
33     std::vector<PermissionDef> permDefList;
34     PermissionDef permissionDefAlpha = { .permissionName = SYSTEM_APP_PERMISSION,
35         .bundleName = pkgName,
36         .grantMode = GrantMode::SYSTEM_GRANT,
37         .availableScope = AVAILABLE_SCOPE_ALL,
38         .label = TEST_LABEL,
39         .labelId = TEST_LABEL_ID,
40         .description = TEST_DESCRIPTION,
41         .descriptionId = TEST_DESCRIPTION_ID };
42     PermissionDef permissionDefBeta = { .permissionName = DANGER_APP_PERMISSION,
43         .bundleName = pkgName,
44         .grantMode = GrantMode::SYSTEM_GRANT,
45         .availableScope = AVAILABLE_SCOPE_ALL,
46         .label = TEST_LABEL,
47         .labelId = TEST_LABEL_ID,
48         .description = TEST_DESCRIPTION,
49         .descriptionId = TEST_DESCRIPTION_ID };
50     PermissionDef permissionDefGamma = { .permissionName = BIND_DISCOVER_SERVICE,
51         .bundleName = pkgName,
52         .grantMode = GrantMode::SYSTEM_GRANT,
53         .availableScope = AVAILABLE_SCOPE_ALL,
54         .label = TEST_LABEL,
55         .labelId = TEST_LABEL_ID,
56         .description = TEST_DESCRIPTION,
57         .descriptionId = TEST_DESCRIPTION_ID };
58     permDefList.emplace_back(permissionDefAlpha);
59     permDefList.emplace_back(permissionDefBeta);
60     permDefList.emplace_back(permissionDefGamma);
61     PermissionKit::AddDefPermissions(permDefList);
62     std::vector<std::string> permList;
63     permList.push_back(SYSTEM_APP_PERMISSION);
64     permList.push_back(DANGER_APP_PERMISSION);
65     permList.push_back(BIND_DISCOVER_SERVICE);
66     PermissionKit::AddSystemGrantedReqPermissions(pkgName, permList);
67     PermissionKit::GrantSystemGrantedPermission(pkgName, SYSTEM_APP_PERMISSION);
68     PermissionKit::GrantSystemGrantedPermission(pkgName, DANGER_APP_PERMISSION);
69     PermissionKit::GrantSystemGrantedPermission(pkgName, BIND_DISCOVER_SERVICE);
70 }
71 
RemovePermission(const string & pkgName)72 void SoftBus_Test_Permission::RemovePermission(const string& pkgName)
73 {
74     PermissionKit::RemoveDefPermissions(pkgName);
75     PermissionKit::RemoveSystemGrantedReqPermissions(pkgName);
76 }
77