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