• 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_MOCK_ACCESS_TOKEN_KIT_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_MOCK_ACCESS_TOKEN_KIT_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "access_token.h"
23 
24 namespace OHOS {
25 namespace Security {
26 namespace AccessToken {
27 class AccessTokenKit {
28 public:
29     static AccessTokenIDEx AllocHapToken(const HapInfoParams& info, const HapPolicyParams& policy);
30     static int UpdateHapToken(AccessTokenIDEx &tokenIDEx, bool isSystemApp, const std::string& appIDDesc,
31         int32_t apiVersion, const HapPolicyParams& policy);
32     static int DeleteToken(AccessTokenID tokenID);
33     /* Get token type by ATM service */
34     static ATokenTypeEnum GetTokenType(AccessTokenID tokenID);
35     /* Get token type from flag in tokenId, which doesn't depend on ATM service */
36     static ATokenTypeEnum GetTokenTypeFlag(AccessTokenID tokenID);
37     static int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName);
38     static int VerifyAccessToken(
39         AccessTokenID callerTokenID, AccessTokenID firstTokenID, const std::string& permissionName);
40     static int GetDefPermission(const std::string& permissionName, PermissionDef& permissionDefResult);
41     static int GetDefPermissions(AccessTokenID tokenID, std::vector<PermissionDef>& permList);
42     static int GetReqPermissions(
43         AccessTokenID tokenID, std::vector<PermissionStateFull>& reqPermList, bool isSystemGrant);
44     static int GrantPermission(AccessTokenID tokenID, const std::string& permissionName, int flag);
45     static int ClearUserGrantedPermissionState(AccessTokenID tokenID);
46     static AccessTokenID GetHapTokenID(int userID, const std::string& bundleName, int instIndex);
47     static AccessTokenIDEx GetHapTokenIDEx(int userID, const std::string& bundleName, int instIndex);
48     static int GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo &nativeTokenInfo);
49 };
50 } // namespace AccessToken
51 } // namespace Security
52 } // namespace OHOS
53 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_KIT_H