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 #include "utils/storage_radar.h"
17
18 #include "hisysevent.h"
19 #include "storage_service_errno.h"
20 #include "storage_service_log.h"
21
22 namespace OHOS {
23 namespace StorageService {
ReportActiveUserKey(const std::string & funcName,uint32_t userId,int ret,const std::string & keyElxLevel)24 void StorageRadar::ReportActiveUserKey(const std::string &funcName, uint32_t userId, int ret,
25 const std::string &keyElxLevel)
26 {
27 RadarParameter param = {
28 .orgPkg = "account_mgr",
29 .userId = userId,
30 .funcName = funcName,
31 .bizScene = BizScene::USER_KEY_ENCRYPTION,
32 .bizStage = BizStage::BIZ_STAGE_ACTIVE_USER_KEY,
33 .keyElxLevel = keyElxLevel,
34 .errorCode = ret
35 };
36 StorageRadar::GetInstance().RecordFuctionResult(param);
37 }
38
ReportGetStorageStatus(const std::string & funcName,uint32_t userId,int ret,const std::string & orgPkg)39 void StorageRadar::ReportGetStorageStatus(const std::string &funcName, uint32_t userId, int ret,
40 const std::string &orgPkg)
41 {
42 RadarParameter param = {
43 .orgPkg = orgPkg,
44 .userId = userId,
45 .funcName = funcName,
46 .bizScene = BizScene::SPACE_STATISTICS,
47 .bizStage = BizStage::BIZ_STAGE_GET_USER_STORAGE_STATS,
48 .keyElxLevel = "NA",
49 .errorCode = ret
50 };
51 StorageRadar::GetInstance().RecordFuctionResult(param);
52 }
53
ReportVolumeOperation(const std::string & funcName,int ret)54 void StorageRadar::ReportVolumeOperation(const std::string &funcName, int ret)
55 {
56 RadarParameter param = {
57 .orgPkg = DEFAULT_ORGPKGNAME,
58 .userId = DEFAULT_USERID,
59 .funcName = funcName,
60 .bizScene = BizScene::EXTERNAL_VOLUME_MANAGER,
61 .bizStage = BizStage::BIZ_STAGE_MOUNT,
62 .keyElxLevel = "NA",
63 .errorCode = ret
64 };
65 StorageRadar::GetInstance().RecordFuctionResult(param);
66 }
67
ReportUserKeyResult(const std::string & funcName,uint32_t userId,int ret,const std::string & keyLevel,const std::string & extraData)68 void StorageRadar::ReportUserKeyResult(const std::string &funcName, uint32_t userId, int ret,
69 const std::string &keyLevel, const std::string &extraData)
70 {
71 RadarParameter param = {
72 .orgPkg = "init",
73 .userId = userId,
74 .funcName = funcName,
75 .bizScene = BizScene::USER_KEY_ENCRYPTION,
76 .bizStage = BizStage::BIZ_STAGE_INIT_GLOBAL_KEY,
77 .keyElxLevel = keyLevel,
78 .errorCode = ret,
79 .extraData = extraData
80 };
81 StorageRadar::GetInstance().RecordFuctionResult(param);
82 }
83
ReportUserManager(const std::string & funcName,uint32_t userId,int ret,enum BizStage stage)84 void StorageRadar::ReportUserManager(const std::string &funcName, uint32_t userId, int ret,
85 enum BizStage stage)
86 {
87 RadarParameter param = {
88 .orgPkg = "account_mgr",
89 .userId = userId,
90 .funcName = funcName,
91 .bizScene = BizScene::USER_MOUNT_MANAGER,
92 .bizStage = stage,
93 .keyElxLevel = "ELx",
94 .errorCode = ret
95 };
96 StorageRadar::GetInstance().RecordFuctionResult(param);
97 }
98
ReportUpdateUserAuth(const std::string & funcName,uint32_t userId,int ret,const std::string & keyLevel,const std::string & extraData)99 void StorageRadar::ReportUpdateUserAuth(const std::string &funcName, uint32_t userId, int ret,
100 const std::string &keyLevel, const std::string &extraData)
101 {
102 RadarParameter param = {
103 .orgPkg = "account_mgr",
104 .userId = userId,
105 .funcName = funcName,
106 .bizScene = BizScene::USER_KEY_ENCRYPTION,
107 .bizStage = BizStage::BIZ_STAGE_UPDATE_USER_AUTH,
108 .keyElxLevel = keyLevel,
109 .errorCode = ret,
110 .extraData = extraData
111 };
112 StorageRadar::GetInstance().RecordFuctionResult(param);
113 }
114
ReportFbexResult(const std::string & funcName,uint32_t userId,int ret,const std::string & keyLevel,const std::string & extraData)115 void StorageRadar::ReportFbexResult(const std::string &funcName, uint32_t userId, int ret,
116 const std::string &keyLevel, const std::string &extraData)
117 {
118 RadarParameter param = {
119 .orgPkg = "fbex",
120 .userId = userId,
121 .funcName = funcName,
122 .bizScene = BizScene::USER_KEY_ENCRYPTION,
123 .bizStage = BizStage::BIZ_STAGE_ACTIVE_USER_KEY,
124 .keyElxLevel = keyLevel,
125 .errorCode = ret,
126 .extraData = extraData
127 };
128 StorageRadar::GetInstance().RecordFuctionResult(param);
129 }
130
ReportIamResult(const std::string & funcName,uint32_t userId,int ret)131 void StorageRadar::ReportIamResult(const std::string &funcName, uint32_t userId, int ret)
132 {
133 RadarParameter param = {
134 .orgPkg = "iam",
135 .userId = userId,
136 .funcName = funcName,
137 .bizScene = BizScene::USER_KEY_ENCRYPTION,
138 .bizStage = BizStage::BIZ_STAGE_ACTIVE_USER_KEY,
139 .keyElxLevel = "NA",
140 .errorCode = ret
141 };
142 StorageRadar::GetInstance().RecordFuctionResult(param);
143 }
144
ReportHuksResult(const std::string & funcName,int ret)145 void StorageRadar::ReportHuksResult(const std::string &funcName, int ret)
146 {
147 RadarParameter param = {
148 .orgPkg = "huks",
149 .userId = DEFAULT_USERID,
150 .funcName = funcName,
151 .bizScene = BizScene::USER_KEY_ENCRYPTION,
152 .bizStage = BizStage::BIZ_STAGE_ACTIVE_USER_KEY,
153 .keyElxLevel = "NA",
154 .errorCode = ret
155 };
156 StorageRadar::GetInstance().RecordFuctionResult(param);
157 }
158
RecordKillProcessResult(std::string processName,int32_t errcode)159 bool StorageRadar::RecordKillProcessResult(std::string processName, int32_t errcode)
160 {
161 int32_t res = E_OK;
162 if (errcode == E_OK) {
163 res = HiSysEventWrite(
164 STORAGESERVICE_DOAMIN,
165 UMOUNT_FAIL_BEHAVIOR,
166 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
167 "ORG_PKG", DEFAULT_ORGPKGNAME,
168 "FUNC", "FindAndKillProcess",
169 "BIZ_SCENE", static_cast<int32_t>(BizScene::STORAGE_START),
170 "BIZ_STAGE", static_cast<int32_t>(BizStage::BIZ_STAGE_SA_START),
171 "STAGE_RES", static_cast<int32_t>(StageRes::STAGE_SUCC),
172 "BIZ_STATE", static_cast<int32_t>(BizState::BIZ_STATE_END));
173 } else {
174 res = HiSysEventWrite(
175 STORAGESERVICE_DOAMIN,
176 UMOUNT_FAIL_BEHAVIOR,
177 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
178 "ORG_PKG", DEFAULT_ORGPKGNAME,
179 "FUNC", "FindAndKillProcess",
180 "BIZ_SCENE", static_cast<int32_t>(BizScene::STORAGE_START),
181 "BIZ_STAGE", static_cast<int32_t>(BizStage::BIZ_STAGE_SA_START),
182 "STAGE_RES", static_cast<int32_t>(StageRes::STAGE_FAIL),
183 "BIZ_STATE", static_cast<int32_t>(BizState::BIZ_STATE_END),
184 "ERROR_CODE", errcode,
185 "PROCESS_NAME", processName);
186 }
187 if (res != E_OK) {
188 LOGE("StorageRadar ERROR, res :%{public}d", res);
189 return false;
190 }
191 return true;
192 }
193
RecordFuctionResult(const RadarParameter & parRes)194 bool StorageRadar::RecordFuctionResult(const RadarParameter &parRes)
195 {
196 int32_t res = E_OK;
197 if (parRes.errorCode == E_OK) {
198 res = HiSysEventWrite(
199 STORAGESERVICE_DOAMIN,
200 FILE_STORAGE_MANAGER_FAULT_BEHAVIOR,
201 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
202 "ORG_PKG", parRes.orgPkg,
203 "USER_ID", parRes.userId,
204 "FUNC", parRes.funcName,
205 "BIZ_SCENE", static_cast<int32_t>(parRes.bizScene),
206 "BIZ_STAGE", static_cast<int32_t>(parRes.bizStage),
207 "kEY_ELX_LEVEL", parRes.keyElxLevel,
208 "TO_CALL_PKG", "FBEX, HUKS, KEY_RING, BUNDLE_MANAGER, HMDFS",
209 "DISK_VOLUME_INFO", "{\"diskId\":\"ab12\", \"volumeId\":\"34cd\", \"fsType\":\"ntfs\"}",
210 "FILE_STATUS", parRes.extraData,
211 "STAGE_RES", static_cast<int32_t>(StageRes::STAGE_SUCC),
212 "BIZ_STATE", static_cast<int32_t>(BizState::BIZ_STATE_START));
213 } else {
214 res = HiSysEventWrite(
215 STORAGESERVICE_DOAMIN,
216 FILE_STORAGE_MANAGER_FAULT_BEHAVIOR,
217 HiviewDFX::HiSysEvent::EventType::FAULT,
218 "ORG_PKG", parRes.orgPkg,
219 "USER_ID", parRes.userId,
220 "FUNC", parRes.funcName,
221 "BIZ_SCENE", static_cast<int32_t>(parRes.bizScene),
222 "BIZ_STAGE", static_cast<int32_t>(parRes.bizStage),
223 "kEY_ELX_LEVEL", parRes.keyElxLevel,
224 "TO_CALL_PKG", "FBEX, HUKS, KEY_RING, BUNDLE_MANAGER, HMDFS",
225 "DISK_VOLUME_INFO", "{\"diskId\":\"ab12\", \"volumeId\":\"34cd\", \"fsType\":\"ntfs\"}",
226 "FILE_STATUS", parRes.extraData,
227 "STAGE_RES", static_cast<int32_t>(StageRes::STAGE_FAIL),
228 "BIZ_STATE", static_cast<int32_t>(BizState::BIZ_STATE_START),
229 "ERROR_CODE", parRes.errorCode);
230 }
231 if (res != E_OK) {
232 LOGE("StorageRadar ERROR, res :%{public}d", res);
233 return false;
234 }
235 return true;
236 }
237 } // namespace StorageService
238 } // namespace OHOS