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     void HandleLockEvent(const std::string& action, const int32_t userId);
51 
52 private:
53     ffrt::mutex mutex_;
54     std::weak_ptr<BundleActiveGroupController> activeGroupController_;
55     std::weak_ptr<BundleActiveReportHandler> bundleActiveReportHandler_;
56 };
57 }  // namespace DeviceUsageStats
58 }  // namespace OHOS
59 #endif  // BUNDLE_ACTIVE_COMMON_EVENT_SUBSCRIBER_H
60 
61