1 /* 2 * Copyright (C) 2021 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 MEDIALIBRARY_DATA_ABILITY_UTILS 17 #define MEDIALIBRARY_DATA_ABILITY_UTILS 18 19 #include <string> 20 #include <sys/stat.h> 21 22 #include "media_data_ability_const.h" 23 #include "media_lib_service_const.h" 24 #include "media_log.h" 25 #include "rdb_store.h" 26 #include "medialibrary_album_operations.h" 27 #include "fetch_result.h" 28 #include "file_asset.h" 29 30 namespace OHOS { 31 namespace Media { 32 class MediaLibraryDataAbilityUtils { 33 public: 34 MediaLibraryDataAbilityUtils(); 35 ~MediaLibraryDataAbilityUtils(); 36 37 static std::string GetFileName(const std::string &path); 38 static std::string GetParentPath(const std::string &path); 39 static int32_t GetParentIdFromDb(const std::string &path, const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 40 static bool IsNumber(const std::string &str); 41 static int64_t GetAlbumDateModified(const std::string &albumPath); 42 static std::string GetOperationType(const std::string &uri); 43 static std::string GetIdFromUri(const std::string &uri); 44 static std::string GetMediaTypeUri(MediaType mediaType); 45 static bool isFileExistInDb(const std::string &relativePath, 46 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 47 static std::string GetPathFromDb(const std::string &id, const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 48 static shared_ptr<FileAsset> GetFileAssetFromDb(const std::string &id, 49 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 50 static bool checkFilePending(const std::shared_ptr<FileAsset> fileAsset); 51 static bool checkOpenMode(const std::string &mode); 52 static int32_t setFilePending(string &id, bool isPending, const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 53 static NativeAlbumAsset CreateDirectorys(const std::string relativePath, 54 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore, 55 vector<int32_t> &outIds); 56 static int32_t DeleteDirectorys(vector<int32_t> &outIds, 57 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 58 static NativeAlbumAsset GetAlbumAsset(const std::string &id, const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 59 static std::string GetFileTitle(const std::string& displayName); 60 static bool isAlbumExistInDb(const std::string &relativePath, 61 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore, 62 int32_t &outRow); 63 static NativeAlbumAsset GetLastAlbumExistInDb(const std::string &relativePath, 64 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore); 65 static int64_t UTCTimeSeconds(); 66 static bool CheckDisplayName(std::string displayName); 67 static std::unique_ptr<AbsSharedResultSet> QueryFiles(const std::string &strQueryCondition, 68 const std::shared_ptr<RdbStore> &rdbStore); 69 static std::unique_ptr<AbsSharedResultSet> QueryFavFiles(const std::shared_ptr<RdbStore> &rdbStore); 70 static std::unique_ptr<AbsSharedResultSet> QueryTrashFiles(const std::shared_ptr<RdbStore> &rdbStore); 71 static string GetParentDisplayNameFromDb(const int &id, const shared_ptr<RdbStore> &rdbStore); 72 static std::string GetNetworkIdFromUri(const std::string &uri); 73 static std::string GetDistributedAlbumSql(const std::string &strQueryCondition, const std::string &tableName); 74 }; 75 } // namespace Media 76 } // namespace OHOS 77 #endif // MEDIALIBRARY_DATA_ABILITY_UTILS 78