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 "backup_hi_audit_helper.h"
17
18 #include "backup_hi_audit.h"
19 #include "backup_log_utils.h"
20
21 namespace OHOS::Media {
WriteErrorAuditLog(const ErrorInfo & info)22 void BackupHiAuditHelper::WriteErrorAuditLog(const ErrorInfo &info)
23 {
24 BackupAuditLog auditLog;
25 SetErrorAuditLog(auditLog, info);
26 BackupHiAudit::GetInstance().Write(auditLog);
27 }
28
WriteProgressAuditLog(const std::string & status,const std::string & extend)29 void BackupHiAuditHelper::WriteProgressAuditLog(const std::string &status, const std::string &extend)
30 {
31 BackupAuditLog auditLog;
32 SetProgressAuditLog(auditLog, status, extend);
33 BackupHiAudit::GetInstance().Write(auditLog);
34 }
35
WriteReportAuditLog(const std::string & extend)36 void BackupHiAuditHelper::WriteReportAuditLog(const std::string &extend)
37 {
38 BackupAuditLog auditLog;
39 SetReportAuditLog(auditLog, extend);
40 BackupHiAudit::GetInstance().Write(auditLog);
41 }
42
SetBasicAuditLog(BackupAuditLog & auditLog,const std::string & extend)43 void BackupHiAuditHelper::SetBasicAuditLog(BackupAuditLog &auditLog, const std::string &extend)
44 {
45 auditLog.operationScenario = std::to_string(sceneCode_);
46 auditLog.taskId = taskId_;
47 auditLog.extend = BackupLogUtils::Format(extend);
48 }
49
SetErrorAuditLog(BackupAuditLog & auditLog,const ErrorInfo & info)50 void BackupHiAuditHelper::SetErrorAuditLog(BackupAuditLog &auditLog, const ErrorInfo &info)
51 {
52 auditLog.operationType = "RESTORE";
53 auditLog.cause = BackupLogUtils::RestoreErrorToString(info.error);
54 auditLog.operationCount = static_cast<uint32_t>(info.count);
55 auditLog.operationStatus = info.status.empty() ? "failed" : info.status;
56 SetBasicAuditLog(auditLog, info.extend);
57 }
58
SetProgressAuditLog(BackupAuditLog & auditLog,const std::string & status,const std::string & extend)59 void BackupHiAuditHelper::SetProgressAuditLog(BackupAuditLog &auditLog, const std::string &status,
60 const std::string &extend)
61 {
62 auditLog.operationType = "STAT";
63 auditLog.cause = "PROGRESS";
64 auditLog.operationStatus = status.empty() ? "success" : status;
65 SetBasicAuditLog(auditLog, extend);
66 }
67
SetReportAuditLog(BackupAuditLog & auditLog,const std::string & extend)68 void BackupHiAuditHelper::SetReportAuditLog(BackupAuditLog &auditLog, const std::string &extend)
69 {
70 auditLog.operationType = "STAT";
71 auditLog.cause = "DFX";
72 auditLog.operationStatus = "success";
73 SetBasicAuditLog(auditLog, extend);
74 }
75 } // namespace OHOS::Media