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