• 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 #include "apn_manager.h"
22 #include "cellular_data_net_agent.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 // EVENT
27 static constexpr const char *DATA_CONNECTION_STATE_EVENT = "DATA_CONNECTION_STATE";
28 static constexpr const char *ROAMING_DATA_CONNECTION_STATE_EVENT = "ROAMING_DATA_CONNECTION_STATE";
29 static constexpr const char *DATA_ACTIVATE_FAILED_EVENT = "DATA_ACTIVATE_FAILED";
30 static constexpr const char *DATA_DEACTIVED_EVENT = "DATA_DEACTIVED";
31 static constexpr const char *CELLULAR_REQUEST_EVENT = "CELLULAR_REQUEST";
32 static constexpr const char *APN_INFO_EVENT = "APN_INFO_EVENT";
33 
34 // KEY
35 static constexpr const char *MODULE_NAME_KEY = "MODULE";
36 static constexpr const char *SLOT_ID_KEY = "SLOT_ID";
37 static constexpr const char *SUPPLIER_ID_KEY = "SUPPLIER_ID";
38 static constexpr const char *STATE_KEY = "STATE";
39 static constexpr const char *DATA_SWITCH_KEY = "DATA_SWITCH";
40 static constexpr const char *UPLINK_DATA_KEY = "UPLINK_DATA";
41 static constexpr const char *DOWNLINK_DATA_KEY = "DOWNLINK_DATA";
42 static constexpr const char *DATASTATE_KEY = "DATASTATE";
43 static constexpr const char *ERROR_TYPE_KEY = "ERROR_TYPE";
44 static constexpr const char *ERROR_MSG_KEY = "ERROR_MSG";
45 static constexpr const char *TYPE_KEY = "TYPE";
46 static constexpr const char *APN_TYPE_KEY = "APN_TYPE";
47 static constexpr const char *CALL_UID_KEY = "CALL_UID";
48 static constexpr const char *CALL_PID_KEY = "CALL_PID";
49 static constexpr const char *NAME_KEY = "NAME";
50 static constexpr const char *REQUEST_ID_KEY = "REQUEST_ID";
51 
52 static constexpr const char *CARDID_KEY = "CARDID";
53 static constexpr const char *CARRIER_KEY = "CARRIER";
54 static constexpr const char *APN_KEY = "APN";
55 static constexpr const char *PROXY_KEY = "PROXY";
56 static constexpr const char *MMSPROXY_KEY = "MMSPROXY";
57 static constexpr const char *NUMERIC_KEY = "NUMERIC";
58 static constexpr const char *AUTHTYPE_KEY = "AUTHTYPE";
59 static constexpr const char *APNTYPES_KEY = "APNTYPES";
60 static constexpr const char *PROTOCOL_KEY = "PROTOCOL";
61 static constexpr const char *ROAMINGPROTOCOL_KEY = "ROAMINGPROTOCOL";
62 static constexpr const char *BEARER_KEY = "BEARER";
63 static constexpr const char *MVNOTYPE_KEY = "MVNOTYPE";
64 static constexpr const char *MVNOMATCHDATA_KEY = "MVNOMATCHDATA";
65 static constexpr const char *ISCREATEDAPN_KEY = "ISCREATEDAPN";
66 static constexpr const char *HASUSERPSD_KEY = "HASUSERPSD";
67 static constexpr const char *SERVER_KEY = "SERVER";
68 
69 // VALUE
70 static constexpr const char *CELLULAR_DATA_MODULE = "CELLULAR_DATA";
71 static constexpr int32_t NUMBER_MINUS_ONE = -1;
72 
WriteDataDeactiveBehaviorEvent(const int32_t slotId,const DataDisconnectCause type,const std::string & apnType)73 void CellularDataHiSysEvent::WriteDataDeactiveBehaviorEvent(const int32_t slotId, const DataDisconnectCause type,
74     const std::string &apnType)
75 {
76     int32_t bitMap = ApnManager::FindApnTypeByApnName(apnType);
77     HiWriteBehaviorEvent(DATA_DEACTIVED_EVENT, SLOT_ID_KEY, slotId, APN_TYPE_KEY, bitMap,
78         TYPE_KEY, static_cast<int32_t>(type));
79 }
80 
WriteDataConnectStateBehaviorEvent(const int32_t slotId,const std::string & apnType,const uint64_t capability,const int32_t state)81 void CellularDataHiSysEvent::WriteDataConnectStateBehaviorEvent(const int32_t slotId, const std::string &apnType,
82     const uint64_t capability, const int32_t state)
83 {
84     int32_t bitMap = ApnManager::FindApnTypeByApnName(apnType);
85     CellularDataNetAgent &netAgent = CellularDataNetAgent::GetInstance();
86     int32_t supplierId = netAgent.GetSupplierId(slotId, capability);
87     HiWriteBehaviorEvent(DATA_CONNECTION_STATE_EVENT, SLOT_ID_KEY, slotId, APN_TYPE_KEY, bitMap,
88         SUPPLIER_ID_KEY, supplierId, STATE_KEY, state);
89 }
90 
WriteRoamingConnectStateBehaviorEvent(const int32_t state)91 void CellularDataHiSysEvent::WriteRoamingConnectStateBehaviorEvent(const int32_t state)
92 {
93     HiWriteBehaviorEvent(ROAMING_DATA_CONNECTION_STATE_EVENT, STATE_KEY, state);
94 }
95 
WriteCellularRequestBehaviorEvent(const uint32_t uid,const std::string name,const uint64_t type,const int32_t state)96 void CellularDataHiSysEvent::WriteCellularRequestBehaviorEvent(
97     const uint32_t uid, const std::string name, const uint64_t type, const int32_t state)
98 {
99     HiWriteBehaviorEvent(CELLULAR_REQUEST_EVENT, CALL_UID_KEY, static_cast<int32_t>(uid),
100         CALL_PID_KEY, NUMBER_MINUS_ONE, NAME_KEY, name, REQUEST_ID_KEY, NUMBER_MINUS_ONE,
101         TYPE_KEY, static_cast<int32_t>(type), STATE_KEY, state);
102 }
103 
WriteDataActivateFaultEvent(const int32_t slotId,const int32_t switchState,const CellularDataErrorCode errorType,const std::string & errorMsg)104 void CellularDataHiSysEvent::WriteDataActivateFaultEvent(
105     const int32_t slotId, const int32_t switchState, const CellularDataErrorCode errorType, const std::string &errorMsg)
106 {
107     HiWriteFaultEvent(DATA_ACTIVATE_FAILED_EVENT, MODULE_NAME_KEY, CELLULAR_DATA_MODULE, SLOT_ID_KEY, slotId,
108         DATA_SWITCH_KEY, switchState, UPLINK_DATA_KEY, INVALID_PARAMETER, DOWNLINK_DATA_KEY, INVALID_PARAMETER,
109         DATASTATE_KEY, INVALID_PARAMETER, ERROR_TYPE_KEY, static_cast<int32_t>(errorType), ERROR_MSG_KEY, errorMsg);
110 }
111 
WriteApnInfoBehaviorEvent(const int32_t slotId,struct PdpProfile & apnData)112 void CellularDataHiSysEvent::WriteApnInfoBehaviorEvent(const int32_t slotId, struct PdpProfile &apnData)
113 {
114     std::string numeric = apnData.mcc + apnData.mnc;
115     int32_t apnHasPsd = apnData.authPwd.empty() ? 1 : 0;
116     HiWriteBehaviorEvent(APN_INFO_EVENT,
117         CARDID_KEY, slotId,
118         CARRIER_KEY, apnData.profileName,
119         APN_KEY, apnData.apn,
120         PROXY_KEY, apnData.proxyIpAddress,
121         MMSPROXY_KEY, apnData.mmsIpAddress,
122         NUMERIC_KEY, numeric,
123         AUTHTYPE_KEY, apnData.authType,
124         APNTYPES_KEY, apnData.apnTypes,
125         PROTOCOL_KEY, apnData.pdpProtocol,
126         ROAMINGPROTOCOL_KEY, apnData.roamPdpProtocol,
127         BEARER_KEY, apnData.bearingSystemType,
128         MVNOTYPE_KEY, apnData.mvnoType,
129         MVNOMATCHDATA_KEY, apnData.mvnoMatchData,
130         ISCREATEDAPN_KEY, apnData.edited,
131         HASUSERPSD_KEY, apnHasPsd,
132         SERVER_KEY, apnData.server);
133 }
134 
SetCellularDataActivateStartTime()135 void CellularDataHiSysEvent::SetCellularDataActivateStartTime()
136 {
137     dataActivateStartTime_ =
138         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
139             .count();
140 }
141 
JudgingDataActivateTimeOut(const int32_t slotId,const int32_t switchState)142 void CellularDataHiSysEvent::JudgingDataActivateTimeOut(const int32_t slotId, const int32_t switchState)
143 {
144     int64_t dataActivateEndTime =
145         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
146             .count();
147     if (dataActivateEndTime - dataActivateStartTime_ > DATA_ACTIVATE_TIME) {
148         WriteDataActivateFaultEvent(slotId, switchState, CellularDataErrorCode::DATA_ERROR_DATA_ACTIVATE_TIME_OUT,
149             "data activate time out " + std::to_string(dataActivateEndTime - dataActivateStartTime_));
150     }
151 }
152 } // namespace Telephony
153 } // namespace OHOS
154