1 /* 2 * Copyright (c) 2021-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 ACCESSTOKEN_HAP_TOKEN_INFO_INNER_H 17 #define ACCESSTOKEN_HAP_TOKEN_INFO_INNER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "access_token.h" 24 #include "generic_values.h" 25 #include "hap_token_info.h" 26 #include "permission_def.h" 27 #include "permission_policy_set.h" 28 #include "permission_state_full.h" 29 30 namespace OHOS { 31 namespace Security { 32 namespace AccessToken { 33 class HapTokenInfoInner final { 34 public: 35 HapTokenInfoInner(); 36 HapTokenInfoInner(AccessTokenID id, const HapInfoParams& info, const HapPolicyParams& policy); 37 HapTokenInfoInner(AccessTokenID id, const HapTokenInfo &info, 38 const std::vector<PermissionStateFull>& permStateList); 39 virtual ~HapTokenInfoInner(); 40 41 void Update(const std::string& appIDDesc, int32_t apiVersion, const HapPolicyParams& policy, bool isSystemApp); 42 void TranslateToHapTokenInfo(HapTokenInfo& infoParcel) const; 43 void StoreHapInfo(std::vector<GenericValues>& hapInfoValues, 44 std::vector<GenericValues>& permStateValues) const; 45 int RestoreHapTokenInfo(AccessTokenID tokenId, const GenericValues& tokenValue, 46 const std::vector<GenericValues>& permStateRes); 47 48 std::shared_ptr<PermissionPolicySet> GetHapInfoPermissionPolicySet() const; 49 HapTokenInfo GetHapInfoBasic() const; 50 int GetUserID() const; 51 int GetDlpType() const; 52 std::string GetBundleName() const; 53 int GetInstIndex() const; 54 AccessTokenID GetTokenID() const; 55 void SetTokenBaseInfo(const HapTokenInfo& baseInfo); 56 void SetPermissionPolicySet(std::shared_ptr<PermissionPolicySet>& policySet); 57 void ToString(std::string& info) const; 58 bool IsRemote() const; 59 void SetRemote(bool isRemote); 60 61 uint64_t permUpdateTimestamp_; 62 private: 63 void StoreHapBasicInfo(std::vector<GenericValues>& valueList) const; 64 void TranslationIntoGenericValues(GenericValues& outGenericValues) const; 65 int RestoreHapTokenBasicInfo(const GenericValues& inGenericValues); 66 67 HapTokenInfo tokenInfoBasic_; 68 69 // true means sync from remote. 70 bool isRemote_; 71 72 std::shared_ptr<PermissionPolicySet> permPolicySet_; 73 }; 74 } // namespace AccessToken 75 } // namespace Security 76 } // namespace OHOS 77 #endif // ACCESSTOKEN_HAP_TOKEN_INFO_INNER_H 78