• 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 NET_STATS_RDB_H
17 #define NET_STATS_RDB_H
18 
19 #include "rdb_errno.h"
20 #include "rdb_helper.h"
21 #include "rdb_open_callback.h"
22 #include "rdb_store.h"
23 #include "result_set.h"
24 #include "rdb_sql_utils.h"
25 #include "net_stats_service.h"
26 #include "rdb_predicates.h"
27 
28 namespace OHOS {
29 namespace NetManagerStandard {
30 namespace NetStatsRdbFiledConst {
31     const std::string FILED_SIMID = "simId";
32     const std::string FILED_MON_W = "monthWarningdate";
33     const std::string FILED_DAY_N = "dayNontificationdate";
34     const std::string FILED_MON_N = "monthNontificationdate";
35     const std::string FILED_MON_W_S = "monthWarningState";
36     const std::string FILED_DAY_N_S = "dayNontificationState";
37     const std::string FILED_MON_N_S = "monNontificationState";
38 
39     constexpr int32_t FILED_COLUMN_INDEX_ZERO = 0;
40     constexpr int32_t FILED_COLUMN_INDEX_ONE = 1;
41     constexpr int32_t FILED_COLUMN_INDEX_TWO = 2;
42     constexpr int32_t FILED_COLUMN_INDEX_THR = 3;
43     constexpr int32_t FILED_COLUMN_INDEX_FUR = 4;
44     constexpr int32_t FILED_COLUMN_INDEX_FW = 5;
45     constexpr int32_t FILED_COLUMN_INDEX_SIX = 6;
46 }
47 
48 constexpr const char* NOTICE_DATABASE_NAME = "/data/service/el1/public/netmanager/net_stats_notice_freq.db";
49 constexpr const char* NOTICE_DATABASE_BACK_NAME = "/data/service/el1/public/netmanager/net_stats_notice_freq_back.db";
50 
51 typedef struct NetStatsData {
52     int32_t simId;
53     int monWarningDate;
54     int dayNoticeDate;
55     int monNoticeDate;
56     int monWarningState;
57     int dayNoticeState;
58     int monNoticeState;
59 } NetStatsData;
60 
61 class NetStatsRDB {
62 public:
63     NetStatsRDB() = default;
64     ~NetStatsRDB() = default;
65     int32_t InitRdbStore();
66     int32_t GetRdbStore();
67     int32_t InsertData(NetStatsData state);
68     int32_t DeleteBySimId(int32_t simId);
69     int32_t UpdateBySimId(int32_t simId, NetStatsData state);
70 
71     std::vector<NetStatsData> QueryAll();
72     int32_t QueryBySimId(int simId, NetStatsData& simStats);
73     int32_t BackUpNetStatsFreqDB(const std::string &sourceDB, const std::string &targetDB);
74     int32_t InitRdbStoreBackupDB();
75 
76     class RdbDataOpenCallback : public NativeRdb::RdbOpenCallback {
77     public:
78         int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override;
79         int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override;
80     private:
81         void UpgradeDbVersionTo(NativeRdb::RdbStore &store, int newVersion);
82     };
83     friend class RdbDataOpenCallback;
84 
85 private:
86     std::shared_ptr<NativeRdb::RdbStore> rdbStore_{nullptr};
87     std::mutex mutex_;
88 };
89 } // namespace NetManagerStandard
90 } // namespace OHOS
91 #endif // NET_ACCESS_POLICY_RDB_H
92