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 if (stateMachine->netSupplierInfo_ != nullptr) { 38 stateMachine->netSupplierInfo_->isAvailable_ = false; 39 } 40 // send MSG_DISCONNECT_DATA_COMPLETE to CellularDataHandler 41 auto netInfo = std::make_shared<SetupDataCallResultInfo>(); 42 if (netInfo == nullptr) { 43 TELEPHONY_LOGE("Create data disconnect params failed"); 44 return; 45 } 46 netInfo->cid = stateMachine->cid_; 47 netInfo->flag = deActiveApnTypeId_; 48 netInfo->active = 0; 49 if (resultInfo_ != nullptr) { 50 netInfo->reason = resultInfo_->reason; 51 netInfo->retryTime = resultInfo_->retryTime; 52 netInfo->retryScene = resultInfo_->retryScene; 53 } 54 AppExecFwk::InnerEvent::Pointer event = 55 AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_DISCONNECT_DATA_COMPLETE, netInfo); 56 if (event == nullptr) { 57 TELEPHONY_LOGE("Create event failed"); 58 return; 59 } 60 if (stateMachine->cellularDataHandler_ != nullptr) { 61 stateMachine->cellularDataHandler_->SendEvent(event); 62 } 63 deActiveApnTypeId_ = ERROR_APN_ID; 64 resultInfo_ = nullptr; 65 } 66 stateMachine->SetCurrentState(sptr<State>(this)); 67 } 68 StateEnd()69void Inactive::StateEnd() 70 { 71 TELEPHONY_LOGI("Exit inactive state"); 72 isActive_ = false; 73 } 74 StateProcess(const AppExecFwk::InnerEvent::Pointer & event)75bool Inactive::StateProcess(const AppExecFwk::InnerEvent::Pointer &event) 76 { 77 if (event == nullptr) { 78 TELEPHONY_LOGE("event is null"); 79 return false; 80 } 81 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 82 if (stateMachine == nullptr) { 83 TELEPHONY_LOGE("stateMachine is null"); 84 return false; 85 } 86 bool retVal = false; 87 uint32_t eventCode = event->GetInnerEventId(); 88 switch (eventCode) { 89 case CellularDataEventCode::MSG_SM_CONNECT: { 90 TELEPHONY_LOGD("Inactive::MSG_SM_CONNECT"); 91 stateMachine->DoConnect(*(event->GetUniqueObject<DataConnectionParams>())); 92 stateMachine->TransitionTo(stateMachine->activatingState_); 93 retVal = PROCESSED; 94 break; 95 } 96 case CellularDataEventCode::MSG_SM_DISCONNECT: { 97 TELEPHONY_LOGI("Inactive::MSG_SM_DISCONNECT"); 98 retVal = PROCESSED; 99 break; 100 } 101 case CellularDataEventCode::MSG_SM_DISCONNECT_ALL: { 102 TELEPHONY_LOGI("Inactive::MSG_SM_DISCONNECT_ALL"); 103 retVal = PROCESSED; 104 break; 105 } 106 default: 107 break; 108 } 109 return retVal; 110 } 111 SetStateMachine(const std::weak_ptr<CellularDataStateMachine> & stateMachine)112void Inactive::SetStateMachine(const std::weak_ptr<CellularDataStateMachine> &stateMachine) 113 { 114 stateMachine_ = stateMachine; 115 } 116 SetDeActiveApnTypeId(int32_t deActiveApnTypeId)117void Inactive::SetDeActiveApnTypeId(int32_t deActiveApnTypeId) 118 { 119 deActiveApnTypeId_ = deActiveApnTypeId; 120 } 121 SetDataCallResultInfo(std::shared_ptr<SetupDataCallResultInfo> resultInfo)122void Inactive::SetDataCallResultInfo(std::shared_ptr<SetupDataCallResultInfo> resultInfo) 123 { 124 resultInfo_ = resultInfo; 125 } 126 SetPdpErrorReason(PdpErrorReason reason)127void Inactive::SetPdpErrorReason(PdpErrorReason reason) 128 { 129 resultInfo_ = std::make_shared<SetupDataCallResultInfo>(); 130 resultInfo_->reason = static_cast<int32_t>(reason); 131 } 132 } // namespace Telephony 133 } // namespace OHOS 134