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 26 namespace OHOS { 27 namespace Media { 28 #define EXPORT __attribute__ ((visibility ("default"))) 29 enum class StatusEventType { 30 CHARGING, 31 DISCHARGING, 32 SCREEN_OFF, 33 SCREEN_ON, 34 BATTERY_CHANGED, 35 THERMAL_LEVEL_CHANGED 36 }; 37 38 class EXPORT MedialibrarySubscriber : public EventFwk::CommonEventSubscriber { 39 public: 40 EXPORT MedialibrarySubscriber() = default; 41 EXPORT explicit MedialibrarySubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); 42 EXPORT static bool Subscribe(void); 43 EXPORT virtual ~MedialibrarySubscriber(); 44 45 EXPORT virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; 46 EXPORT static bool IsCellularNetConnected(); 47 EXPORT static bool IsWifiConnected(); 48 EXPORT static bool IsCurrentStatusOn(); 49 50 private: 51 static const std::vector<std::string> events_; 52 bool isScreenOff_ {false}; 53 bool isCharging_ {false}; 54 bool isPowerSufficient_{false}; 55 bool isDeviceTemperatureProper_{false}; 56 static bool isWifiConnected_; 57 static bool currentStatus_; 58 bool timerStatus_{false}; 59 static bool isCellularNetConnected_; 60 std::mutex mutex_; 61 int32_t agingCount_ {0}; 62 int32_t deviceTemperatureLevel_ {0}; 63 int32_t newTemperatureLevel_ {0}; 64 int64_t lockTime_ {0}; 65 66 std::mutex delayTaskLock_; 67 std::condition_variable delayTaskCv_; 68 bool isTaskWaiting_{false}; 69 std::thread backgroundOperationThread_; 70 71 EXPORT void DoBackgroundOperation(); 72 EXPORT void StopBackgroundOperation(); 73 EXPORT void StartAnalysisService(); 74 void WalCheckPointAsync(); 75 76 #ifdef MEDIALIBRARY_MTP_ENABLE 77 void DoStartMtpService(); 78 #endif 79 void RevertPendingByPackage(const std::string &bundleName); 80 int64_t GetNowTime(); 81 void Init(); 82 void UpdateBackgroundOperationStatus(const AAFwk::Want &want, const StatusEventType statusEventType); 83 void UpdateCloudMediaAssetDownloadStatus(const AAFwk::Want &want, const StatusEventType statusEventType); 84 void UpdateCurrentStatus(); 85 void CheckHalfDayMissions(); 86 void UpdateBackgroundTimer(); 87 void DoThumbnailOperation(); 88 bool IsDelayTaskTimeOut(); 89 void EndBackgroundOperationThread(); 90 void UpdateCloudMediaAssetDownloadTaskStatus(); 91 }; 92 } // namespace Media 93 } // namespace OHOS 94 95 #endif // MEDIALIBRARY_SUBSCRIBER_H 96