1  /*
2   * Copyright (C) 2021 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 DATA_STORAGE_RDB_PDP_OPERATOR_HELPER_H
17  #define DATA_STORAGE_RDB_PDP_OPERATOR_HELPER_H
18  
19  #include "iosfwd"
20  #include "rdb_base_helper.h"
21  #include "string"
22  
23  namespace OHOS {
24  namespace Telephony {
25  class RdbPdpProfileHelper : public RdbBaseHelper {
26  public:
27      RdbPdpProfileHelper();
28      ~RdbPdpProfileHelper() = default;
29  
30      /**
31       * Init dataBase
32       *
33       * @return 0 is succeed else failed
34       */
35      int Init();
36  
37      /**
38       * Update dataBase path
39       *
40       * @param path path
41       */
42      void UpdateDbPath(const std::string &path);
43  
44      /**
45       * Reload pdp_profile table data form config json file
46       *
47       * @return 0 is succeed else failed
48       */
49      int ResetApn();
50  
51      /**
52       * Init pdp_profile table data form config json file
53       *
54       * @param slotId slotId
55       * @param opkey opkey
56       * @param isNeedCheckFile is need Check File
57       * @return 0 is succeed else failed
58       */
59      int InitAPNDatabase(int slotId, const std::string &opkey, bool isNeedCheckFile);
60  
61  private:
62      /**
63       * Create pdp_profile table
64       *
65       * @param createTableStr Create table statement
66       * @param tableName tableName
67       */
68      void CreatePdpProfileTableStr(std::string &createTableStr, const std::string &tableName);
69  
70      /**
71       * Commit the transaction action
72       *
73       * @return 0 is succeed else failed
74       */
75      int CommitTransactionAction();
76  
77      /**
78       * Is ApnDb need Update
79       *
80       * @param opkey opkey
81       * @param checksum checksum to compare
82       * @return bool Is ApnDb need Update
83       */
84      bool IsApnDbUpdateNeeded(const std::string &opkey, std::string &checksum);
85  
86      /**
87       * Set the Checksum of ApnConf file
88       *
89       * @param opkey opkey
90       * @param checkSum checksum to set
91       * @return 0 is succeed else failed
92       */
93      int SetPreferApnConfChecksum(const std::string &opkey, std::string &checkSum);
94  
95      /**
96       * Clear old pdp profile Data
97       *
98       * @return 0 is succeed else failed
99       */
100      int ClearData(const std::string &opKey);
101  
102  private:
103      const std::string DB_NAME = "net.db";
104      std::string dbPath_ = FOLDER_PATH + DB_NAME;
105      const int VERSION = 4;
106  };
107  } // namespace Telephony
108  } // namespace OHOS
109  #endif // DATA_STORAGE_RDB_PDP_OPERATOR_HELPER_H
110