• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "hisysevent_adapter.h"
16 #include "account_log_wrapper.h"
17 #ifdef HAS_HISYSEVENT_PART
18 #include "hisysevent.h"
19 #endif // HAS_HISYSEVENT_PART
20 
21 namespace OHOS {
22 namespace AccountSA {
23 namespace {
24 #ifdef HAS_HISYSEVENT_PART
25 using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent;
26 const std::string DOMAIN_STR = std::string(HiSysEventNameSpace::Domain::ACCOUNT);
27 #endif // HAS_HISYSEVENT_PART
28 }
29 
ReportServiceStartFail(int32_t errCode,const std::string & errMsg)30 void ReportServiceStartFail(int32_t errCode, const std::string& errMsg)
31 {
32 #ifdef HAS_HISYSEVENT_PART
33     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "SERVICE_START_FAILED",
34         HiSysEventNameSpace::EventType::FAULT,
35         "ERROR_TYPE", errCode,
36         "ERROR_MSG", errMsg);
37     if (ret != 0) {
38         ACCOUNT_LOGE("hisysevent write failed! ret %{public}d. errCode %{public}d", ret, errCode);
39     }
40 #else // HAS_HISYSEVENT_PART
41     (void)errCode;
42 #endif // HAS_HISYSEVENT_PART
43 }
44 
ReportPermissionFail(int32_t callerUid,int32_t callerPid,const std::string & permName)45 void ReportPermissionFail(int32_t callerUid, int32_t callerPid, const std::string& permName)
46 {
47 #ifdef HAS_HISYSEVENT_PART
48     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "PERMISSION_EXCEPTION",
49         HiSysEventNameSpace::EventType::SECURITY,
50         "CALLER_UID", callerUid,
51         "CALLER_PID", callerPid,
52         "PERMISSION_NAME", permName);
53     if (ret != 0) {
54         ACCOUNT_LOGE("hisysevent write failed! ret %{public}d. uid %{public}d, pid %{public}d permName %{public}s.",
55             ret, callerUid, callerPid, permName.c_str());
56     }
57 #else // HAS_HISYSEVENT_PART
58     (void)callerUid;
59     (void)callerPid;
60     (void)permName;
61 #endif // HAS_HISYSEVENT_PART
62 }
63 
ReportOsAccountOperationFail(int32_t id,const std::string & operationStr,int32_t errCode,const std::string & errMsg)64 void ReportOsAccountOperationFail(
65     int32_t id, const std::string& operationStr, int32_t errCode, const std::string& errMsg)
66 {
67 #ifdef HAS_HISYSEVENT_PART
68     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "OS_ACCOUNT_FAILED",
69         HiSysEventNameSpace::EventType::FAULT,
70         "ID", id,
71         "OPERATE_TYPE", operationStr,
72         "ERROR_TYPE", errCode,
73         "ERROR_MSG", errMsg);
74     if (ret != 0) {
75         ACCOUNT_LOGE("ret %{public}d, id %{public}d, opStr %{public}s, errCode %{public}d errMsg %{public}s.",
76             ret, id, operationStr.c_str(), errCode, errMsg.c_str());
77     }
78 #else // HAS_HISYSEVENT_PART
79     (void)id;
80     (void)errCode;
81     (void)operationStr;
82     (void)errMsg;
83 #endif // HAS_HISYSEVENT_PART
84 }
85 
ReportOhosAccountOperationFail(int32_t userId,const std::string & operationStr,int32_t errCode,const std::string & errMsg)86 void ReportOhosAccountOperationFail(
87     int32_t userId, const std::string& operationStr, int32_t errCode, const std::string& errMsg)
88 {
89 #ifdef HAS_HISYSEVENT_PART
90     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "DISTRIBUTED_ACCOUNT_FAILED",
91         HiSysEventNameSpace::EventType::FAULT,
92         "USER_ID", userId,
93         "OPERATE_TYPE", operationStr,
94         "ERROR_TYPE", errCode,
95         "ERROR_MSG", errMsg);
96     if (ret != 0) {
97         ACCOUNT_LOGE("ret %{public}d, userId %{public}d, opStr %{public}s, errCode %{public}d errMsg %{public}s.",
98             ret, userId, operationStr.c_str(), errCode, errMsg.c_str());
99     }
100 #else // HAS_HISYSEVENT_PART
101     (void)userId;
102     (void)operationStr;
103     (void)errCode;
104     (void)errMsg;
105 #endif // HAS_HISYSEVENT_PART
106 }
107 
ReportAppAccountOperationFail(const std::string & name,const std::string & owner,const std::string & operationStr,int32_t errCode,const std::string & errMsg)108 void ReportAppAccountOperationFail(const std::string &name, const std::string &owner, const std::string& operationStr,
109     int32_t errCode, const std::string& errMsg)
110 {
111 #ifdef HAS_HISYSEVENT_PART
112     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "APP_ACCOUNT_FAILED",
113         HiSysEventNameSpace::EventType::FAULT,
114         "NAME", name,
115         "OWNER", owner,
116         "OPERATE_TYPE", operationStr,
117         "ERROR_TYPE", errCode,
118         "ERROR_MSG", errMsg);
119     if (ret != 0) {
120         ACCOUNT_LOGE(
121             "ret %{public}d, name %{public}s, owner %{public}s, opStr %{public}s, "
122             "errCode %{public}d, errMsg %{public}s.",
123             ret, name.c_str(), owner.c_str(), operationStr.c_str(), errCode, errMsg.c_str());
124     }
125 #else // HAS_HISYSEVENT_PART
126     (void)name;
127     (void)owner;
128     (void)errCode;
129     (void)operationStr;
130     (void)errMsg;
131 #endif // HAS_HISYSEVENT_PART
132 }
133 
ReportOsAccountLifeCycle(int32_t id,const std::string & operationStr)134 void ReportOsAccountLifeCycle(int32_t id, const std::string& operationStr)
135 {
136 #ifdef HAS_HISYSEVENT_PART
137     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "OS_ACCOUNT_LIFE_CYCLE",
138         HiSysEventNameSpace::EventType::BEHAVIOR,
139         "ACCOUNT_ID", id,
140         "OPERATE_TYPE", operationStr);
141     if (ret != 0) {
142         ACCOUNT_LOGE("ret %{public}d, operationStr %{public}s, id %{public}d.",
143             ret, operationStr.c_str(), id);
144     }
145 #else // HAS_HISYSEVENT_PART
146     (void)id;
147     (void)operationStr;
148 #endif // HAS_HISYSEVENT_PART
149 }
150 
ReportOsAccountSwitch(int32_t currentId,int32_t oldId)151 void ReportOsAccountSwitch(int32_t currentId, int32_t oldId)
152 {
153 #ifdef HAS_HISYSEVENT_PART
154     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "OS_ACCOUNT_SWITCH",
155         HiSysEventNameSpace::EventType::BEHAVIOR,
156         "CURRENT_ID", currentId,
157         "OLD_ID", oldId);
158     if (ret != 0) {
159         ACCOUNT_LOGE("ret %{public}d, currentId %{public}d, oldId %{public}d.",
160             ret, currentId, oldId);
161     }
162 #else // HAS_HISYSEVENT_PART
163     (void)currentId;
164     (void)oldId;
165 #endif // HAS_HISYSEVENT_PART
166 }
167 
ReportOhosAccountStateChange(int32_t userId,int32_t operateType,int32_t oldStat,int32_t newStat)168 void ReportOhosAccountStateChange(int32_t userId, int32_t operateType, int32_t oldStat, int32_t newStat)
169 {
170 #ifdef HAS_HISYSEVENT_PART
171     int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "DISTRIBUTED_ACCOUNT_CHANGE",
172         HiSysEventNameSpace::EventType::BEHAVIOR,
173         "USER_ID", userId,
174         "OPERATION_TYPE", operateType,
175         "OLD_STATE", oldStat,
176         "NEW_STATE", newStat);
177     if (ret != 0) {
178         ACCOUNT_LOGE("ret %{public}d, [%{public}d, %{public}d, %{public}d, %{public}d]",
179             ret, userId, operateType, oldStat, newStat);
180     }
181 #else // HAS_HISYSEVENT_PART
182     (void)userId;
183     (void)operateType;
184     (void)oldStat;
185     (void)newStat;
186 #endif // HAS_HISYSEVENT_PART
187 }
188 } // AccountSA
189 } // OHOS
190