• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef MEDIALIBRARY_SUBSCRIBER_H
16 #define MEDIALIBRARY_SUBSCRIBER_H
17 
18 #include <thread>
19 
20 #include "common_event_manager.h"
21 #include "common_event_subscribe_info.h"
22 #include "common_event_subscriber.h"
23 #include "common_event_support.h"
24 #include "matching_skills.h"
25 #include "medialibrary_async_worker.h"
26 #include "media_background_task_factory.h"
27 
28 namespace OHOS {
29 namespace Media {
30 #define EXPORT __attribute__ ((visibility ("default")))
31 enum class StatusEventType {
32     CHARGING,
33     DISCHARGING,
34     SCREEN_OFF,
35     SCREEN_ON,
36     BATTERY_CHANGED,
37     THERMAL_LEVEL_CHANGED,
38     TIME_TICK
39 };
40 
41 class EXPORT MedialibrarySubscriber : public EventFwk::CommonEventSubscriber {
42 public:
43     class DelayTask {
44     public:
DelayTask(std::string taskName)45         DelayTask(std::string taskName) : taskName(std::move(taskName)) {}
~DelayTask()46         ~DelayTask() { EndBackgroundOperationThread();}
47         bool IsDelayTaskTimeOut();
48         void EndBackgroundOperationThread();
49         void SetOperationThread(std::function<void()> operationTask);
50     private:
51         std::string taskName;
52         int64_t delayTime;
53         std::mutex lock;
54         std::condition_variable cv;
55         bool isTaskWaiting{false};
56         std::thread operationThread;
57     };
58     EXPORT MedialibrarySubscriber() = default;
59     EXPORT explicit MedialibrarySubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo);
60     EXPORT static bool Subscribe(void);
61     EXPORT virtual ~MedialibrarySubscriber();
62 
63     EXPORT virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override;
64     EXPORT static bool IsCellularNetConnected();
65     EXPORT static bool IsWifiConnected();
66     EXPORT static bool IsCurrentStatusOn();
67     EXPORT static void RefreshCellularNetStatus();
68 private:
69     static const std::vector<std::string> events_;
70     bool isScreenOff_ {false};
71     bool isCharging_ {false};
72     bool isDeviceTemperatureProper_{false};
73     static bool isWifiConnected_;
74     static bool currentStatus_;
75     bool thumbnailBgGenerationStatus_{false};
76     bool timerStatus_{false};
77     static bool isCellularNetConnected_;
78     std::mutex mutex_;
79     int32_t agingCount_ {0};
80     int32_t deviceTemperatureLevel_ {0};
81     int32_t newTemperatureLevel_ {0};
82     int32_t batteryCapacity_ {0};
83     int64_t lockTime_ {0};
84     Background::MediaBackgroundTaskFactory backgroundTaskFactory_;
85 
86     DelayTask backgroundDelayTask_{"backgroundTask"};
87     DelayTask thumbnailBgDelayTask_{"thumbnailBgTask"};
88     EXPORT void ClearDirtyData();
89     EXPORT void DoBackgroundOperation();
90     EXPORT void DoThumbnailBgOperation();
91     EXPORT void StopBackgroundOperation();
92     EXPORT void StopThumbnailBgOperation();
93     EXPORT void StartAnalysisService();
94     EXPORT static void ClearContinueCloneData(AsyncTaskData *data);
95     EXPORT int32_t DoClearContinueCloneData();
96     EXPORT bool IsClearContinueCloneData(const std::string &path);
97     EXPORT bool TryClearContinueCloneData();
98     EXPORT std::string GetDataCloneDescriptionJsonPath();
99     EXPORT bool GetCloneTimestamp(const std::string &path, int64_t &cloneTimestamp);
100     EXPORT void WalCheckPointAsync();
101 
102 #ifdef MEDIALIBRARY_MTP_ENABLE
103     void DoStartMtpService();
104 #endif
105     void RevertPendingByPackage(const std::string &bundleName);
106     int64_t GetNowTime();
107     void Init();
108     void UpdateBackgroundOperationStatus(const AAFwk::Want &want, const StatusEventType statusEventType);
109     void UpdateCloudMediaAssetDownloadStatus(const AAFwk::Want &want, const StatusEventType statusEventType);
110     void UpdateCurrentStatus();
111     void UpdateThumbnailBgGenerationStatus();
112     void CheckHalfDayMissions();
113     void UpdateBackgroundTimer();
114     void DoAgingOperation();
115     void UpdateCloudMediaAssetDownloadTaskStatus();
116     void DealWithEventsAfterUpdateStatus(const StatusEventType statusEventType);
117 };
118 }  // namespace Media
119 }  // namespace OHOS
120 
121 #endif // MEDIALIBRARY_SUBSCRIBER_H
122