• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SIM_HELPER_H
17 #define DATA_STORAGE_RDB_SIM_HELPER_H
18 
19 #include "rdb_base_helper.h"
20 #include "sim_data.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 class RdbSimHelper : public RdbBaseHelper {
25 public:
26     enum class SimCardType {
27         MAIN = 0, VOICE, MESSAGE, CELLULAR_DATA
28     };
29 
30     RdbSimHelper();
31     ~RdbSimHelper() = default;
32 
33     /**
34      * Update dataBase path
35      *
36      * @param path path
37      */
38     void UpdateDbPath(const std::string &path);
39 
40     /**
41      * Clear sim_info table data
42      * @return 0 is succeed else failed
43      */
44     int32_t ClearData();
45 
46     /**
47      * Init dataBase
48      *
49      * @return 0 is succeed else failed
50      */
51     int Init();
52 
53     /**
54      * Set default card by card type
55      *
56      * @param simId  simId
57      * @param type card type
58      * @return 0 is succeed else failed
59      */
60     int32_t SetDefaultCardByType(int32_t simId, int32_t type);
61 
62 private:
63     /**
64      * Create SimInfo table
65      *
66      * @param createTableStr Create table statement
67      */
68     void CreateSimInfoTableStr(std::string &createTableStr);
69 
70     /**
71      * Update sim_info table card state by card type
72      *
73      * @param type card type
74      * @param updateState Updated value that is 0 or 1
75      * @param whereSate Previous value
76      * @return 0 is succeed else failed
77      */
78     int32_t UpdateCardStateByType(int32_t type, int32_t updateState, int32_t whereSate);
79 
80     /**
81      * End the transaction action
82      *
83      * @return 0 is succeed else failed
84      */
85     int EndTransactionAction();
86 
87     /**
88      * Commit the transaction action
89      *
90      * @return 0 is succeed else failed
91      */
92     int CommitTransactionAction();
93 
94 private:
95     const std::string DB_NAME = "sim.db";
96     std::string dbPath_ = FOLDER_PATH + DB_NAME;
97     const int VERSION = 1;
98 };
99 } // namespace Telephony
100 } // namespace OHOS
101 #endif // DATA_STORAGE_RDB_SIM_HELPER_H