1 /* 2 * Copyright (C) 2021 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 #ifndef DATA_CONNECTION_MONITOR_H 17 #define DATA_CONNECTION_MONITOR_H 18 19 #include "apn_holder.h" 20 #include "inner_event.h" 21 #include "tel_event_handler.h" 22 #include "traffic_management.h" 23 24 namespace OHOS { 25 namespace Telephony { 26 class DataConnectionMonitor : public TelEventHandler { 27 public: 28 explicit DataConnectionMonitor(int32_t slotId); 29 ~DataConnectionMonitor() = default; 30 31 /** 32 * Start the data detection 33 */ 34 void StartStallDetectionTimer(); 35 36 /** 37 * Data detection is in progress 38 */ 39 void OnStallDetectionTimer(); 40 41 /** 42 * Stop the data detection 43 */ 44 void StopStallDetectionTimer(); 45 46 /** 47 * Update flow info 48 */ 49 void UpdateFlowInfo(); 50 51 /** 52 * Data recovery processing 53 */ 54 void HandleRecovery(); 55 56 /** 57 * Start the statistical network 58 */ 59 void BeginNetStatistics(); 60 61 /** 62 * End the statistical network 63 */ 64 void EndNetStatistics(); 65 66 /** 67 * Update call state 68 */ 69 void UpdateCallState(int32_t state); 70 71 /** 72 * Update the up and down data status of the network 73 */ 74 void UpdateNetTrafficState(); 75 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 76 void GetPdpContextList(); 77 78 /** 79 * Set the radio state 80 * 81 * @param radioState RADIO_STATUS_OFF = 0 or RADIO_STATUS_ON = 1 82 * @param eventCode distinguish between the identity of the event 83 */ 84 void SetRadioState(const int32_t &radioState, const int32_t &eventCode); 85 86 /** 87 * Get the preferred network 88 */ 89 void GetPreferredNetworkPara(); 90 91 /** 92 * Update data flow type 93 */ 94 void UpdateDataFlowType(); 95 96 CellDataFlowType GetDataFlowType(); 97 98 void SetDataFlowType(CellDataFlowType dataFlowType); 99 100 /** 101 * Set the preferred network 102 * 103 * @param event distinguish between the identity of the event 104 */ 105 void SetPreferredNetworkPara(const AppExecFwk::InnerEvent::Pointer &event); 106 107 RecoveryState GetDataRecoveryState(); 108 109 void IsNeedDoRecovery(bool needDoRecovery); 110 111 void HandleScreenStateChanged(bool isScreenOn); 112 113 private: 114 bool IsAggressiveRecovery(); 115 int32_t GetStallDetectionPeriod(); 116 bool IsScreenOn(); 117 118 std::unique_ptr<TrafficManagement> trafficManager_; 119 std::unique_ptr<TrafficManagement> stallDetectionTrafficManager_; 120 bool updateNetStat_ = false; 121 bool stallDetectionEnabled_ = false; 122 bool isScreenOn_ = false; 123 int64_t noRecvPackets_ = 0; 124 RecoveryState dataRecoveryState_ = RecoveryState::STATE_REQUEST_CONTEXT_LIST; 125 CellDataFlowType dataFlowType_ = CellDataFlowType::DATA_FLOW_TYPE_NONE; 126 const int32_t slotId_; 127 int32_t callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE); 128 }; 129 } // namespace Telephony 130 } // namespace OHOS 131 #endif // DATA_CONNECTION_MONITOR_H