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 OHOS_MEDIA_OTHERS_CLONE_RESTORE_H 17 #define OHOS_MEDIA_OTHERS_CLONE_RESTORE_H 18 19 #include <sys/stat.h> 20 21 #include "base_restore.h" 22 #include "photos_restore.h" 23 24 namespace OHOS { 25 namespace Media { 26 27 struct CloneDbInfo { 28 std::string displayName; 29 std::string data; 30 double dateModified {0.0}; 31 double dateTaken {0.0}; 32 }; 33 34 class OthersCloneRestore : public BaseRestore { 35 public: 36 OthersCloneRestore(int32_t sceneCode, const std::string &mediaAppName, const std::string &bundleInfo = ""); 37 virtual ~OthersCloneRestore() = default; 38 39 int32_t Init(const std::string &backupRetorePath, const std::string &upgradePath, bool isUpgrade); 40 NativeRdb::ValuesBucket GetInsertValue(const FileInfo &fileInfo, const std::string &newPath, 41 int32_t sourceType); 42 43 private: 44 void RestorePhoto(void); 45 void RestoreAudio(void); 46 void HandleRestData(void); 47 bool ParseResultSet(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, FileInfo &info, 48 std::string dbName = ""); 49 bool ParseResultSetForAudio(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, FileInfo &info); 50 void AnalyzeSource(); 51 52 void InsertPhoto(std::vector<FileInfo> &fileInfos); 53 void RestoreAlbum(std::vector<FileInfo> &fileInfos); 54 void UpdateAlbumInfo(FileInfo &info); 55 bool NeedBatchQueryPhotoForPortrait(const std::vector<FileInfo> &fileInfos, NeedQueryMap &needQueryMap); 56 void SetFileInfosInCurrentDir(const std::string &file, struct stat &statInfo); 57 int32_t GetAllfilesInCurrentDir(const std::string &path); 58 void UpDateFileModifiedTime(FileInfo &fileInfo); 59 void GetCloneDbInfos(const std::string &dbName, std::vector<CloneDbInfo> &mediaDbInfo); 60 bool HasSameFileForDualClone(FileInfo &fileInfo); 61 void HandleSelectBatch(std::shared_ptr<NativeRdb::RdbStore> mediaRdb, int32_t offset, int32_t sceneCode, 62 std::vector<CloneDbInfo> &mediaDbInfo); 63 void CloneInfoPushBack(std::vector<CloneDbInfo> &pushInfos, std::vector<CloneDbInfo> &popInfos); 64 void HandleInsertBatch(int32_t offset); 65 PhotoAlbumDao::PhotoAlbumRowData FindAlbumInfo(FileInfo &fileInfo); 66 67 private: 68 std::mutex cloneMutex_; 69 std::string clonePhoneName_; 70 std::string mediaAppName_; 71 std::vector<FileInfo> photoInfos_; 72 std::vector<FileInfo> audioInfos_; 73 std::vector<CloneDbInfo> photoDbInfo_; 74 std::vector<CloneDbInfo> audioDbInfo_; 75 std::shared_ptr<NativeRdb::RdbStore> mediaRdb_; 76 PhotoAlbumDao photoAlbumDao_; 77 PhotoAlbumRestore photoAlbumRestore_; 78 PhotosRestore photosRestore_; 79 }; 80 } // namespace Media 81 } // namespace OHOS 82 83 #endif // OHOS_MEDIA_OTHERS_CLONE_RESTORE_H 84