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 16 #ifndef BUNDLE_ACTIVE_COMMON_EVENT_SUBSCRIBER_H 17 #define BUNDLE_ACTIVE_COMMON_EVENT_SUBSCRIBER_H 18 19 #include <memory> 20 21 #include "common_event_manager.h" 22 #include "common_event_support.h" 23 #include "common_event_data.h" 24 #include "time_service_client.h" 25 26 #include "ibundle_active_service.h" 27 #include "ffrt.h" 28 29 namespace OHOS { 30 namespace DeviceUsageStats { 31 using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 32 using CommonEventData = OHOS::EventFwk::CommonEventData; 33 using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 34 using CommonEventSupport = OHOS::EventFwk::CommonEventSupport; 35 using CommonEventManager = OHOS::EventFwk::CommonEventManager; 36 using MatchingSkills = OHOS::EventFwk::MatchingSkills; 37 class BundleActiveGroupController; 38 class BundleActiveReportHandler; 39 40 class BundleActiveCommonEventSubscriber : public CommonEventSubscriber { 41 public: BundleActiveCommonEventSubscriber(const CommonEventSubscribeInfo & subscriberInfo,const std::shared_ptr<BundleActiveGroupController> activeGroupController,const std::weak_ptr<BundleActiveReportHandler> bundleActiveReportHandler)42 BundleActiveCommonEventSubscriber(const CommonEventSubscribeInfo &subscriberInfo, 43 const std::shared_ptr<BundleActiveGroupController> activeGroupController, 44 const std::weak_ptr<BundleActiveReportHandler> 45 bundleActiveReportHandler) : CommonEventSubscriber(subscriberInfo), 46 activeGroupController_(activeGroupController), 47 bundleActiveReportHandler_(bundleActiveReportHandler) {} 48 ~BundleActiveCommonEventSubscriber() = default; 49 void OnReceiveEvent(const CommonEventData &data) override; 50 51 private: 52 void HandleScreenEvent(); 53 void HandleUserRemoveEvent(const CommonEventData &data); 54 void HandleUserSwitchEvent(const CommonEventData &data); 55 void HandlePackageRemoveEvent(const CommonEventData &data); 56 void HandlePackageAddEvent(const CommonEventData &data); 57 void HandleLockEvent(const CommonEventData &data); 58 ffrt::mutex mutex_; 59 std::weak_ptr<BundleActiveGroupController> activeGroupController_; 60 std::weak_ptr<BundleActiveReportHandler> bundleActiveReportHandler_; 61 }; 62 } // namespace DeviceUsageStats 63 } // namespace OHOS 64 #endif // BUNDLE_ACTIVE_COMMON_EVENT_SUBSCRIBER_H 65 66