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 #ifndef PRIVACY_TEST_COMMON_H 17 #define PRIVACY_TEST_COMMON_H 18 19 #include "access_token.h" 20 #include "accesstoken_kit.h" 21 #include "nativetoken_kit.h" 22 #include "token_setproc.h" 23 24 namespace OHOS { 25 namespace Security { 26 namespace AccessToken { 27 class MockNativeToken { 28 public: 29 explicit MockNativeToken(const std::string& process); 30 ~MockNativeToken(); 31 private: 32 uint64_t selfToken_; 33 }; 34 35 class MockHapToken { 36 public: 37 explicit MockHapToken( 38 const std::string& bundle, const std::vector<std::string>& reqPerm, bool isSystemApp = true); 39 ~MockHapToken(); 40 private: 41 uint64_t selfToken_; 42 uint32_t mockToken_; 43 }; 44 class PrivacyTestCommon { 45 public: 46 static constexpr int32_t DEFAULT_API_VERSION = 12; 47 static void SetTestEvironment(uint64_t shellTokenId); 48 static void ResetTestEvironment(); 49 static uint64_t GetShellTokenId(); 50 51 static AccessTokenIDEx AllocTestHapToken(const HapInfoParams& hapInfo, HapPolicyParams& hapPolicy); 52 static int32_t DeleteTestHapToken(AccessTokenID tokenID); 53 static AccessTokenID GetNativeTokenIdFromProcess(const std::string& process); 54 static AccessTokenIDEx GetHapTokenIdFromBundle( 55 int32_t userID, const std::string& bundleName, int32_t instIndex); 56 }; 57 } // namespace AccessToken 58 } // namespace Security 59 } // namespace OHOS 60 #endif // PRIVACY_TEST_COMMON_H 61