1 /* 2 * Copyright (C) 2024 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 DATASHARE_HELPER_H 17 #define DATASHARE_HELPER_H 18 19 #include <cstdint> 20 #include <string> 21 22 #include "data_ability_observer_interface.h" 23 #include "datashare_result_set.h" 24 #include "uri.h" 25 26 namespace OHOS { 27 namespace DataShare { 28 constexpr int32_t E_OK = 0; 29 30 struct CreateOptions { 31 /** Specifies whether the {@link DataShareHelper} in proxy mode. */ 32 bool isProxy_ = true; 33 /** Specifies the System token. */ 34 sptr<IRemoteObject> token_; 35 /** Specifies whether use options to create DataShareHelper. */ 36 bool enabled_ = false; 37 }; 38 39 class DataSharePredicates { 40 public: 41 DataSharePredicates *EqualTo(const std::string &field, const std::string &value); 42 }; 43 class DatashareBusinessError {}; 44 45 class DataShareHelper { 46 public: 47 DataShareHelper() = default; 48 ~DataShareHelper() = default; 49 static std::shared_ptr<DataShareHelper> Creator( 50 const std::string &strUri, const CreateOptions &options, const std::string &bundleName = "com.ohos.photos"); 51 std::shared_ptr<DataShareResultSet> Query(Uri &uri, const DataSharePredicates &predicates, 52 std::vector<std::string> &columns, DatashareBusinessError *businessError = nullptr); 53 54 static void RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver); 55 static void UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver); 56 static bool Release(); 57 58 private: 59 static std::shared_ptr<DataShareHelper> instance_; 60 std::shared_ptr<DataShareResultSet> resultSet_; 61 }; 62 63 64 } // namespace OHOS 65 } // namespace DataShare 66 #endif // DATASHARE_HELPER_H