• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class EnhancementManager {
44 public:
45     EXPORT static EnhancementManager& GetInstance();
46     EXPORT bool Init();
47     EXPORT bool InitAsync();
48     EXPORT bool LoadService();
49     EXPORT void CancelTasksInternal(const std::vector<std::string> &fildIds, std::vector<std::string> &photoIds,
50         CloudEnhancementAvailableType type);
51     EXPORT void RemoveTasksInternal(const std::vector<std::string> &fildIds, std::vector<std::string> &photoIds);
52     EXPORT bool RevertEditUpdateInternal(int32_t fileId);
53     EXPORT bool RecoverTrashUpdateInternal(const std::vector<std::string> &fildIds);
54 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT
55     EXPORT int32_t HandleAddOperation(MediaLibraryCommand &cmd, const bool hasCloudWatermark, int triggerMode = 0);
56     EXPORT int32_t AddServiceTask(OHOS::MediaEnhance::MediaEnhanceBundleHandle* mediaEnhanceBundle, int32_t fileId,
57         const std::string &photoId, const bool hasCloudWatermark, const bool isAuto = false);
58     EXPORT int32_t HandleAutoAddOperation(bool isReboot = false);
59     EXPORT int32_t AddAutoServiceTask(OHOS::MediaEnhance::MediaEnhanceBundleHandle* mediaEnhanceBundle, int32_t fileId,
60         const std::string &photoId);
61 #endif
62 
63     EXPORT int32_t HandleEnhancementUpdateOperation(MediaLibraryCommand &cmd);
64     EXPORT std::shared_ptr<NativeRdb::ResultSet> HandleEnhancementQueryOperation(MediaLibraryCommand &cmd,
65         const std::vector<std::string> &columns);
66 
67     EXPORT int32_t HandlePrioritizeOperation(MediaLibraryCommand &cmd);
68     EXPORT std::shared_ptr<NativeRdb::ResultSet> HandleQueryOperation(MediaLibraryCommand &cmd,
69         const std::vector<std::string> &columns);
70     EXPORT int32_t HandleCancelOperation(MediaLibraryCommand &cmd);
71     EXPORT int32_t HandleCancelAllOperation();
72     EXPORT int32_t HandlePauseAllOperation();
73     EXPORT int32_t HandleResumeAllOperation();
74     EXPORT int32_t HandleSyncOperation();
75     EXPORT std::shared_ptr<NativeRdb::ResultSet> HandleGetPairOperation(MediaLibraryCommand &cmd);
76     EXPORT int32_t HandleStateChangedOperation(const bool isCameraIdle);
77     EXPORT int32_t HandlePhotosAutoOptionChange(const std::string &photosAutoOption);
78     EXPORT int32_t HandleNetChange(const bool isWifiConnected, const bool isCellularNetConnected);
79     EXPORT void HandlePhotosWaterMarkChange(const bool shouldAddWaterMark);
80 
81 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT
82     std::shared_ptr<EnhancementServiceAdapter> enhancementService_;
83 #endif
84     std::shared_ptr<EnhancementThreadManager> threadManager_;
85 
86 private:
87     EnhancementManager();
88     ~EnhancementManager();
89     EnhancementManager(const EnhancementManager &manager) = delete;
90     const EnhancementManager &operator=(const EnhancementManager &manager) = delete;
91 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT
92     void GenerateAddServicePredicates(bool isAuto, NativeRdb::RdbPredicates &servicePredicates);
93     void GenerateAddAutoServicePredicates(NativeRdb::RdbPredicates &servicePredicates);
94     void GenerateCancelOperationPredicates(int32_t fileId, NativeRdb::RdbPredicates &servicePredicates);
95     sptr<PhotosAutoOptionObserver> photosAutoOptionObserver_ = nullptr;
96     sptr<PhotosWaterMarkObserver> photosWaterMarkObserver_ = nullptr;
97     bool IsAutoTaskEnabled();
98     int32_t HandleCancelAllAutoOperation();
99     void ResetProcessingAutoToSupport();
100     bool IsAddOperationEnabled(int32_t triggerMode);
101 #endif
102     void InitPhotosSettingsMonitor();
103     bool isCameraIdle_ = true;
104     std::string photosAutoOption_ = PHOTO_OPTION_CLOSE;
105     bool isWifiConnected_ = false;
106     bool isCellularNetConnected_ = false;
107     bool shouldAddWaterMark_ = true;
108 
109     static std::mutex mutex_;
110 };
111 } // namespace Media
112 } // namespace OHOS
113 #endif  // FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_HANDLER_H