1 /*
2  * Copyright (c) 2021-2023 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 FOUNDATION_ACE_FRAMEWORKS_BASE_RESSCHED_RESSCHED_REPORT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_RESSCHED_RESSCHED_REPORT_H
18 
19 #include <string>
20 #include <unordered_map>
21 
22 #include "base/utils/macros.h"
23 #include "base/utils/noncopyable.h"
24 #include "core/event/touch_event.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26 #include "base/geometry/offset.h"
27 
28 namespace OHOS::Ace {
29 namespace ResDefine {
30 constexpr int32_t LOAD_PAGE_START_EVENT = 0;
31 constexpr int32_t LOAD_PAGE_COMPLETE_EVENT = 1;
32 constexpr double JUDGE_DISTANCE = 3.125;
33 }
34 
35 using ReportDataFunc = void (*)(uint32_t resType, int64_t value,
36     const std::unordered_map<std::string, std::string>& payload);
37 
38 ReportDataFunc ACE_EXPORT LoadReportDataFunc();
39 
40 class ACE_EXPORT ResSchedReport final {
41 public:
42     static ResSchedReport& GetInstance();
43     void ResSchedDataReport(const char* name, const std::unordered_map<std::string, std::string>& param = {});
44     void ResSchedDataReport(uint32_t resType, int32_t value = 0,
45         const std::unordered_map<std::string, std::string>& payload = {});
46     void OnTouchEvent(const TouchEvent& touchEvent);
47     void LoadPageEvent(int32_t value);
48 
49 private:
ResSchedReport()50     ResSchedReport() {}
~ResSchedReport()51     ~ResSchedReport() {}
52     void HandleTouchDown(const TouchEvent& touchEvent);
53     void HandleTouchUp(const TouchEvent& touchEvent);
54     void HandleTouchMove(const TouchEvent& touchEvent);
55     void HandleTouchCancel(const TouchEvent& touchEvent);
56     void HandleTouchPullDown(const TouchEvent& touchEvent);
57     void HandleTouchPullUp(const TouchEvent& touchEvent);
58     void HandleTouchPullMove(const TouchEvent& touchEvent);
59     double GetUpVelocity(const TouchEvent& lastMoveInfo,
60         const TouchEvent& upEventInfo);
61     void RecordTouchEvent(const TouchEvent& touchEvent, bool enforce = false);
62 
63     ReportDataFunc reportDataFunc_ = nullptr;
64     bool loadPageOn_ = false;
65     TouchEvent curTouchEvent_;
66     TouchEvent lastTouchEvent_;
67     Offset averageDistance_;
68     bool isInSilde = false;
69     double dpi_ = PipelineBase::GetCurrentDensity();
70 };
71 
72 class ACE_EXPORT ResSchedReportScope final {
73 public:
74     ACE_DISALLOW_COPY_AND_MOVE(ResSchedReportScope);
75 
76     explicit ResSchedReportScope(const std::string& name,
77         const std::unordered_map<std::string, std::string>& param = {});
78     ~ResSchedReportScope();
79 
80 private:
81     std::string name_;
82     std::unordered_map<std::string, std::string> payload_;
83 };
84 } // namespace OHOS::Ace
85 
86 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_RESSCHED_RESSCHED_REPORT_H