• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_REPORT_HANDLER_H
17 #define BUNDLE_ACTIVE_REPORT_HANDLER_H
18 
19 #include "ffrt.h"
20 #include <map>
21 #include <queue>
22 
23 #include "ibundle_active_service.h"
24 #include "bundle_active_core.h"
25 
26 namespace OHOS {
27 namespace DeviceUsageStats {
28 class BundleActiveReportHandler {
29 public:
30     BundleActiveReportHandler() = default;
31     ~BundleActiveReportHandler() = default;
32         /**
33      * Process the event. Developers should override this method.
34      *
35      * @param eventId The event id
36      * @param handlerobj The eventobj
37      */
38     void ProcessEvent(const int32_t& eventId, const std::shared_ptr<BundleActiveReportHandlerObject>& handlerobj);
39     void SendEvent(const int32_t& eventId,
40         const std::shared_ptr<BundleActiveReportHandlerObject>& handlerobj, const int64_t& delayTime = 0);
41     void RemoveEvent(const int32_t& eventId);
42     bool HasEvent(const int32_t& eventId);
43     void Init(const std::shared_ptr<BundleActiveCore>& bundleActiveCore);
44     void DeInit();
45 
46     static const int32_t MSG_REPORT_EVENT;
47     static const int32_t MSG_FLUSH_TO_DISK;
48     static const int32_t MSG_REMOVE_USER;
49     static const int32_t MSG_BUNDLE_UNINSTALLED;
50     static const int32_t MSG_SWITCH_USER;
51     static const int32_t MSG_BUNDLE_INSTALLED;
52 
53 private:
54     void ProcessReportEvent(BundleActiveReportHandlerObject& tmpHandlerobj);
55     void ProcessFlushToDiskEvent(const BundleActiveReportHandlerObject& tmpHandlerobj);
56     void ProcessRmoveUserEvent(const BundleActiveReportHandlerObject& tmpHandlerobj);
57     void ProcessUserSwitchEvent(const BundleActiveReportHandlerObject& tmpHandlerobj);
58     void ProcessBundleUninstallEvent(const BundleActiveReportHandlerObject& tmpHandlerobj);
59     void ProcessBundleInstallEvent(const BundleActiveReportHandlerObject& tmpHandlerobj);
60     bool isInited_ = false;
61     ffrt::mutex taskHandlerMutex_;
62     std::shared_ptr<ffrt::queue> ffrtQueue_;
63     std::map<int32_t, std::queue<ffrt::task_handle>> taskHandlerMap_;
64     std::shared_ptr<BundleActiveCore> bundleActiveCore_;
65 };
66 }  // namespace DeviceUsageStats
67 }  // namespace OHOS
68 #endif  // BUNDLE_ACTIVE_REPORT_HANDLER_H
69 
70