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 FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MEDIA_ASSET_RDBSTORE_H
17 #define FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MEDIA_ASSET_RDBSTORE_H
18 
19 #include "application_context.h"
20 #include "datashare_helper.h"
21 #include "datashare_predicates.h"
22 #include "medialibrary_db_const.h"
23 #include "medialibrary_operation.h"
24 #include "rdb_errno.h"
25 #include "rdb_helper.h"
26 #include "rdb_open_callback.h"
27 #include "rdb_sql_utils.h"
28 #include "rdb_store.h"
29 #include "rdb_store_config.h"
30 #include "rdb_types.h"
31 #include "rdb_utils.h"
32 
33 namespace OHOS {
34 namespace Media {
35 #define EXPORT __attribute__ ((visibility ("default")))
36 
37 class MediaAssetRdbStore {
38 public:
39     ~MediaAssetRdbStore() = default;
40     EXPORT static MediaAssetRdbStore* GetInstance();
41     EXPORT std::shared_ptr<DataShare::DataShareResultSet> Query(const DataShare::DataSharePredicates& predicates,
42         std::vector<std::string>& columns, OperationObject& object, int& errCode);
43     EXPORT bool IsQueryAccessibleViaSandBox(Uri& uri, OperationObject& object,
44         const DataShare::DataSharePredicates& predicates, bool isIgnoreSELinux = false);
45     EXPORT bool IsSupportSharedAssetQuery(Uri& uri, OperationObject& object, bool isIgnoreSELinux = false);
46     EXPORT std::shared_ptr<NativeRdb::ResultSet> QueryRdb(const DataShare::DataSharePredicates& predicates,
47         std::vector<std::string>& columns, OperationObject& object);
48     EXPORT int32_t QueryTimeIdBatch(int32_t start, int32_t count, std::vector<std::string> &batchKeys);
49     EXPORT std::shared_ptr<NativeRdb::AbsSharedResultSet> AddQueryDateTakenTime(std::vector<std::string>& colums);
50 private:
51     MediaAssetRdbStore();
52     int32_t TryGetRdbStore(bool isIngnoreSELinux = false);
53     EXPORT static const std::string CloudSyncTriggerFunc(const std::vector<std::string>& args);
54     EXPORT static const std::string IsCallerSelfFunc(const std::vector<std::string>& args);
55     EXPORT static const std::string PhotoAlbumNotifyFunc(const std::vector<std::string>& args);
56     bool IsQueryGroupPhotoAlbumAssets(const std::string& albumId);
57     std::shared_ptr<NativeRdb::RdbStore> rdbStore_ {nullptr};
58 };
59 
60 class MediaLibraryDataCallBack : public NativeRdb::RdbOpenCallback {
61 public:
62     int32_t OnCreate(NativeRdb::RdbStore& rdbStore) override;
63     int32_t OnUpgrade(NativeRdb::RdbStore& rdbStore, int32_t oldVersion, int32_t newVersion) override;
64 };
65 
66 } // Media
67 } // OHOS
68 
69 #endif // FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MEDIA_ASSET_RDBSTORE_H