1 /*
2  * Copyright (C) 2022-2023 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_PASTEBOARD_EVENT_DFX_H
17 #define DISTRIBUTEDDATAMGR_PASTEBOARD_EVENT_DFX_H
18 
19 #include "hisysevent.h"
20 namespace OHOS {
21 namespace MiscServices {
22 namespace RadarReporter {
23 using namespace OHOS::HiviewDFX;
24 enum BizScene : std::int32_t {
25     DFX_SET_PASTEBOARD = 1,
26     DFX_DISTRIBUTED_PASTEBOARD_BROADCAST_SEND = 2,
27     DFX_DISTRIBUTED_PASTEBOARD_BROADCAST_RECEIVE = 3,
28     DFX_DISTRIBUTED_PASTEBOARD_BROADCAST_PULL = 4,
29     DFX_GET_PASTEBOARD = 5,
30     DFX_CLEAR_PASTEBOARD = 6,
31     DFX_OBSERVER = 7,
32     DFX_PLUGIN_CREATE_DESTROY = 8,
33 };
34 
35 enum BizStageSetPasteboard : std::int32_t {
36     DFX_SET_BIZ_SCENE = 0,
37     DFX_CHECK_SET_SERVER = 1,
38     DFX_CHECK_SET_DELAY_COPY = 2,
39     DFX_CHECK_SET_AUTHORITY = 3,
40     DFX_CHECK_ONLINE_DEVICE = 4,
41     DFX_LOAD_DISTRIBUTED_PLUGIN = 5,
42 };
43 
44 enum BizStageBroadcastSend : std::int32_t {
45     DFX_REGISTER_SEND_LISTEN = 1,
46     DFX_RECORD_SEND_BROADCAST = 2,
47 };
48 
49 enum BizStageBroadcastReceive : std::int32_t {
50     DFX_REGISTER_RECEIVE_LISTEN = 1,
51     DFX_RECORD_RECEIVE_BROADCAST = 2,
52 };
53 
54 enum BizStageBroadcastPull : std::int32_t {
55     DFX_PRE_SYNC = 1,
56     DFX_GET_PASTE_DATA_SYNC = 2,
57     DFX_SYNC_DETAIL = 3,
58 };
59 
60 enum BizStageGetPasteboard : std::int32_t {
61     DFX_GET_BIZ_SCENE = 0,
62     DFX_CHECK_GET_SERVER = 1,
63     DFX_CHECK_GET_DELAY_PASTE = 2,
64     DFX_CHECK_GET_AUTHORITY = 3,
65     DFX_GET_DATA_INFO = 4,
66     DFX_LOCAL_PASTE_END = 5,
67     DFX_DISTRIBUTED_PASTE_END = 6,
68     DFX_DISTRIBUTED_FILE_START = 7,
69     DFX_DISTRIBUTED_FILE_END = 8,
70 };
71 
72 enum BizStageClearPasteboard : std::int32_t {
73     DFX_MANUAL_CLEAR = 1,
74     DFX_AUTO_CLEAR = 2,
75 };
76 
77 enum BizStageObserver : std::int32_t {
78     DFX_ADD_OBSERVER = 1,
79     DFX_REMOVE_SINGLE_OBSERVER = 2,
80     DFX_REMOVE_ALL_OBSERVER = 3,
81 };
82 
83 enum BizStagePlugin : std::int32_t {
84     DFX_PLUGIN_CREATE = 1,
85     DFX_PLUGIN_DESTROY = 2,
86 };
87 
88 enum StageRes : std::int32_t {
89     DFX_IDLE = 0,
90     DFX_SUCCESS = 1,
91     DFX_FAILED = 2,
92     DFX_CANCELLED = 3,
93 };
94 
95 enum BizState : std::int32_t {
96     DFX_BEGIN = 1,
97     DFX_END = 2,
98 };
99 
100 class PasteboardDfxUntil {
101 public:
102     static std::string GetAnonymousID(const std::string &deviceId);
103 private:
104     static constexpr int minIdLen = 10;
105     static constexpr int maskIdLen = 5;
106 };
107 
108 constexpr char DOMAIN[] = "DISTDATAMGR";
109 constexpr const char *EVENT_NAME = "DISTRIBUTED_PASTEBOARD_BEHAVIOR";
110 constexpr const char *ORG_PKG = "distributeddata";
111 constexpr const char *BIZ_STATE = "BIZ_STATE";
112 constexpr const char *ERROR_CODE = "ERROR_CODE";
113 constexpr const char *SET_DATA_APP = "SET_DATA_APP";
114 constexpr const char *SET_DATA_TYPE = "SET_DATA_TYPE";
115 constexpr const char *GET_DATA_APP = "GET_DATA_APP";
116 constexpr const char *GET_DATA_TYPE = "GET_DATA_TYPE";
117 constexpr const char *LOCAL_DEV_TYPE = "LOCAL_DEV_TYPE";
118 constexpr const char *COVER_DELAY_DATA = "COVER_DELAY_DATA";
119 constexpr const char *SEND_BROADCAST_TIME = "SEND_BROADCAST_TIME_64";
120 constexpr const char *RECEIVE_BROADCAST_TIME = "RECEIVE_BROADCAST_TIME_64";
121 constexpr const char *SEQ_ID = "SEQ_ID";
122 constexpr const char *CONCURRENT_ID = "CONCURRENT_ID";
123 constexpr const char *DIS_SYNC_TIME = "DIS_SYNC_TIME";
124 constexpr const char *PACKAGE_NAME = "PACKAGE_NAME";
125 constexpr const char *PEER_NET_ID = "PEER_NET_ID";
126 constexpr const char *PEER_UDID = "PEER_UDID";
127 constexpr HiviewDFX::HiSysEvent::EventType TYPE = HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
128 
129 #define RADAR_REPORT(bizScene, bizStage, stageRes, ...)                                    \
130 ({                                                                                         \
131     HiSysEventWrite(RadarReporter::DOMAIN, RadarReporter::EVENT_NAME, RadarReporter::TYPE, \
132         "ORG_PKG", RadarReporter::ORG_PKG, "FUNC", __FUNCTION__,                           \
133         "BIZ_SCENE", bizScene, "BIZ_STAGE", bizStage, "STAGE_RES", stageRes,               \
134         ##__VA_ARGS__);                                                                    \
135 })
136 } // namespace RadarReporter
137 } // namespace MiscServices
138 } // namespace OHOS
139 #endif // DISTRIBUTEDDATAMGR_PASTEBOARD_EVENT_DFX_H
140