• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "sam_mock_permission.h"
17 
18 #ifdef SUPPORT_ACCESS_TOKEN
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21 #endif
22 
23 namespace OHOS {
MockPermission()24 void SamMockPermission::MockPermission()
25 {
26 #ifdef SUPPORT_ACCESS_TOKEN
27     static const char *PERMS[] = {
28         "ohos.permission.DISTRIBUTED_DATASYNC",
29         "ohos.permission.ACCESS_EXT_SYSTEM_ABILITY"
30     };
31     uint64_t tokenId;
32     NativeTokenInfoParams infoInstance = {
33         .dcapsNum = 0,
34         .permsNum = 1,
35         .aclsNum = 0,
36         .dcaps = nullptr,
37         .perms = PERMS,
38         .acls = nullptr,
39         .processName = "distributedsched",
40         .aplStr = "system_core",
41     };
42     tokenId = GetAccessTokenId(&infoInstance);
43     SetSelfTokenID(tokenId);
44 #endif
45 }
46 
MockProcess(const char * processName)47 void SamMockPermission::MockProcess(const char* processName)
48 {
49 #ifdef SUPPORT_ACCESS_TOKEN
50     static const char *PERMS[] = {
51         "ohos.permission.DISTRIBUTED_DATASYNC"
52     };
53     uint64_t tokenId;
54     NativeTokenInfoParams infoInstance = {
55         .dcapsNum = 0,
56         .permsNum = 1,
57         .aclsNum = 0,
58         .dcaps = nullptr,
59         .perms = PERMS,
60         .acls = nullptr,
61         .processName = processName,
62         .aplStr = "system_core",
63     };
64     tokenId = GetAccessTokenId(&infoInstance);
65     SetSelfTokenID(tokenId);
66 #endif
67 }
68 }