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