• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef USERFILE_CLIENT_H
16 #define USERFILE_CLIENT_H
17 
18 #include "datashare_helper.h"
19 #include "datashare_predicates.h"
20 #include "medialibrary_helper_container.h"
21 #include "photo_accesshelper_log.h"
22 #include "uri.h"
23 
24 namespace OHOS {
25 namespace Media {
26 
27 class UserFileClient {
28 public:
UserFileClient()29     UserFileClient() {}
~UserFileClient()30     virtual ~UserFileClient() {}
31     static bool IsValid();
32 
33     static void Init(const sptr<IRemoteObject> &token);
34     static void Init(int64_t contextId);
35     static std::shared_ptr<DataShare::DataShareResultSet> Query(Uri &uri,
36         const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, int &errCode);
37     static int Insert(Uri &uri, const DataShare::DataShareValuesBucket &value);
38     static int InsertExt(Uri &uri, const DataShare::DataShareValuesBucket &value, std::string &result);
39     static int BatchInsert(Uri& uri, const std::vector<DataShare::DataShareValuesBucket>& values);
40     static int Update(Uri &uri, const DataShare::DataSharePredicates &predicates,
41         const DataShare::DataShareValuesBucket &value);
42     static int Delete(Uri &uri, const DataShare::DataSharePredicates &predicates);
43     static void NotifyChange(const Uri &uri);
44     static void RegisterObserverExt(const Uri &uri,
45         std::shared_ptr<DataShare::DataShareObserver> dataObserver, bool isDescendants);
46     static void UnregisterObserverExt(const Uri &uri,
47         std::shared_ptr<DataShare::DataShareObserver> dataObserver);
48     static void RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
49     static void UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
50     static int OpenFile(Uri &uri, const std::string &mode);
51     static void SetUserId(const int32_t userId);
52     static int32_t GetUserId();
53     static void SetLastUserId(const int32_t userId);
54     static int32_t GetLastUserId();
55 
56 private:
57     static inline std::shared_ptr<DataShare::DataShareHelper> sDataShareHelper_ = nullptr;
58     static int32_t userId_;
59     static int32_t lastUserId_;
60 };
61 }
62 }
63 #endif