• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #include "sharing_hisysevent.h"
16 #include "hisysevent.h"
17 #ifdef HISYSEVENT_DEBUG
18 #include "sharing_log.h"
19 #endif
20 namespace OHOS {
21 namespace Sharing {
22 static constexpr char SHARING_DFX_DOMAIN_NAME[] = "WIFI_DISPLAY";
23 static constexpr char ORG_PKG[] = "sharing_service";
24 static constexpr char HOST_PKG[] = "cast_engine_service";
25 static constexpr char EVENT_NAME[] = "MIRACAST_BEHAVIOR";
26 
27 static const uint8_t WIFI_DISPLAY_SYSTEM_ID = 227;
28 static const uint8_t WIFI_DISPLAY_MODULE_ID = 11;
29 
SharingHiSysEvent(BIZSceneType scene,std::string callPkg)30 SharingHiSysEvent::SharingHiSysEvent(BIZSceneType scene, std::string callPkg)
31     : bizScene_(static_cast<int32_t>(scene)), toCallPkg_(callPkg)
32 {}
33 
~SharingHiSysEvent()34 SharingHiSysEvent::~SharingHiSysEvent()
35 {
36     ReportEnd(__func__, lastStage_, BlzErrorCode::ERROR_FAIL);
37 }
38 
ReportStart(std::string funcName,BIZSceneStage stage)39 void SharingHiSysEvent::ReportStart(std::string funcName, BIZSceneStage stage)
40 {
41 #ifdef HISYSEVENT_DEBUG
42     SHARING_LOGE("[FUNC:%s][%s][%s][BIZ_SCENE:%d][BIZ_STAGE:%d][BIZ_STATE:%d]", funcName.c_str(),
43                  SHARING_DFX_DOMAIN_NAME, EVENT_NAME, bizScene_, static_cast<int32_t>(stage),
44                  static_cast<int32_t>(BIZStateType::BIZ_STATE_BEGIN));
45 #endif
46     HiSysEventWrite(SHARING_DFX_DOMAIN_NAME, EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", ORG_PKG,
47                     "HOST_PKG", HOST_PKG, "FUNC", funcName, "BIZ_SCENE", bizScene_, "BIZ_STATE",
48                     static_cast<int32_t>(BIZStateType::BIZ_STATE_BEGIN), "BIZ_STAGE", static_cast<int32_t>(stage),
49                     "STAGE_RES", static_cast<int32_t>(StageResType::STAGE_RES_IDLE), "ERROR_CODE", 0, "TO_CALL_PKG",
50                     toCallPkg_, "LOCAL_MAC", localMac_, "PEER_MAC", peerMac_);
51     lastStage_ = stage;
52 }
53 
ReportEnd(std::string funcName,BIZSceneStage stage,BlzErrorCode errCode)54 void SharingHiSysEvent::ReportEnd(std::string funcName, BIZSceneStage stage, BlzErrorCode errCode)
55 {
56     if (sceneDisposed) {
57         return;
58     }
59 
60 #ifdef HISYSEVENT_DEBUG
61     SHARING_LOGE("[FUNC:%s][%s][%s][BIZ_SCENE:%d][BIZ_STAGE:%d][BIZ_STATE:%d]", funcName.c_str(),
62                  SHARING_DFX_DOMAIN_NAME, EVENT_NAME, bizScene_, static_cast<int32_t>(stage),
63                  static_cast<int32_t>(BIZStateType::BIZ_STATE_END));
64 #endif
65     int32_t stageResType = static_cast<int32_t>(StageResType::STAGE_RES_SUCCESS);
66     if (errCode != BlzErrorCode::ERROR_NONE) {
67         stageResType = static_cast<int32_t>(StageResType::STAGE_RES_FAILED);
68     }
69 
70     int32_t err = (WIFI_DISPLAY_SYSTEM_ID << 24) | (WIFI_DISPLAY_MODULE_ID << 18) | static_cast<int32_t>(errCode);
71     HiSysEventWrite(SHARING_DFX_DOMAIN_NAME, EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", ORG_PKG,
72                     "HOST_PKG", HOST_PKG, "FUNC", funcName, "BIZ_SCENE", bizScene_, "BIZ_STATE",
73                     static_cast<int32_t>(BIZStateType::BIZ_STATE_END), "BIZ_STAGE", static_cast<int32_t>(stage),
74                     "STAGE_RES", stageResType, "ERROR_CODE", err, "TO_CALL_PKG", toCallPkg_, "LOCAL_MAC", localMac_,
75                     "PEER_MAC", peerMac_);
76     lastStage_ = stage;
77     sceneDisposed = true;
78 }
79 
Report(std::string funcName,BIZSceneStage stage,StageResType resType,std::string peerMac)80 void SharingHiSysEvent::Report(std::string funcName, BIZSceneStage stage, StageResType resType, std::string peerMac)
81 {
82     auto tmpPeerMac = peerMac.empty() ? peerMac_ : peerMac;
83 #ifdef HISYSEVENT_DEBUG
84     SHARING_LOGE("[FUNC:%s][%s][%s][BIZ_SCENE:%d][BIZ_STAGE:%d][PEERMAC:%s]", funcName.c_str(), SHARING_DFX_DOMAIN_NAME,
85                  EVENT_NAME, bizScene_, static_cast<int32_t>(stage), tmpPeerMac.c_str());
86 #endif
87     HiSysEventWrite(SHARING_DFX_DOMAIN_NAME, EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", ORG_PKG,
88                     "HOST_PKG", HOST_PKG, "FUNC", funcName, "BIZ_SCENE", bizScene_, "BIZ_STAGE",
89                     static_cast<int32_t>(stage), "STAGE_RES", static_cast<int32_t>(resType), "ERROR_CODE",
90                     static_cast<int32_t>(BlzErrorCode::ERROR_NONE), "TO_CALL_PKG", toCallPkg_, "LOCAL_MAC", localMac_,
91                     "PEER_MAC", tmpPeerMac);
92     lastStage_ = stage;
93 }
94 
SetCallPkg(const std::string callPkg)95 void SharingHiSysEvent::SetCallPkg(const std::string callPkg)
96 {
97     toCallPkg_ = callPkg;
98 }
99 
SetLocalMac(const std::string mac)100 void SharingHiSysEvent::SetLocalMac(const std::string mac)
101 {
102     localMac_ = mac;
103 }
104 
SetPeerMac(const std::string mac)105 void SharingHiSysEvent::SetPeerMac(const std::string mac)
106 {
107     peerMac_ = mac;
108 }
109 
ChangeScene(BIZSceneType scene)110 void SharingHiSysEvent::ChangeScene(BIZSceneType scene)
111 {
112     if (!sceneDisposed) {
113         this->ReportEnd(__func__, lastStage_, BlzErrorCode::ERROR_FAIL);
114     } else {
115         sceneDisposed = false;
116     }
117     bizScene_ = static_cast<int32_t>(scene);
118 }
119 
GetScene() const120 int32_t SharingHiSysEvent::GetScene() const
121 {
122     return bizScene_;
123 }
124 } // namespace Sharing
125 } // namespace OHOS
126