1 /*
2 * Copyright (c) 2024 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 "scan_service_ability_mock.h"
17
18 #include "accesstoken_kit.h"
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21
22 namespace OHOS {
23 namespace Scan {
MockPermission()24 void ScanServiceAbilityMock::MockPermission()
25 {
26 const int32_t permsNum = 2;
27 static const char *PERMS[] = {
28 "ohos.permission.MANAGE_USB_CONFIG",
29 "ohos.permission.PRINT"
30 };
31 uint64_t tokenId;
32 NativeTokenInfoParams infoInstance = {
33 .dcapsNum = 0,
34 .permsNum = permsNum,
35 .aclsNum = 0,
36 .dcaps = nullptr,
37 .perms = PERMS,
38 .acls = nullptr,
39 .processName = "scan_service_test",
40 .aplStr = "system_core",
41 };
42 tokenId = GetAccessTokenId(&infoInstance);
43 SetSelfTokenID(tokenId);
44 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
45 }
46 }
47 }