• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "usb_common_test.h"
17 #include "hilog_wrapper.h"
18 
19 using namespace OHOS::Security::AccessToken;
20 
21 namespace OHOS {
22 namespace USB {
23 namespace Common {
24 TokenInfoParams g_normalInfoInstance = {
25     .dcapsNum = 0,
26     .permsNum = 0,
27     .aclsNum = 0,
28     .dcaps = nullptr,
29     .perms = nullptr,
30     .acls = nullptr,
31     .processName = "usb_manager",
32     .aplStr = "normal",
33 };
34 
35 TokenInfoParams g_sysInfoInstance = {
36     .dcapsNum = 0,
37     .permsNum = 0,
38     .aclsNum = 0,
39     .dcaps = nullptr,
40     .perms = nullptr,
41     .acls = nullptr,
42     .processName = "usb_manager",
43     .aplStr = "system_basic",
44 };
45 
SetTestCaseNative(TokenInfoParams * infoInstance)46 void UsbCommonTest::SetTestCaseNative(TokenInfoParams *infoInstance)
47 {
48     uint64_t tokenId = GetAccessTokenId(infoInstance);
49     int ret = SetSelfTokenID(tokenId);
50     if (ret == 0) {
51         USB_HILOGI(MODULE_USB_SERVICE, "SetSelfTokenID success %{public}d", __LINE__);
52     } else {
53         USB_HILOGE(MODULE_USB_SERVICE, "SetSelfTokenID fail %{public}d", __LINE__);
54     }
55     AccessTokenKit::ReloadNativeTokenInfo();
56 }
57 
GrantPermissionSysNative()58 void UsbCommonTest::GrantPermissionSysNative()
59 {
60     SetTestCaseNative(&g_sysInfoInstance);
61 }
62 
GrantPermissionNormalNative()63 void UsbCommonTest::GrantPermissionNormalNative()
64 {
65     SetTestCaseNative(&g_normalInfoInstance);
66 }
67 } // namespace Common
68 } // namespace USB
69 } // namespace OHOS
70