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 #ifndef OHOS_FILEMGMT_BACKUP_B_RADAR_H
17 #define OHOS_FILEMGMT_BACKUP_B_RADAR_H
18 #include <chrono>
19 #include <string>
20 
21 namespace OHOS::FileManagement::Backup {
22 enum class BizStageBackup : int32_t {
23     BIZ_STAGE_DEFAULT = 0,
24     BIZ_STAGE_BOOT_BACKUP_SA_FAIL,
25     BIZ_STAGE_GET_LOCAL_CAPABILITIES_FAIL,
26     BIZ_STAGE_CREATE_BACKUP_SESSION_FAIL,
27     BIZ_STAGE_APPEND_BUNDLES_FAIL,
28     BIZ_STAGE_CONNECT_EXTENSION_FAIL,
29     BIZ_STAGE_START_DISPOSE_FAIL,
30     BIZ_STAGE_EXTENSION_ABNORMAL_EXIT,
31     BIZ_STAGE_GET_BACKUP_INFO_FAIL,
32     BIZ_STAGE_ON_BACKUP,
33     BIZ_STAGE_DO_BACKUP,
34     BIZ_STAGE_CHECK_DATA_FAIL,
35     BIZ_STAGE_END_DISPOSE_FAIL,
36     BIZ_STAGE_CLIENT_ABNORMAL_EXIT,
37     BIZ_STAGE_PERMISSION_CHECK_FAIL
38 };
39 
40 enum class BizStageRestore : int32_t {
41     BIZ_STAGE_DEFAULT = 0,
42     BIZ_STAGE_BOOT_BACKUP_SA_FAIL,
43     BIZ_STAGE_GET_LOCAL_CAPABILITIES_FAIL,
44     BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL,
45     BIZ_STAGE_APPEND_BUNDLES_FAIL,
46     BIZ_STAGE_CONNECT_EXTENSION_FAIL,
47     BIZ_STAGE_START_DISPOSE_FAIL,
48     BIZ_STAGE_EXTENSION_ABNORMAL_EXIT,
49     BIZ_STAGE_GET_FILE_HANDLE_FAIL,
50     BIZ_STAGE_DO_RESTORE,
51     BIZ_STAGE_CHECK_DATA_FAIL,
52     BIZ_STAGE_ON_RESTORE,
53     BIZ_STAGE_END_DISPOSE_FAIL,
54     BIZ_STAGE_CLIENT_ABNORMAL_EXIT,
55     BIZ_STAGE_PERMISSION_CHECK_FAIL
56 };
57 
58 class AppRadar {
59 public:
GetInstance()60     static AppRadar &GetInstance()
61     {
62         static AppRadar instance;
63         return instance;
64     }
65 
66 public:
67     struct Info {
68         std::string bundleName;
69         std::string status;
70         std::string resInfo;
71 
InfoOHOS::FileManagement::Backup::AppRadar::Info72         Info(const std::string &bundleName, const std::string &status, const std::string &resInfo)
73             : bundleName(bundleName), status(status), resInfo(resInfo) {}
74     };
75 
76     struct DoRestoreInfo {
77         uint32_t bigFileNum;
78         uint64_t bigFileSize;
79         int64_t bigFileSpendTime;
80         uint32_t tarFileNum;
81         uint64_t tarFileSize;
82         int64_t tarFileSpendTime;
83         int64_t totalFileSpendTime;
84     };
85 
86 public:
87     int32_t GetUserId();
88     void RecordDefaultFuncRes(Info &info, const std::string &func, int32_t userId,
89                               enum BizStageBackup bizStage, int32_t resultCode);
90     void RecordBackupFuncRes(Info &info, const std::string &func, int32_t userId,
91                              enum BizStageBackup bizStage, int32_t resultCode);
92     void RecordRestoreFuncRes(Info &info, const std::string &func, int32_t userId,
93                               enum BizStageRestore bizStage, int32_t resultCode);
94 private:
95     AppRadar() = default;
96     ~AppRadar() = default;
97     AppRadar(const AppRadar &) = delete;
98     AppRadar &operator=(const AppRadar &) = delete;
99     AppRadar(AppRadar &&) = delete;
100     AppRadar &operator=(AppRadar &&) = delete;
101 };
102 } // namespace OHOS::FileManagement::AppRadar
103 #endif // OHOS_FILEMGMT_BACKUP_B_RADAR_H
104