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 AppExecFwk::InnerEvent::Pointer event = 47 AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_DISCONNECT_DATA_COMPLETE, object); 48 if (stateMachine->cellularDataHandler_ != nullptr) { 49 stateMachine->cellularDataHandler_->SendEvent(event); 50 } 51 deActiveApnTypeId_ = ERROR_APN_ID; 52 reason_ = DisConnectionReason::REASON_RETRY_CONNECTION; 53 } 54 stateMachine->SetCurrentState(sptr<State>(this)); 55 if (stateMachine->cdConnectionManager_ != nullptr) { 56 stateMachine->cdConnectionManager_->RemoveActiveConnectionByCid(stateMachine->GetCid()); 57 } 58 } 59 StateEnd()60void Inactive::StateEnd() 61 { 62 TELEPHONY_LOGI("Exit inactive state"); 63 isActive_ = false; 64 } 65 StateProcess(const AppExecFwk::InnerEvent::Pointer & event)66bool Inactive::StateProcess(const AppExecFwk::InnerEvent::Pointer &event) 67 { 68 if (event == nullptr) { 69 TELEPHONY_LOGE("event is null"); 70 return false; 71 } 72 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 73 if (stateMachine == nullptr) { 74 TELEPHONY_LOGE("stateMachine is null"); 75 return false; 76 } 77 bool retVal = false; 78 uint32_t eventCode = event->GetInnerEventId(); 79 switch (eventCode) { 80 case CellularDataEventCode::MSG_SM_CONNECT: { 81 TELEPHONY_LOGI("Inactive::MSG_SM_CONNECT"); 82 stateMachine->DoConnect(*(event->GetUniqueObject<DataConnectionParams>())); 83 stateMachine->TransitionTo(stateMachine->activatingState_); 84 retVal = PROCESSED; 85 break; 86 } 87 case CellularDataEventCode::MSG_SM_DISCONNECT: { 88 TELEPHONY_LOGI("Inactive::MSG_SM_DISCONNECT"); 89 retVal = PROCESSED; 90 break; 91 } 92 case CellularDataEventCode::MSG_SM_DISCONNECT_ALL: { 93 TELEPHONY_LOGI("Inactive::MSG_SM_DISCONNECT_ALL"); 94 retVal = PROCESSED; 95 break; 96 } 97 default: 98 TELEPHONY_LOGE("StateProcess handle nothing!"); 99 break; 100 } 101 return retVal; 102 } 103 SetStateMachine(const std::weak_ptr<CellularDataStateMachine> & stateMachine)104void Inactive::SetStateMachine(const std::weak_ptr<CellularDataStateMachine> &stateMachine) 105 { 106 stateMachine_ = stateMachine; 107 } 108 SetDeActiveApnTypeId(int32_t deActiveApnTypeId)109void Inactive::SetDeActiveApnTypeId(int32_t deActiveApnTypeId) 110 { 111 deActiveApnTypeId_ = deActiveApnTypeId; 112 } 113 SetReason(DisConnectionReason reason)114void Inactive::SetReason(DisConnectionReason reason) 115 { 116 reason_ = reason; 117 } 118 } // namespace Telephony 119 } // namespace OHOS 120