• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_DP_TRUST_PROFILE_MANAGER_H
17 #define OHOS_DP_TRUST_PROFILE_MANAGER_H
18 
19 
20 #include <map>
21 #include <string>
22 #include <memory>
23 #include <mutex>
24 #include <vector>
25 
26 #include "irdb_adapter.h"
27 #include "access_control_profile.h"
28 #include "trust_device_profile.h"
29 #include "values_bucket.h"
30 #include "single_instance.h"
31 
32 
33 namespace OHOS {
34 namespace DistributedDeviceProfile {
35 using namespace OHOS::NativeRdb;
36 
37 class TrustProfileManager {
38     DECLARE_SINGLE_INSTANCE(TrustProfileManager);
39 
40 public:
41     int32_t Init();
42     int32_t UnInit();
43     int32_t PutTrustDeviceProfile(const TrustDeviceProfile& profile);
44     int32_t PutAccessControlProfile(const AccessControlProfile& profile);
45     int32_t UpdateTrustDeviceProfile(const TrustDeviceProfile& profile);
46     int32_t UpdateAccessControlProfile(const AccessControlProfile& profile);
47     int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& profile);
48     int32_t GetAllTrustDeviceProfile(std::vector<TrustDeviceProfile>& profile);
49     int32_t GetAllAccessControlProfile(std::vector<AccessControlProfile>& profile);
50     int32_t GetAccessControlProfile(const std::map<std::string, std::string>& params,
51         std::vector<AccessControlProfile>& profile);
52     int32_t DeleteTrustDeviceProfile(const std::string& deviceId);
53     int32_t DeleteAccessControlProfile(int64_t accessControlId);
54 
55 private:
56     int32_t CreateTable();
57     int32_t CreateUniqueIndex();
58     int32_t GetAccessControlProfile(const std::string& bundleName, int32_t bindType,
59         int32_t status, std::vector<AccessControlProfile>& profile);
60     int32_t GetAccessControlProfile(const std::string& bundleName,
61         const std::string& trustDeviceId, int32_t status, std::vector<AccessControlProfile>& profile);
62     int32_t GetAccessControlProfile(int32_t userId, const std::string& bundleName,
63         int32_t bindType, int32_t status, std::vector<AccessControlProfile>& profile);
64     int32_t GetAccessControlProfile(int32_t userId, const std::string& bundleName,
65         const std::string& trustDeviceId, int32_t status, std::vector<AccessControlProfile>& profile);
66     int32_t GetAccessControlProfile(int32_t userId, const std::string& accountId,
67         std::vector<AccessControlProfile>& profile);
68     int32_t GetAccessControlProfile(int32_t userId, std::vector<AccessControlProfile>& profile);
69     int32_t GetAccessControlProfileByTokenId(int64_t tokenId, const std::string& trustDeviceId,
70         int32_t status, std::vector<AccessControlProfile>& profile);
71     int32_t GetAclProfileByUserIdAndBundleName(std::shared_ptr<ResultSet> resultSet,
72         int32_t userId, const std::string& bundleName, std::vector<AccessControlProfile>& profile);
73     int32_t GetAclProfileByUserIdAndAccountId(std::shared_ptr<ResultSet> resultSet, int64_t accesserId,
74         int64_t accesseeId, int32_t userId, const std::string& accountId, std::vector<AccessControlProfile>& profile);
75     int32_t GetAclProfileByTokenId(std::shared_ptr<ResultSet> resultSet, const std::string& trustDeviceId,
76         int64_t tokenId, std::vector<AccessControlProfile>& profile);
77     int32_t GetAclProfileByBundleName(std::shared_ptr<ResultSet> resultSet,
78         const std::string& bundleName, std::vector<AccessControlProfile>& profile);
79     int32_t PutAccesserProfile(const AccessControlProfile& profile);
80     int32_t PutAccesseeProfile(const AccessControlProfile& profile);
81     int32_t SetAccessControlId(AccessControlProfile& profile);
82     int32_t SetAccesserId(AccessControlProfile& profile);
83     int32_t SetAccesseeId(AccessControlProfile& profile);
84     int32_t UpdateAccesserProfile(AccessControlProfile& profile);
85     int32_t UpdateAccesseeProfile(AccessControlProfile& profile);
86     int32_t UpdateTrustDeviceProfileNotify(const TrustDeviceProfile& oldProfile,
87         const TrustDeviceProfile& newProfile);
88     int32_t GetResultStatus(const std::string& trustDeviceId, int32_t& trustDeviceStatus);
89     int32_t GetAccessControlProfile(std::shared_ptr<ResultSet> resultSet,
90         int64_t accesserId, int64_t accesseeId, std::vector<AccessControlProfile>& profile);
91     int32_t GetAccessControlProfilesByDeviceId(std::shared_ptr<ResultSet> resultSet, int64_t accesserId,
92         int64_t accesseeId, const std::string& trustDeviceId, std::vector<AccessControlProfile>& profile);
93     int32_t DeleteAccessControlProfileCheck(const AccessControlProfile& profile);
94     std::shared_ptr<ResultSet> GetResultSet(const std::string& sql, std::vector<ValueObject> condition);
95     int32_t SetAccessControlProfileId(AccessControlProfile& accessControlProfile);
96     int32_t GetAccessControlProfiles(std::shared_ptr<ResultSet> resultSet, int64_t accesserId,
97         int64_t accesseeId, int32_t userId, std::vector<AccessControlProfile>& profile);
98     int32_t GetAccessControlProfiles(std::shared_ptr<ResultSet> resultSet,
99         int64_t accesserId, int64_t accesseeId, int32_t userId, const std::string& bundleName,
100         std::vector<AccessControlProfile>& profile);
101     int32_t GetAccessControlProfiles(std::shared_ptr<ResultSet> resultSet, int64_t accesserId,
102         int64_t accesseeId, const std::string& bundleName, std::vector<AccessControlProfile>& profile);
103     int32_t GetAccessControlProfilesByTokenId(std::shared_ptr<ResultSet> resultSet, int64_t accesserId,
104         int64_t accesseeId, const std::string& trustDeviceId, int64_t tokenId,
105         std::vector<AccessControlProfile>& profile);
106     int32_t DeleteAccesserCheck(int64_t accesserId, Accesser& accesser);
107     int32_t UpdateAclCheck(const AccessControlProfile& profile, AccessControlProfile& oldProfile);
108     int32_t PutAclCheck(const AccessControlProfile& profile, bool peerDevInfoExists);
109     bool CheckUserIdExists(int64_t accesserId, int64_t accesseeId, const std::string& peerDeviceId,
110         int32_t peerUserId, const std::string& localDeviceId, int32_t localUserId);
111 
112 private:
113     std::shared_ptr<IRdbAdapter> rdbStore_;
114     std::mutex rdbMutex_;
115 };
116 
117 } // namespace DistributedDeviceProfile
118 } // namespace OHOS
119 
120 #endif // OHOS_DP_TRUST_PROFILE_MANAGER_H
121