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 STORAGE_RADAR_H
17 #define STORAGE_RADAR_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 namespace StorageService {
23 const std::string DEFAULT_ORGPKGNAME = "storageService";
24 const std::string ADD_NEW_USER_BEHAVIOR = "ADD_NEW_USER_BEHAVIOR";
25 const std::string FILE_STORAGE_MANAGER_FAULT_BEHAVIOR  = "FILE_STORAGE_MANAGER_FAULT";
26 const std::string UMOUNT_FAIL_BEHAVIOR = "UMOUNT_FAIL_BEHAVIOR";
27 constexpr char STORAGESERVICE_DOAMIN[] = "FILEMANAGEMENT";
28 const int32_t DEFAULT_USERID = 100;
29 enum class BizScene : int32_t {
30     STORAGE_START = 0,
31     USER_MOUNT_MANAGER,
32     USER_KEY_ENCRYPTION,
33     SPACE_STATISTICS,
34     EXTERNAL_VOLUME_MANAGER,
35 };
36 
37 enum class StageRes : int32_t {
38     STAGE_IDLE = 0,
39     STAGE_SUCC = 1,
40     STAGE_FAIL = 2,
41     STAGE_STOP = 3,
42 };
43 
44 enum class BizState : int32_t {
45     BIZ_STATE_START = 1,
46     BIZ_STATE_END = 2,
47 };
48 
49 enum class BizStage : int32_t {
50     BIZ_STAGE_SA_START = 1,
51     BIZ_STAGE_CONNECT = 2,
52     BIZ_STAGE_ENABLE = 3,
53     BIZ_STAGE_SA_STOP = 4,
54 
55     BIZ_STAGE_PREPARE_ADD_USER = 11,
56     BIZ_STAGE_START_USER,
57     BIZ_STAGE_STOP_USER,
58     BIZ_STAGE_REMOVE_USER,
59 
60     BIZ_STAGE_GENERATE_USER_KEYS = 20,
61     BIZ_STAGE_ACTIVE_USER_KEY,
62     BIZ_STAGE_UPDATE_USER_AUTH,
63     BIZ_STAGE_INACTIVE_USER_KEY,
64     BIZ_STAGE_DELETE_USER_KEYS,
65     BIZ_STAGE_CREATE_RECOVERY_KEY,
66     BIZ_STAGE_LOCK_USER_SCREEN,
67     BIZ_STAGE_UNLOCK_USER_SCREEN,
68     BIZ_STAGE_GET_FILE_ENCRYPT_STATUS,
69     BIZ_STAGE_UPDATE_KEY_CONTEXT,
70     BIZ_STAGE_INIT_GLOBAL_KEY,
71 
72     BIZ_STAGE_GET_TOTAL_SIZE = 31,
73     BIZ_STAGE_GET_FREE_SIZE,
74     BIZ_STAGE_GET_SYSTEM_SIZE,
75     BIZ_STAGE_GET_BUNDLE_STATS,
76     BIZ_STAGE_GET_USER_STORAGE_STATS,
77 
78     BIZ_STAGE_MOUNT = 41,
79     BIZ_STAGE_UNMOUNT,
80     BIZ_STAGE_PARTITION,
81     BIZ_STAGE_FORMAT,
82     BIZ_STAGE_SET_VOLUME_DESCRIPTION,
83     BIZ_STAGE_GET_ALL_VOLUMES,
84 };
85 
86 struct RadarParameter {
87     std::string orgPkg;
88     int32_t userId;
89     std::string funcName;
90     enum BizScene bizScene;
91     enum BizStage bizStage;
92     std::string keyElxLevel;
93     int32_t errorCode;
94     std::string extraData;
95 };
96 
97 class StorageRadar {
98 public:
GetInstance()99     static StorageRadar &GetInstance()
100     {
101         static StorageRadar instance;
102         return instance;
103     }
104 
105 public:
106     bool RecordKillProcessResult(std::string processName, int32_t errcode);
107     bool RecordFuctionResult(const RadarParameter &parameterRes);
108     static void ReportActiveUserKey(const std::string &funcName, uint32_t userId, int ret,
109         const std::string &keyElxLevel);
110     static void ReportGetStorageStatus(const std::string &funcName, uint32_t userId, int ret,
111         const std::string &orgPkg);
112     static void ReportVolumeOperation(const std::string &funcName, int ret);
113     static void ReportUserKeyResult(const std::string &funcName, uint32_t userId, int ret,
114         const std::string &keyElxLevel, const std::string &extraData);
115     static void ReportUserManager(const std::string &funcName, uint32_t userId, int ret, enum BizStage bizStage);
116     static void ReportUpdateUserAuth(const std::string &funcName, uint32_t userId, int ret,
117         const std::string &keyLevel, const std::string &extraData);
118     static void ReportFbexResult(const std::string &funcName, uint32_t userId, int ret,
119         const std::string &keyLevel, const std::string &extraData);
120     static void ReportIamResult(const std::string &funcName, uint32_t userId, int ret);
121     static void ReportHuksResult(const std::string &funcName, int ret);
122 
123 private:
124     StorageRadar() = default;
125     ~StorageRadar() = default;
126     StorageRadar(const StorageRadar &) = delete;
127     StorageRadar &operator=(const StorageRadar &) = delete;
128     StorageRadar(StorageRadar &&) = delete;
129     StorageRadar &operator=(StorageRadar &&) = delete;
130 };
131 } // namespace StorageService
132 } // namespace OHOS
133 #endif // STORAGE_RADAR_H