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_PDP_PROFILE_ABILITY_H 17 #define DATA_STORAGE_PDP_PROFILE_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_pdp_profile_helper.h" 27 #include "string" 28 #include "telephony_permission.h" 29 #include "vector" 30 31 namespace OHOS { 32 class Uri; 33 namespace NativeRdb { 34 class AbsRdbPredicates; 35 class AbsSharedResultSet; 36 class DataAbilityPredicates; 37 class ValuesBucket; 38 } 39 namespace Telephony { 40 enum class PdpProfileUriType { 41 UNKNOW, PDP_PROFILE, RESET 42 }; 43 class PdpProfileAbility : 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 PdpProfileUriType 62 */ 63 PdpProfileUriType 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 * Check whether the initialization succeeds 76 * 77 * @return true : succeed ,false : failed 78 */ 79 bool IsInitOk(); 80 81 /** 82 * Init UriMap 83 */ 84 void InitUriMap(); 85 86 private: 87 RdbPdpProfileHelper helper_; 88 std::mutex lock_; 89 std::map<std::string, PdpProfileUriType> pdpProfileUriMap; 90 bool initDatabaseDir = false; 91 bool initRdbStore = false; 92 }; 93 } // namespace Telephony 94 } // namespace OHOS 95 #endif // DATA_STORAGE_PDP_PROFILE_ABILITY_H 96