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_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_MANAGER_H 17 #define FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_MANAGER_H 18 19 #include <string> 20 #include <unordered_map> 21 #include <mutex> 22 23 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT 24 #include "enhancement_service_adapter.h" 25 #include "enhancement_database_operations.h" 26 #endif 27 28 #include "medialibrary_type_const.h" 29 #include "medialibrary_command.h" 30 #include "result_set.h" 31 #include "rdb_predicates.h" 32 #include "rdb_store.h" 33 #include "rdb_utils.h" 34 #include "medialibrary_rdbstore.h" 35 #include "enhancement_thread_manager.h" 36 #include "cloud_enhancement_dfx_get_count.h" 37 #include "settings_monitor.h" 38 39 namespace OHOS { 40 namespace Media { 41 #define EXPORT __attribute__ ((visibility ("default"))) 42 43 const std::string PHOTO_OPTION_CLOSE = "close"; 44 constexpr const char *SETTINGS_DATASHARE_AUTO_OPTION_URI = 45 "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=persist.photos.ce.auto.option"; 46 const std::string SETTINGS_DATASHARE_URI = 47 "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true"; 48 const std::string SETTINGS_DATASHARE_WATER_MARK_URI = SETTINGS_DATASHARE_URI + 49 "&key=persist.photos.ce.watermark.enable"; 50 class EnhancementManager { 51 public: 52 EXPORT static EnhancementManager& GetInstance(); 53 EXPORT bool Init(); 54 EXPORT bool InitAsync(); 55 EXPORT bool LoadService(); 56 EXPORT void CancelTasksInternal(const std::vector<std::string> &fildIds, std::vector<std::string> &photoIds, 57 CloudEnhancementAvailableType type); 58 EXPORT void RemoveTasksInternal(const std::vector<std::string> &fildIds, std::vector<std::string> &photoIds); 59 EXPORT bool RevertEditUpdateInternal(int32_t fileId); 60 EXPORT bool RecoverTrashUpdateInternal(const std::vector<std::string> &fildIds); 61 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT 62 EXPORT int32_t HandleAddOperation(MediaLibraryCommand &cmd, const bool hasCloudWatermark, int triggerMode = 0); 63 EXPORT int32_t AddServiceTask(OHOS::MediaEnhance::MediaEnhanceBundleHandle* mediaEnhanceBundle, int32_t fileId, 64 const std::string &photoId, const bool hasCloudWatermark, const bool isAuto = false); 65 EXPORT int32_t HandleAutoAddOperation(bool isReboot = false); 66 EXPORT int32_t AddAutoServiceTask(OHOS::MediaEnhance::MediaEnhanceBundleHandle* mediaEnhanceBundle, int32_t fileId, 67 const std::string &photoId); 68 #endif 69 70 EXPORT int32_t HandleEnhancementUpdateOperation(MediaLibraryCommand &cmd); 71 EXPORT std::shared_ptr<NativeRdb::ResultSet> HandleEnhancementQueryOperation(MediaLibraryCommand &cmd, 72 const std::vector<std::string> &columns); 73 74 EXPORT int32_t HandlePrioritizeOperation(MediaLibraryCommand &cmd); 75 EXPORT std::shared_ptr<NativeRdb::ResultSet> HandleQueryOperation(MediaLibraryCommand &cmd, 76 const std::vector<std::string> &columns); 77 EXPORT int32_t HandleCancelOperation(MediaLibraryCommand &cmd); 78 EXPORT int32_t HandleCancelAllOperation(); 79 EXPORT int32_t HandlePauseAllOperation(); 80 EXPORT int32_t HandleResumeAllOperation(); 81 EXPORT int32_t HandleSyncOperation(); 82 EXPORT std::shared_ptr<NativeRdb::ResultSet> HandleGetPairOperation(MediaLibraryCommand &cmd); 83 EXPORT int32_t HandleStateChangedOperation(const bool isCameraIdle); 84 EXPORT int32_t HandlePhotosAutoOptionChange(const std::string &photosAutoOption); 85 EXPORT int32_t HandleNetChange(const bool isWifiConnected, const bool isCellularNetConnected); 86 EXPORT void HandlePhotosWaterMarkChange(const bool shouldAddWaterMark); 87 88 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT 89 std::shared_ptr<EnhancementServiceAdapter> enhancementService_; 90 #endif 91 std::shared_ptr<EnhancementThreadManager> threadManager_; 92 93 private: 94 EnhancementManager(); 95 ~EnhancementManager(); 96 EnhancementManager(const EnhancementManager &manager) = delete; 97 const EnhancementManager &operator=(const EnhancementManager &manager) = delete; 98 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT 99 void GenerateAddServicePredicates(bool isAuto, NativeRdb::RdbPredicates &servicePredicates); 100 EXPORT void GenerateAddAutoServicePredicates(NativeRdb::RdbPredicates &servicePredicates); 101 EXPORT void GenerateCancelOperationPredicates(int32_t fileId, NativeRdb::RdbPredicates &servicePredicates); 102 sptr<PhotosAutoOptionObserver> photosAutoOptionObserver_ = nullptr; 103 sptr<PhotosWaterMarkObserver> photosWaterMarkObserver_ = nullptr; 104 bool IsAutoTaskEnabled(); 105 EXPORT int32_t HandleCancelAllAutoOperation(); 106 void ResetProcessingAutoToSupport(); 107 bool IsAddOperationEnabled(int32_t triggerMode); 108 #endif 109 void InitPhotosSettingsMonitor(); 110 bool isCameraIdle_ = true; 111 std::string photosAutoOption_ = PHOTO_OPTION_CLOSE; 112 bool isWifiConnected_ = false; 113 bool isCellularNetConnected_ = false; 114 bool shouldAddWaterMark_ = true; 115 116 static std::mutex mutex_; 117 }; 118 } // namespace Media 119 } // namespace OHOS 120 #endif // FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_HANDLER_H