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 typedef struct NetStatsData { 49 int32_t simId; 50 int monWarningDate; 51 int dayNoticeDate; 52 int monNoticeDate; 53 int monWarningState; 54 int dayNoticeState; 55 int monNoticeState; 56 } NetStatsData; 57 58 class NetStatsRDB { 59 public: 60 NetStatsRDB() = default; 61 ~NetStatsRDB() = default; 62 int32_t InitRdbStore(); 63 int32_t GetRdbStore(); 64 int32_t InsertData(NetStatsData state); 65 int32_t DeleteBySimId(int32_t simId); 66 int32_t UpdateBySimId(int32_t simId, NetStatsData state); 67 68 std::vector<NetStatsData> QueryAll(); 69 int32_t QueryBySimId(int simId, NetStatsData& simStats); 70 71 class RdbDataOpenCallback : public NativeRdb::RdbOpenCallback { 72 public: 73 int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; 74 int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; 75 private: 76 void UpgradeDbVersionTo(NativeRdb::RdbStore &store, int newVersion); 77 }; 78 friend class RdbDataOpenCallback; 79 80 private: 81 std::shared_ptr<NativeRdb::RdbStore> rdbStore_{nullptr}; 82 }; 83 } // namespace NetManagerStandard 84 } // namespace OHOS 85 #endif // NET_ACCESS_POLICY_RDB_H 86