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 27 namespace OHOS { 28 namespace DeviceProfile { 29 const std::string ORGPKGNAME = "deviceprofile"; 30 const std::string SAMAGRNAME = "SA"; 31 const std::string kvNAME = "distrubitedKv"; 32 const std::string DP_DATA_OPERATE_BEHAVIOR = "DP_DATA_OPERATE_BEHAVIOR"; 33 const int32_t SUBSYS_DISTRIBUTEDHARDWARE_DP = 205; 34 constexpr int32_t INVALID_UDID_LENGTH = 10; 35 constexpr int32_t SUBSTR_UDID_LENGTH = 5; 36 enum class BizScene : int32_t { 37 DP_GET_SA = 0x1, 38 DP_ADD_DATA = 0x2, 39 DP_DELET_DATA = 0x3, 40 DP_GET_DATA = 0x4, 41 DP_SUBSCRIBE_DATA = 0x5, 42 DP_UNSUBSCRIBE_DATA = 0x6, 43 DP_SYNC_DATA = 0x7, 44 }; 45 46 enum class StageRes : int32_t { 47 STAGE_IDLE = 0x0, 48 STAGE_SUCC = 0x1, 49 STAGE_FAIL = 0x2, 50 STAGE_CANCEL = 0x3, 51 STAGE_UNKNOW = 0x4, 52 }; 53 54 enum class BizState : int32_t { 55 BIZ_STATE_START = 0x1, 56 BIZ_STATE_END = 0x2, 57 BIZ_STATE_CANCEL = 0x3, 58 }; 59 60 enum class GetSaStage : int32_t { 61 DP_CHECK_SA = 0x1, 62 DP_LOAD_SA = 0x2, 63 DP_SA_CHACK_AUTH = 0x3, 64 }; 65 66 enum class GetDataStage : int32_t { 67 DP_GET_DATA = 0x1, 68 }; 69 70 enum class AddDataStage : int32_t { 71 DP_ADD_DATA = 0x1, 72 }; 73 74 enum class DelDataStage : int32_t { 75 DP_DELET_DATA = 0x1, 76 }; 77 78 enum class SubscribeDataStage : int32_t { 79 DP_SUBSCRIBE_DATA = 0x1, 80 DP_RECIVE_DATA_CHANGE = 0x2, 81 }; 82 83 enum class UnSubscribeDataStage : int32_t { 84 DP_UNSUBSCRIBE_DATA = 0x1, 85 }; 86 87 enum class SyncDataStage : int32_t { 88 DP_SYNC_DATA = 0x1, 89 DP_RECIVE_SYNC_CALLBACK = 0x2, 90 }; 91 92 enum class Module : int32_t { 93 DEVICE_PROFILE = 0x0, 94 SA_MGR = 0x1, 95 DISTRIBUTED_KV = 0x2, 96 }; 97 98 struct RadarInfo { 99 std::string funcName; 100 int32_t stageRes; 101 int32_t bizState; 102 std::string toCallPkg; 103 std::string hostName; 104 std::string localUdid; 105 std::string peerUdid; 106 int32_t errCode; 107 }; 108 109 class DpRadarHelper { 110 DECLARE_SINGLE_INSTANCE(DpRadarHelper); 111 public: 112 bool ReportCheckDpSa(struct RadarInfo info); 113 bool ReportLoadDpSa(struct RadarInfo info); 114 bool ReportLoadDpSaCb(struct RadarInfo info); 115 bool ReportSaCheckAuth(struct RadarInfo info); 116 bool ReportGetData(struct RadarInfo info); 117 bool ReportAddData(struct RadarInfo info); 118 bool ReportDeleteData(struct RadarInfo info); 119 bool ReportSubscribeData(struct RadarInfo info); 120 bool ReportNotifyDataChange(struct RadarInfo info); 121 bool ReportUnsbscribeData(struct RadarInfo info); 122 bool ReportSyncData(struct RadarInfo info); 123 bool ReportSyncDataCb(struct RadarInfo info); 124 std::string GetHostNameByServiceId(std::string serviceId); 125 std::string GetStringUdidList(std::list<std::string> &udidList); 126 private: 127 int32_t GetErrorCode(int32_t errCode, int32_t module); 128 std::string GetAnonyUdid(std::string udid); 129 std::map<std::string, std::string> hostNameMap_ = { 130 {"infoCollection", "CollaborationFwk"}, 131 {"pasteboardService", "pasteboardService"}, 132 {"appInfo", "dmsfwk"}, 133 {"deviceStatus", "msdp"}, 134 }; 135 }; 136 } // namespace DeviceProfile 137 } // namespace OHOS 138 #endif // OHOS_DP_RADAR_HELPER_H