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 "default.h"
17
18 #include "cellular_data_utils.h"
19 #include "core_manager_inner.h"
20 #include "telephony_log_wrapper.h"
21
22 namespace OHOS {
23 namespace Telephony {
StateBegin()24 void Default::StateBegin()
25 {
26 TELEPHONY_LOGD("Enter default state");
27 isActive_ = true;
28 }
29
StateEnd()30 void Default::StateEnd()
31 {
32 TELEPHONY_LOGD("Exit default state");
33 isActive_ = false;
34 }
35
StateProcess(const AppExecFwk::InnerEvent::Pointer &event)36 bool Default::StateProcess(const AppExecFwk::InnerEvent::Pointer &event)
37 {
38 if (event == nullptr) {
39 TELEPHONY_LOGE("event is null");
40 return false;
41 }
42 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock();
43 if (stateMachine == nullptr) {
44 TELEPHONY_LOGE("stateMachine is null");
45 return false;
46 }
47 uint32_t eventCode = event->GetInnerEventId();
48 std::map<uint32_t, Fun>::iterator it = eventIdFunMap_.find(eventCode);
49 if (it != eventIdFunMap_.end()) {
50 return it->second(event);
51 }
52 return false;
53 }
54
ProcessConnectDone(const AppExecFwk::InnerEvent::Pointer &event)55 bool Default::ProcessConnectDone(const AppExecFwk::InnerEvent::Pointer &event)
56 {
57 TELEPHONY_LOGI("Default::MSG_SM_CONNECT");
58 return false;
59 }
60
ProcessDisconnectDone(const AppExecFwk::InnerEvent::Pointer &event)61 bool Default::ProcessDisconnectDone(const AppExecFwk::InnerEvent::Pointer &event)
62 {
63 if (event == nullptr) {
64 TELEPHONY_LOGE("event is null");
65 return false;
66 }
67 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock();
68 if (stateMachine == nullptr) {
69 TELEPHONY_LOGE("The state machine pointer is null");
70 return false;
71 }
72 TELEPHONY_LOGI("The data connection is disconnected by default");
73 stateMachine->DeferEvent(std::move(event));
74 return true;
75 }
76
ProcessDisconnectAllDone(const AppExecFwk::InnerEvent::Pointer &event)77 bool Default::ProcessDisconnectAllDone(const AppExecFwk::InnerEvent::Pointer &event)
78 {
79 if (event == nullptr) {
80 TELEPHONY_LOGE("event is null");
81 return false;
82 }
83 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock();
84 if (stateMachine == nullptr) {
85 TELEPHONY_LOGE("The state machine pointer is null");
86 return false;
87 }
88 TELEPHONY_LOGI("All data connections are disconnected by default");
89 stateMachine->DeferEvent(std::move(event));
90 return true;
91 }
92
ProcessDataConnectionDrsOrRatChanged(const AppExecFwk::InnerEvent::Pointer &event)93 bool Default::ProcessDataConnectionDrsOrRatChanged(const AppExecFwk::InnerEvent::Pointer &event)
94 {
95 if (event == nullptr) {
96 TELEPHONY_LOGE("event is null");
97 return false;
98 }
99 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock();
100 if (stateMachine == nullptr) {
101 TELEPHONY_LOGE("stateMachine is null");
102 return false;
103 }
104 TELEPHONY_LOGI("The RAT changes by default");
105 CellularDataNetAgent &netAgent = CellularDataNetAgent::GetInstance();
106 int32_t supplierId = netAgent.GetSupplierId(stateMachine->GetSlotId(), stateMachine->GetCapability());
107 netAgent.UpdateNetSupplierInfo(supplierId, stateMachine->netSupplierInfo_);
108 if (stateMachine->IsActiveState() || stateMachine->IsActivatingState()) {
109 netAgent.UpdateNetLinkInfo(supplierId, stateMachine->netLinkInfo_);
110 }
111 int32_t radioTech = static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_INVALID);
112 CoreManagerInner::GetInstance().GetPsRadioTech(stateMachine->GetSlotId(), radioTech);
113 netAgent.RegisterSlotType(supplierId, radioTech);
114 TELEPHONY_LOGI("RegisterSlotType: supplierId[%{public}d] slotId[%{public}d] radioTech[%{public}d]",
115 supplierId, stateMachine->GetSlotId(), radioTech);
116 return false;
117 }
118
ProcessDataConnectionRoamOn(const AppExecFwk::InnerEvent::Pointer &event)119 bool Default::ProcessDataConnectionRoamOn(const AppExecFwk::InnerEvent::Pointer &event)
120 {
121 TELEPHONY_LOGI("Default::EVENT_DATA_CONNECTION_ROAM_ON");
122 return false;
123 }
124
ProcessDataConnectionRoamOff(const AppExecFwk::InnerEvent::Pointer &event)125 bool Default::ProcessDataConnectionRoamOff(const AppExecFwk::InnerEvent::Pointer &event)
126 {
127 TELEPHONY_LOGI("Default::EVENT_DATA_CONNECTION_ROAM_OFF");
128 return false;
129 }
130
ProcessUpdateNetworkInfo(const AppExecFwk::InnerEvent::Pointer &event)131 bool Default::ProcessUpdateNetworkInfo(const AppExecFwk::InnerEvent::Pointer &event)
132 {
133 std::shared_ptr<CellularDataStateMachine> shareStateMachine = stateMachine_.lock();
134 if (shareStateMachine == nullptr) {
135 TELEPHONY_LOGE("shareStateMachine is null");
136 return false;
137 }
138 shareStateMachine->UpdateNetworkInfo();
139 return true;
140 }
141 } // namespace Telephony
142 } // namespace OHOS
143