• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "event_handler.h"
20 #include "inner_event.h"
21 
22 #include "apn_holder.h"
23 #include "traffic_management.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 class DataConnectionMonitor : public AppExecFwk::EventHandler {
28 public:
29     explicit DataConnectionMonitor(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId);
30     ~DataConnectionMonitor() = default;
31 
32     /**
33      * Start the data detection
34      */
35     void StartStallDetectionTimer();
36 
37     /**
38      * Data detection is in progress
39      */
40     void OnStallDetectionTimer();
41 
42     /**
43      * Stop the data detection
44      */
45     void StopStallDetectionTimer();
46 
47     /**
48      * Update flow info
49      */
50     void UpdateFlowInfo();
51 
52     /**
53      * Data recovery processing
54      */
55     void HandleRecovery();
56 
57     /**
58      * Start the statistical network
59      */
60     void BeginNetStatistics();
61 
62     /**
63      * End the statistical network
64      */
65     void EndNetStatistics();
66 
67     /**
68      * Update the up and down data status of the network
69      */
70     void UpdateNetTrafficState();
71     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
72     void GetPdpContextList();
73 
74     /**
75      * Set the radio state
76      *
77      * @param radioState RADIO_STATUS_OFF = 0 or RADIO_STATUS_ON = 1
78      * @param eventCode distinguish between the identity of the event
79      */
80     void SetRadioState(const int32_t &radioState, const int32_t &eventCode);
81 
82     /**
83      * Get the preferred network
84      */
85     void GetPreferredNetworkPara();
86 
87     /**
88      * Update data flow type
89      */
90     void UpdateDataFlowType();
91 
92     CellDataFlowType GetDataFlowType();
93 
94     void SetDataFlowType(CellDataFlowType dataFlowType);
95 
96     /**
97      * Set the preferred network
98      *
99      * @param event distinguish between the identity of the event
100      */
101     void SetPreferredNetworkPara(const AppExecFwk::InnerEvent::Pointer &event);
102 
103 private:
104     std::unique_ptr<TrafficManagement> trafficManager_;
105     std::unique_ptr<TrafficManagement> stallDetectionTrafficManager_;
106     bool updateNetStat_ = false;
107     bool stallDetectionEnabled = false;
108     int64_t noRecvPackets_ = 0;
109     RecoveryState dataRecoveryState_ = RecoveryState::STATE_REQUEST_CONTEXT_LIST;
110     CellDataFlowType dataFlowType_ = CellDataFlowType::DATA_FLOW_TYPE_NONE;
111     const int32_t slotId_;
112 };
113 } // namespace Telephony
114 } // namespace OHOS
115 #endif // DATA_CONNECTION_MONITOR_H