• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_data_brief.h"
27 #include "permission_def.h"
28 #include "permission_status.h"
29 #include "rwlock.h"
30 
31 namespace OHOS {
32 namespace Security {
33 namespace AccessToken {
34 class HapTokenInfoInner final {
35 public:
36     HapTokenInfoInner();
37     HapTokenInfoInner(AccessTokenID id, const HapInfoParams& info, const HapPolicy& policy);
38     HapTokenInfoInner(AccessTokenID id, const HapTokenInfo &info,
39         const std::vector<PermissionStatus>& permStateList);
40     HapTokenInfoInner(AccessTokenID id, const HapTokenInfoForSync& info);
41     virtual ~HapTokenInfoInner();
42 
43     void Update(const UpdateHapInfoParams& info, const std::vector<PermissionStatus>& permStateList,
44         const HapPolicy& hapPolicy);
45     void TranslateToHapTokenInfo(HapTokenInfo& infoParcel) const;
46     void StoreHapInfo(std::vector<GenericValues>& valueList, const std::string& appId, ATokenAplEnum apl) const;
47     void StorePermissionPolicy(std::vector<GenericValues>& permStateValues);
48     int RestoreHapTokenInfo(AccessTokenID tokenId, const GenericValues& tokenValue,
49         const std::vector<GenericValues>& permStateRes, const std::vector<GenericValues> extendedPermRes);
50 
51     uint32_t GetReqPermissionSize();
52     HapTokenInfo GetHapInfoBasic() const;
53     int GetUserID() const;
54     int GetDlpType() const;
55     AccessTokenAttr GetAttr() const;
56     std::string GetBundleName() const;
57     int GetInstIndex() const;
58     AccessTokenID GetTokenID() const;
59     void SetTokenBaseInfo(const HapTokenInfo& baseInfo);
60     std::string ToString();
61     bool IsRemote() const;
62     void SetRemote(bool isRemote);
63     bool IsPermDialogForbidden() const;
64     void SetPermDialogForbidden(bool isForbidden);
65 
66     int32_t UpdatePermissionStatus(
67         const std::string& permissionName, bool isGranted, uint32_t flag, bool& statusChanged);
68     int32_t GetPermissionStateList(std::vector<PermissionStatus>& permList);
69     int32_t ResetUserGrantPermissionStatus(void);
70     void UpdateRemoteHapTokenInfo(AccessTokenID mapID,
71         const HapTokenInfo& baseInfo, std::vector<PermissionStatus>& permStateList);
72 
73     static void RefreshPermStateToKernel(const std::vector<std::string>& constrainedList,
74         bool hapUserIsActive, AccessTokenID tokenId, std::map<std::string, bool>& refreshedPermList);
75     static int32_t VerifyPermissionStatus(AccessTokenID tokenID, const std::string& permissionName);
76     static PermUsedTypeEnum GetPermissionUsedType(AccessTokenID tokenID, const std::string& permissionName);
77     static int32_t QueryPermissionFlag(AccessTokenID tokenID, const std::string& permissionName, uint32_t& flag);
78     static void GetPermStatusListByTokenId(AccessTokenID tokenID,
79         const std::vector<uint32_t> constrainedList, std::vector<uint32_t>& opCodeList, std::vector<bool>& statusList);
80     static void GetGrantedPermByTokenId(AccessTokenID tokenID,
81         const std::vector<std::string>& constrainedList, std::vector<std::string>& permissionList);
82     static void ClearAllSecCompGrantedPerm();
83     static bool IsPermissionGrantedWithSecComp(AccessTokenID tokenID, const std::string& permissionName);
84 
85     uint64_t permUpdateTimestamp_;
86 private:
87     int32_t GetApiVersion(int32_t apiVersion);
88     void StoreHapBasicInfo(std::vector<GenericValues>& valueList) const;
89     void TranslationIntoGenericValues(GenericValues& outGenericValues) const;
90     int RestoreHapTokenBasicInfo(const GenericValues& inGenericValues);
91     bool UpdateStatesToDB(AccessTokenID tokenID, std::vector<PermissionStatus>& stateChangeList);
92 
93     HapTokenInfo tokenInfoBasic_;
94 
95     // true means sync from remote.
96     bool isRemote_;
97     /** permission dialog is forbidden */
98     bool isPermDialogForbidden_ = false;
99 
100     OHOS::Utils::RWLock policySetLock_;
101 };
102 } // namespace AccessToken
103 } // namespace Security
104 } // namespace OHOS
105 #endif // ACCESSTOKEN_HAP_TOKEN_INFO_INNER_H
106