• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PREFERENCES_DFX_ADAPTER_H
17 #define PREFERENCES_DFX_ADAPTER_H
18 
19 #include <string>
20 
21 #include "concurrent_map.h"
22 #include "preferences_errno.h"
23 
24 namespace OHOS {
25 namespace NativePreferences {
26 
27 static constexpr const char *NORMAL_DB = "XMLDB";
28 static constexpr const char *ENHANCE_DB = "ENHANCEDB";
29 static constexpr const char *EVENT_NAME_DB_CORRUPTED = "DATABASE_CORRUPTED";
30 static constexpr const char *EVENT_NAME_PREFERENCES_FAULT = "PREFERENCES_FAULT";
31 static constexpr const char *EVENT_NAME_ARKDATA_PREFERENCES_FAULT = "ARKDATA_PREFERENCES_FAULT";
32 static constexpr const char *DISTRIBUTED_DATAMGR = "DISTDATAMGR";
33 
34 enum class ReportedFaultBitMap {
35     RESTORE_FROM_BAK,
36     USE_WHEN_SCREEN_LOCKED,
37     OBJECT_IS_NOT_ACTIVE
38 };
39 
40 struct ReportParam {
41     std::string bundleName; // bundleName
42     std::string dbType;     // NORMAL_DB or ENHANCE_DB
43     std::string storeName;  // filename
44     uint32_t errCode = E_OK;
45     int32_t errnoCode = 0;  // errno
46     // additional info, "operation: reason", such as "read failed"
47     std::string appendix;   // additional info
48 };
49 
50 struct ReportFaultParam {
51     std::string faultType; // faultType
52     std::string bundleName; // bundleName
53     std::string dbType;     // NORMAL_DB or ENHANCE_DB
54     std::string storeName;  // filename
55     int32_t errCode = E_OK;
56     // additional info, "operation: reason", such as "read failed"
57     std::string appendix;   // additional info
58 };
59 
60 class PreferencesDfxManager {
61 public:
62     static void Report(const ReportParam &reportParam, const char *eventName);
63     static void ReportFault(const ReportFaultParam &reportParam);
64     static std::string GetModuleName();
65 
66     static void ReportAbnormalOperation(const ReportFaultParam &reportParam, ReportedFaultBitMap faultOffset);
67 private:
68     static ConcurrentMap<std::string, uint64_t> reportedFaults_;
69 };
70 } // namespace NativePreferences
71 } // namespace OHOS
72 #endif