1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci#ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 16f857971dSopenharmony_ci#include "drag_hisysevent.h" 17f857971dSopenharmony_ci 18f857971dSopenharmony_ci#include "fi_log.h" 19f857971dSopenharmony_ci 20f857971dSopenharmony_ci#undef LOG_TAG 21f857971dSopenharmony_ci#define LOG_TAG "DragHiSysEvent" 22f857971dSopenharmony_ci 23f857971dSopenharmony_cinamespace OHOS { 24f857971dSopenharmony_cinamespace Msdp { 25f857971dSopenharmony_cinamespace DeviceStatus { 26f857971dSopenharmony_ci 27f857971dSopenharmony_cistd::map<DragState, std::string> DragDFX::dragState_ = { 28f857971dSopenharmony_ci { DragState::ERROR, "ERROR" }, 29f857971dSopenharmony_ci { DragState::START, "START" }, 30f857971dSopenharmony_ci { DragState::STOP, "STOP" }, 31f857971dSopenharmony_ci { DragState::CANCEL, "CANCEL" }, 32f857971dSopenharmony_ci { DragState::MOTION_DRAGGING, "MOTION_DRAGGING" } 33f857971dSopenharmony_ci}; 34f857971dSopenharmony_ci 35f857971dSopenharmony_cistd::map<DragCursorStyle, std::string> DragDFX::dragStyle_ = { 36f857971dSopenharmony_ci { DragCursorStyle::DEFAULT, "DEFAULT" }, 37f857971dSopenharmony_ci { DragCursorStyle::FORBIDDEN, "FORBIDDEN" }, 38f857971dSopenharmony_ci { DragCursorStyle::COPY, "COPY" }, 39f857971dSopenharmony_ci { DragCursorStyle::MOVE, "MOVE" } 40f857971dSopenharmony_ci}; 41f857971dSopenharmony_ci 42f857971dSopenharmony_cistd::map<DragResult, std::string> DragDFX::dragResult_ = { 43f857971dSopenharmony_ci { DragResult::DRAG_SUCCESS, "DRAG_SUCCESS" }, 44f857971dSopenharmony_ci { DragResult::DRAG_FAIL, "DRAG_FAIL" }, 45f857971dSopenharmony_ci { DragResult::DRAG_CANCEL, "DRAG_CANCEL" }, 46f857971dSopenharmony_ci { DragResult::DRAG_EXCEPTION, "DRAG_EXPECTION" } 47f857971dSopenharmony_ci}; 48f857971dSopenharmony_ci 49f857971dSopenharmony_cistd::map<DragType, std::pair<std::string, std::string>> DragDFX::serialStr_ = { 50f857971dSopenharmony_ci { DragType::STA_DRAG_SUCC, { "START_DRAG_SUCCESS", "Start drag successfully" } }, 51f857971dSopenharmony_ci { DragType::STA_DRAG_FAIL, { "START_DRAG_FAILED", "Start drag failed" } }, 52f857971dSopenharmony_ci { DragType::SET_DRAG_WINDOW_SUCC, { "SET_DRAG_WINDOW_VISIBLE_SUCCESS", "Set drag window visible successfully" } }, 53f857971dSopenharmony_ci { DragType::SET_DRAG_WINDOW_FAIL, { "SET_DRAG_WINDOW_VISIBLE_FAILED", "Set drag window visible failed" } }, 54f857971dSopenharmony_ci { DragType::UPDATE_DRAG_STYLE_SUCC, { "UPDATE_DRAG_STYLE_SUCCESS", "Update Drag Style Successfully" } }, 55f857971dSopenharmony_ci { DragType::UPDATE_DRAG_STYLE_FAIL, { "UPDATE_DRAG_STYLE_FAILED", "Update drag style failed"} }, 56f857971dSopenharmony_ci { DragType::SEND_TOKENID, { "SEND_TOKENID", "Send token id failed" } }, 57f857971dSopenharmony_ci { DragType::STOP_DRAG_SUCC, { "STOP_DRAG_SUCCESS", "Stop drag successfully" } }, 58f857971dSopenharmony_ci { DragType::STOP_DRAG_FAIL, { "STOP_DRAG_FAILED", "Stop drag failed"} }, 59f857971dSopenharmony_ci { DragType::NOTIFY_DRAG_RESULT_SUCC, { "NOTIFY_DRAG_RESULT_SUCCESS", "Notify drag result successfully" } }, 60f857971dSopenharmony_ci { DragType::NOTIFY_DRAG_RESULT_FAIL, { "NOTIFY_DRAG_RESULT_FAILED", "Notify drag result failed"} } 61f857971dSopenharmony_ci}; 62f857971dSopenharmony_ci 63f857971dSopenharmony_citemplate<typename... Types> 64f857971dSopenharmony_ciint32_t DragDFX::WriteModel(const DragType &dragType, Types... paras) 65f857971dSopenharmony_ci{ 66f857971dSopenharmony_ci if (serialStr_.find(dragType) == serialStr_.end()) { 67f857971dSopenharmony_ci FI_HILOGE("serialStr_ can't find the drag hisysevent type"); 68f857971dSopenharmony_ci return RET_ERR; 69f857971dSopenharmony_ci } 70f857971dSopenharmony_ci auto &[label, dec] = serialStr_[dragType]; 71f857971dSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType eventType = (static_cast<uint32_t>(dragType) & 1) ? 72f857971dSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType::FAULT : OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR; 73f857971dSopenharmony_ci int32_t ret = HiSysEventWrite( 74f857971dSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::Domain::MSDP, 75f857971dSopenharmony_ci label, 76f857971dSopenharmony_ci eventType, 77f857971dSopenharmony_ci "MSG", 78f857971dSopenharmony_ci dec, 79f857971dSopenharmony_ci paras...); 80f857971dSopenharmony_ci if (ret == RET_ERR) { 81f857971dSopenharmony_ci FI_HILOGE("HiviewDFX write failed, ret:%{public}d", ret); 82f857971dSopenharmony_ci } 83f857971dSopenharmony_ci return ret; 84f857971dSopenharmony_ci} 85f857971dSopenharmony_ci 86f857971dSopenharmony_ciint32_t DragDFX::WriteStartDrag(const DragState &dragState, OHOS::HiviewDFX::HiSysEvent::EventType type) 87f857971dSopenharmony_ci{ 88f857971dSopenharmony_ci if (dragState_.find(dragState) == dragState_.end()) { 89f857971dSopenharmony_ci FI_HILOGE("dragState_ can't find the drag state"); 90f857971dSopenharmony_ci return RET_ERR; 91f857971dSopenharmony_ci } 92f857971dSopenharmony_ci std::string curDragState = dragState_[dragState]; 93f857971dSopenharmony_ci if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { 94f857971dSopenharmony_ci return WriteModel(DragType::STA_DRAG_SUCC, "dragState", curDragState); 95f857971dSopenharmony_ci } 96f857971dSopenharmony_ci return WriteModel(DragType::STA_DRAG_FAIL, "dragState", curDragState); 97f857971dSopenharmony_ci} 98f857971dSopenharmony_ci 99f857971dSopenharmony_ciint32_t DragDFX::WriteDragWindowVisible(const DragState &dragState, bool visible, 100f857971dSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType type) 101f857971dSopenharmony_ci{ 102f857971dSopenharmony_ci if (dragState_.find(dragState) == dragState_.end()) { 103f857971dSopenharmony_ci FI_HILOGE("dragState_ can't find the drag state"); 104f857971dSopenharmony_ci return RET_ERR; 105f857971dSopenharmony_ci } 106f857971dSopenharmony_ci std::string curDragState = dragState_[dragState]; 107f857971dSopenharmony_ci if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { 108f857971dSopenharmony_ci return WriteModel(DragType::SET_DRAG_WINDOW_SUCC, "IsVisible", visible, "dragState", curDragState); 109f857971dSopenharmony_ci } 110f857971dSopenharmony_ci return WriteModel(DragType::SET_DRAG_WINDOW_FAIL, "IsVisible", visible, "dragState", curDragState); 111f857971dSopenharmony_ci} 112f857971dSopenharmony_ci 113f857971dSopenharmony_ciint32_t DragDFX::WriteUpdateDragStyle(const DragCursorStyle &style, OHOS::HiviewDFX::HiSysEvent::EventType type) 114f857971dSopenharmony_ci{ 115f857971dSopenharmony_ci if (dragStyle_.find(style) == dragStyle_.end()) { 116f857971dSopenharmony_ci FI_HILOGE("dragStyle_ can't find the drag style"); 117f857971dSopenharmony_ci return RET_ERR; 118f857971dSopenharmony_ci } 119f857971dSopenharmony_ci std::string dragStyle = dragStyle_[style]; 120f857971dSopenharmony_ci if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { 121f857971dSopenharmony_ci return WriteModel(DragType::UPDATE_DRAG_STYLE_SUCC, "dragStyle", dragStyle); 122f857971dSopenharmony_ci } 123f857971dSopenharmony_ci return WriteModel(DragType::UPDATE_DRAG_STYLE_FAIL, "dragStyle", dragStyle); 124f857971dSopenharmony_ci} 125f857971dSopenharmony_ci 126f857971dSopenharmony_ciint32_t DragDFX::WriteSendTokenid(int32_t targetTid, const std::string &udKey) 127f857971dSopenharmony_ci{ 128f857971dSopenharmony_ci return WriteModel(DragType::SEND_TOKENID, "targetTid", targetTid, "udKey", udKey); 129f857971dSopenharmony_ci} 130f857971dSopenharmony_ci 131f857971dSopenharmony_ciint32_t DragDFX::WriteStopDrag(const DragState &dragState, const DragDropResult &dropResult, 132f857971dSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType type) 133f857971dSopenharmony_ci{ 134f857971dSopenharmony_ci if (dragState_.find(dragState) == dragState_.end()) { 135f857971dSopenharmony_ci FI_HILOGE("dragState_ can't find the drag state"); 136f857971dSopenharmony_ci return RET_ERR; 137f857971dSopenharmony_ci } 138f857971dSopenharmony_ci std::string curDragState = dragState_[dragState]; 139f857971dSopenharmony_ci if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { 140f857971dSopenharmony_ci return WriteModel(DragType::STOP_DRAG_SUCC, "dragState", curDragState, "animate", 141f857971dSopenharmony_ci dropResult.hasCustomAnimation); 142f857971dSopenharmony_ci } 143f857971dSopenharmony_ci return WriteModel(DragType::STOP_DRAG_FAIL, "dragstate", curDragState, "animate", dropResult.hasCustomAnimation); 144f857971dSopenharmony_ci} 145f857971dSopenharmony_ci 146f857971dSopenharmony_ciint32_t DragDFX::WriteNotifyDragResult(const DragResult &result, OHOS::HiviewDFX::HiSysEvent::EventType type) 147f857971dSopenharmony_ci{ 148f857971dSopenharmony_ci if (dragResult_.find(result) == dragResult_.end()) { 149f857971dSopenharmony_ci FI_HILOGE("dragResult_ can't find the drag result"); 150f857971dSopenharmony_ci return RET_ERR; 151f857971dSopenharmony_ci } 152f857971dSopenharmony_ci std::string dragResult = dragResult_[result]; 153f857971dSopenharmony_ci if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { 154f857971dSopenharmony_ci return WriteModel(DragType::NOTIFY_DRAG_RESULT_SUCC, "DragResult", dragResult); 155f857971dSopenharmony_ci } 156f857971dSopenharmony_ci return WriteModel(DragType::NOTIFY_DRAG_RESULT_FAIL, "DragResult", dragResult); 157f857971dSopenharmony_ci} 158f857971dSopenharmony_ci} // namespace DeviceStatus 159f857971dSopenharmony_ci} // namespace Msdp 160f857971dSopenharmony_ci} // namespace OHOS 161f857971dSopenharmony_ci#endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE