• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 FRAMEWORKS_ANI_SRC_INCLUDE_USER_FILE_CLIENT_H
17 #define FRAMEWORKS_ANI_SRC_INCLUDE_USER_FILE_CLIENT_H
18 
19 #include "datashare_helper.h"
20 #include "datashare_predicates.h"
21 #include "ani_error.h"
22 #include "rdb_store.h"
23 #include "uri.h"
24 
25 namespace OHOS {
26 namespace Media {
27 #define EXPORT __attribute__ ((visibility ("default")))
28 class UserFileClient {
29 public:
UserFileClient()30     EXPORT UserFileClient() {}
~UserFileClient()31     EXPORT virtual ~UserFileClient() {}
32     EXPORT static bool IsValid();
33     EXPORT static ani_status CheckIsStage(ani_env *env, ani_object object, bool &result);
34     EXPORT static sptr<IRemoteObject> ParseTokenInStageMode(ani_env *env, ani_object object);
35     EXPORT static sptr<IRemoteObject> ParseTokenInAbility(ani_env *env, ani_object object);
36 
37     EXPORT static void Init(const sptr<IRemoteObject> &token, bool isSetHelper = false);
38     EXPORT static void Init(ani_env *env, ani_object object);
39     EXPORT static std::shared_ptr<DataShare::DataShareResultSet> Query(Uri &uri,
40         const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, int &errCode);
41     EXPORT static int Insert(Uri &uri, const DataShare::DataShareValuesBucket &value);
42     EXPORT static int InsertExt(Uri &uri, const DataShare::DataShareValuesBucket &value, std::string &result);
43     EXPORT static int BatchInsert(Uri &uri, const std::vector<DataShare::DataShareValuesBucket> &values);
44     EXPORT static int Delete(Uri &uri, const DataShare::DataSharePredicates &predicates);
45     EXPORT static void NotifyChange(const Uri &uri);
46     EXPORT static void RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
47     EXPORT static void UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
48     EXPORT static int OpenFile(Uri &uri, const std::string &mode);
49     EXPORT static int Update(Uri &uri, const DataShare::DataSharePredicates &predicates,
50         const DataShare::DataShareValuesBucket &value);
51     EXPORT static void RegisterObserverExt(const Uri &uri,
52         std::shared_ptr<DataShare::DataShareObserver> dataObserver, bool isDescendants);
53     EXPORT static void UnregisterObserverExt(const Uri &uri,
54         std::shared_ptr<DataShare::DataShareObserver> dataObserver);
55     EXPORT static void Clear();
56     EXPORT static std::shared_ptr<NativeRdb::ResultSet> QueryRdb(Uri &uri,
57         const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns);
58 private:
59     static inline std::shared_ptr<DataShare::DataShareHelper> sDataShareHelper_ = nullptr;
60     static std::shared_ptr<DataShare::DataShareHelper> GetDataShareHelper(ani_env *env, ani_object object);
61 };
62 }
63 }
64 
65 #endif // FRAMEWORKS_ANI_SRC_INCLUDE_USER_FILE_CLIENT_H