• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 HIVIEW_PLUGINS_USAGE_EVENT_REPORT_SREVICE_FOLD_EVENT_CACHER_H
17 #define HIVIEW_PLUGINS_USAGE_EVENT_REPORT_SREVICE_FOLD_EVENT_CACHER_H
18 
19 #include <memory>
20 #include <map>
21 #include <vector>
22 
23 #include "fold_app_usage_db_helper.h"
24 #include "sys_event.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 class FoldEventCacher {
29 public:
30     FoldEventCacher(const std::string& workPath);
~FoldEventCacher()31     ~FoldEventCacher() {}
32 
33     void ProcessEvent(std::shared_ptr<SysEvent> event);
34 private:
35     void ProcessFocusWindowEvent(std::shared_ptr<SysEvent> event);
36     void ProcessForegroundEvent(std::shared_ptr<SysEvent> event);
37     void ProcessBackgroundEvent(std::shared_ptr<SysEvent> event);
38     void ProcessSceenStatusChangedEvent(std::shared_ptr<SysEvent> event);
39     void CountLifeCycleDuration(AppEventRecord& appEventRecord);
40     void UpdateFoldStatus(int32_t status);
41     void UpdateVhMode(int32_t mode);
42     int GetStartIndex(const std::string& bundleName);
43     void CalCulateDuration(uint64_t dayStartTime, std::vector<AppEventRecord>& events,
44         std::map<int, uint64_t>& durations);
45     bool CanCalcDuration(uint32_t preId, uint32_t id);
46     void Accumulative(int foldStatus, uint64_t duration, std::map<int, uint64_t>& durations);
47     void ProcessCountDurationEvent(AppEventRecord& appEventRecord, std::map<int, uint64_t>& durations);
48     void UpdateMultiWindowInfos(uint8_t multiNum, const std::string& multiWindow);
49     int32_t GetWindowModeOfFocusedApp();
50 
51 private:
52     std::unique_ptr<FoldAppUsageDbHelper> dbHelper_;
53     std::pair<std::string, bool> focusedAppPair_;
54     std::unordered_map<std::string, int32_t> multiWindowInfos_;
55     int32_t foldStatus_ = 0;
56     int32_t vhMode_ = 0;
57     uint64_t timelyStart_ = 0;
58 };
59 } // namespace HiviewDFX
60 } // namespace OHOS
61 #endif // HIVIEW_PLUGINS_USAGE_EVENT_REPORT_SREVICE_EVENT_CACHER_H
62