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 #include <algorithm>
17 #include <sstream>
18 #include <iomanip>
19 #include <cstdlib>
20 #include "avsession_radar.h"
21 #include "device_manager.h"
22 #include "radar_constants.h"
23 #include "avsession_log.h"
24 #include "avsession_sysevent.h"
25 #include "ipc_skeleton.h"
26 #include "iservice_registry.h"
27 #include "system_ability_definition.h"
28 #include "cJSON.h"
29
30 namespace OHOS::AVSession {
GetInstance()31 AVSessionRadar& AVSessionRadar::GetInstance()
32 {
33 static AVSessionRadar avSessionRadar;
34 return avSessionRadar;
35 }
36
37 // LCOV_EXCL_START
GetAnonymousDeviceId(std::string deviceId)38 std::string AVSessionRadar::GetAnonymousDeviceId(std::string deviceId)
39 {
40 const uint32_t half = DEVICE_ID_MIN_LEN / 2;
41 if (deviceId.empty() || deviceId.length() < DEVICE_ID_MIN_LEN) {
42 return "unknown";
43 }
44 return deviceId.substr(0, half) + "**" + deviceId.substr(deviceId.length() - half);
45 }
46
GetRadarErrorCode(int32_t err)47 int32_t AVSessionRadar::GetRadarErrorCode(int32_t err)
48 {
49 constexpr int32_t systemShift = 21;
50 constexpr int32_t moduleShift = 16;
51 uint32_t errorCode =
52 (AV_SESSION_SYSTEM_ID << systemShift) | (AV_SESSION_MODULE_ID << moduleShift) |
53 (static_cast<uint>(abs(err)) & 0xFFFF);
54 SLOGI("GetRadarErrorCode err:%{public}d -> %{public}d", abs(err), errorCode);
55 return errorCode;
56 }
57
GetLocalDeviceNetworkId()58 std::string AVSessionRadar::GetLocalDeviceNetworkId()
59 {
60 std::string networkId = "";
61 if (OHOS::DistributedHardware::DeviceManager::GetInstance()
62 .GetLocalDeviceNetWorkId(AVSESSION_PKG_NAME, networkId) != 0) {
63 SLOGE("GetLocalDeviceNetWorkId failed");
64 }
65
66 return networkId;
67 }
68
GetUdidByNetworkId(const std::string & networkId)69 std::string AVSessionRadar::GetUdidByNetworkId(const std::string &networkId)
70 {
71 std::string localDevUdid = "";
72 if (OHOS::DistributedHardware::DeviceManager::GetInstance()
73 .GetUdidByNetworkId(AVSESSION_PKG_NAME, networkId, localDevUdid) != 0) {
74 SLOGE("GetUdidByNetworkId failed");
75 }
76 return localDevUdid;
77 }
78
ConvertHexToString(int32_t hex)79 std::string AVSessionRadar::ConvertHexToString(int32_t hex)
80 {
81 std::stringstream str;
82 int32_t width = 3;
83 str << std::hex << std::setw(width) << std::setfill('0') << hex;
84 std::string hexStr = str.str();
85 transform(hexStr.begin(), hexStr.end(), hexStr.begin(), ::toupper);
86 return hexStr;
87 }
88 // LCOV_EXCL_STOP
89
GetLocalDevType()90 std::string AVSessionRadar::GetLocalDevType()
91 {
92 SLOGI("GetLocalDevType");
93 int32_t localDevType = 0;
94 if (OHOS::DistributedHardware::DeviceManager::GetInstance()
95 .GetLocalDeviceType(AVSESSION_PKG_NAME, localDevType) != 0) {
96 SLOGE("GetLocalDevType failed");
97 } else {
98 SLOGI("GetLocalDevType: %{public}d", localDevType);
99 }
100 return ConvertHexToString(localDevType);
101 }
102
reset()103 void AVSessionRadar::reset()
104 {
105 localNetId_.clear();
106 localUdid_.clear();
107 localDevType_.clear();
108 }
109
InitBMS()110 void AVSessionRadar::InitBMS()
111 {
112 SLOGI("InitBMS");
113 auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
114 if (!systemAbilityManager) {
115 SLOGE("fail to get system ability mgr");
116 return;
117 }
118
119 auto remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
120 if (!remoteObject) {
121 SLOGE("fail to get bundle manager proxy");
122 return;
123 }
124
125 SLOGI("get bundle manager proxy success");
126 bundleMgrProxy_ = iface_cast<AppExecFwk::BundleMgrProxy>(remoteObject);
127 }
128
129 // LCOV_EXCL_START
GetJsonCastDeviceList(const OutputDeviceInfo & deviceInfo,std::string & deviceList)130 void AVSessionRadar::GetJsonCastDeviceList(const OutputDeviceInfo &deviceInfo, std::string& deviceList)
131 {
132 cJSON* jDeviceInfos = cJSON_CreateArray();
133 for (const DeviceInfo& deviceInfo : deviceInfo.deviceInfos_) {
134 cJSON* jDeviceInfo = cJSON_CreateObject();
135 if (jDeviceInfo == nullptr) {
136 SLOGE("fail create jDeviceInfo");
137 continue;
138 }
139 if (cJSON_IsInvalid(jDeviceInfo) || cJSON_IsNull(jDeviceInfo)) {
140 SLOGE("create jDeviceInfo invalid");
141 cJSON_Delete(jDeviceInfo);
142 continue;
143 }
144 cJSON_AddStringToObject(jDeviceInfo, PEER_UDID,
145 GetAnonymousDeviceId(GetUdidByNetworkId(deviceInfo.networkId_)).c_str());
146 cJSON_AddStringToObject(jDeviceInfo, PEER_BT_MAC, "");
147 cJSON_AddStringToObject(jDeviceInfo, PEER_DEV_TYPE, ConvertHexToString(deviceInfo.deviceType_).c_str());
148 cJSON_AddStringToObject(jDeviceInfo, PEER_DEV_NAME, deviceInfo.deviceName_.c_str());
149 cJSON_AddItemToArray(jDeviceInfos, jDeviceInfo);
150 }
151
152 char* jDeviceInfosStr = cJSON_Print(jDeviceInfos);
153 if (jDeviceInfosStr != nullptr) {
154 deviceList = jDeviceInfosStr;
155 cJSON_free(jDeviceInfosStr);
156 } else {
157 SLOGE("get jDeviceInfosStr with nullptr");
158 }
159 cJSON_Delete(jDeviceInfos);
160 }
161
GetPeerInfoFromDeviceInfo(const DeviceInfo & deviceInfo,AVSessionRadarInfo & info)162 void AVSessionRadar::GetPeerInfoFromDeviceInfo(const DeviceInfo &deviceInfo, AVSessionRadarInfo &info)
163 {
164 info.peerUdid_ = GetAnonymousDeviceId(GetUdidByNetworkId(deviceInfo.networkId_));
165 info.peerBtMac_ = "";
166 info.peerNetId_ = GetAnonymousDeviceId(deviceInfo.networkId_);
167 info.peerDevType_ = ConvertHexToString(deviceInfo.deviceType_);
168 info.isTrust_ = (deviceInfo.authenticationStatus_ == 0) ?
169 static_cast<int32_t>(TrustStatus::UNTRUST) : static_cast<int32_t>(TrustStatus::TRUST);
170 }
171
GetBundleNameFromUid(int32_t uid)172 std::string AVSessionRadar::GetBundleNameFromUid(int32_t uid)
173 {
174 std::string bundleName{""};
175 if (bundleMgrProxy_ != nullptr) {
176 bundleMgrProxy_->GetNameForUid(uid, bundleName);
177 SLOGI("get bundleName:%{public}s uid:%{public}d", bundleName.c_str(), uid);
178 } else {
179 SLOGE("can't get bundleName for uid:%{public}d", uid);
180 }
181 return bundleName;
182 }
183
GetPeerInfo(const OutputDeviceInfo & outputDeviceInfo,AVSessionRadarInfo & info)184 void AVSessionRadar::GetPeerInfo(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info)
185 {
186 if (outputDeviceInfo.deviceInfos_.size() > 0) {
187 GetPeerInfoFromDeviceInfo(outputDeviceInfo.deviceInfos_[0], info);
188 }
189 }
190
ReportWithoutTrustInfo(AVSessionRadarInfo & info)191 void AVSessionRadar::ReportWithoutTrustInfo(AVSessionRadarInfo &info)
192 {
193 HISYSEVENT_BEHAVIOR(AVSESSION_CAST_BEHAVIOR,
194 ORG_PKG, orgPkg_,
195 HOST_PKG, info.hostPkg_,
196 TO_CALL_PKG, info.toCallPkg_,
197 TRIGGER_MODE, info.triggerMode_,
198 FUNC, info.func_,
199 BIZ_SCENE, info.bizScene_,
200 BIZ_STAGE, info.bizStage_,
201 STAGE_RES, info.stageRes_,
202 BIZ_STATE, info.bizState_,
203 ERROR_CODE, info.errorCode_,
204 DISCOVERY_DEVICE_LIST, info.discoveryDeviceList_,
205 LOCAL_UDID, localUdid_,
206 LOCAL_NET_ID, localNetId_,
207 LOCAL_DEV_TYPE, localDevType_,
208 PEER_UDID, info.peerUdid_,
209 PEER_BT_MAC, info.peerBtMac_,
210 PEER_NET_ID, info.peerNetId_,
211 PEER_DEV_TYPE, info.peerDevType_,
212 SOURCE_TYPE, info.sourceType_);
213 }
214
ReportWithTrustInfo(AVSessionRadarInfo & info)215 void AVSessionRadar::ReportWithTrustInfo(AVSessionRadarInfo &info)
216 {
217 HISYSEVENT_BEHAVIOR(AVSESSION_CAST_BEHAVIOR,
218 ORG_PKG, orgPkg_,
219 HOST_PKG, info.hostPkg_,
220 TO_CALL_PKG, info.toCallPkg_,
221 TRIGGER_MODE, info.triggerMode_,
222 FUNC, info.func_,
223 BIZ_SCENE, info.bizScene_,
224 BIZ_STAGE, info.bizStage_,
225 STAGE_RES, info.stageRes_,
226 BIZ_STATE, info.bizState_,
227 ERROR_CODE, info.errorCode_,
228 DISCOVERY_DEVICE_LIST, info.discoveryDeviceList_,
229 LOCAL_UDID, localUdid_,
230 LOCAL_NET_ID, localNetId_,
231 LOCAL_DEV_TYPE, localDevType_,
232 PEER_UDID, info.peerUdid_,
233 PEER_BT_MAC, info.peerBtMac_,
234 PEER_NET_ID, info.peerNetId_,
235 PEER_DEV_TYPE, info.peerDevType_,
236 SOURCE_TYPE, info.sourceType_,
237 IS_TRUST, info.isTrust_);
238 }
239
ReportHiSysEventBehavior(AVSessionRadarInfo & info)240 void AVSessionRadar::ReportHiSysEventBehavior(AVSessionRadarInfo &info)
241 {
242 if (localNetId_.empty()) {
243 localNetId_ = GetAnonymousDeviceId(GetLocalDeviceNetworkId());
244 }
245 if (localUdid_.empty()) {
246 localUdid_ = GetAnonymousDeviceId(GetUdidByNetworkId(GetLocalDeviceNetworkId()));
247 }
248 if (localDevType_.empty()) {
249 localDevType_ = GetLocalDevType();
250 }
251 if (info.bundleName_.empty()) {
252 int32_t uid = OHOS::IPCSkeleton::GetCallingUid();
253 SLOGI("%{public}s func:%{public}s callingUid:%{public}d", __FUNCTION__, info.func_.c_str(), uid);
254 info.bundleName_ = GetBundleNameFromUid(uid);
255 }
256 info.CheckTriggerMode();
257 if (!info.bundleName_.empty()) {
258 info.hostPkg_ =
259 (info.bundleName_.find(MEDIA_CONTROL_PKG) != std::string::npos) ? MEDIA_CONTROL_PKG : info.bundleName_;
260 }
261 if (info.errorCode_ == 0) {
262 info.errorCode_ = GetRadarErrorCode(0);
263 }
264 if (info.isTrust_ == static_cast<int32_t>(TrustStatus::UNKOWN)) {
265 ReportWithoutTrustInfo(info);
266 } else {
267 ReportWithTrustInfo(info);
268 }
269 }
270
StartCastDiscoveryBegin(AVSessionRadarInfo & info)271 void AVSessionRadar::StartCastDiscoveryBegin(AVSessionRadarInfo &info)
272 {
273 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_DISCOVERY);
274 info.bizStage_ = static_cast<int32_t>(CastDiscoveryStage::START);
275 info.stageRes_ = static_cast<int32_t>(StageResult::IDLE);
276 info.bizState_ = static_cast<int32_t>(BizState::BEGIN);
277 ReportHiSysEventBehavior(info);
278 }
279
StartCastDiscoveryEnd(AVSessionRadarInfo & info)280 void AVSessionRadar::StartCastDiscoveryEnd(AVSessionRadarInfo &info)
281 {
282 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_DISCOVERY);
283 info.bizStage_ = static_cast<int32_t>(CastDiscoveryStage::START);
284 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
285 info.bizState_ = static_cast<int32_t>(BizState::END);
286 ReportHiSysEventBehavior(info);
287 }
288
FailToStartCastDiscovery(AVSessionRadarInfo & info)289 void AVSessionRadar::FailToStartCastDiscovery(AVSessionRadarInfo &info)
290 {
291 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_DISCOVERY);
292 info.bizStage_ = static_cast<int32_t>(CastDiscoveryStage::START);
293 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
294 info.bizState_ = static_cast<int32_t>(BizState::END);
295 ReportHiSysEventBehavior(info);
296 }
297
CastDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo,AVSessionRadarInfo & info)298 void AVSessionRadar::CastDeviceAvailable(const OutputDeviceInfo &castOutputDeviceInfo, AVSessionRadarInfo &info)
299 {
300 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_DISCOVERY);
301 info.bizStage_ = static_cast<int32_t>(CastDiscoveryStage::DISPLAY);
302 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
303 info.bizState_ = static_cast<int32_t>(BizState::END);
304
305 GetJsonCastDeviceList(castOutputDeviceInfo, info.discoveryDeviceList_);
306 ReportHiSysEventBehavior(info);
307 }
308
StopCastDiscoveryBegin(AVSessionRadarInfo & info)309 void AVSessionRadar::StopCastDiscoveryBegin(AVSessionRadarInfo &info)
310 {
311 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_DISCOVERY);
312 info.bizStage_ = static_cast<int32_t>(CastDiscoveryStage::STOP);
313 info.stageRes_ = static_cast<int32_t>(StageResult::IDLE);
314 info.bizState_ = static_cast<int32_t>(BizState::BEGIN);
315 ReportHiSysEventBehavior(info);
316 }
317
StopCastDiscoveryEnd(AVSessionRadarInfo & info)318 void AVSessionRadar::StopCastDiscoveryEnd(AVSessionRadarInfo &info)
319 {
320 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_DISCOVERY);
321 info.bizStage_ = static_cast<int32_t>(CastDiscoveryStage::STOP);
322 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
323 info.bizState_ = static_cast<int32_t>(BizState::END);
324 ReportHiSysEventBehavior(info);
325 }
326
FailToStopCastDiscovery(AVSessionRadarInfo & info)327 void AVSessionRadar::FailToStopCastDiscovery(AVSessionRadarInfo &info)
328 {
329 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_DISCOVERY);
330 info.bizStage_ = static_cast<int32_t>(CastDiscoveryStage::STOP);
331 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
332 info.bizState_ = static_cast<int32_t>(BizState::END);
333 ReportHiSysEventBehavior(info);
334 }
335
StartCastBegin(const OutputDeviceInfo & outputDeviceInfo,AVSessionRadarInfo & info)336 void AVSessionRadar::StartCastBegin(const OutputDeviceInfo &outputDeviceInfo, AVSessionRadarInfo &info)
337 {
338 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
339 info.bizStage_ = static_cast<int32_t>(CastStartStage::START);
340 info.stageRes_ = static_cast<int32_t>(StageResult::IDLE);
341 info.bizState_ = static_cast<int32_t>(BizState::BEGIN);
342 GetPeerInfo(outputDeviceInfo, info);
343 ReportHiSysEventBehavior(info);
344 }
345 // LCOV_EXCL_STOP
346
StartCastEnd(const OutputDeviceInfo & outputDeviceInfo,AVSessionRadarInfo & info)347 void AVSessionRadar::StartCastEnd(const OutputDeviceInfo &outputDeviceInfo, AVSessionRadarInfo &info)
348 {
349 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
350 info.bizStage_ = static_cast<int32_t>(CastStartStage::START);
351 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
352 info.bizState_ = static_cast<int32_t>(BizState::END);
353 GetPeerInfo(outputDeviceInfo, info);
354 ReportHiSysEventBehavior(info);
355 }
356
357 // LCOV_EXCL_START
FailToStartCast(AVSessionRadarInfo & info)358 void AVSessionRadar::FailToStartCast(AVSessionRadarInfo &info)
359 {
360 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
361 info.bizStage_ = static_cast<int32_t>(CastStartStage::START);
362 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
363 info.bizState_ = static_cast<int32_t>(BizState::END);
364 ReportHiSysEventBehavior(info);
365 }
366
FailToStartCast(const OutputDeviceInfo & outputDeviceInfo,AVSessionRadarInfo & info)367 void AVSessionRadar::FailToStartCast(const OutputDeviceInfo &outputDeviceInfo, AVSessionRadarInfo &info)
368 {
369 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
370 info.bizStage_ = static_cast<int32_t>(CastStartStage::START);
371 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
372 info.bizState_ = static_cast<int32_t>(BizState::END);
373 GetPeerInfo(outputDeviceInfo, info);
374 ReportHiSysEventBehavior(info);
375 }
376
StartConnect(AVSessionRadarInfo & info)377 void AVSessionRadar::StartConnect(AVSessionRadarInfo &info)
378 {
379 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
380 info.bizStage_ = static_cast<int32_t>(CastStartStage::CONNECT);
381 info.stageRes_ = static_cast<int32_t>(StageResult::IDLE);
382 info.bizState_ = static_cast<int32_t>(BizState::BEGIN);
383 ReportHiSysEventBehavior(info);
384 }
385
ConnectFinish(const DeviceInfo & deviceInfo,AVSessionRadarInfo & info)386 void AVSessionRadar::ConnectFinish(const DeviceInfo &deviceInfo, AVSessionRadarInfo &info)
387 {
388 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
389 info.bizStage_ = static_cast<int32_t>(CastStartStage::CONNECT);
390 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
391 info.bizState_ = static_cast<int32_t>(BizState::END);
392 GetPeerInfoFromDeviceInfo(deviceInfo, info);
393 ReportHiSysEventBehavior(info);
394 }
395
StartPlayBegin(AVSessionRadarInfo & info)396 void AVSessionRadar::StartPlayBegin(AVSessionRadarInfo &info)
397 {
398 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
399 info.bizStage_ = static_cast<int32_t>(CastStartStage::STARTED);
400 info.stageRes_ = static_cast<int32_t>(StageResult::IDLE);
401 info.bizState_ = static_cast<int32_t>(BizState::BEGIN);
402 ReportHiSysEventBehavior(info);
403 }
404
StartPlayEnd(AVSessionRadarInfo & info)405 void AVSessionRadar::StartPlayEnd(AVSessionRadarInfo &info)
406 {
407 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
408 info.bizStage_ = static_cast<int32_t>(CastStartStage::STARTED);
409 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
410 info.bizState_ = static_cast<int32_t>(BizState::END);
411 ReportHiSysEventBehavior(info);
412 }
413
StartPlayFailed(AVSessionRadarInfo & info)414 void AVSessionRadar::StartPlayFailed(AVSessionRadarInfo &info)
415 {
416 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
417 info.bizStage_ = static_cast<int32_t>(CastStartStage::STARTED);
418 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
419 info.bizState_ = static_cast<int32_t>(BizState::END);
420 ReportHiSysEventBehavior(info);
421 }
422
PlayerStarted(AVSessionRadarInfo & info)423 void AVSessionRadar::PlayerStarted(AVSessionRadarInfo &info)
424 {
425 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_START);
426 info.bizStage_ = static_cast<int32_t>(CastStartStage::STARTED);
427 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
428 info.bizState_ = static_cast<int32_t>(BizState::END);
429 ReportHiSysEventBehavior(info);
430 }
431
SendControlCommandBegin(AVSessionRadarInfo & info)432 void AVSessionRadar::SendControlCommandBegin(AVSessionRadarInfo &info)
433 {
434 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_CONTROL);
435 info.bizStage_ = static_cast<int32_t>(CastControlStage::SEND_COMMAND);
436 info.stageRes_ = static_cast<int32_t>(StageResult::IDLE);
437 info.bizState_ = static_cast<int32_t>(BizState::BEGIN);
438 ReportHiSysEventBehavior(info);
439 }
440
SendControlCommandEnd(AVSessionRadarInfo & info)441 void AVSessionRadar::SendControlCommandEnd(AVSessionRadarInfo &info)
442 {
443 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_CONTROL);
444 info.bizStage_ = static_cast<int32_t>(CastControlStage::SEND_COMMAND);
445 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
446 info.bizState_ = static_cast<int32_t>(BizState::END);
447 ReportHiSysEventBehavior(info);
448 }
449
FailToSendControlCommand(AVSessionRadarInfo & info)450 void AVSessionRadar::FailToSendControlCommand(AVSessionRadarInfo &info)
451 {
452 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_CONTROL);
453 info.bizStage_ = static_cast<int32_t>(CastControlStage::SEND_COMMAND);
454 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
455 info.bizState_ = static_cast<int32_t>(BizState::END);
456 ReportHiSysEventBehavior(info);
457 }
458
ControlCommandRespond(AVSessionRadarInfo & info)459 void AVSessionRadar::ControlCommandRespond(AVSessionRadarInfo &info)
460 {
461 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_CONTROL);
462 info.bizStage_ = static_cast<int32_t>(CastControlStage::RECV_COMMAND);
463 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
464 info.bizState_ = static_cast<int32_t>(BizState::END);
465 ReportHiSysEventBehavior(info);
466 }
467
ControlCommandError(AVSessionRadarInfo & info)468 void AVSessionRadar::ControlCommandError(AVSessionRadarInfo &info)
469 {
470 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_CONTROL);
471 info.bizStage_ = static_cast<int32_t>(CastControlStage::RECV_COMMAND);
472 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
473 info.bizState_ = static_cast<int32_t>(BizState::END);
474 ReportHiSysEventBehavior(info);
475 }
476
StopCastBegin(const OutputDeviceInfo & outputDeviceInfo,AVSessionRadarInfo & info)477 void AVSessionRadar::StopCastBegin(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info)
478 {
479 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_END);
480 info.bizStage_ = static_cast<int32_t>(CastStopStage::STOP_BEGIN);
481 info.stageRes_ = static_cast<int32_t>(StageResult::IDLE);
482 info.bizState_ = static_cast<int32_t>(BizState::BEGIN);
483 GetPeerInfo(outputDeviceInfo, info);
484 ReportHiSysEventBehavior(info);
485 }
486
StopCastEnd(const OutputDeviceInfo & outputDeviceInfo,AVSessionRadarInfo & info)487 void AVSessionRadar::StopCastEnd(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info)
488 {
489 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_END);
490 info.bizStage_ = static_cast<int32_t>(CastStopStage::STOP_BEGIN);
491 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
492 info.bizState_ = static_cast<int32_t>(BizState::END);
493 GetPeerInfo(outputDeviceInfo, info);
494 ReportHiSysEventBehavior(info);
495 }
496
FailToStopCast(AVSessionRadarInfo & info)497 void AVSessionRadar::FailToStopCast(AVSessionRadarInfo &info)
498 {
499 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_END);
500 info.bizStage_ = static_cast<int32_t>(CastStopStage::STOP_BEGIN);
501 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
502 info.bizState_ = static_cast<int32_t>(BizState::END);
503 ReportHiSysEventBehavior(info);
504 }
505
FailToStopCast(const OutputDeviceInfo & outputDeviceInfo,AVSessionRadarInfo & info)506 void AVSessionRadar::FailToStopCast(const OutputDeviceInfo &outputDeviceInfo, AVSessionRadarInfo &info)
507 {
508 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_END);
509 info.bizStage_ = static_cast<int32_t>(CastStopStage::STOP_BEGIN);
510 info.stageRes_ = static_cast<int32_t>(StageResult::FAIL);
511 info.bizState_ = static_cast<int32_t>(BizState::END);
512 GetPeerInfo(outputDeviceInfo, info);
513 ReportHiSysEventBehavior(info);
514 }
515
StopCastFinish(const DeviceInfo & deviceInfo,AVSessionRadarInfo & info)516 void AVSessionRadar::StopCastFinish(const DeviceInfo &deviceInfo, AVSessionRadarInfo &info)
517 {
518 info.bizScene_ = static_cast<int32_t>(BizScene::CAST_END);
519 info.bizStage_ = static_cast<int32_t>(CastStopStage::STOP_END);
520 info.stageRes_ = static_cast<int32_t>(StageResult::SUCCESS);
521 info.bizState_ = static_cast<int32_t>(BizState::END);
522 GetPeerInfoFromDeviceInfo(deviceInfo, info);
523 ReportHiSysEventBehavior(info);
524 }
525 // LCOV_EXCL_STOP
526 } // namespace OHOS::AVSession
527