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, PDP_PROFILE, RESET 48 }; 49 class PdpProfileAbility : public DataShare::DataShareExtAbility { 50 public: 51 PdpProfileAbility(); 52 virtual ~PdpProfileAbility() override; 53 static PdpProfileAbility* Create(); 54 void DoInit(); 55 sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override; 56 virtual void OnStart(const AppExecFwk::Want &want) override; 57 virtual int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value) override; 58 virtual std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri, 59 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, 60 DataShare::DatashareBusinessError &businessError) override; 61 virtual int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates, 62 const DataShare::DataShareValuesBucket &value) override; 63 virtual int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates) override; 64 virtual std::string GetType(const Uri &uri) override; 65 virtual int OpenFile(const Uri &uri, const std::string &mode) override; 66 67 private: 68 /** 69 * Parse Uri Type 70 * 71 * @param uri Resource address 72 * @return return PdpProfileUriType 73 */ 74 PdpProfileUriType ParseUriType(Uri &uri); 75 76 /** 77 * Convert DataSharePredicates to RdbPredicates 78 * 79 * @param tableName table name of the predicates 80 * @param predicates DataSharePredicates 81 */ 82 OHOS::NativeRdb::RdbPredicates ConvertPredicates( 83 const std::string &tableName, const DataShare::DataSharePredicates &predicates); 84 85 /** 86 * Check whether the initialization succeeds 87 * 88 * @return true : succeed ,false : failed 89 */ 90 bool IsInitOk(); 91 92 private: 93 RdbPdpProfileHelper helper_; 94 std::mutex lock_; 95 bool initDatabaseDir = false; 96 bool initRdbStore = false; 97 }; 98 } // namespace Telephony 99 } // namespace OHOS 100 #endif // DATA_STORAGE_PDP_PROFILE_ABILITY_H 101