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_RADAR_HELPER_H
17 #define OHOS_DP_RADAR_HELPER_H
18 
19 #include <cstdint>
20 #include <chrono>
21 #include <string>
22 #include <map>
23 #include <list>
24 
25 #include "single_instance.h"
26 #include "access_control_profile.h"
27 #include "characteristic_profile.h"
28 #include "device_profile.h"
29 #include "dp_subscribe_info.h"
30 #include "service_profile.h"
31 #include "trust_device_profile.h"
32 
33 namespace OHOS {
34 namespace DistributedDeviceProfile {
35 const std::string ORGPKG_NAME = "deviceprofile";
36 const std::string SA_MAGR_NAME = "distributed.sa.manager";
37 const std::string KV_NAME = "distrubitedKv";
38 const std::string RDB_NAME = "relational_store";
39 const std::string DP_DATA_OPERATE_BEHAVIOR = "DP_DATA_OPERATE_BEHAVIOR";
40 const int32_t SUBSYS_DISTRIBUTEDHARDWARE_DP = 205;
41 constexpr int32_t INVALID_UDID_LENGTH = 10;
42 constexpr int32_t SUBSTR_UDID_LENGTH = 5;
43 enum class BizScene : int32_t {
44     DP_GET_SA = 1,
45     DP_ADD_DATA = 2,
46     DP_DELET_DATA = 3,
47     DP_GET_DATA = 4,
48     DP_SUBSCRIBE_DATA = 5,
49     DP_UNSUBSCRIBE_DATA = 6,
50     DP_SYNC_DATA = 7,
51     DP_PUT_ACL_PROFILE = 8,
52     DP_UPDATE_ACL_PROFILE = 9,
53     DP_GET_TRUST_PROFILE = 10,
54     DP_GET_ALL_TRUST_PROFILE = 11,
55     DP_GET_ACL_PROFILE = 12,
56     DP_GET_ALL_ACL_PROFILE = 13,
57     DP_DELETE_ACL_PROFILE = 14,
58     DP_PUT_SERVICE_PROFILE = 15,
59     DP_PUT_CHAR_PROFILE = 16,
60     DP_GET_DEVICE_PROFILE = 17,
61     DP_GET_SERVICE_PROFILE = 18,
62     DP_GET_CHAR_PROFILE = 19,
63     DP_DELETE_SERVICE_PROFILE = 20,
64     DP_DELETE_CHAR_PROFILE = 21,
65     DP_SUBSCRIBE_DEVICE_PROFILE = 22,
66     DP_UNSUNBSCRIBE_DEVICE_PROFILE = 23,
67     DP_SYNC_DEVICE_PROFILE = 24,
68 };
69 
70 enum class StageRes : int32_t {
71     STAGE_IDLE = 0x0,
72     STAGE_SUCC = 0x1,
73     STAGE_FAIL = 0x2,
74     STAGE_CANCEL = 0x3,
75     STAGE_UNKNOW = 0x4,
76 };
77 
78 enum class GetSaStage : int32_t {
79     DP_CHECK_SA = 0x1,
80     DP_LOAD_SA = 0x2,
81     DP_SA_CHACK_AUTH = 0x3,
82 };
83 
84 enum class BizState : int32_t {
85     BIZ_STATE_START = 0x1,
86     BIZ_STATE_END = 0x2,
87     BIZ_STATE_CANCEL = 0x3,
88 };
89 
90 enum class ProfileOperateStage : int32_t {
91     DP_PROFILE_OPERATE = 0x1,
92     DP_NOTIFY_PROFILE_CHANGE = 0x2,
93 };
94 
95 class DpRadarHelper {
96     DECLARE_SINGLE_INSTANCE(DpRadarHelper);
97 public:
98     void ReportCheckDpSa(int32_t stageRes);
99     void ReportLoadDpSa(int32_t stageRes);
100     void ReportLoadDpSaCb(int32_t stageRes);
101     void ReportSaCheckAuth(int32_t stageRes);
102     void ReportPutAclProfile(int32_t errCode, const AccessControlProfile& accessControlProfile);
103     void ReportUpdateAclProfile(int32_t errCode, const AccessControlProfile& accessControlProfile);
104     void ReportGetTrustProfile(int32_t errCode, const std::string& deviceId,
105         const TrustDeviceProfile& trustDeviceProfile);
106     void ReportGetAllTrustProfile(int32_t errCode, std::vector<TrustDeviceProfile>& trustDeviceProfiles);
107     void ReportGetAclProfile(int32_t errCode, std::vector<AccessControlProfile>& accessControlProfiles);
108     void ReportGetAllAclProfile(int32_t errCode, std::vector<AccessControlProfile>& accessControlProfiles);
109     void ReportDeleteAclProfile(int32_t errCode);
110     void ReportPutServiceProfile(int32_t errCode, const ServiceProfile& serviceProfile);
111     void ReportPutServiceProfileBatch(int32_t errCode, const std::vector<ServiceProfile>& serviceProfiles);
112     void ReportPutCharProfile(int32_t errCode, const CharacteristicProfile& characteristicProfile);
113     void ReportPutCharProfileBatch(int32_t errCode,
114         const std::vector<CharacteristicProfile>& characteristicProfiles);
115     void ReportGetDeviceProfile(int32_t errCode, const std::string& deviceId, DeviceProfile& deviceProfile);
116     void ReportGetServiceProfile(int32_t errCode,
117         const std::string& deviceId, ServiceProfile& serviceProfile);
118     void ReportGetCharProfile(int32_t errCode,
119         const std::string& deviceId, CharacteristicProfile& characteristicProfile);
120     void ReportDeleteServiceProfile(int32_t errCode, const std::string& deviceId);
121     void ReportDeleteCharProfile(int32_t errCode, const std::string& deviceId);
122     void ReportSubscribeDeviceProfile(int32_t errCode, const SubscribeInfo& subscribeInfo);
123     void ReportUnSubscribeDeviceProfile(int32_t errCode, const SubscribeInfo& subscribeInfo);
124     void ReportSyncDeviceProfile(int32_t errCode);
125     void ReportNotifyProfileChange(int32_t code);
126     std::string GetPeerUdidList(const std::vector<TrustDeviceProfile>& trustDeviceProfiles);
127     std::string GetPeerUdidList(const std::vector<AccessControlProfile>& accessControlProfiles);
128     std::string GetPeerUdidList(const std::vector<ServiceProfile>& serviceProfiles);
129     std::string GetPeerUdidList(const std::vector<CharacteristicProfile>& characteristicProfiles);
130     bool IsDeviceProfileInit();
131     void SetDeviceProfileInit(bool isInit);
132 private:
133     std::string GetAnonyUdid(std::string udid);
134     std::string GetLocalUdid();
135     std::string GetPeerUdid(std::string udid);
136     bool isInit_ = false;
137 };
138 } // namespace DistributedDeviceProfile
139 } // namespace OHOS
140 #endif // OHOS_DP_RADAR_HELPER_H