• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cellular_data_hisysevent.h"
17 
18 #include "chrono"
19 #include "string"
20 #include "type_traits"
21 
22 namespace OHOS {
23 namespace Telephony {
24 // EVENT
25 static constexpr const char *DATA_CONNECTION_STATE_EVENT = "DATA_CONNECTION_STATE";
26 static constexpr const char *ROAMING_DATA_CONNECTION_STATE_EVENT = "ROAMING_DATA_CONNECTION_STATE";
27 static constexpr const char *DATA_ACTIVATE_FAILED_EVENT = "DATA_ACTIVATE_FAILED";
28 static constexpr const char *DATA_DEACTIVED_EVENT = "DATA_DEACTIVED";
29 
30 // KEY
31 static constexpr const char *MODULE_NAME_KEY = "MODULE";
32 static constexpr const char *SLOT_ID_KEY = "SLOT_ID";
33 static constexpr const char *STATE_KEY = "STATE";
34 static constexpr const char *DATA_SWITCH_KEY = "DATA_SWITCH";
35 static constexpr const char *UPLINK_DATA_KEY = "UPLINK_DATA";
36 static constexpr const char *DOWNLINK_DATA_KEY = "DOWNLINK_DATA";
37 static constexpr const char *DATASTATE_KEY = "DATASTATE";
38 static constexpr const char *ERROR_TYPE_KEY = "ERROR_TYPE";
39 static constexpr const char *ERROR_MSG_KEY = "ERROR_MSG";
40 static constexpr const char *TYPE_KEY = "TYPE";
41 
42 // VALUE
43 static constexpr const char *CELLULAR_DATA_MODULE = "CELLULAR_DATA";
44 
WriteDataDeactiveBehaviorEvent(const int32_t slotId,const DataDisconnectCause type)45 void CellularDataHiSysEvent::WriteDataDeactiveBehaviorEvent(const int32_t slotId, const DataDisconnectCause type)
46 {
47     HiWriteBehaviorEvent(DATA_DEACTIVED_EVENT, SLOT_ID_KEY, slotId, TYPE_KEY, static_cast<int32_t>(type));
48 }
49 
WriteDataConnectStateBehaviorEvent(const int32_t state)50 void CellularDataHiSysEvent::WriteDataConnectStateBehaviorEvent(const int32_t state)
51 {
52     HiWriteBehaviorEvent(DATA_CONNECTION_STATE_EVENT, STATE_KEY, state);
53 }
54 
WriteRoamingConnectStateBehaviorEvent(const int32_t state)55 void CellularDataHiSysEvent::WriteRoamingConnectStateBehaviorEvent(const int32_t state)
56 {
57     HiWriteBehaviorEvent(ROAMING_DATA_CONNECTION_STATE_EVENT, STATE_KEY, state);
58 }
59 
WriteDataActivateFaultEvent(const int32_t slotId,const int32_t switchState,const CellularDataErrorCode errorType,const std::string & errorMsg)60 void CellularDataHiSysEvent::WriteDataActivateFaultEvent(
61     const int32_t slotId, const int32_t switchState, const CellularDataErrorCode errorType, const std::string &errorMsg)
62 {
63     HiWriteFaultEvent(DATA_ACTIVATE_FAILED_EVENT, MODULE_NAME_KEY, CELLULAR_DATA_MODULE, SLOT_ID_KEY, slotId,
64         DATA_SWITCH_KEY, switchState, UPLINK_DATA_KEY, INVALID_PARAMETER, DOWNLINK_DATA_KEY, INVALID_PARAMETER,
65         DATASTATE_KEY, INVALID_PARAMETER, ERROR_TYPE_KEY, static_cast<int32_t>(errorType), ERROR_MSG_KEY, errorMsg);
66 }
67 
SetCellularDataActivateStartTime()68 void CellularDataHiSysEvent::SetCellularDataActivateStartTime()
69 {
70     dataActivateStartTime_ =
71         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
72             .count();
73 }
74 
JudgingDataActivateTimeOut(const int32_t slotId,const int32_t switchState)75 void CellularDataHiSysEvent::JudgingDataActivateTimeOut(const int32_t slotId, const int32_t switchState)
76 {
77     int64_t dataActivateEndTime =
78         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
79             .count();
80     if (dataActivateEndTime - dataActivateStartTime_ > DATA_ACTIVATE_TIME) {
81         WriteDataActivateFaultEvent(slotId, switchState, CellularDataErrorCode::DATA_ERROR_DATA_ACTIVATE_TIME_OUT,
82             "data activate time out " + std::to_string(dataActivateEndTime - dataActivateStartTime_));
83     }
84 }
85 } // namespace Telephony
86 } // namespace OHOS
87