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 #include "inactive.h" 17 18 #include "telephony_log_wrapper.h" 19 20 #include "apn_manager.h" 21 #include "cellular_data_event_code.h" 22 23 namespace OHOS { 24 namespace Telephony { StateBegin()25void Inactive::StateBegin() 26 { 27 TELEPHONY_LOGI("Enter inactive state"); 28 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 29 if (stateMachine == nullptr) { 30 TELEPHONY_LOGE("stateMachine is null"); 31 return; 32 } 33 stateMachine->connectId_++; 34 isActive_ = true; 35 if (deActiveApnTypeId_ != ERROR_APN_ID) { 36 // set net manager connection false 37 CellularDataNetAgent &netAgent = CellularDataNetAgent::GetInstance(); 38 int32_t supplierId = netAgent.GetSupplierId(stateMachine->GetSlotId(), stateMachine->GetCapability()); 39 if (stateMachine->netSupplierInfo_ != nullptr) { 40 stateMachine->netSupplierInfo_->isAvailable_ = false; 41 netAgent.UpdateNetSupplierInfo(supplierId, stateMachine->netSupplierInfo_); 42 } 43 // send MSG_DISCONNECT_DATA_COMPLETE to CellularDataHandler 44 std::string apnType = ApnManager::FindApnNameByApnId(deActiveApnTypeId_); 45 std::unique_ptr<DataDisconnectParams> object = std::make_unique<DataDisconnectParams>(apnType, reason_); 46 if (object == nullptr) { 47 TELEPHONY_LOGE("Create data disconnect params failed"); 48 return; 49 } 50 AppExecFwk::InnerEvent::Pointer event = 51 AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_DISCONNECT_DATA_COMPLETE, object); 52 if (stateMachine->cellularDataHandler_ != nullptr) { 53 stateMachine->cellularDataHandler_->SendEvent(event); 54 } 55 deActiveApnTypeId_ = ERROR_APN_ID; 56 reason_ = DisConnectionReason::REASON_RETRY_CONNECTION; 57 } 58 stateMachine->SetCurrentState(sptr<State>(this)); 59 if (stateMachine->cdConnectionManager_ != nullptr) { 60 stateMachine->cdConnectionManager_->RemoveActiveConnectionByCid(stateMachine->GetCid()); 61 } 62 } 63 StateEnd()64void Inactive::StateEnd() 65 { 66 TELEPHONY_LOGI("Exit inactive state"); 67 isActive_ = false; 68 } 69 StateProcess(const AppExecFwk::InnerEvent::Pointer & event)70bool Inactive::StateProcess(const AppExecFwk::InnerEvent::Pointer &event) 71 { 72 if (event == nullptr) { 73 TELEPHONY_LOGE("event is null"); 74 return false; 75 } 76 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 77 if (stateMachine == nullptr) { 78 TELEPHONY_LOGE("stateMachine is null"); 79 return false; 80 } 81 bool retVal = false; 82 uint32_t eventCode = event->GetInnerEventId(); 83 switch (eventCode) { 84 case CellularDataEventCode::MSG_SM_CONNECT: { 85 TELEPHONY_LOGI("Inactive::MSG_SM_CONNECT"); 86 stateMachine->DoConnect(*(event->GetUniqueObject<DataConnectionParams>())); 87 stateMachine->TransitionTo(stateMachine->activatingState_); 88 retVal = PROCESSED; 89 break; 90 } 91 case CellularDataEventCode::MSG_SM_DISCONNECT: { 92 TELEPHONY_LOGI("Inactive::MSG_SM_DISCONNECT"); 93 retVal = PROCESSED; 94 break; 95 } 96 case CellularDataEventCode::MSG_SM_DISCONNECT_ALL: { 97 TELEPHONY_LOGI("Inactive::MSG_SM_DISCONNECT_ALL"); 98 retVal = PROCESSED; 99 break; 100 } 101 default: 102 TELEPHONY_LOGE("StateProcess handle nothing!"); 103 break; 104 } 105 return retVal; 106 } 107 SetStateMachine(const std::weak_ptr<CellularDataStateMachine> & stateMachine)108void Inactive::SetStateMachine(const std::weak_ptr<CellularDataStateMachine> &stateMachine) 109 { 110 stateMachine_ = stateMachine; 111 } 112 SetDeActiveApnTypeId(int32_t deActiveApnTypeId)113void Inactive::SetDeActiveApnTypeId(int32_t deActiveApnTypeId) 114 { 115 deActiveApnTypeId_ = deActiveApnTypeId; 116 } 117 SetReason(DisConnectionReason reason)118void Inactive::SetReason(DisConnectionReason reason) 119 { 120 reason_ = reason; 121 } 122 } // namespace Telephony 123 } // namespace OHOS 124