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 "telephony_log_wrapper.h" 19 20 namespace OHOS { 21 namespace Telephony { StateBegin()22void Default::StateBegin() 23 { 24 TELEPHONY_LOGI("Enter default state"); 25 isActive_ = true; 26 } 27 StateEnd()28void Default::StateEnd() 29 { 30 TELEPHONY_LOGI("Exit default state"); 31 isActive_ = false; 32 } 33 StateProcess(const AppExecFwk::InnerEvent::Pointer & event)34bool Default::StateProcess(const AppExecFwk::InnerEvent::Pointer &event) 35 { 36 if (event == nullptr) { 37 TELEPHONY_LOGE("event is null"); 38 return false; 39 } 40 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 41 if (stateMachine == nullptr) { 42 TELEPHONY_LOGE("stateMachine is null"); 43 return false; 44 } 45 uint32_t eventCode = event->GetInnerEventId(); 46 std::map<uint32_t, Fun>::iterator it = eventIdFunMap_.find(eventCode); 47 if (it != eventIdFunMap_.end()) { 48 return (this->*(it->second))(event); 49 } 50 return false; 51 } 52 ProcessConnectDone(const AppExecFwk::InnerEvent::Pointer & event)53bool Default::ProcessConnectDone(const AppExecFwk::InnerEvent::Pointer &event) 54 { 55 TELEPHONY_LOGI("Default::MSG_SM_CONNECT"); 56 return false; 57 } 58 ProcessDisconnectDone(const AppExecFwk::InnerEvent::Pointer & event)59bool Default::ProcessDisconnectDone(const AppExecFwk::InnerEvent::Pointer &event) 60 { 61 if (event == nullptr) { 62 TELEPHONY_LOGE("event is null"); 63 return false; 64 } 65 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 66 if (stateMachine == nullptr) { 67 TELEPHONY_LOGE("The state machine pointer is null"); 68 return false; 69 } 70 TELEPHONY_LOGI("The data connection is disconnected by default"); 71 stateMachine->DeferEvent(std::move(event)); 72 return true; 73 } 74 ProcessDisconnectAllDone(const AppExecFwk::InnerEvent::Pointer & event)75bool Default::ProcessDisconnectAllDone(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("The state machine pointer is null"); 84 return false; 85 } 86 TELEPHONY_LOGI("All data connections are disconnected by default"); 87 stateMachine->DeferEvent(std::move(event)); 88 return true; 89 } 90 ProcessDataConnectionDrsOrRatChanged(const AppExecFwk::InnerEvent::Pointer & event)91bool Default::ProcessDataConnectionDrsOrRatChanged(const AppExecFwk::InnerEvent::Pointer &event) 92 { 93 if (event == nullptr) { 94 TELEPHONY_LOGE("event is null"); 95 return false; 96 } 97 std::shared_ptr<CellularDataStateMachine> stateMachine = stateMachine_.lock(); 98 if (stateMachine == nullptr) { 99 TELEPHONY_LOGE("stateMachine is null"); 100 return false; 101 } 102 TELEPHONY_LOGI("The RAT changes by default"); 103 CellularDataNetAgent &netAgent = CellularDataNetAgent::GetInstance(); 104 int32_t supplierId = netAgent.GetSupplierId(stateMachine->GetSlotId(), stateMachine->GetCapability()); 105 netAgent.UpdateNetSupplierInfo(supplierId, stateMachine->netSupplierInfo_); 106 netAgent.UpdateNetLinkInfo(supplierId, stateMachine->netLinkInfo_); 107 return false; 108 } 109 ProcessDataConnectionRoamOn(const AppExecFwk::InnerEvent::Pointer & event)110bool Default::ProcessDataConnectionRoamOn(const AppExecFwk::InnerEvent::Pointer &event) 111 { 112 TELEPHONY_LOGI("Default::EVENT_DATA_CONNECTION_ROAM_ON"); 113 return false; 114 } 115 ProcessDataConnectionRoamOff(const AppExecFwk::InnerEvent::Pointer & event)116bool Default::ProcessDataConnectionRoamOff(const AppExecFwk::InnerEvent::Pointer &event) 117 { 118 TELEPHONY_LOGI("Default::EVENT_DATA_CONNECTION_ROAM_OFF"); 119 return false; 120 } 121 } // namespace Telephony 122 } // namespace OHOS 123