• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()27 void 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()39 void Disconnecting::StateEnd()
40 {
41     TELEPHONY_LOGI("Disconnecting::exit");
42     isActive_ = false;
43 }
44 
ProcessDisconnectTimeout(const AppExecFwk::InnerEvent::Pointer & event)45 void 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_CLEAR_CONNECTION);
63     stateMachine->TransitionTo(stateMachine->inActiveState_);
64     TELEPHONY_LOGI("ProcessDisconnectTimeout");
65 }
66 
StateProcess(const AppExecFwk::InnerEvent::Pointer & event)67 bool 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     uint32_t eventCode = event->GetInnerEventId();
80     switch (eventCode) {
81         case CellularDataEventCode::MSG_SM_CONNECT:
82             TELEPHONY_LOGI("Disconnecting::MSG_SM_CONNECT");
83             stateMachine->DeferEvent(std::move(event));
84             retVal = PROCESSED;
85             break;
86         case RadioEvent::RADIO_RIL_DEACTIVATE_DATA_CALL: {
87             Inactive *inActive = static_cast<Inactive *>(stateMachine->inActiveState_.GetRefPtr());
88             std::shared_ptr<HRilRadioResponseInfo> rilInfo = event->GetSharedObject<HRilRadioResponseInfo>();
89             if (rilInfo == nullptr) {
90                 TELEPHONY_LOGE("SetupDataCallResultInfo and HRilRadioResponseInfo is null");
91                 stateMachine->stateMachineEventHandler_->RemoveEvent(CellularDataEventCode::MSG_CONNECT_TIMEOUT_CHECK);
92                 inActive->SetDeActiveApnTypeId(stateMachine->apnId_);
93                 stateMachine->TransitionTo(stateMachine->inActiveState_);
94                 retVal = PROCESSED;
95                 break;
96             }
97             if (stateMachine->connectId_ != rilInfo->flag) {
98                 TELEPHONY_LOGE("connectId is %{public}d, flag is %{public}d", stateMachine->connectId_, rilInfo->flag);
99                 retVal = PROCESSED;
100                 break;
101             }
102             TELEPHONY_LOGI("HRilRadioResponseInfo error is %{public}d", static_cast<int32_t>(rilInfo->error));
103             stateMachine->stateMachineEventHandler_->RemoveEvent(CellularDataEventCode::MSG_CONNECT_TIMEOUT_CHECK);
104             inActive->SetDeActiveApnTypeId(stateMachine->apnId_);
105             stateMachine->TransitionTo(stateMachine->inActiveState_);
106             retVal = PROCESSED;
107             break;
108         }
109         case CellularDataEventCode::MSG_DISCONNECT_TIMEOUT_CHECK:
110             ProcessDisconnectTimeout(event);
111             retVal = PROCESSED;
112             break;
113         default:
114             TELEPHONY_LOGE("disconnecting StateProcess do nothing!");
115             break;
116     }
117     return retVal;
118 }
119 } // namespace Telephony
120 } // namespace OHOS
121