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 DISTRIBUTEDDATAMGR_RADAR_REPORTER_H 17 #define DISTRIBUTEDDATAMGR_RADAR_REPORTER_H 18 #include <stdint.h> 19 #include <string> 20 21 #include "visibility.h" 22 23 namespace OHOS { 24 namespace DistributedDataDfx { 25 26 enum BizScene { 27 // cloud sync 28 CLOUD_SYNC = 1, 29 30 // cloud share 31 SHARE = 1, 32 UNSHARE = 2, 33 CONFIRM_INVITATION = 3, 34 CHANGE_CONFIRMATION = 4, 35 CHANGE_PRIVILEGE = 5, 36 EXIT_SHARING = 6, 37 }; 38 39 enum BizStage { 40 // cloud share 41 GENERAL_STAGE = 1, 42 43 // cloud sync 44 TRIGGER_SYNC = 1, 45 CHECK_SYNC_CONDITION = 2, 46 START_SYNC = 3, 47 FINISH_SYNC = 4, 48 }; 49 50 enum BizState { 51 BEGIN = 1, 52 END = 2, 53 }; 54 55 enum StageRes { 56 RES_IDLE = 0, 57 RES_SUCCESS = 1, 58 RES_FAILED = 2, 59 RES_CANCELLED = 3, 60 RES_UNKNOWN = 4, 61 }; 62 63 struct EventName { 64 static constexpr const char *CLOUD_SYNC_BEHAVIOR = "DISTRIBUTED_CLOUD_SYNC_BEHAVIOR"; 65 static constexpr const char *CLOUD_SHARING_BEHAVIOR = "DISTRIBUTED_CLOUD_SHARE_BEHAVIOR"; 66 }; 67 68 struct RadarParam { 69 const char *bundleName_ = ""; 70 int32_t scene_ = CLOUD_SYNC; 71 int32_t stage_ = GENERAL_STAGE; 72 uint64_t syncId_ = 0; 73 int32_t triggerMode_ = 0; 74 uint64_t changeCount = 0; 75 int32_t errCode_ = 0; 76 int32_t res_ = RES_SUCCESS; 77 }; 78 79 class RadarReporter { 80 public: 81 KVSTORE_API RadarReporter(const char *eventName, int32_t scene, const char *bundleName, const char *funcName); 82 KVSTORE_API ~RadarReporter(); 83 KVSTORE_API RadarReporter &operator=(int32_t errCode); 84 KVSTORE_API static void Report(const RadarParam ¶m, const char *funcName, int32_t state = 0, 85 const char *eventName = EventName::CLOUD_SYNC_BEHAVIOR); 86 87 private: 88 static std::string AnonymousUuid(const std::string &uuid); 89 RadarParam radarParam_; 90 const char *eventName_ = EventName::CLOUD_SYNC_BEHAVIOR; 91 const char *funcName_; 92 93 static constexpr const char *ORG_PKG_LABEL = "ORG_PKG"; 94 static constexpr const char *ORG_PKG = "distributddata"; 95 static constexpr const char *FUNC_LABEL = "FUNC"; 96 static constexpr const char *BIZ_SCENE_LABEL = "BIZ_SCENE"; 97 static constexpr const char *BIZ_STATE_LABEL = "BIZ_STATE"; 98 static constexpr const char *BIZ_STAGE_LABEL = "BIZ_STAGE"; 99 static constexpr const char *STAGE_RES_LABEL = "STAGE_RES"; 100 static constexpr const char *ERROR_CODE_LABEL = "ERROR_CODE"; 101 static constexpr const char *LOCAL_UUID_LABEL = "LOCAL_UUID"; 102 static constexpr const char *HOST_PKG = "HOST_PKG"; 103 static constexpr const char *UNKNOW = "UNKNOW"; 104 static constexpr const char *REPLACE_CHAIN = "**"; 105 static constexpr const char *DEFAULT_ANONYMOUS = "************"; 106 static constexpr const char *CONCURRENT_ID = "CONCURRENT_ID"; 107 static constexpr const char *TRIGGER_MODE = "TRIGGER_MODE"; 108 static constexpr const char *WATER_VERSION = "WATER_VERSION"; 109 static constexpr const int32_t NO_ERROR = 0; 110 static constexpr const int32_t HEAD_SIZE = 5; 111 static constexpr const int32_t END_SIZE = 5; 112 static constexpr const int32_t BASE_SIZE = 12; 113 }; 114 } // namespace DistributedDataDfx 115 } // namespace OHOS 116 #endif // DISTRIBUTEDDATAMGR_RADAR_REPORTER_H