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 CONTACTSDATAABILITY_CONTACT_DATA_ABILITY_TEST_H 17 #define CONTACTSDATAABILITY_CONTACT_DATA_ABILITY_TEST_H 18 19 #include <map> 20 21 #include "abs_shared_result_set.h" 22 #include "datashare_ext_ability.h" 23 #include "datashare_values_bucket.h" 24 #include "predicates_convert.h" 25 #include "rdb_predicates.h" 26 #include "telephony_permission.h" 27 #include "want.h" 28 29 #include "contacts_database.h" 30 31 namespace OHOS { 32 namespace AbilityRuntime { 33 class ContactsDataAbility : public DataShare::DataShareExtAbility { 34 public: 35 ContactsDataAbility(); 36 virtual ~ContactsDataAbility() override; 37 static ContactsDataAbility* Create(); 38 sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override; 39 virtual int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value) override; 40 virtual int BatchInsert(const Uri &uri, const std::vector<DataShare::DataShareValuesBucket> &values) override; 41 virtual void OnStart(const Want &want) override; 42 virtual int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates, 43 const DataShare::DataShareValuesBucket &value) override; 44 virtual int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates) override; 45 virtual std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri, 46 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, 47 DataShare::DatashareBusinessError &businessError) override; 48 49 private: 50 static std::shared_ptr<Contacts::ContactsDataBase> contactDataBase_; 51 static std::shared_ptr<Contacts::ProfileDatabase> profileDataBase_; 52 static std::map<std::string, int> uriValueMap_; 53 int InsertExecute(int &code, const OHOS::NativeRdb::ValuesBucket &value); 54 int UriParseAndSwitch(Uri &uri); 55 void SwitchProfile(Uri &uri); 56 bool QueryExecute(std::shared_ptr<OHOS::NativeRdb::ResultSet> &result, 57 DataShare::DataSharePredicates &dataSharePredicates, std::vector<std::string> &columnsTemp, 58 int &parseCode); 59 bool QueryExecuteSwitchSplit(std::shared_ptr<OHOS::NativeRdb::ResultSet> &result, 60 DataShare::DataSharePredicates &dataSharePredicates, std::vector<std::string> &columnsTemp, 61 int &parseCode); 62 void UpdateExecute(int &retCode, int code, const OHOS::NativeRdb::ValuesBucket &value, 63 DataShare::DataSharePredicates &dataSharePredicates); 64 void SwitchUpdate(int &retCode, int &code, const OHOS::NativeRdb::ValuesBucket &value, 65 DataShare::DataSharePredicates &dataSharePredicates); 66 void DeleteExecute(int &retCode, int code, DataShare::DataSharePredicates &dataSharePredicates); 67 void DataBaseNotifyChange(int code, Uri uri); 68 bool IsBeginTransactionOK(int code, std::mutex &mutex); 69 bool IsCommitOK(int code, std::mutex &mutex); 70 int BackUp(); 71 int Recover(int &code); 72 }; 73 } // namespace AbilityRuntime 74 } // namespace OHOS 75 76 #endif // CONTACTSDATAABILITY_CONTACT_DATA_ABILITY_TEST_H 77