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 #include "interfaces/inner_api/ace_kit/include/ui/base/geometry/point.h" 24 25 namespace OHOS::Ace::NG { 26 enum class DragStartResult : int32_t { 27 UNKNOW = -1, 28 DRAG_START_SUCCESS = 0, 29 APP_REFUSE_DRAG = 1, 30 DRAGFWK_START_FAIL = 2, 31 SET_DATA_FAIL = 3, 32 REPEAT_DRAG_FAIL = 4, 33 SNAPSHOT_FAIL = 5, 34 TEXT_NOT_SELECT = 6 35 }; 36 37 enum class DragStopResult : int32_t { 38 UNKNOW = -1, 39 DRAG_SOTP_SUCCESS = 0, 40 APP_REFUSE_DATA = 1, 41 APP_RECEIVE_FAIL = 2, 42 APP_DATA_UNSUPPORT = 3, 43 USER_STOP_DRAG = 4, 44 GET_UDKEY_FAIL = 5, 45 GET_UDMF_FAIL = 6, 46 DRAGFWK_STOP_FAIL = 7 47 }; 48 49 enum class CrossingEnd : int32_t { 50 NOT_CROSSING = 0, 51 IS_CROSSING = 1 52 }; 53 54 enum class DragReporterPharse { 55 DRAG_START, 56 DRAG_STOP 57 }; 58 59 enum class DropResult { 60 DROP_SUCCESS, 61 DROP_FAIL, 62 }; 63 64 class DragDropBehaviorReporter { 65 public: 66 static DragDropBehaviorReporter& GetInstance(); 67 68 void UpdateAllowDropType(const std::set<std::string>& allowDropType); 69 void UpdateIsCrossing(CrossingEnd isCrossing); 70 void UpdateDragStartResult(DragStartResult result); 71 void UpdateDragStopResult(DragStopResult result); 72 void UpdateRecordSize(int32_t recordSize); 73 void UpdateSummaryType(const std::string& summaryType); 74 void UpdateStartPoint(Point startPoint); 75 void UpdateEndPoint(Point endPoint); 76 void UpdateFrameNodeStartId(int32_t startId); 77 void UpdateFrameNodeDropId(int32_t dropId); 78 void UpdateLongPressDurationStart(int64_t longPressDurationStart); 79 void UpdateLongPressDurationEnd(int64_t longPressDurationEnd); 80 void UpdateDropResult(DropResult dropResult); 81 void HandleDragReport(DragReporterPharse pharse, std::string hostName); 82 void UpdateContainerId(int32_t containerId); 83 void Submit(DragReporterPharse pharse, int32_t contanerID); 84 void HandleBehaviorEventReport(DragReporterPharse pharse, int32_t contanerID); 85 void HandleUISessionReport(DragReporterPharse pharse, int32_t contanerID); 86 87 private: 88 DragDropBehaviorReporter() = default; 89 ~DragDropBehaviorReporter() = default; 90 void Reset(); 91 92 int32_t containerId_ = INSTANCE_ID_UNDEFINED; 93 int32_t recordSize_ = 0; 94 CrossingEnd isCrossing_ = CrossingEnd::NOT_CROSSING; 95 DragStartResult startResult_ = DragStartResult::UNKNOW; 96 DragStopResult stopResult_ = DragStopResult::UNKNOW; 97 std::string summaryType_; 98 std::set<std::string> allowDropType_; 99 Point startPoint_; 100 Point endPoint_; 101 int32_t startId_; 102 int32_t dropId_; 103 int64_t longPressDurationStart_ = 0; 104 int64_t longPressDurationEnd_ = 500; 105 DropResult dropResult_ = DropResult::DROP_FAIL; 106 }; 107 108 class DragDropBehaviorReporterTrigger final { 109 public: DragDropBehaviorReporterTrigger(DragReporterPharse pharse,int32_t containerId)110 DragDropBehaviorReporterTrigger(DragReporterPharse pharse, int32_t containerId) 111 : pharse_(pharse), containerId_(containerId) {} ~DragDropBehaviorReporterTrigger()112 ~DragDropBehaviorReporterTrigger() 113 { 114 DragDropBehaviorReporter::GetInstance().Submit(pharse_, containerId_); 115 } 116 117 private: 118 DragReporterPharse pharse_; 119 int32_t containerId_ = 0; 120 }; 121 } // namespace OHOS::Ace::NG 122 123 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_BEHAVIOR_REPORTER_H 124