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 "grant_sys_permission.h"
17
18 using namespace OHOS::Security::AccessToken;
19
20 using OHOS::USB::MODULE_USB_SERVICE;
21 using OHOS::USB::USB_MGR_LABEL;
22
SetTestCaseNative(TokenInfoParams * infoInstance)23 static void SetTestCaseNative(TokenInfoParams *infoInstance)
24 {
25 uint64_t tokenId = GetAccessTokenId(infoInstance);
26 int ret = SetSelfTokenID(tokenId);
27 if (ret == 0) {
28 USB_HILOGI(MODULE_USB_SERVICE, "SetSelfTokenID success %{public}d", __LINE__);
29 } else {
30 USB_HILOGE(MODULE_USB_SERVICE, "SetSelfTokenID fail %{public}d", ret);
31 }
32 ret = AccessTokenKit::ReloadNativeTokenInfo();
33 if (ret == 0) {
34 USB_HILOGI(MODULE_USB_SERVICE, "ReloadNativeTokenInfo success %{public}d", __LINE__);
35 } else {
36 USB_HILOGE(MODULE_USB_SERVICE, "ReloadNativeTokenInfo fail %{public}d", ret);
37 }
38 }
39
GrantPermissionSysNative()40 void GrantPermissionSysNative()
41 {
42 const char **permsInfo = new(std::nothrow)const char* [1];
43 permsInfo[0] = "ohos.permission.MANAGE_USB_CONFIG";
44 TokenInfoParams g_sysInfoInstance = {
45 .dcapsNum = 0,
46 .permsNum = 1,
47 .aclsNum = 0,
48 .dcaps = nullptr,
49 .perms = permsInfo,
50 .acls = nullptr,
51 .processName = "usb_manager_test_sys_with_perms",
52 .aplStr = "system_basic",
53 };
54 SetTestCaseNative(&g_sysInfoInstance);
55 }