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_setting_observer.h" 17 18#include "cellular_data_constant.h" 19#include "cellular_data_event_code.h" 20#include "cellular_data_settings_rdb_helper.h" 21#include "telephony_errors.h" 22#include "telephony_log_wrapper.h" 23 24namespace OHOS { 25namespace Telephony { 26CellularDataSettingObserver::CellularDataSettingObserver(std::weak_ptr<TelEventHandler> &&cellularDataHandler) 27 : cellularDataHandler_(std::move(cellularDataHandler)) 28{} 29 30CellularDataSettingObserver::~CellularDataSettingObserver() = default; 31 32void CellularDataSettingObserver::OnChange() 33{ 34 std::shared_ptr<CellularDataSettingsRdbHelper> settingHelper = CellularDataSettingsRdbHelper::GetInstance(); 35 if (settingHelper == nullptr) { 36 return; 37 } 38 Uri uri(CELLULAR_DATA_SETTING_DATA_ENABLE_URI); 39 int value = static_cast<int32_t>(RoamingSwitchCode::CELLULAR_DATA_ROAMING_DISABLED); 40 if (settingHelper->GetValue(uri, CELLULAR_DATA_COLUMN_ENABLE, value) != TELEPHONY_SUCCESS) { 41 TELEPHONY_LOGE("GetValue failed!"); 42 return; 43 } 44 TELEPHONY_LOGI("cellular data switch is %{public}d", value); 45 auto cellularDataHandler = cellularDataHandler_.lock(); 46 if (cellularDataHandler != nullptr) { 47 cellularDataHandler->SendEvent(CellularDataEventCode::MSG_DB_SETTING_ENABLE_CHANGED, value, 0); 48 } 49} 50} // namespace Telephony 51} // namespace OHOS