1 /* 2 * Copyright (c) 2023 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 GALLERY_DATA_SYNCER_H 17 #define GALLERY_DATA_SYNCER_H 18 19 #include "functional" 20 21 #include "album_data_handler.h" 22 #include "data_syncer.h" 23 #include "file_data_handler.h" 24 #include "gallery_sysevent.h" 25 #include "rdb_data_handler.h" 26 27 namespace OHOS { 28 namespace FileManagement { 29 namespace CloudSync { 30 class GalleryDataSyncer : public DataSyncer, std::enable_shared_from_this<GalleryDataSyncer> { 31 public: 32 GalleryDataSyncer(const std::string bundleName, const int32_t userId); 33 virtual ~GalleryDataSyncer() = default; 34 35 virtual void Schedule() override; 36 virtual void ScheduleByType(SyncTriggerType syncTriggerType) override; 37 virtual void Reset() override; 38 39 virtual int32_t StartDownloadFile(const std::string path, const int32_t userId) override; 40 virtual int32_t Init(const std::string bundleName, const int32_t userId) override; 41 virtual int32_t Clean(const int action) override; 42 virtual int32_t DisableCloud() override; 43 virtual int32_t OptimizeStorage(const int32_t agingDays) override; 44 virtual int32_t Lock() override; 45 virtual void Unlock() override; 46 virtual void ForceUnlock() override; 47 virtual int32_t DownloadThumb(const int32_t type) override; 48 virtual void StopDownloadThumb() override; 49 virtual int32_t InitSysEventData() override; 50 virtual void FreeSysEventData() override; 51 virtual void ReportSysEvent(uint32_t code) override; 52 virtual void SetFullSyncSysEvent() override; 53 virtual void SetCheckSysEvent() override; 54 virtual int32_t CompletePull() override; 55 56 private: 57 enum { 58 BEGIN, 59 PREPARE, 60 DOWNLOADALBUM, 61 DOWNLOADFILE, 62 COMPLETEPULL, 63 UPLOADALBUM, 64 UPLOADFILE, 65 COMPLETEPUSH, 66 END 67 }; 68 69 int32_t Prepare(); 70 int32_t DownloadAlbum(); 71 int32_t DownloadFile(); 72 int32_t UploadAlbum(); 73 int32_t UploadFile(); 74 int32_t Complete(bool isNeedNotify = true) override; 75 std::shared_ptr<NativeRdb::RdbStore> RdbInit(const std::string &bundleName, const int32_t userId); 76 77 /* sync stat */ 78 void UpdateBasicEventStat(uint32_t code); 79 80 /* stage */ 81 int32_t stage_ = BEGIN; 82 83 /* rdb */ 84 const std::string DATA_APP_EL2 = "/data/app/el2/"; 85 const std::string DATABASE_DIR = "/database/com.ohos.medialibrary.medialibrarydata/rdb/"; 86 const std::string DATABASE_NAME = "media_library.db"; 87 const std::string BUNDLE_NAME = "com.ohos.medialibrary.medialibrarydata"; 88 const int32_t CONNECT_SIZE = 10; 89 90 /* handler */ 91 std::shared_ptr<FileDataHandler> fileHandler_; 92 std::shared_ptr<AlbumDataHandler> albumHandler_; 93 uint32_t timeId_{0}; 94 95 /* sync stat */ 96 std::shared_ptr<GalleryIncSyncStat> syncStat_; 97 /* check stat */ 98 std::shared_ptr<GalleryCheckSatat> checkStat_; 99 }; 100 101 class RdbCallback : public NativeRdb::RdbOpenCallback { 102 public: OnCreate(NativeRdb::RdbStore & r)103 virtual int32_t OnCreate(NativeRdb::RdbStore &r) override 104 { 105 return 0; 106 } 107 OnUpgrade(NativeRdb::RdbStore & r,int32_t oldVersion,int32_t newVersion)108 virtual int32_t OnUpgrade(NativeRdb::RdbStore &r, int32_t oldVersion, 109 int32_t newVersion) override 110 { 111 return 0; 112 } 113 }; 114 } // namespace CloudSync 115 } // namespace FileManagement 116 } // namespace OHOS 117 #endif // GALLERY_DATA_SYNCER_H 118