1 /*
2  * Copyright (c) 2024 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_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_BEHAVIOR_REPORTER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_BEHAVIOR_REPORTER_H
18 
19 #include <set>
20 #include <string>
21 
22 #include "core/common/container_consts.h"
23 
24 namespace OHOS::Ace::NG {
25 enum class DragStartResult : int32_t {
26     UNKNOW = -1,
27     DRAG_START_SUCCESS = 0,
28     APP_REFUSE_DRAG = 1,
29     DRAGFWK_START_FAIL = 2,
30     SET_DATA_FAIL = 3,
31     REPEAT_DRAG_FAIL = 4,
32     SNAPSHOT_FAIL = 5,
33     TEXT_NOT_SELECT = 6
34 };
35 
36 enum class DragStopResult : int32_t {
37     UNKNOW = -1,
38     DRAG_SOTP_SUCCESS = 0,
39     APP_REFUSE_DATA = 1,
40     APP_RECEIVE_FAIL = 2,
41     APP_DATA_UNSUPPORT = 3,
42     USER_STOP_DRAG = 4,
43     GET_UDKEY_FAIL = 5,
44     GET_UDMF_FAIL = 6,
45     DRAGFWK_STOP_FAIL = 7
46 };
47 
48 enum class CrossingEnd : int32_t {
49     NOT_CROSSING = 0,
50     IS_CROSSING = 1
51 };
52 
53 enum class DragReporterPharse {
54     DRAG_START,
55     DRAG_STOP
56 };
57 
58 class DragDropBehaviorReporter {
59 public:
60     static DragDropBehaviorReporter& GetInstance();
61 
62     void UpdateAllowDropType(const std::set<std::string>& allowDropType);
63     void UpdateIsCrossing(CrossingEnd isCrossing);
64     void UpdateDragStartResult(DragStartResult result);
65     void UpdateDragStopResult(DragStopResult result);
66     void UpdateRecordSize(int32_t recordSize);
67     void UpdateSummaryType(const std::string& summaryType);
68     void UpdateContainerId(int32_t containerId);
69     void Submit(DragReporterPharse pharse, int32_t contanerID);
70 
71 private:
72     DragDropBehaviorReporter() = default;
73     ~DragDropBehaviorReporter() = default;
74     void Reset();
75 
76     int32_t containerId_ = INSTANCE_ID_UNDEFINED;
77     int32_t recordSize_ = 0;
78     CrossingEnd isCrossing_ = CrossingEnd::NOT_CROSSING;
79     DragStartResult startResult_ = DragStartResult::UNKNOW;
80     DragStopResult stopResult_ = DragStopResult::UNKNOW;
81     std::string summaryType_;
82     std::set<std::string> allowDropType_;
83 };
84 
85 class DragDropBehaviorReporterTrigger final {
86 public:
DragDropBehaviorReporterTrigger(DragReporterPharse pharse,int32_t containerId)87     DragDropBehaviorReporterTrigger(DragReporterPharse pharse, int32_t containerId)
88         : pharse_(pharse), containerId_(containerId) {}
~DragDropBehaviorReporterTrigger()89     ~DragDropBehaviorReporterTrigger()
90     {
91         DragDropBehaviorReporter::GetInstance().Submit(pharse_, containerId_);
92     }
93 
94 private:
95     DragReporterPharse pharse_;
96     int32_t containerId_ = 0;
97 };
98 } // namespace OHOS::Ace::NG
99 
100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_BEHAVIOR_REPORTER_H