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 <hril_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 DataConnectionManager(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId); 32 ~DataConnectionManager(); 33 void AddConnectionStateMachine(const std::shared_ptr<CellularDataStateMachine> &stateMachine); 34 void RemoveConnectionStateMachine(const std::shared_ptr<CellularDataStateMachine> &stateMachine); 35 void AddActiveConnectionByCid(const std::shared_ptr<CellularDataStateMachine> &stateMachine); 36 std::shared_ptr<CellularDataStateMachine> GetActiveConnectionByCid(int32_t cid); 37 bool isNoActiveConnection(); 38 std::map<int32_t, std::shared_ptr<CellularDataStateMachine>> GetActiveConnection(); 39 bool IsBandwidthSourceModem() const; 40 void RemoveActiveConnectionByCid(int32_t cid); 41 void StartStallDetectionTimer(); 42 void StopStallDetectionTimer(); 43 void RegisterRadioObserver(); 44 void UnRegisterRadioObserver() const; 45 void BeginNetStatistics(); 46 void EndNetStatistics(); 47 int32_t GetDataFlowType(); 48 void SetDataFlowType(CellDataFlowType dataFlowType); 49 int32_t GetSlotId() const; 50 std::vector<std::shared_ptr<CellularDataStateMachine>> GetAllConnectionMachine(); 51 void GetDefaultBandWidthsConfig(); 52 void GetDefaultTcpBufferConfig(); 53 LinkBandwidthInfo GetBandwidthsByRadioTech(const int32_t radioTech); 54 std::string GetTcpBufferByRadioTech(const int32_t radioTech); 55 56 private: 57 void UpdateBandWidthsUseLte(); 58 59 private: 60 std::shared_ptr<DataConnectionMonitor> connectionMonitor_; 61 std::vector<std::shared_ptr<CellularDataStateMachine>> stateMachines_; 62 std::map<int32_t, std::shared_ptr<CellularDataStateMachine>> cidActiveConnectionMap_; 63 std::mutex stateMachineMutex_; 64 std::mutex activeConnectionMutex_; 65 sptr<State> ccmDefaultState_; 66 const int32_t slotId_; 67 std::map<std::string, LinkBandwidthInfo> bandwidthConfigMap_; 68 std::map<std::string, std::string> tcpBufferConfigMap_; 69 bool bandwidthSourceModem_ = true; 70 bool uplinkUseLte_ = false; 71 }; 72 73 class CcmDefaultState : public State { 74 public: CcmDefaultState(DataConnectionManager & connectManager,std::string && name)75 CcmDefaultState(DataConnectionManager &connectManager, std::string &&name) 76 : State(std::move(name)), connectManager_(connectManager) 77 {} 78 virtual ~CcmDefaultState() = default; 79 virtual void StateBegin(); 80 virtual void StateEnd(); 81 virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event); 82 83 protected: 84 void RadioDataCallListChanged(const AppExecFwk::InnerEvent::Pointer &event); 85 void RadioLinkCapabilityChanged(const AppExecFwk::InnerEvent::Pointer &event); 86 void UpdateNetworkInfo(const AppExecFwk::InnerEvent::Pointer &event); 87 88 private: 89 DataConnectionManager &connectManager_; 90 }; 91 } // namespace Telephony 92 } // namespace OHOS 93 #endif // DATA_CONNECTION_MANAGER_H 94