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 "cellular_data_controller.h"
17
18#include "cellular_data_constant.h"
19#include "common_event_manager.h"
20#include "common_event_support.h"
21#include "core_manager_inner.h"
22#include "network_search_callback.h"
23#include "radio_event.h"
24#include "telephony_log_wrapper.h"
25#include "uri.h"
26
27namespace OHOS {
28namespace Telephony {
29using namespace NetManagerStandard;
30using namespace OHOS::EventFwk;
31
32CellularDataController::CellularDataController(int32_t slotId)
33    : TelEventHandler("CellularDataController"), slotId_(slotId)
34{}
35
36CellularDataController::~CellularDataController()
37{
38    UnRegisterEvents();
39    if (systemAbilityListener_ != nullptr) {
40        auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
41        if (samgrProxy != nullptr) {
42            samgrProxy->UnSubscribeSystemAbility(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID, systemAbilityListener_);
43            samgrProxy->UnSubscribeSystemAbility(COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID, systemAbilityListener_);
44            samgrProxy->UnSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, systemAbilityListener_);
45            samgrProxy->UnSubscribeSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, systemAbilityListener_);
46            systemAbilityListener_ = nullptr;
47        }
48    }
49}
50
51void CellularDataController::Init()
52{
53    EventFwk::MatchingSkills matchingSkills;
54    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED);
55    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
56    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
57    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
58    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
59    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY);
60    EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
61    subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
62    cellularDataHandler_ = std::make_shared<CellularDataHandler>(subscriberInfo, slotId_);
63    if (cellularDataHandler_ == nullptr) {
64        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
65        return;
66    }
67    cellularDataHandler_->Init();
68    auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
69    if (samgrProxy == nullptr) {
70        TELEPHONY_LOGE("samgrProxy is nullptr");
71        return;
72    }
73    systemAbilityListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(slotId_, cellularDataHandler_);
74    if (systemAbilityListener_ == nullptr) {
75        TELEPHONY_LOGE("systemAbilityListener_ is nullptr");
76        return;
77    }
78    samgrProxy->SubscribeSystemAbility(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID, systemAbilityListener_);
79    samgrProxy->SubscribeSystemAbility(COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID, systemAbilityListener_);
80    samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, systemAbilityListener_);
81    samgrProxy->SubscribeSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, systemAbilityListener_);
82}
83
84int32_t CellularDataController::SetCellularDataEnable(bool userDataEnabled)
85{
86    if (cellularDataHandler_ == nullptr) {
87        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
88        return TELEPHONY_ERR_LOCAL_PTR_NULL;
89    }
90    return cellularDataHandler_->SetCellularDataEnable(userDataEnabled);
91}
92
93int32_t CellularDataController::GetIntelligenceSwitchState(bool &switchState)
94{
95    if (cellularDataHandler_ == nullptr) {
96        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
97        return TELEPHONY_ERR_LOCAL_PTR_NULL;
98    }
99    return cellularDataHandler_->GetIntelligenceSwitchState(switchState);
100}
101
102int32_t CellularDataController::SetIntelligenceSwitchEnable(bool userDataEnabled)
103{
104    if (cellularDataHandler_ == nullptr) {
105        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
106        return TELEPHONY_ERR_LOCAL_PTR_NULL;
107    }
108    return cellularDataHandler_->SetIntelligenceSwitchEnable(userDataEnabled);
109}
110
111int32_t CellularDataController::IsCellularDataEnabled(bool &dataEnabled) const
112{
113    if (cellularDataHandler_ == nullptr) {
114        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
115        return TELEPHONY_ERR_LOCAL_PTR_NULL;
116    }
117    return cellularDataHandler_->IsCellularDataEnabled(dataEnabled);
118}
119
120ApnProfileState CellularDataController::GetCellularDataState() const
121{
122    if (cellularDataHandler_ == nullptr) {
123        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
124        return ApnProfileState::PROFILE_STATE_FAILED;
125    }
126    return cellularDataHandler_->GetCellularDataState();
127}
128
129ApnProfileState CellularDataController::GetCellularDataState(const std::string &apnType) const
130{
131    if (cellularDataHandler_ == nullptr) {
132        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
133        return ApnProfileState::PROFILE_STATE_FAILED;
134    }
135    return cellularDataHandler_->GetCellularDataState(apnType);
136}
137
138int32_t CellularDataController::IsCellularDataRoamingEnabled(bool &dataRoamingEnabled) const
139{
140    if (cellularDataHandler_ == nullptr) {
141        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
142        return TELEPHONY_ERR_LOCAL_PTR_NULL;
143    }
144    return cellularDataHandler_->IsCellularDataRoamingEnabled(dataRoamingEnabled);
145}
146
147int32_t CellularDataController::SetCellularDataRoamingEnabled(bool dataRoamingEnabled)
148{
149    if (cellularDataHandler_ == nullptr) {
150        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler is null", slotId_);
151        return TELEPHONY_ERR_LOCAL_PTR_NULL;
152    }
153    return cellularDataHandler_->SetCellularDataRoamingEnabled(dataRoamingEnabled);
154}
155
156bool CellularDataController::ReleaseNet(const NetRequest &request)
157{
158    if (cellularDataHandler_ == nullptr) {
159        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
160        return false;
161    }
162    return cellularDataHandler_->ReleaseNet(request);
163}
164
165bool CellularDataController::RequestNet(const NetRequest &request)
166{
167    if (cellularDataHandler_ == nullptr) {
168        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
169        return false;
170    }
171    return cellularDataHandler_->RequestNet(request);
172}
173
174bool CellularDataController::AddUid(const NetRequest &request)
175{
176    if (cellularDataHandler_ == nullptr) {
177        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
178        return false;
179    }
180    return cellularDataHandler_->AddUid(request);
181}
182
183bool CellularDataController::RemoveUid(const NetRequest &request)
184{
185    if (cellularDataHandler_ == nullptr) {
186        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
187        return false;
188    }
189    return cellularDataHandler_->RemoveUid(request);
190}
191
192void CellularDataController::AsynchronousRegister()
193{
194    if (CoreManagerInner::GetInstance().IsInitFinished()) {
195        TELEPHONY_LOGI("Slot%{public}d: core inited", slotId_);
196        Init();
197        RegisterEvents();
198        return;
199    }
200    SendEvent(CellularDataEventCode::MSG_ASYNCHRONOUS_REGISTER_EVENT_ID, CORE_INIT_DELAY_TIME, Priority::HIGH);
201}
202
203void CellularDataController::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
204{
205    if (event == nullptr) {
206        TELEPHONY_LOGE("Slot%{public}d: event is null.", slotId_);
207        return;
208    }
209    size_t eventId = event->GetInnerEventId();
210    switch (eventId) {
211        case CellularDataEventCode::MSG_ASYNCHRONOUS_REGISTER_EVENT_ID:
212            AsynchronousRegister();
213            break;
214        default:
215            TELEPHONY_LOGE("Slot%{public}d: nothing to do", slotId_);
216            break;
217    }
218}
219
220void CellularDataController::RegisterEvents()
221{
222    if (cellularDataHandler_ == nullptr) {
223        TELEPHONY_LOGE("Slot%{public}d: core is null or cellularDataHandler is null", slotId_);
224        return;
225    }
226    TELEPHONY_LOGI("Slot%{public}d: start", slotId_);
227    CoreManagerInner &coreInner = CoreManagerInner::GetInstance();
228    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_STATE_CHANGE, nullptr);
229    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_RECORDS_LOADED, nullptr);
230    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_ACCOUNT_LOADED, nullptr);
231    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_ATTACHED, nullptr);
232    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_DETACHED, nullptr);
233    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_ROAMING_OPEN, nullptr);
234    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_ROAMING_CLOSE, nullptr);
235    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_STATE_CHANGED, nullptr);
236    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_DSDS_MODE_CHANGED, nullptr);
237    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_RAT_CHANGED, nullptr);
238    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_CALL_STATUS_INFO, nullptr);
239    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_EMERGENCY_STATE_OPEN, nullptr);
240    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_EMERGENCY_STATE_CLOSE, nullptr);
241    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NR_STATE_CHANGED, nullptr);
242    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NR_FREQUENCY_CHANGED, nullptr);
243    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED, nullptr);
244    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_FACTORY_RESET, nullptr);
245    coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NV_REFRESH_FINISHED, nullptr);
246
247    if (slotId_ == 0) {
248        sptr<NetworkSearchCallback> networkSearchCallback = std::make_unique<NetworkSearchCallback>().release();
249        if (networkSearchCallback != nullptr) {
250            coreInner.RegisterCellularDataObject(networkSearchCallback);
251        } else {
252            TELEPHONY_LOGE("Slot%{public}d: networkSearchCallback is null", slotId_);
253        }
254    }
255    coreInner.CleanAllConnections(slotId_, RadioEvent::RADIO_CLEAN_ALL_DATA_CONNECTIONS, cellularDataHandler_);
256}
257
258void CellularDataController::UnRegisterEvents()
259{
260    if (cellularDataHandler_ == nullptr) {
261        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
262        return;
263    }
264    TELEPHONY_LOGI("Slot%{public}d: start", slotId_);
265    CoreManagerInner &coreInner = CoreManagerInner::GetInstance();
266    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_STATE_CHANGE);
267    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_RECORDS_LOADED);
268    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_ACCOUNT_LOADED);
269    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_ATTACHED);
270    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_DETACHED);
271    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_ROAMING_OPEN);
272    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_ROAMING_CLOSE);
273    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_STATE_CHANGED);
274    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_DSDS_MODE_CHANGED);
275    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_RAT_CHANGED);
276    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_CALL_STATUS_INFO);
277    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_EMERGENCY_STATE_OPEN);
278    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_EMERGENCY_STATE_CLOSE);
279    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NR_STATE_CHANGED);
280    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NR_FREQUENCY_CHANGED);
281    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED);
282    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_FACTORY_RESET);
283    coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NV_REFRESH_FINISHED);
284    TELEPHONY_LOGI("Slot%{public}d: end", slotId_);
285}
286
287bool CellularDataController::HandleApnChanged()
288{
289    if (cellularDataHandler_ == nullptr) {
290        TELEPHONY_LOGE("Slot%{public}d: ApnChanged cellularDataHandler_ is null", slotId_);
291        return static_cast<int32_t>(DataRespondCode::SET_FAILED);
292    }
293    return cellularDataHandler_->HandleApnChanged();
294}
295
296int32_t CellularDataController::GetCellularDataFlowType()
297{
298    if (cellularDataHandler_ == nullptr) {
299        TELEPHONY_LOGE("Slot%{public}d: cellular data handler is null", slotId_);
300        return static_cast<int32_t>(CellDataFlowType::DATA_FLOW_TYPE_NONE);
301    }
302    return cellularDataHandler_->GetCellularDataFlowType();
303}
304
305int32_t CellularDataController::SetPolicyDataOn(bool enable)
306{
307    if (cellularDataHandler_ != nullptr) {
308        cellularDataHandler_->SetPolicyDataOn(enable);
309    }
310    return static_cast<int32_t>(DataRespondCode::SET_SUCCESS);
311}
312
313bool CellularDataController::IsRestrictedMode() const
314{
315    if (cellularDataHandler_ != nullptr) {
316        return cellularDataHandler_->IsRestrictedMode();
317    }
318    return false;
319}
320
321DisConnectionReason CellularDataController::GetDisConnectionReason()
322{
323    if (cellularDataHandler_ != nullptr) {
324        return cellularDataHandler_->GetDisConnectionReason();
325    }
326    return DisConnectionReason::REASON_NORMAL;
327}
328
329bool CellularDataController::HasInternetCapability(const int32_t cid) const
330{
331    if (cellularDataHandler_ == nullptr) {
332        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler_ is null", slotId_);
333        return false;
334    }
335    return cellularDataHandler_->HasInternetCapability(cid);
336}
337
338bool CellularDataController::ChangeConnectionForDsds(bool enable) const
339{
340    if (cellularDataHandler_ == nullptr) {
341        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler is null", slotId_);
342        return false;
343    }
344    cellularDataHandler_->ChangeConnectionForDsds(enable);
345    return true;
346}
347
348bool CellularDataController::ClearAllConnections(DisConnectionReason reason) const
349{
350    if (cellularDataHandler_ == nullptr) {
351        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler is null", slotId_);
352        return false;
353    }
354    cellularDataHandler_->ClearAllConnections(reason);
355    return true;
356}
357
358CellularDataController::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
359    int32_t slotId, std::shared_ptr<CellularDataHandler> handler)
360    : slotId_(slotId), handler_(handler)
361{}
362
363void CellularDataController::SystemAbilityStatusChangeListener::OnAddSystemAbility(
364    int32_t systemAbilityId, const std::string &deviceId)
365{
366    switch (systemAbilityId) {
367        case COMM_NET_CONN_MANAGER_SYS_ABILITY_ID:
368            TELEPHONY_LOGI("COMM_NET_CONN_MANAGER_SYS_ABILITY_ID running");
369            CellularDataNetAgent::GetInstance().RegisterNetSupplier(slotId_);
370            if (handler_ != nullptr) {
371                bool ret = handler_->UpdateNetworkInfo();
372                TELEPHONY_LOGI("UpdateNetworkInfo result = %{public}d", ret);
373            }
374            break;
375        case COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID:
376            TELEPHONY_LOGI("COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID running");
377            if (slotId_ == 0) {
378                CellularDataNetAgent::GetInstance().UnregisterPolicyCallback();
379                CellularDataNetAgent::GetInstance().RegisterPolicyCallback();
380            }
381            break;
382        case COMMON_EVENT_SERVICE_ID:
383            TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID running");
384            if (handler_ != nullptr) {
385                bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(handler_);
386                TELEPHONY_LOGI("subscribeResult = %{public}d", subscribeResult);
387            }
388            break;
389        case DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID:
390            TELEPHONY_LOGI("DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID running");
391            if (handler_ != nullptr) {
392                handler_->RegisterDataSettingObserver();
393                handler_->SendEvent(CellularDataEventCode::MSG_DB_SETTING_ENABLE_CHANGED, 0, 0);
394            }
395            break;
396        default:
397            TELEPHONY_LOGE("systemAbilityId is invalid");
398            break;
399    }
400}
401
402void CellularDataController::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
403    int32_t systemAbilityId, const std::string &deviceId)
404{
405    switch (systemAbilityId) {
406        case COMM_NET_CONN_MANAGER_SYS_ABILITY_ID:
407            TELEPHONY_LOGE("COMM_NET_CONN_MANAGER_SYS_ABILITY_ID stopped");
408            break;
409        case COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID:
410            TELEPHONY_LOGE("COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID stopped");
411            break;
412        case COMMON_EVENT_SERVICE_ID:
413            TELEPHONY_LOGE("COMMON_EVENT_SERVICE_ID stopped");
414            if (handler_ != nullptr) {
415                bool unSubscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(handler_);
416                TELEPHONY_LOGI("unSubscribeResult = %{public}d", unSubscribeResult);
417            }
418            break;
419        case DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID:
420            TELEPHONY_LOGE("DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID stopped");
421            break;
422        default:
423            TELEPHONY_LOGE("systemAbilityId is invalid");
424            break;
425    }
426}
427
428void CellularDataController::GetDataConnApnAttr(ApnItem::Attribute &apnAttr) const
429{
430    if (cellularDataHandler_ == nullptr) {
431        TELEPHONY_LOGE("Slot%{public}d: GetDataConnApnAttr cellularDataHandler_ is null", slotId_);
432        return;
433    }
434    cellularDataHandler_->GetDataConnApnAttr(apnAttr);
435}
436
437std::string CellularDataController::GetDataConnIpType() const
438{
439    if (cellularDataHandler_ == nullptr) {
440        TELEPHONY_LOGE("Slot%{public}d: GetDataConnIpType cellularDataHandler_ is null", slotId_);
441        return "";
442    }
443    return cellularDataHandler_->GetDataConnIpType();
444}
445
446int32_t CellularDataController::GetDataRecoveryState()
447{
448    if (cellularDataHandler_ == nullptr) {
449        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler is null", slotId_);
450        return false;
451    }
452    return cellularDataHandler_->GetDataRecoveryState();
453}
454
455void CellularDataController::IsNeedDoRecovery(bool needDoRecovery) const
456{
457    if (cellularDataHandler_ == nullptr) {
458        TELEPHONY_LOGE("Slot%{public}d: IsNeedDoRecovery cellularDataHandler_ is null", slotId_);
459        return;
460    }
461    cellularDataHandler_->IsNeedDoRecovery(needDoRecovery);
462}
463
464bool CellularDataController::EstablishAllApnsIfConnectable() const
465{
466    if (cellularDataHandler_ == nullptr) {
467        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler is null", slotId_);
468        return false;
469    }
470    TELEPHONY_LOGI("EstablishAllApnsIfConnectable slot%{public}d", slotId_);
471    cellularDataHandler_->EstablishAllApnsIfConnectable();
472    return true;
473}
474
475bool CellularDataController::ReleaseCellularDataConnection() const
476{
477    if (cellularDataHandler_ == nullptr) {
478        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler is null", slotId_);
479        return false;
480    }
481    TELEPHONY_LOGI("ReleaseCellularDataConnection slot%{public}d", slotId_);
482    cellularDataHandler_->ReleaseCellularDataConnection();
483    return true;
484}
485
486bool CellularDataController::UpdateNetworkInfo()
487{
488    if (cellularDataHandler_ == nullptr) {
489        TELEPHONY_LOGE("Slot%{public}d: cellularDataHandler is null", slotId_);
490        return false;
491    }
492    return cellularDataHandler_->UpdateNetworkInfo();
493}
494
495} // namespace Telephony
496} // namespace OHOS
497