1 /*
2 * Copyright (C) 2022 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 "sms_hisysevent.h"
17
18 namespace OHOS {
19 namespace Telephony {
20 // EVENT
21 static constexpr const char *SMS_RECEIVE_FAILED_EVENT = "SMS_RECEIVE_FAILED";
22 static constexpr const char *SMS_SEND_FAILED_EVENT = "SMS_SEND_FAILED";
23 static constexpr const char *SMS_SEND_EVENT = "SMS_SEND";
24 static constexpr const char *SMS_RECEIVE_EVENT = "SMS_RECEIVE";
25
26 // KEY
27 static constexpr const char *MODULE_KEY = "MODULE";
28 static constexpr const char *SLOT_ID_KEY = "SLOT_ID";
29 static constexpr const char *MSG_TYPE_KEY = "MSG_TYPE";
30 static constexpr const char *ERROR_TYPE_KEY = "ERROR_TYPE";
31 static constexpr const char *ERROR_MSG_KEY = "ERROR_MSG";
32
33 // VALUE
34 static constexpr const char *SMS_MMS_MODULE = "SMS_MMS";
35 static const int32_t NORMAL_SMS_BROADCAST_TIME = 7 * 1000;
36
WriteSmsSendBehaviorEvent(const int32_t slotId,const SmsMmsMessageType type)37 void SmsHiSysEvent::WriteSmsSendBehaviorEvent(const int32_t slotId, const SmsMmsMessageType type)
38 {
39 HiWriteBehaviorEvent(SMS_SEND_EVENT, SLOT_ID_KEY, slotId, MSG_TYPE_KEY, static_cast<int32_t>(type));
40 }
41
WriteSmsReceiveBehaviorEvent(const int32_t slotId,const SmsMmsMessageType type)42 void SmsHiSysEvent::WriteSmsReceiveBehaviorEvent(const int32_t slotId, const SmsMmsMessageType type)
43 {
44 HiWriteBehaviorEvent(SMS_RECEIVE_EVENT, SLOT_ID_KEY, slotId, MSG_TYPE_KEY, static_cast<int32_t>(type));
45 }
46
WriteSmsSendFaultEvent(const int32_t slotId,const SmsMmsMessageType type,const SmsMmsErrorCode errorCode,const std::string & desc)47 void SmsHiSysEvent::WriteSmsSendFaultEvent(
48 const int32_t slotId, const SmsMmsMessageType type, const SmsMmsErrorCode errorCode, const std::string &desc)
49 {
50 HiWriteFaultEvent(SMS_SEND_FAILED_EVENT, MODULE_KEY, SMS_MMS_MODULE, SLOT_ID_KEY, slotId, MSG_TYPE_KEY,
51 static_cast<int32_t>(type), ERROR_TYPE_KEY, static_cast<int32_t>(errorCode), ERROR_MSG_KEY, desc);
52 }
53
WriteSmsReceiveFaultEvent(const int32_t slotId,const SmsMmsMessageType type,const SmsMmsErrorCode errorCode,const std::string & desc)54 void SmsHiSysEvent::WriteSmsReceiveFaultEvent(
55 const int32_t slotId, const SmsMmsMessageType type, const SmsMmsErrorCode errorCode, const std::string &desc)
56 {
57 HiWriteFaultEvent(SMS_RECEIVE_FAILED_EVENT, MODULE_KEY, SMS_MMS_MODULE, SLOT_ID_KEY, slotId, MSG_TYPE_KEY,
58 static_cast<int32_t>(type), ERROR_TYPE_KEY, static_cast<int32_t>(errorCode), ERROR_MSG_KEY, desc);
59 }
60
SetSmsBroadcastStartTime()61 void SmsHiSysEvent::SetSmsBroadcastStartTime()
62 {
63 smsBroadcastStartTime_ =
64 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
65 .count();
66 }
67
JudgingSmsBroadcastTimeOut(const int32_t slotId,const SmsMmsMessageType type)68 void SmsHiSysEvent::JudgingSmsBroadcastTimeOut(const int32_t slotId, const SmsMmsMessageType type)
69 {
70 int64_t smsBroadcastEndTime =
71 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
72 .count();
73 if (smsBroadcastEndTime - smsBroadcastStartTime_ > NORMAL_SMS_BROADCAST_TIME) {
74 WriteSmsReceiveFaultEvent(slotId, type, SmsMmsErrorCode::SMS_ERROR_BROADCAST_TIME_OUT,
75 "smsbroadcast time out " + std::to_string(smsBroadcastEndTime - smsBroadcastStartTime_));
76 }
77 }
78
SetCbBroadcastStartTime()79 void SmsHiSysEvent::SetCbBroadcastStartTime()
80 {
81 cbBroadcastStartTime_ =
82 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
83 .count();
84 }
85
JudgingCbBroadcastTimeOut(const int32_t slotId,const SmsMmsMessageType type)86 void SmsHiSysEvent::JudgingCbBroadcastTimeOut(const int32_t slotId, const SmsMmsMessageType type)
87 {
88 int64_t cbBroadcastEndTime =
89 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
90 .count();
91 if (cbBroadcastEndTime - cbBroadcastStartTime_ > NORMAL_SMS_BROADCAST_TIME) {
92 WriteSmsReceiveFaultEvent(slotId, type, SmsMmsErrorCode::SMS_ERROR_BROADCAST_TIME_OUT,
93 "cbbroadcast time out " + std::to_string(cbBroadcastEndTime - cbBroadcastStartTime_));
94 }
95 }
96
SetWapPushBroadcastStartTime()97 void SmsHiSysEvent::SetWapPushBroadcastStartTime()
98 {
99 wapPushBroadcastStartTime_ =
100 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
101 .count();
102 }
103
JudgingWapPushBroadcastTimeOut(const int32_t slotId,const SmsMmsMessageType type)104 void SmsHiSysEvent::JudgingWapPushBroadcastTimeOut(const int32_t slotId, const SmsMmsMessageType type)
105 {
106 int64_t wapPushBroadcastEndTime =
107 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
108 .count();
109 if (wapPushBroadcastEndTime - wapPushBroadcastStartTime_ > NORMAL_SMS_BROADCAST_TIME) {
110 WriteSmsReceiveFaultEvent(slotId, type, SmsMmsErrorCode::SMS_ERROR_BROADCAST_TIME_OUT,
111 "wappushbroadcast time out " + std::to_string(wapPushBroadcastEndTime - wapPushBroadcastStartTime_));
112 }
113 }
114 } // namespace Telephony
115 } // namespace OHOS
116