• 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_SIM_ABILITY_H
17 #define DATA_STORAGE_SIM_ABILITY_H
18 
19 #include "__functional_base"
20 #include "__mutex_base"
21 #include "ability.h"
22 #include "ability_lifecycle.h"
23 #include "iosfwd"
24 #include "map"
25 #include "memory"
26 #include "rdb_sim_helper.h"
27 #include "string"
28 #include "vector"
29 
30 namespace OHOS {
31 namespace NativeRdb {
32 class AbsRdbPredicates;
33 class AbsSharedResultSet;
34 class DataAbilityPredicates;
35 class ValuesBucket;
36 class ValueObject;
37 }
38 namespace Telephony {
39 enum class SimUriType {
40     UNKNOW, SIM_INFO, SET_CARD
41 };
42 class SimAbility : public AppExecFwk::Ability {
43 public:
44     virtual void OnStart(const AppExecFwk::Want &want) override;
45     virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override;
46     virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(
47         const Uri &uri, const std::vector<std::string> &columns,
48         const NativeRdb::DataAbilityPredicates &predicates) override;
49     virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
50         const NativeRdb::DataAbilityPredicates &predicates) override;
51     virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override;
52     virtual std::string GetType(const Uri &uri) override;
53     virtual int OpenFile(const Uri &uri, const std::string &mode) override;
54 
55 private:
56     /**
57      * Parse Uri Type
58      *
59      * @param uri Resource address
60      * @return return SimUriType
61      */
62     SimUriType ParseUriType(Uri &uri);
63 
64     /**
65      * Convert DataAbilityPredicates to AbsRdbPredicates
66      *
67      * @param predicates DataAbilityPredicates
68      * @param absRdbPredicates AbsRdbPredicates
69      */
70     void ConvertPredicates(
71         const NativeRdb::DataAbilityPredicates &predicates, NativeRdb::AbsRdbPredicates *absRdbPredicates);
72 
73     /**
74     * Set card type
75     *
76     * @param value Table field data
77     * @return Is it successful
78     */
79 
80     int SetCard(const NativeRdb::ValuesBucket &value);
81 
82     /**
83     * Check whether the initialization succeeds
84     *
85     * @return true : succeed ,false : failed
86     */
87     bool IsInitOk();
88 
89     /**
90      * Init SimUriMap
91      */
92     void InitUriMap();
93 
94 private:
95     RdbSimHelper helper_;
96     std::mutex lock_;
97     std::map<std::string, SimUriType> simUriMap;
98     bool initDatabaseDir = false;
99     bool initRdbStore = false;
100 };
101 } // namespace Telephony
102 } // namespace OHOS
103 #endif // DATA_STORAGE_SIM_ABILITY_H
104