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 HapTokenInfoInner(AccessTokenID id, const HapTokenInfoForSync& info); 40 virtual ~HapTokenInfoInner(); 41 42 void Update(const std::string& appIDDesc, int32_t apiVersion, const HapPolicyParams& policy, bool isSystemApp); 43 void TranslateToHapTokenInfo(HapTokenInfo& infoParcel) const; 44 void StoreHapInfo(std::vector<GenericValues>& valueList) const; 45 void StorePermissionPolicy(std::vector<GenericValues>& permStateValues) const; 46 int RestoreHapTokenInfo(AccessTokenID tokenId, const GenericValues& tokenValue, 47 const std::vector<GenericValues>& permStateRes); 48 49 std::shared_ptr<PermissionPolicySet> GetHapInfoPermissionPolicySet() const; 50 HapTokenInfo GetHapInfoBasic() const; 51 int GetUserID() const; 52 int GetDlpType() const; 53 std::string GetBundleName() const; 54 int GetInstIndex() const; 55 AccessTokenID GetTokenID() const; 56 void SetTokenBaseInfo(const HapTokenInfo& baseInfo); 57 void SetPermissionPolicySet(std::shared_ptr<PermissionPolicySet>& policySet); 58 void ToString(std::string& info) const; 59 bool IsRemote() const; 60 void SetRemote(bool isRemote); 61 bool IsPermDialogForbidden() const; 62 void SetPermDialogForbidden(bool isForbidden); 63 64 uint64_t permUpdateTimestamp_; 65 private: 66 int32_t GetApiVersion(int32_t apiVersion); 67 void StoreHapBasicInfo(std::vector<GenericValues>& valueList) const; 68 void TranslationIntoGenericValues(GenericValues& outGenericValues) const; 69 int RestoreHapTokenBasicInfo(const GenericValues& inGenericValues); 70 71 HapTokenInfo tokenInfoBasic_; 72 73 // true means sync from remote. 74 bool isRemote_; 75 /** permission dialog is forbidden */ 76 bool isPermDialogForbidden_ = false; 77 78 std::shared_ptr<PermissionPolicySet> permPolicySet_; 79 }; 80 } // namespace AccessToken 81 } // namespace Security 82 } // namespace OHOS 83 #endif // ACCESSTOKEN_HAP_TOKEN_INFO_INNER_H 84