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_MANAGER_H
17 #define DATA_CONNECTION_MANAGER_H
18 
19 #include <tel_ril_data_parcel.h>
20 #include <map>
21 #include <memory>
22 
23 #include "data_connection_monitor.h"
24 #include "state_machine.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class CellularDataStateMachine;
29 class DataConnectionManager : public StateMachine, public RefBase {
30 public:
31     explicit DataConnectionManager(int32_t slotId);
32     ~DataConnectionManager();
33     void Init();
34     void AddConnectionStateMachine(const std::shared_ptr<CellularDataStateMachine> &stateMachine);
35     void RemoveConnectionStateMachine(const std::shared_ptr<CellularDataStateMachine> &stateMachine);
36     void AddActiveConnectionByCid(const std::shared_ptr<CellularDataStateMachine> &stateMachine);
37     std::shared_ptr<CellularDataStateMachine> GetActiveConnectionByCid(int32_t cid);
38     bool isNoActiveConnection();
39     std::map<int32_t, std::shared_ptr<CellularDataStateMachine>> GetActiveConnection();
40     bool IsBandwidthSourceModem() const;
41     void RemoveActiveConnectionByCid(int32_t cid);
42     void StartStallDetectionTimer();
43     void StopStallDetectionTimer();
44     void RegisterRadioObserver();
45     void UnRegisterRadioObserver() const;
46     void BeginNetStatistics();
47     void EndNetStatistics();
48     int32_t GetDataFlowType();
49     void SetDataFlowType(CellDataFlowType dataFlowType);
50     int32_t GetSlotId() const;
51     std::vector<std::shared_ptr<CellularDataStateMachine>> GetAllConnectionMachine();
52     void GetDefaultBandWidthsConfig();
53     void GetDefaultTcpBufferConfig();
54     LinkBandwidthInfo GetBandwidthsByRadioTech(const int32_t radioTech);
55     std::string GetTcpBufferByRadioTech(const int32_t radioTech);
56     void UpdateCallState(int32_t state);
57     int32_t GetDataRecoveryState();
58     void IsNeedDoRecovery(bool needDoRecovery) const;
59     void HandleScreenStateChanged(bool isScreenOn) const;
60 
61 private:
62     void UpdateBandWidthsUseLte();
63 
64 private:
65     std::shared_ptr<DataConnectionMonitor> connectionMonitor_;
66     std::vector<std::shared_ptr<CellularDataStateMachine>> stateMachines_;
67     std::map<int32_t, std::shared_ptr<CellularDataStateMachine>> cidActiveConnectionMap_;
68     std::mutex stateMachineMutex_;
69     std::mutex activeConnectionMutex_;
70     sptr<State> ccmDefaultState_;
71     const int32_t slotId_;
72     std::map<std::string, LinkBandwidthInfo> bandwidthConfigMap_;
73     std::map<std::string, std::string> tcpBufferConfigMap_;
74     bool bandwidthSourceModem_ = true;
75     bool uplinkUseLte_ = false;
76 };
77 
78 class CcmDefaultState : public State {
79 public:
CcmDefaultState(DataConnectionManager & connectManager,std::string && name)80     CcmDefaultState(DataConnectionManager &connectManager, std::string &&name)
81         : State(std::move(name)), connectManager_(connectManager)
82     {}
83     virtual ~CcmDefaultState() = default;
84     virtual void StateBegin();
85     virtual void StateEnd();
86     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
87 
88 protected:
89     void RadioDataCallListChanged(const AppExecFwk::InnerEvent::Pointer &event);
90     void RadioLinkCapabilityChanged(const AppExecFwk::InnerEvent::Pointer &event);
91     void UpdateNetworkInfo(const AppExecFwk::InnerEvent::Pointer &event);
92 
93 private:
94     DataConnectionManager &connectManager_;
95 };
96 } // namespace Telephony
97 } // namespace OHOS
98 #endif // DATA_CONNECTION_MANAGER_H
99