1 /*
2 * Copyright (c) 2025 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 #include "hisysevent_common.h"
17 #include "common_defs.h"
18 #include "hc_log.h"
19 #include "hc_dev_info.h"
20 #include "string_util.h"
21
22 #define REQ_ID 999999999999
23 #ifdef DEV_AUTH_HIVIEW_ENABLE
24
25 static int32_t WHITE_LIST[] = {
26 PEER_OCCUR_ERROR,
27 ACCOUNT_NOT_LOGIN,
28 ACCOUNT_LOGINED_NOT_SAME_AS_PEER
29 };
30
GetAddMemberCallEventFuncName(const char * addParams)31 const char *GetAddMemberCallEventFuncName(const char *addParams)
32 {
33 if (addParams == NULL) {
34 LOGE("add params is null!");
35 return ADD_MEMBER_EVENT;
36 }
37 CJson *in = CreateJsonFromString(addParams);
38 if (in == NULL) {
39 LOGE("Failed to create json param!");
40 return ADD_MEMBER_EVENT;
41 }
42 int32_t protocolExpandVal = INVALID_PROTOCOL_EXPAND_VALUE;
43 (void)GetIntFromJson(in, FIELD_PROTOCOL_EXPAND, &protocolExpandVal);
44 FreeJson(in);
45 if (protocolExpandVal == LITE_PROTOCOL_STANDARD_MODE) {
46 return ADD_MEMBER_WITH_LITE_STANDARD;
47 } else if (protocolExpandVal == LITE_PROTOCOL_COMPATIBILITY_MODE) {
48 return ADD_MEMBER_WITH_LITE_COMPATIBILITY;
49 } else {
50 return ADD_MEMBER_EVENT;
51 }
52 }
53
GetBizScene(bool isBind,bool isClient)54 DevAuthBizScene GetBizScene(bool isBind, bool isClient)
55 {
56 if (isBind) {
57 if (isClient) {
58 return BIZ_SCENE_ADD_MEMBER_CLIENT;
59 } else {
60 return BIZ_SCENE_ADD_MEMBER_SERVER;
61 }
62 } else {
63 if (isClient) {
64 return BIZ_SCENE_AUTH_DEVICE_CLIENT;
65 } else {
66 return BIZ_SCENE_AUTH_DEVICE_SERVER;
67 }
68 }
69 }
BuildStageRes(DevAuthBehaviorEvent * eventData,int32_t errorCode)70 void BuildStageRes(DevAuthBehaviorEvent *eventData, int32_t errorCode)
71 {
72 for (uint32_t i = 0; i < sizeof(WHITE_LIST) / sizeof(WHITE_LIST[0]); i++) {
73 if (WHITE_LIST[i] == errorCode) {
74 eventData->stageRes = STAGE_RES_IGNORE;
75 return;
76 }
77 }
78 eventData->stageRes = STAGE_RES_FAILED;
79 }
80
81 #endif
82
ReportBehaviorBeginEvent(bool isBind,bool isClient,int64_t reqId)83 void ReportBehaviorBeginEvent(bool isBind, bool isClient, int64_t reqId)
84 {
85 #ifdef DEV_AUTH_HIVIEW_ENABLE
86 char *funcName = isBind ? ADD_MEMBER_EVENT : AUTH_DEV_EVENT;
87 DevAuthBizScene scene = GetBizScene(isBind, isClient);
88 DevAuthBehaviorEvent eventData = { 0 };
89 BuildBehaviorEventData(&eventData, funcName, scene, BIZ_STATE_BEGIN, BIZ_STAGE_BEGIN);
90 char anonymousLocalUdid[ANONYMOUS_UDID_LEN + 1] = { 0 };
91 if (isBind) {
92 eventData.hostPkg = ADD_MEMBER_HOST_PKG_NAME;
93 eventData.toCallPkg = ADD_MEMBER_TO_CALL_PKG_NAME;
94 } else {
95 eventData.hostPkg = AUTH_DEVICE_HOST_PKG_NAME;
96 char selfUdid[INPUT_UDID_LEN] = { 0 };
97 (void)HcGetUdid((uint8_t *)selfUdid, INPUT_UDID_LEN);
98 if (GetAnonymousString(selfUdid, anonymousLocalUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) {
99 eventData.localUdid = anonymousLocalUdid;
100 }
101 }
102 char concurrentId[MAX_REQUEST_ID_LEN] = { 0 };
103 (void)sprintf_s(concurrentId, sizeof(concurrentId), "%" PRId64, reqId);
104 eventData.concurrentId = concurrentId;
105 DevAuthReportBehaviorEvent(&eventData);
106 #else
107 (void)isBind;
108 (void)isClient;
109 (void)reqId;
110 #endif
111 }
112
ReportBehaviorBeginResultEvent(bool isBind,bool isClient,int64_t reqId,const char * peerUdid,int32_t res)113 void ReportBehaviorBeginResultEvent(bool isBind, bool isClient, int64_t reqId, const char *peerUdid, int32_t res)
114 {
115 #ifdef DEV_AUTH_HIVIEW_ENABLE
116 char *funcName = isBind ? ADD_MEMBER_EVENT : AUTH_DEV_EVENT;
117 DevAuthBizScene scene = GetBizScene(isBind, isClient);
118 DevAuthBehaviorEvent eventData = { 0 };
119 BuildBehaviorEventData(&eventData, funcName, scene, BIZ_STATE_PROCESS, BIZ_STAGE_BEGIN);
120 char anonymousLocalUdid[ANONYMOUS_UDID_LEN + 1] = { 0 };
121 char anonymousPeerUdid[ANONYMOUS_UDID_LEN + 1] = { 0 };
122 if (isBind) {
123 eventData.hostPkg = ADD_MEMBER_HOST_PKG_NAME;
124 eventData.toCallPkg = ADD_MEMBER_TO_CALL_PKG_NAME;
125 } else {
126 eventData.hostPkg = AUTH_DEVICE_HOST_PKG_NAME;
127 char selfUdid[INPUT_UDID_LEN] = { 0 };
128 (void)HcGetUdid((uint8_t *)selfUdid, INPUT_UDID_LEN);
129 if (GetAnonymousString(selfUdid, anonymousLocalUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) {
130 eventData.localUdid = anonymousLocalUdid;
131 }
132 if (GetAnonymousString(peerUdid, anonymousPeerUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) {
133 eventData.peerUdid = anonymousPeerUdid;
134 }
135 }
136 char concurrentId[MAX_REQUEST_ID_LEN] = { 0 };
137 (void)sprintf_s(concurrentId, sizeof(concurrentId), "%" PRId64, reqId);
138 eventData.concurrentId = concurrentId;
139 if (res == HC_SUCCESS) {
140 eventData.stageRes = STAGE_RES_SUCCESS;
141 } else {
142 BuildStageRes(&eventData, res);
143 eventData.errorCode = res;
144 }
145 DevAuthReportBehaviorEvent(&eventData);
146 #else
147 (void)isBind;
148 (void)isClient;
149 (void)reqId;
150 (void)peerUdid;
151 (void)res;
152 #endif
153 }
154
ReportRadarEvent(int32_t res)155 void ReportRadarEvent(int32_t res)
156 {
157 ReportBehaviorBeginEvent(false, true, REQ_ID);
158 ReportBehaviorBeginResultEvent(false, true, REQ_ID, NULL, res);
159 }