1bc03f14fSopenharmony_ci/*
2bc03f14fSopenharmony_ci * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License.
5bc03f14fSopenharmony_ci * You may obtain a copy of the License at
6bc03f14fSopenharmony_ci *
7bc03f14fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc03f14fSopenharmony_ci *
9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc03f14fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and
13bc03f14fSopenharmony_ci * limitations under the License.
14bc03f14fSopenharmony_ci */
15bc03f14fSopenharmony_ci
16bc03f14fSopenharmony_ci#ifndef MISCSERVICES_PASTEBOARD_HI_VIEW_ADAPTER_H
17bc03f14fSopenharmony_ci#define MISCSERVICES_PASTEBOARD_HI_VIEW_ADAPTER_H
18bc03f14fSopenharmony_ci
19bc03f14fSopenharmony_ci#include <map>
20bc03f14fSopenharmony_ci#include <mutex>
21bc03f14fSopenharmony_ci#include <string>
22bc03f14fSopenharmony_ci#include <sys/time.h>
23bc03f14fSopenharmony_ci#include <vector>
24bc03f14fSopenharmony_ci
25bc03f14fSopenharmony_ci#include "dfx_code_constant.h"
26bc03f14fSopenharmony_ci#include "dfx_types.h"
27bc03f14fSopenharmony_ci#include "hisysevent_c.h"
28bc03f14fSopenharmony_ci#include "paste_data.h"
29bc03f14fSopenharmony_ci
30bc03f14fSopenharmony_cinamespace OHOS {
31bc03f14fSopenharmony_cinamespace MiscServices {
32bc03f14fSopenharmony_cienum DataConsumingLevel : std::int32_t {
33bc03f14fSopenharmony_ci    DATA_LEVEL_ONE = 0,
34bc03f14fSopenharmony_ci    DATA_LEVEL_TWO,
35bc03f14fSopenharmony_ci    DATA_LEVEL_THREE,
36bc03f14fSopenharmony_ci    DATA_LEVEL_FOUR,
37bc03f14fSopenharmony_ci    DATA_LEVEL_FIVE,
38bc03f14fSopenharmony_ci    DATA_LEVEL_SIX,
39bc03f14fSopenharmony_ci    DATA_LEVEL_SEVEN,
40bc03f14fSopenharmony_ci};
41bc03f14fSopenharmony_cienum TimeConsumingLevel : std::int32_t {
42bc03f14fSopenharmony_ci    TIME_LEVEL_ONE = 0,
43bc03f14fSopenharmony_ci    TIME_LEVEL_TWO,
44bc03f14fSopenharmony_ci    TIME_LEVEL_THREE,
45bc03f14fSopenharmony_ci    TIME_LEVEL_FOUR,
46bc03f14fSopenharmony_ci    TIME_LEVEL_FIVE,
47bc03f14fSopenharmony_ci    TIME_LEVEL_SIX,
48bc03f14fSopenharmony_ci    TIME_LEVEL_SEVEN,
49bc03f14fSopenharmony_ci    TIME_LEVEL_EIGHT,
50bc03f14fSopenharmony_ci    TIME_LEVEL_NINE,
51bc03f14fSopenharmony_ci    TIME_LEVEL_TEN,
52bc03f14fSopenharmony_ci    TIME_LEVEL_ELEVEN,
53bc03f14fSopenharmony_ci};
54bc03f14fSopenharmony_ci
55bc03f14fSopenharmony_ciclass API_EXPORT HiViewAdapter {
56bc03f14fSopenharmony_cipublic:
57bc03f14fSopenharmony_ci    ~HiViewAdapter();
58bc03f14fSopenharmony_ci
59bc03f14fSopenharmony_ci    static inline const char *PASTEBOARD_STATE = "PASTEBOARD_STATE";
60bc03f14fSopenharmony_ci    static inline const char *COPY_STATE = "COPY_STATE";
61bc03f14fSopenharmony_ci    static inline const char *PASTE_STATE = "PASTE_STATE";
62bc03f14fSopenharmony_ci    static inline const char *PASTEBOARD_DOMAIN = "PASTEBOARD";
63bc03f14fSopenharmony_ci
64bc03f14fSopenharmony_ci    static void ReportPasteboardFault(int dfxCode, const PasteboardFaultMsg &msg);
65bc03f14fSopenharmony_ci    static void ReportTimeConsumingStatistic(const TimeConsumingStat &stat);
66bc03f14fSopenharmony_ci    static void ReportPasteboardBehaviour(const PasteboardBehaviourMsg &msg);
67bc03f14fSopenharmony_ci    static void StartTimerThread();
68bc03f14fSopenharmony_ci    static std::map<int, int> InitDataMap();
69bc03f14fSopenharmony_ci    static std::map<int, int> InitTimeMap();
70bc03f14fSopenharmony_ci
71bc03f14fSopenharmony_ci    static void ReportUseBehaviour(PasteData &pastData, const char *state, int32_t result);
72bc03f14fSopenharmony_ci
73bc03f14fSopenharmony_ciprivate:
74bc03f14fSopenharmony_ci    static void InvokePasteBoardBehaviour();
75bc03f14fSopenharmony_ci    static void InitializeTimeConsuming(int initFlag);
76bc03f14fSopenharmony_ci    static void CopyTimeConsumingCount(int dataLevel, int timeLevel);
77bc03f14fSopenharmony_ci    static void PasteTimeConsumingCount(int dataLevel, int timeLevel);
78bc03f14fSopenharmony_ci    static void RemotePasteTimeConsumingCount(int dataLevel, int timeLevel);
79bc03f14fSopenharmony_ci    static void CopyTimeConsuming(const TimeConsumingStat &stat, int level);
80bc03f14fSopenharmony_ci    static void PasteTimeConsuming(const TimeConsumingStat &stat, int level);
81bc03f14fSopenharmony_ci    static const char *GetDataLevel(int dataLevel);
82bc03f14fSopenharmony_ci    static void InvokeTimeConsuming();
83bc03f14fSopenharmony_ci    static void ReportBehaviour(std::map<std::string, int> &behaviour, const char *statePasteboard);
84bc03f14fSopenharmony_ci    static void ReportStatisticEvent(
85bc03f14fSopenharmony_ci        const std::vector<std::map<int, int>> &timeConsumingStat, const std::string &pasteboardState);
86bc03f14fSopenharmony_ci
87bc03f14fSopenharmony_ci    static std::mutex timeConsumingMutex_;
88bc03f14fSopenharmony_ci    static std::vector<std::map<int, int>> copyTimeConsumingStat_;
89bc03f14fSopenharmony_ci    static std::vector<std::map<int, int>> pasteTimeConsumingStat_;
90bc03f14fSopenharmony_ci    static std::vector<std::map<int, int>> remotePasteTimeConsumingStat_;
91bc03f14fSopenharmony_ci
92bc03f14fSopenharmony_ci    static std::mutex behaviourMutex_;
93bc03f14fSopenharmony_ci    static std::map<std::string, int> copyPasteboardBehaviour_;
94bc03f14fSopenharmony_ci    static std::map<std::string, int> pastePasteboardBehaviour_;
95bc03f14fSopenharmony_ci    static std::map<std::string, int> remotePastePasteboardBehaviour_;
96bc03f14fSopenharmony_ci
97bc03f14fSopenharmony_ci    static std::map<int, int> dataMap_;
98bc03f14fSopenharmony_ci    static std::map<int, int> timeMap_;
99bc03f14fSopenharmony_ci
100bc03f14fSopenharmony_ci    static std::string CoverEventID(int dfxCode);
101bc03f14fSopenharmony_ci
102bc03f14fSopenharmony_ciprivate:
103bc03f14fSopenharmony_ci    static std::mutex runMutex_;
104bc03f14fSopenharmony_ci    static bool running_;
105bc03f14fSopenharmony_ci
106bc03f14fSopenharmony_ci    static inline constexpr int ONE_DAY_IN_HOURS = 24;
107bc03f14fSopenharmony_ci    static inline constexpr int EXEC_HOUR_TIME = 23;
108bc03f14fSopenharmony_ci    static inline constexpr int EXEC_MIN_TIME = 60;
109bc03f14fSopenharmony_ci    static inline constexpr int ONE_MINUTE_IN_SECONDS = 60;
110bc03f14fSopenharmony_ci    static inline constexpr int ONE_HOUR_IN_SECONDS = 1 * 60 * 60; // 1 hour
111bc03f14fSopenharmony_ci
112bc03f14fSopenharmony_ci    // statistic key
113bc03f14fSopenharmony_ci    static inline const char *ZERO_TO_HUNDRED_KB = "ZERO_TO_HUNDRED_KB";
114bc03f14fSopenharmony_ci    static inline const char *HUNDRED_TO_FIVE_HUNDREDS_KB = "HUNDRED_TO_FIVE_HUNDREDS_KB";
115bc03f14fSopenharmony_ci    static inline const char *FIVE_HUNDREDS_TO_THOUSAND_KB = "FIVE_HUNDREDS_TO_THOUSAND_KB";
116bc03f14fSopenharmony_ci    static inline const char *ONE_TO_FIVE_MB = "ONE_TO_FIVE_MB";
117bc03f14fSopenharmony_ci    static inline const char *FIVE_TO_TEN_MB = "FIVE_TO_TEN_MB";
118bc03f14fSopenharmony_ci    static inline const char *TEN_TO_FIFTY_MB = "TEN_TO_FIFTY_MB";
119bc03f14fSopenharmony_ci    static inline const char *OVER_FIFTY_MB = "OVER_FIFTY_MB";
120bc03f14fSopenharmony_ci    static inline const char *CONSUMING_DATA = "CONSUMING_DATA";
121bc03f14fSopenharmony_ci    static inline const char *DATA_LEVEL = "DATA_LEVEL";
122bc03f14fSopenharmony_ci    static inline constexpr const char *NET_TYPE = "NET_TYPE";
123bc03f14fSopenharmony_ci    // behaviour key
124bc03f14fSopenharmony_ci    static inline const char *TOP_ONE_APP = "TOP_ONE_APP";
125bc03f14fSopenharmony_ci    static inline const char *TOP_TOW_APP = "TOP_TOW_APP";
126bc03f14fSopenharmony_ci    static inline const char *TOP_THREE_APP = "TOP_THREE_APP";
127bc03f14fSopenharmony_ci    static inline const char *TOP_FOUR_APP = "TOP_FOUR_APP";
128bc03f14fSopenharmony_ci    static inline const char *TOP_FIVE_APP = "TOP_FIVE_APP";
129bc03f14fSopenharmony_ci    static inline const char *TOP_SIX_APP = "TOP_SIX_APP";
130bc03f14fSopenharmony_ci    static inline const char *TOP_SEVEN_APP = "TOP_SEVEN_APP";
131bc03f14fSopenharmony_ci    static inline const char *TOP_EIGHT_APP = "TOP_EIGHT_APP";
132bc03f14fSopenharmony_ci    static inline const char *TOP_NINE_APP = "TOP_NINE_APP";
133bc03f14fSopenharmony_ci    static inline const char *TOP_TEN_APP = "TOP_TEN_APP";
134bc03f14fSopenharmony_ci
135bc03f14fSopenharmony_ci    static inline constexpr const char *REMOTE_PASTE_STATE = "REMOTE_PASTE_STATE";
136bc03f14fSopenharmony_ci
137bc03f14fSopenharmony_ci    // use behaviour key
138bc03f14fSopenharmony_ci    static inline const char *BOOTTIME = "BOOTTIME";
139bc03f14fSopenharmony_ci    static inline const char *WALLTIME = "WALLTIME";
140bc03f14fSopenharmony_ci    static inline const char *RESULT = "RESULT";
141bc03f14fSopenharmony_ci    static inline const char *OPERATE_APP = "OPERATE_APP";
142bc03f14fSopenharmony_ci    static inline const char *PRI_MIME_TYPE = "PRI_MIME_TYPE";
143bc03f14fSopenharmony_ci    static inline const char *ISLOCALPASTE = "ISLOCALPASTE";
144bc03f14fSopenharmony_ci    static inline const char *ISREMOTE = "ISREMOTE";
145bc03f14fSopenharmony_ci    static inline const char *SHAREOPTION = "SHAREOPTION";
146bc03f14fSopenharmony_ci
147bc03f14fSopenharmony_ci    static inline const int INIT_COPY_TIME_SONSUMING = 7;
148bc03f14fSopenharmony_ci    static inline const int INIT_PASTE_TIME_SONSUMING = 8;
149bc03f14fSopenharmony_ci    static inline constexpr const int INIT_REMOTE_PASTE_TIME_SONSUMING = 9;
150bc03f14fSopenharmony_ci};
151bc03f14fSopenharmony_ci} // namespace MiscServices
152bc03f14fSopenharmony_ci} // namespace OHOS
153bc03f14fSopenharmony_ci#endif // MISCSERVICES_PASTEBOARD_HI_VIEW_ADAPTER_H
154