• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_PDP_PROFILE_ABILITY_H
17 #define DATA_STORAGE_PDP_PROFILE_ABILITY_H
18 
19 #include <functional>
20 
21 #include "__mutex_base"
22 #include "ability.h"
23 #include "ability_lifecycle.h"
24 #include "abs_shared_result_set.h"
25 #include "datashare_ext_ability.h"
26 #include "datashare_ext_ability_context.h"
27 #include "datashare_values_bucket.h"
28 #include "iosfwd"
29 #include "map"
30 #include "memory"
31 #include "rdb_pdp_profile_helper.h"
32 #include "rdb_predicates.h"
33 #include "string"
34 #include "vector"
35 #include "want.h"
36 
37 namespace OHOS {
38 class Uri;
39 namespace NativeRdb {
40 class AbsRdbPredicates;
41 class ResultSet;
42 class DataAbilityPredicates;
43 class ValuesBucket;
44 }
45 namespace Telephony {
46 enum class PdpProfileUriType {
47     UNKNOW,
48     PDP_PROFILE,
49     RESET,
50     PREFER_APN,
51 };
52 class PdpProfileAbility : public DataShare::DataShareExtAbility {
53 public:
54     PdpProfileAbility();
55     virtual ~PdpProfileAbility() override;
56     static PdpProfileAbility* Create();
57     void DoInit();
58     sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override;
59     virtual void OnStart(const AppExecFwk::Want &want) override;
60     virtual int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value) override;
61     virtual std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri,
62         const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns,
63         DataShare::DatashareBusinessError &businessError) override;
64     virtual int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates,
65         const DataShare::DataShareValuesBucket &value) override;
66     virtual int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates) override;
67     virtual std::string GetType(const Uri &uri) override;
68     virtual int OpenFile(const Uri &uri, const std::string &mode) override;
69 
70 private:
71     /**
72      * Parse Uri Type
73      *
74      * @param uri Resource address
75      * @return return PdpProfileUriType
76      */
77     PdpProfileUriType ParseUriType(Uri &uri);
78 
79     /**
80      * Convert DataSharePredicates to RdbPredicates
81      *
82      * @param tableName table name of the predicates
83      * @param predicates DataSharePredicates
84      */
85     OHOS::NativeRdb::RdbPredicates ConvertPredicates(
86         const std::string &tableName, const DataShare::DataSharePredicates &predicates);
87 
88     /**
89     * Check whether the initialization succeeds
90     *
91     * @return true : succeed ,false : failed
92     */
93     bool IsInitOk();
94     int UpdatePreferApn(const DataShare::DataShareValuesBucket &value);
95     int SetPreferApn(int simId, int profileId);
96     int GetPreferApn(const std::string &queryString);
97     std::string GetQueryKey(const std::string &queryString, const std::string &key);
98     bool HasColumnValue(
99         const OHOS::NativeRdb::ValuesBucket &value, const char *columnName, NativeRdb::ValueObject &valueObject);
100 
101 private:
102     RdbPdpProfileHelper helper_;
103     std::mutex lock_;
104     bool initDatabaseDir = false;
105     bool initRdbStore = false;
106 };
107 } // namespace Telephony
108 } // namespace OHOS
109 #endif // DATA_STORAGE_PDP_PROFILE_ABILITY_H
110