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 "disconnecting.h" 17 18 #include "hril_data_parcel.h" 19 #include "telephony_log_wrapper.h" 20 #include "radio_event.h" 21 22 #include "cellular_data_event_code.h" 23 #include "inactive.h" 24 25 namespace OHOS { 26 namespace Telephony { StateBegin()27void Disconnecting::StateBegin() 28 { 29 TELEPHONY_LOGI("Enter disconnecting state"); 30 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 31 if (stateMachine == nullptr) { 32 TELEPHONY_LOGE("stateMachine is null"); 33 return; 34 } 35 isActive_ = true; 36 stateMachine->SetCurrentState(sptr<State>(this)); 37 } 38 StateEnd()39void Disconnecting::StateEnd() 40 { 41 TELEPHONY_LOGI("Disconnecting::exit"); 42 isActive_ = false; 43 } 44 ProcessDisconnectTimeout(const AppExecFwk::InnerEvent::Pointer & event)45void Disconnecting::ProcessDisconnectTimeout(const AppExecFwk::InnerEvent::Pointer &event) 46 { 47 if (event == nullptr) { 48 TELEPHONY_LOGE("event is null"); 49 return; 50 } 51 int32_t connectId = event->GetParam(); 52 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 53 if (stateMachine == nullptr) { 54 TELEPHONY_LOGE("stateMachine is null"); 55 return; 56 } 57 if (connectId != stateMachine->connectId_) { 58 return; 59 } 60 Inactive *inActive = static_cast<Inactive *>(stateMachine->inActiveState_.GetRefPtr()); 61 inActive->SetDeActiveApnTypeId(stateMachine->apnId_); 62 inActive->SetReason(DisConnectionReason::REASON_RETRY_CONNECTION); 63 stateMachine->TransitionTo(stateMachine->inActiveState_); 64 TELEPHONY_LOGI("ProcessDisconnectTimeout"); 65 } 66 StateProcess(const AppExecFwk::InnerEvent::Pointer & event)67bool Disconnecting::StateProcess(const AppExecFwk::InnerEvent::Pointer &event) 68 { 69 if (event == nullptr) { 70 TELEPHONY_LOGE("event is null"); 71 return false; 72 } 73 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 74 if (stateMachine == nullptr) { 75 TELEPHONY_LOGE("stateMachine is null"); 76 return false; 77 } 78 bool retVal = false; 79 switch (event->GetInnerEventId()) { 80 case CellularDataEventCode::MSG_SM_CONNECT: 81 TELEPHONY_LOGI("Disconnecting::MSG_SM_CONNECT"); 82 stateMachine->DeferEvent(std::move(event)); 83 retVal = PROCESSED; 84 break; 85 case RadioEvent::RADIO_RIL_DEACTIVATE_DATA_CALL: { 86 Inactive *inActive = static_cast<Inactive *>(stateMachine->inActiveState_.GetRefPtr()); 87 std::shared_ptr<HRilRadioResponseInfo> rilInfo = event->GetSharedObject<HRilRadioResponseInfo>(); 88 if (rilInfo == nullptr) { 89 TELEPHONY_LOGE("SetupDataCallResultInfo and HRilRadioResponseInfo is null"); 90 stateMachine->stateMachineEventHandler_->RemoveEvent(CellularDataEventCode::MSG_CONNECT_TIMEOUT_CHECK); 91 inActive->SetDeActiveApnTypeId(stateMachine->apnId_); 92 stateMachine->TransitionTo(stateMachine->inActiveState_); 93 retVal = PROCESSED; 94 break; 95 } 96 if (stateMachine->connectId_ != rilInfo->flag) { 97 TELEPHONY_LOGE("connectId is %{public}d, flag is %{public}d", stateMachine->connectId_, rilInfo->flag); 98 retVal = PROCESSED; 99 break; 100 } 101 TELEPHONY_LOGI("HRilRadioResponseInfo error is %{public}d", static_cast<int32_t>(rilInfo->error)); 102 stateMachine->stateMachineEventHandler_->RemoveEvent(CellularDataEventCode::MSG_CONNECT_TIMEOUT_CHECK); 103 inActive->SetDeActiveApnTypeId(stateMachine->apnId_); 104 stateMachine->TransitionTo(stateMachine->inActiveState_); 105 retVal = PROCESSED; 106 break; 107 } 108 case CellularDataEventCode::MSG_DISCONNECT_TIMEOUT_CHECK: 109 ProcessDisconnectTimeout(event); 110 retVal = PROCESSED; 111 break; 112 default: 113 TELEPHONY_LOGE("disconnecting StateProcess do nothing!"); 114 break; 115 } 116 return retVal; 117 } 118 } // namespace Telephony 119 } // namespace OHOS 120