• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #ifndef OHOS_DM_DEVICEPROFILE_CONNECTOR_H
16 #define OHOS_DM_DEVICEPROFILE_CONNECTOR_H
17 #include <string>
18 #include <algorithm>
19 #include "access_control_profile.h"
20 #include "dm_device_info.h"
21 #include "single_instance.h"
22 
23 constexpr uint32_t ALLOW_AUTH_ONCE = 1;
24 constexpr uint32_t ALLOW_AUTH_ALWAYS = 2;
25 
26 constexpr uint32_t INVALIED_TYPE = 0;
27 constexpr uint32_t APP_PEER_TO_PEER_TYPE = 1;
28 constexpr uint32_t APP_ACROSS_ACCOUNT_TYPE = 2;
29 constexpr uint32_t DEVICE_PEER_TO_PEER_TYPE = 3;
30 constexpr uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 4;
31 constexpr uint32_t IDENTICAL_ACCOUNT_TYPE = 5;
32 
33 constexpr uint32_t DM_IDENTICAL_ACCOUNT = 1;
34 constexpr uint32_t DM_POINT_TO_POINT = 256;
35 constexpr uint32_t DM_ACROSS_ACCOUNT = 1282;
36 
37 constexpr uint32_t DEVICE = 1;
38 constexpr uint32_t SERVICE = 2;
39 constexpr uint32_t APP = 3;
40 
41 constexpr uint32_t INACTIVE = 0;
42 constexpr uint32_t ACTIVE = 1;
43 
44 typedef struct DmDiscoveryInfo {
45     std::string pkgname;
46     std::string localDeviceId;
47     std::string remoteDeviceIdHash;
48 } DmDiscoveryInfo;
49 
50 typedef struct DmAclInfo {
51     std::string sessionKey;
52     int32_t bindType;
53     int32_t state;
54     std::string trustDeviceId;
55     int32_t bindLevel;
56     int32_t authenticationType;
57     std::string deviceIdHash;
58 } DmAclInfo;
59 
60 typedef struct DmAccesser {
61     uint64_t requestTokenId;
62     std::string requestBundleName;
63     int32_t requestUserId;
64     std::string requestAccountId;
65     std::string requestDeviceId;
66     int32_t requestTargetClass;
67 } DmAccesser;
68 
69 typedef struct DmAccessee {
70     uint64_t trustTokenId;
71     std::string trustBundleName;
72     int32_t trustUserId;
73     std::string trustAccountId;
74     std::string trustDeviceId;
75     int32_t trustTargetClass;
76 } DmAccessee;
77 
78 typedef struct DmOfflineParam {
79     uint32_t bindType;
80     std::vector<std::string> pkgNameVec;
81     int32_t leftAclNumber;
82 } DmOfflineParam;
83 
84 namespace OHOS {
85 namespace DistributedHardware {
86 class IDeviceProfileConnector {
87 public:
~IDeviceProfileConnector()88     virtual ~IDeviceProfileConnector() {}
89     virtual std::vector<DistributedDeviceProfile::AccessControlProfile> GetAccessControlProfile() = 0;
90     virtual uint32_t CheckBindType(std::string trustDeviceId, std::string requestDeviceId) = 0;
91     virtual int32_t PutAccessControlList(DmAclInfo aclInfo, DmAccesser dmAccesser, DmAccessee dmAccessee) = 0;
92     virtual int32_t UpdateAccessControlList(int32_t userId, std::string &oldAccountId, std::string &newAccountId) = 0;
93     virtual std::map<std::string, DmAuthForm> GetAppTrustDeviceList(const std::string &pkgName,
94         const std::string &deviceId) = 0;
95     virtual DmOfflineParam GetOfflineParamFromAcl(std::string trustDeviceId, std::string requestDeviceId) = 0;
96     virtual std::vector<int32_t> GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId,
97         std::string trustUdid) = 0;
98     virtual std::vector<int32_t> SyncAclByBindType(std::string pkgName, std::vector<int32_t> bindTypeVec,
99         std::string localDeviceId, std::string targetDeviceId) = 0;
100     virtual int32_t GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm) = 0;
101     virtual int32_t DeleteAccessControlList(int32_t userId, std::string &accountId) = 0;
102     virtual DmOfflineParam DeleteAccessControlList(std::string pkgName, std::string localDeviceId,
103         std::string remoteDeviceId) = 0;
104     virtual std::vector<std::string> GetPkgNameFromAcl(std::string &localDeviceId, std::string &targetDeviceId) = 0;
105     virtual bool CheckIdenticalAccount(int32_t userId, const std::string &accountId) = 0;
106     virtual int32_t DeleteP2PAccessControlList(int32_t userId, std::string &accountId) = 0;
107     virtual bool CheckSrcDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId) = 0;
108     virtual bool CheckSinkDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId) = 0;
109     virtual uint32_t DeleteTimeOutAcl(const std::string &deviceId) = 0;
110     virtual int32_t GetTrustNumber(const std::string &deviceId) = 0;
111     virtual bool CheckDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId) = 0;
112     virtual bool CheckPkgnameInAcl(std::string pkgName, std::string localDeviceId, std::string remoteDeviceId) = 0;
113     virtual std::vector<int32_t> CompareBindType(std::vector<DistributedDeviceProfile::AccessControlProfile> profiles,
114         std::string pkgName, std::vector<int32_t> &sinkBindType, std::string localDeviceId,
115         std::string targetDeviceId) = 0;
116 };
117 
118 class DeviceProfileConnector : public IDeviceProfileConnector {
119     DECLARE_SINGLE_INSTANCE(DeviceProfileConnector);
120 public:
121     std::vector<DistributedDeviceProfile::AccessControlProfile> GetAccessControlProfile();
122     uint32_t CheckBindType(std::string trustDeviceId, std::string requestDeviceId);
123     int32_t PutAccessControlList(DmAclInfo aclInfo, DmAccesser dmAccesser, DmAccessee dmAccessee);
124     int32_t UpdateAccessControlList(int32_t userId, std::string &oldAccountId, std::string &newAccountId);
125     std::map<std::string, DmAuthForm> GetAppTrustDeviceList(const std::string &pkgName, const std::string &deviceId);
126     DmOfflineParam GetOfflineParamFromAcl(std::string trustDeviceId, std::string requestDeviceId);
127     std::vector<int32_t> GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId,
128         std::string trustUdid);
129     std::vector<int32_t> SyncAclByBindType(std::string pkgName, std::vector<int32_t> bindTypeVec,
130         std::string localDeviceId, std::string targetDeviceId);
131     int32_t GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm);
132     int32_t DeleteAccessControlList(int32_t userId, std::string &accountId);
133     DmOfflineParam DeleteAccessControlList(std::string pkgName, std::string localDeviceId,
134         std::string remoteDeviceId);
135     std::vector<std::string> GetPkgNameFromAcl(std::string &localDeviceId, std::string &targetDeviceId);
136     bool CheckIdenticalAccount(int32_t userId, const std::string &accountId);
137     int32_t DeleteP2PAccessControlList(int32_t userId, std::string &accountId);
138     bool CheckSrcDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId);
139     bool CheckSinkDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId);
140     uint32_t DeleteTimeOutAcl(const std::string &deviceId);
141     int32_t GetTrustNumber(const std::string &deviceId);
142     bool CheckDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId);
143     bool CheckPkgnameInAcl(std::string pkgName, std::string localDeviceId, std::string remoteDeviceId);
144     std::vector<int32_t> CompareBindType(std::vector<DistributedDeviceProfile::AccessControlProfile> profiles,
145         std::string pkgName, std::vector<int32_t> &sinkBindType, std::string localDeviceId, std::string targetDeviceId);
146 private:
147     int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo);
148     void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string pkgName,
149         std::string requestDeviceId, std::vector<int32_t> &bindTypeVec);
150     void ProcessBindType(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo paramInfo,
151         std::vector<int32_t> &sinkBindType, std::vector<int32_t> &bindTypeIndex, uint32_t index);
152 };
153 
154 extern "C" IDeviceProfileConnector *CreateDpConnectorInstance();
155 using CreateDpConnectorFuncPtr = IDeviceProfileConnector *(*)(void);
156 } // namespace DistributedHardware
157 } // namespace OHOS
158 #endif // OHOS_DM_DEVICEPROFILE_CONNECTOR_H
159