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(AccessTokenID tokenID, const std::string& appIDDesc, const HapPolicyParams& policy); 31 static int DeleteToken(AccessTokenID tokenID); 32 /* Get token type by ATM service */ 33 static ATokenTypeEnum GetTokenType(AccessTokenID tokenID); 34 /* Get token type from flag in tokenId, which doesn't depend on ATM service */ 35 static ATokenTypeEnum GetTokenTypeFlag(AccessTokenID tokenID); 36 static int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName); 37 static int VerifyAccessToken( 38 AccessTokenID callerTokenID, AccessTokenID firstTokenID, const std::string& permissionName); 39 static int GetDefPermission(const std::string& permissionName, PermissionDef& permissionDefResult); 40 static int GetDefPermissions(AccessTokenID tokenID, std::vector<PermissionDef>& permList); 41 static int GetReqPermissions( 42 AccessTokenID tokenID, std::vector<PermissionStateFull>& reqPermList, bool isSystemGrant); 43 static int GrantPermission(AccessTokenID tokenID, const std::string& permissionName, int flag); 44 static int ClearUserGrantedPermissionState(AccessTokenID tokenID); 45 static AccessTokenID GetHapTokenID(int userID, const std::string& bundleName, int instIndex); 46 }; 47 } // namespace AccessToken 48 } // namespace Security 49 } // namespace OHOS 50 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_KIT_H