15b8fca66Sopenharmony_ci/* 25b8fca66Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 35b8fca66Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45b8fca66Sopenharmony_ci * you may not use this file except in compliance with the License. 55b8fca66Sopenharmony_ci * You may obtain a copy of the License at 65b8fca66Sopenharmony_ci * 75b8fca66Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85b8fca66Sopenharmony_ci * 95b8fca66Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105b8fca66Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115b8fca66Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125b8fca66Sopenharmony_ci * See the License for the specific language governing permissions and 135b8fca66Sopenharmony_ci * limitations under the License. 145b8fca66Sopenharmony_ci */ 155b8fca66Sopenharmony_ci 165b8fca66Sopenharmony_ci#include "telephony_state_registry_stub.h" 175b8fca66Sopenharmony_ci 185b8fca66Sopenharmony_ci#include "ipc_skeleton.h" 195b8fca66Sopenharmony_ci#include "string_ex.h" 205b8fca66Sopenharmony_ci 215b8fca66Sopenharmony_ci#include "sim_state_type.h" 225b8fca66Sopenharmony_ci#include "state_registry_errors.h" 235b8fca66Sopenharmony_ci#include "telephony_permission.h" 245b8fca66Sopenharmony_ci 255b8fca66Sopenharmony_ci#ifdef HICOLLIE_ENABLE 265b8fca66Sopenharmony_ci#include "xcollie/xcollie.h" 275b8fca66Sopenharmony_ci#include "xcollie/xcollie_define.h" 285b8fca66Sopenharmony_ci#define XCOLLIE_TIMEOUT_SECONDS 30 295b8fca66Sopenharmony_ci#endif 305b8fca66Sopenharmony_ci 315b8fca66Sopenharmony_cinamespace OHOS { 325b8fca66Sopenharmony_cinamespace Telephony { 335b8fca66Sopenharmony_ciTelephonyStateRegistryStub::TelephonyStateRegistryStub() 345b8fca66Sopenharmony_ci{ 355b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::CELL_INFO] = 365b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCellInfo(data, reply); }; 375b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::SIM_STATE] = 385b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateSimState(data, reply); }; 395b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::SIGNAL_INFO] = 405b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateSignalInfo(data, reply); }; 415b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::NET_WORK_STATE] = 425b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateNetworkState(data, reply); }; 435b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::CALL_STATE] = 445b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCallState(data, reply); }; 455b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::CALL_STATE_FOR_ID] = 465b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCallStateForSlotId(data, reply); }; 475b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::CELLULAR_DATA_STATE] = 485b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCellularDataConnectState(data, reply); }; 495b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::CELLULAR_DATA_FLOW] = 505b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCellularDataFlow(data, reply); }; 515b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::ADD_OBSERVER] = 525b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnRegisterStateChange(data, reply); }; 535b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::REMOVE_OBSERVER] = 545b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUnregisterStateChange(data, reply); }; 555b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::CFU_INDICATOR] = 565b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCfuIndicator(data, reply); }; 575b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::VOICE_MAIL_MSG_INDICATOR] = 585b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateVoiceMailMsgIndicator(data, reply); }; 595b8fca66Sopenharmony_ci memberFuncMap_[StateNotifyInterfaceCode::ICC_ACCOUNT_CHANGE] = 605b8fca66Sopenharmony_ci [this](MessageParcel &data, MessageParcel &reply) { return OnIccAccountUpdated(data, reply); }; 615b8fca66Sopenharmony_ci} 625b8fca66Sopenharmony_ci 635b8fca66Sopenharmony_ciTelephonyStateRegistryStub::~TelephonyStateRegistryStub() 645b8fca66Sopenharmony_ci{ 655b8fca66Sopenharmony_ci memberFuncMap_.clear(); 665b8fca66Sopenharmony_ci} 675b8fca66Sopenharmony_ci 685b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnRemoteRequest( 695b8fca66Sopenharmony_ci uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 705b8fca66Sopenharmony_ci{ 715b8fca66Sopenharmony_ci TELEPHONY_LOGD("TelephonyStateRegistryStub::OnRemoteRequest start##code = %{public}u", code); 725b8fca66Sopenharmony_ci std::u16string myToken = TelephonyStateRegistryStub::GetDescriptor(); 735b8fca66Sopenharmony_ci std::u16string remoteToken = data.ReadInterfaceToken(); 745b8fca66Sopenharmony_ci if (myToken != remoteToken) { 755b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnRemoteRequest end##descriptor checked fail"); 765b8fca66Sopenharmony_ci return TELEPHONY_ERR_DESCRIPTOR_MISMATCH; 775b8fca66Sopenharmony_ci } 785b8fca66Sopenharmony_ci auto itFunc = memberFuncMap_.find(static_cast<StateNotifyInterfaceCode>(code)); 795b8fca66Sopenharmony_ci if (itFunc != memberFuncMap_.end()) { 805b8fca66Sopenharmony_ci auto memberFunc = itFunc->second; 815b8fca66Sopenharmony_ci if (memberFunc != nullptr) { 825b8fca66Sopenharmony_ci int32_t idTimer = SetTimer(code); 835b8fca66Sopenharmony_ci int32_t result = memberFunc(data, reply); 845b8fca66Sopenharmony_ci CancelTimer(idTimer); 855b8fca66Sopenharmony_ci return result; 865b8fca66Sopenharmony_ci } 875b8fca66Sopenharmony_ci } 885b8fca66Sopenharmony_ci int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); 895b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnRemoteRequest end##ret=%{public}d", ret); 905b8fca66Sopenharmony_ci return ret; 915b8fca66Sopenharmony_ci} 925b8fca66Sopenharmony_ci 935b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::SetTimer(uint32_t code) 945b8fca66Sopenharmony_ci{ 955b8fca66Sopenharmony_ci#ifdef HICOLLIE_ENABLE 965b8fca66Sopenharmony_ci int32_t idTimer = HiviewDFX::INVALID_ID; 975b8fca66Sopenharmony_ci std::map<uint32_t, std::string>::iterator itCollieId = collieCodeStringMap_.find(code); 985b8fca66Sopenharmony_ci if (itCollieId != collieCodeStringMap_.end()) { 995b8fca66Sopenharmony_ci std::string collieStr = itCollieId->second; 1005b8fca66Sopenharmony_ci std::string collieName = "TelephonyStateRegistryStub: " + collieStr; 1015b8fca66Sopenharmony_ci unsigned int flag = HiviewDFX::XCOLLIE_FLAG_NOOP; 1025b8fca66Sopenharmony_ci auto TimerCallback = [collieStr](void *) { 1035b8fca66Sopenharmony_ci TELEPHONY_LOGE("OnRemoteRequest timeout func: %{public}s", collieStr.c_str()); 1045b8fca66Sopenharmony_ci }; 1055b8fca66Sopenharmony_ci idTimer = HiviewDFX::XCollie::GetInstance().SetTimer( 1065b8fca66Sopenharmony_ci collieName, XCOLLIE_TIMEOUT_SECONDS, TimerCallback, nullptr, flag); 1075b8fca66Sopenharmony_ci TELEPHONY_LOGD("SetTimer id: %{public}d, name: %{public}s.", idTimer, collieStr.c_str()); 1085b8fca66Sopenharmony_ci } 1095b8fca66Sopenharmony_ci return idTimer; 1105b8fca66Sopenharmony_ci#else 1115b8fca66Sopenharmony_ci TELEPHONY_LOGD("No HICOLLIE_ENABLE"); 1125b8fca66Sopenharmony_ci return -1; 1135b8fca66Sopenharmony_ci#endif 1145b8fca66Sopenharmony_ci} 1155b8fca66Sopenharmony_ci 1165b8fca66Sopenharmony_civoid TelephonyStateRegistryStub::CancelTimer(int32_t id) 1175b8fca66Sopenharmony_ci{ 1185b8fca66Sopenharmony_ci#ifdef HICOLLIE_ENABLE 1195b8fca66Sopenharmony_ci if (id == HiviewDFX::INVALID_ID) { 1205b8fca66Sopenharmony_ci return; 1215b8fca66Sopenharmony_ci } 1225b8fca66Sopenharmony_ci TELEPHONY_LOGD("CancelTimer id: %{public}d.", id); 1235b8fca66Sopenharmony_ci HiviewDFX::XCollie::GetInstance().CancelTimer(id); 1245b8fca66Sopenharmony_ci#else 1255b8fca66Sopenharmony_ci return; 1265b8fca66Sopenharmony_ci#endif 1275b8fca66Sopenharmony_ci} 1285b8fca66Sopenharmony_ci 1295b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateCallState(MessageParcel &data, MessageParcel &reply) 1305b8fca66Sopenharmony_ci{ 1315b8fca66Sopenharmony_ci int32_t callState = data.ReadInt32(); 1325b8fca66Sopenharmony_ci std::u16string phoneNumber = data.ReadString16(); 1335b8fca66Sopenharmony_ci int32_t ret = UpdateCallState(callState, phoneNumber); 1345b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateCallState end##ret=%{public}d", ret); 1355b8fca66Sopenharmony_ci reply.WriteInt32(ret); 1365b8fca66Sopenharmony_ci return NO_ERROR; 1375b8fca66Sopenharmony_ci} 1385b8fca66Sopenharmony_ci 1395b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateSimState(MessageParcel &data, MessageParcel &reply) 1405b8fca66Sopenharmony_ci{ 1415b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 1425b8fca66Sopenharmony_ci CardType type = static_cast<CardType>(data.ReadInt32()); 1435b8fca66Sopenharmony_ci SimState state = static_cast<SimState>(data.ReadInt32()); 1445b8fca66Sopenharmony_ci LockReason reason = static_cast<LockReason>(data.ReadInt32()); 1455b8fca66Sopenharmony_ci int32_t ret = UpdateSimState(slotId, type, state, reason); 1465b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateSimState end##ret=%{public}d", ret); 1475b8fca66Sopenharmony_ci reply.WriteInt32(ret); 1485b8fca66Sopenharmony_ci return NO_ERROR; 1495b8fca66Sopenharmony_ci} 1505b8fca66Sopenharmony_ci 1515b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateCallStateForSlotId(MessageParcel &data, MessageParcel &reply) 1525b8fca66Sopenharmony_ci{ 1535b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 1545b8fca66Sopenharmony_ci int32_t callState = data.ReadInt32(); 1555b8fca66Sopenharmony_ci std::u16string incomingNumber = data.ReadString16(); 1565b8fca66Sopenharmony_ci int32_t ret = UpdateCallStateForSlotId(slotId, callState, incomingNumber); 1575b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateCallStateForSlotId end##ret=%{public}d", ret); 1585b8fca66Sopenharmony_ci reply.WriteInt32(ret); 1595b8fca66Sopenharmony_ci return NO_ERROR; 1605b8fca66Sopenharmony_ci} 1615b8fca66Sopenharmony_ci 1625b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateCellularDataConnectState(MessageParcel &data, MessageParcel &reply) 1635b8fca66Sopenharmony_ci{ 1645b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 1655b8fca66Sopenharmony_ci int32_t dataState = data.ReadInt32(); 1665b8fca66Sopenharmony_ci int32_t networkType = data.ReadInt32(); 1675b8fca66Sopenharmony_ci int32_t ret = UpdateCellularDataConnectState(slotId, dataState, networkType); 1685b8fca66Sopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 1695b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnUpdateCellularDataConnectState end fail##ret=%{public}d", ret); 1705b8fca66Sopenharmony_ci } 1715b8fca66Sopenharmony_ci reply.WriteInt32(ret); 1725b8fca66Sopenharmony_ci return NO_ERROR; 1735b8fca66Sopenharmony_ci} 1745b8fca66Sopenharmony_ci 1755b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateCellularDataFlow(MessageParcel &data, MessageParcel &reply) 1765b8fca66Sopenharmony_ci{ 1775b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 1785b8fca66Sopenharmony_ci int32_t flowData = data.ReadInt32(); 1795b8fca66Sopenharmony_ci int32_t ret = UpdateCellularDataFlow(slotId, flowData); 1805b8fca66Sopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 1815b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnUpdateCellularDataFlow end fail##ret=%{public}d", ret); 1825b8fca66Sopenharmony_ci } 1835b8fca66Sopenharmony_ci reply.WriteInt32(ret); 1845b8fca66Sopenharmony_ci return NO_ERROR; 1855b8fca66Sopenharmony_ci} 1865b8fca66Sopenharmony_ci 1875b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateSignalInfo(MessageParcel &data, MessageParcel &reply) 1885b8fca66Sopenharmony_ci{ 1895b8fca66Sopenharmony_ci int32_t ret = TELEPHONY_SUCCESS; 1905b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 1915b8fca66Sopenharmony_ci int32_t size = data.ReadInt32(); 1925b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateSignalInfo size=%{public}d", size); 1935b8fca66Sopenharmony_ci size = ((size > SignalInformation::MAX_SIGNAL_NUM) ? 0 : size); 1945b8fca66Sopenharmony_ci if (size < 0) { 1955b8fca66Sopenharmony_ci ret = TELEPHONY_ERR_FAIL; 1965b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnUpdateSignalInfo size < 0"); 1975b8fca66Sopenharmony_ci return ret; 1985b8fca66Sopenharmony_ci } 1995b8fca66Sopenharmony_ci std::vector<sptr<SignalInformation>> result; 2005b8fca66Sopenharmony_ci parseSignalInfos(data, size, result); 2015b8fca66Sopenharmony_ci ret = UpdateSignalInfo(slotId, result); 2025b8fca66Sopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 2035b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnUpdateSignalInfo end fail##ret=%{public}d", ret); 2045b8fca66Sopenharmony_ci } 2055b8fca66Sopenharmony_ci reply.WriteInt32(ret); 2065b8fca66Sopenharmony_ci return NO_ERROR; 2075b8fca66Sopenharmony_ci} 2085b8fca66Sopenharmony_ci 2095b8fca66Sopenharmony_civoid TelephonyStateRegistryStub::parseSignalInfos( 2105b8fca66Sopenharmony_ci MessageParcel &data, const int32_t size, std::vector<sptr<SignalInformation>> &result) 2115b8fca66Sopenharmony_ci{ 2125b8fca66Sopenharmony_ci SignalInformation::NetworkType type; 2135b8fca66Sopenharmony_ci for (int i = 0; i < size; ++i) { 2145b8fca66Sopenharmony_ci type = static_cast<SignalInformation::NetworkType>(data.ReadInt32()); 2155b8fca66Sopenharmony_ci switch (type) { 2165b8fca66Sopenharmony_ci case SignalInformation::NetworkType::GSM: { 2175b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::parseSignalInfos NetworkType::GSM"); 2185b8fca66Sopenharmony_ci std::unique_ptr<GsmSignalInformation> signal = std::make_unique<GsmSignalInformation>(); 2195b8fca66Sopenharmony_ci if (signal != nullptr) { 2205b8fca66Sopenharmony_ci signal->ReadFromParcel(data); 2215b8fca66Sopenharmony_ci result.emplace_back(signal.release()); 2225b8fca66Sopenharmony_ci } 2235b8fca66Sopenharmony_ci break; 2245b8fca66Sopenharmony_ci } 2255b8fca66Sopenharmony_ci case SignalInformation::NetworkType::CDMA: { 2265b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::parseSignalInfos NetworkType::CDMA"); 2275b8fca66Sopenharmony_ci std::unique_ptr<CdmaSignalInformation> signal = std::make_unique<CdmaSignalInformation>(); 2285b8fca66Sopenharmony_ci if (signal != nullptr) { 2295b8fca66Sopenharmony_ci signal->ReadFromParcel(data); 2305b8fca66Sopenharmony_ci result.emplace_back(signal.release()); 2315b8fca66Sopenharmony_ci } 2325b8fca66Sopenharmony_ci break; 2335b8fca66Sopenharmony_ci } 2345b8fca66Sopenharmony_ci case SignalInformation::NetworkType::LTE: 2355b8fca66Sopenharmony_ci [[fallthrough]]; // fall_through 2365b8fca66Sopenharmony_ci case SignalInformation::NetworkType::NR: { 2375b8fca66Sopenharmony_ci ParseLteNrSignalInfos(data, result, type); 2385b8fca66Sopenharmony_ci break; 2395b8fca66Sopenharmony_ci } 2405b8fca66Sopenharmony_ci case SignalInformation::NetworkType::WCDMA: { 2415b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::parseSignalInfos NetworkType::Wcdma"); 2425b8fca66Sopenharmony_ci std::unique_ptr<WcdmaSignalInformation> signal = std::make_unique<WcdmaSignalInformation>(); 2435b8fca66Sopenharmony_ci if (signal != nullptr) { 2445b8fca66Sopenharmony_ci signal->ReadFromParcel(data); 2455b8fca66Sopenharmony_ci result.emplace_back(signal.release()); 2465b8fca66Sopenharmony_ci } 2475b8fca66Sopenharmony_ci break; 2485b8fca66Sopenharmony_ci } 2495b8fca66Sopenharmony_ci default: 2505b8fca66Sopenharmony_ci break; 2515b8fca66Sopenharmony_ci } 2525b8fca66Sopenharmony_ci } 2535b8fca66Sopenharmony_ci} 2545b8fca66Sopenharmony_ci 2555b8fca66Sopenharmony_civoid TelephonyStateRegistryStub::ParseLteNrSignalInfos( 2565b8fca66Sopenharmony_ci MessageParcel &data, std::vector<sptr<SignalInformation>> &result, SignalInformation::NetworkType type) 2575b8fca66Sopenharmony_ci{ 2585b8fca66Sopenharmony_ci switch (type) { 2595b8fca66Sopenharmony_ci case SignalInformation::NetworkType::LTE: { 2605b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::ParseLteNrSignalInfos NetworkType::LTE"); 2615b8fca66Sopenharmony_ci std::unique_ptr<LteSignalInformation> signal = std::make_unique<LteSignalInformation>(); 2625b8fca66Sopenharmony_ci if (signal != nullptr) { 2635b8fca66Sopenharmony_ci signal->ReadFromParcel(data); 2645b8fca66Sopenharmony_ci result.emplace_back(signal.release()); 2655b8fca66Sopenharmony_ci } 2665b8fca66Sopenharmony_ci break; 2675b8fca66Sopenharmony_ci } 2685b8fca66Sopenharmony_ci case SignalInformation::NetworkType::NR: { 2695b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::ParseSignalInfos"); 2705b8fca66Sopenharmony_ci std::unique_ptr<NrSignalInformation> signal = std::make_unique<NrSignalInformation>(); 2715b8fca66Sopenharmony_ci if (signal != nullptr) { 2725b8fca66Sopenharmony_ci signal->ReadFromParcel(data); 2735b8fca66Sopenharmony_ci result.emplace_back(signal.release()); 2745b8fca66Sopenharmony_ci } 2755b8fca66Sopenharmony_ci break; 2765b8fca66Sopenharmony_ci } 2775b8fca66Sopenharmony_ci default: 2785b8fca66Sopenharmony_ci break; 2795b8fca66Sopenharmony_ci } 2805b8fca66Sopenharmony_ci} 2815b8fca66Sopenharmony_ci 2825b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateCellInfo(MessageParcel &data, MessageParcel &reply) 2835b8fca66Sopenharmony_ci{ 2845b8fca66Sopenharmony_ci int32_t ret = TELEPHONY_SUCCESS; 2855b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 2865b8fca66Sopenharmony_ci int32_t size = data.ReadInt32(); 2875b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub OnUpdateCellInfo:size=%{public}d", size); 2885b8fca66Sopenharmony_ci size = ((size > CellInformation::MAX_CELL_NUM) ? 0 : size); 2895b8fca66Sopenharmony_ci if (size <= 0) { 2905b8fca66Sopenharmony_ci ret = TELEPHONY_ERR_FAIL; 2915b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub the size less than or equal to 0!"); 2925b8fca66Sopenharmony_ci return ret; 2935b8fca66Sopenharmony_ci } 2945b8fca66Sopenharmony_ci std::vector<sptr<CellInformation>> cells; 2955b8fca66Sopenharmony_ci CellInformation::CellType type; 2965b8fca66Sopenharmony_ci for (int i = 0; i < size; ++i) { 2975b8fca66Sopenharmony_ci type = static_cast<CellInformation::CellType>(data.ReadInt32()); 2985b8fca66Sopenharmony_ci switch (type) { 2995b8fca66Sopenharmony_ci case CellInformation::CellType::CELL_TYPE_GSM: { 3005b8fca66Sopenharmony_ci std::unique_ptr<GsmCellInformation> cell = std::make_unique<GsmCellInformation>(); 3015b8fca66Sopenharmony_ci if (cell != nullptr) { 3025b8fca66Sopenharmony_ci cell->ReadFromParcel(data); 3035b8fca66Sopenharmony_ci cells.emplace_back(cell.release()); 3045b8fca66Sopenharmony_ci } 3055b8fca66Sopenharmony_ci break; 3065b8fca66Sopenharmony_ci } 3075b8fca66Sopenharmony_ci case CellInformation::CellType::CELL_TYPE_LTE: { 3085b8fca66Sopenharmony_ci std::unique_ptr<LteCellInformation> cell = std::make_unique<LteCellInformation>(); 3095b8fca66Sopenharmony_ci if (cell != nullptr) { 3105b8fca66Sopenharmony_ci cell->ReadFromParcel(data); 3115b8fca66Sopenharmony_ci cells.emplace_back(cell.release()); 3125b8fca66Sopenharmony_ci } 3135b8fca66Sopenharmony_ci break; 3145b8fca66Sopenharmony_ci } 3155b8fca66Sopenharmony_ci case CellInformation::CellType::CELL_TYPE_NR: { 3165b8fca66Sopenharmony_ci std::unique_ptr<NrCellInformation> cell = std::make_unique<NrCellInformation>(); 3175b8fca66Sopenharmony_ci if (cell != nullptr) { 3185b8fca66Sopenharmony_ci cell->ReadFromParcel(data); 3195b8fca66Sopenharmony_ci cells.emplace_back(cell.release()); 3205b8fca66Sopenharmony_ci } 3215b8fca66Sopenharmony_ci break; 3225b8fca66Sopenharmony_ci } 3235b8fca66Sopenharmony_ci default: 3245b8fca66Sopenharmony_ci break; 3255b8fca66Sopenharmony_ci } 3265b8fca66Sopenharmony_ci } 3275b8fca66Sopenharmony_ci ret = UpdateCellInfo(slotId, cells); 3285b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateCellInfo end##ret=%{public}d", ret); 3295b8fca66Sopenharmony_ci reply.WriteInt32(ret); 3305b8fca66Sopenharmony_ci return NO_ERROR; 3315b8fca66Sopenharmony_ci} 3325b8fca66Sopenharmony_ci 3335b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateNetworkState(MessageParcel &data, MessageParcel &reply) 3345b8fca66Sopenharmony_ci{ 3355b8fca66Sopenharmony_ci int32_t ret = TELEPHONY_SUCCESS; 3365b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 3375b8fca66Sopenharmony_ci sptr<NetworkState> result = NetworkState::Unmarshalling(data); 3385b8fca66Sopenharmony_ci if (result == nullptr) { 3395b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnUpdateNetworkState GetNetworkStatus is null"); 3405b8fca66Sopenharmony_ci ret = TELEPHONY_ERR_FAIL; 3415b8fca66Sopenharmony_ci return ret; 3425b8fca66Sopenharmony_ci } 3435b8fca66Sopenharmony_ci ret = UpdateNetworkState(slotId, result); 3445b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateNetworkState end##ret=%{public}d", ret); 3455b8fca66Sopenharmony_ci reply.WriteInt32(ret); 3465b8fca66Sopenharmony_ci return NO_ERROR; 3475b8fca66Sopenharmony_ci} 3485b8fca66Sopenharmony_ci 3495b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnRegisterStateChange(MessageParcel &data, MessageParcel &reply) 3505b8fca66Sopenharmony_ci{ 3515b8fca66Sopenharmony_ci int32_t ret = TELEPHONY_SUCCESS; 3525b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 3535b8fca66Sopenharmony_ci int32_t mask = data.ReadInt32(); 3545b8fca66Sopenharmony_ci bool notifyNow = data.ReadBool(); 3555b8fca66Sopenharmony_ci sptr<TelephonyObserverBroker> callback = nullptr; 3565b8fca66Sopenharmony_ci ret = ReadData(data, reply, callback); 3575b8fca66Sopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 3585b8fca66Sopenharmony_ci reply.WriteInt32(ret); 3595b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnRegisterStateChange ReadData failed"); 3605b8fca66Sopenharmony_ci return NO_ERROR; 3615b8fca66Sopenharmony_ci } 3625b8fca66Sopenharmony_ci ret = RegisterStateChange(callback, slotId, mask, notifyNow); 3635b8fca66Sopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 3645b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnRegisterStateChange end fail##ret=%{public}d", ret); 3655b8fca66Sopenharmony_ci } 3665b8fca66Sopenharmony_ci reply.WriteInt32(ret); 3675b8fca66Sopenharmony_ci return NO_ERROR; 3685b8fca66Sopenharmony_ci} 3695b8fca66Sopenharmony_ci 3705b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUnregisterStateChange(MessageParcel &data, MessageParcel &reply) 3715b8fca66Sopenharmony_ci{ 3725b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 3735b8fca66Sopenharmony_ci int32_t mask = data.ReadInt32(); 3745b8fca66Sopenharmony_ci int32_t ret = UnregisterStateChange(slotId, mask); 3755b8fca66Sopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 3765b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::OnUnregisterStateChange end fail##ret=%{public}d", ret); 3775b8fca66Sopenharmony_ci } 3785b8fca66Sopenharmony_ci reply.WriteInt32(ret); 3795b8fca66Sopenharmony_ci return NO_ERROR; 3805b8fca66Sopenharmony_ci} 3815b8fca66Sopenharmony_ci 3825b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::ReadData( 3835b8fca66Sopenharmony_ci MessageParcel &data, MessageParcel &reply, sptr<TelephonyObserverBroker> &callback) 3845b8fca66Sopenharmony_ci{ 3855b8fca66Sopenharmony_ci int32_t result = TELEPHONY_SUCCESS; 3865b8fca66Sopenharmony_ci sptr<IRemoteObject> remote = data.ReadRemoteObject(); 3875b8fca66Sopenharmony_ci if (remote == nullptr) { 3885b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::ReadData remote is nullptr."); 3895b8fca66Sopenharmony_ci result = TELEPHONY_ERR_FAIL; 3905b8fca66Sopenharmony_ci reply.WriteInt32(result); 3915b8fca66Sopenharmony_ci return result; 3925b8fca66Sopenharmony_ci } 3935b8fca66Sopenharmony_ci callback = iface_cast<TelephonyObserverBroker>(remote); 3945b8fca66Sopenharmony_ci if (callback == nullptr) { 3955b8fca66Sopenharmony_ci TELEPHONY_LOGE("TelephonyStateRegistryStub::ReadData callback is nullptr."); 3965b8fca66Sopenharmony_ci result = TELEPHONY_ERR_FAIL; 3975b8fca66Sopenharmony_ci reply.WriteInt32(result); 3985b8fca66Sopenharmony_ci return result; 3995b8fca66Sopenharmony_ci } 4005b8fca66Sopenharmony_ci return result; 4015b8fca66Sopenharmony_ci} 4025b8fca66Sopenharmony_ci 4035b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateCfuIndicator(MessageParcel &data, MessageParcel &reply) 4045b8fca66Sopenharmony_ci{ 4055b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 4065b8fca66Sopenharmony_ci bool cfuResult = data.ReadBool(); 4075b8fca66Sopenharmony_ci int32_t ret = UpdateCfuIndicator(slotId, cfuResult); 4085b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateCfuIndicator end##ret=%{public}d", ret); 4095b8fca66Sopenharmony_ci reply.WriteInt32(ret); 4105b8fca66Sopenharmony_ci return NO_ERROR; 4115b8fca66Sopenharmony_ci} 4125b8fca66Sopenharmony_ci 4135b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnUpdateVoiceMailMsgIndicator(MessageParcel &data, MessageParcel &reply) 4145b8fca66Sopenharmony_ci{ 4155b8fca66Sopenharmony_ci int32_t slotId = data.ReadInt32(); 4165b8fca66Sopenharmony_ci bool voiceMailMsgResult = data.ReadBool(); 4175b8fca66Sopenharmony_ci int32_t ret = UpdateVoiceMailMsgIndicator(slotId, voiceMailMsgResult); 4185b8fca66Sopenharmony_ci TELEPHONY_LOGI("TelephonyStateRegistryStub::OnUpdateVoiceMailMsgIndicator end##ret=%{public}d", ret); 4195b8fca66Sopenharmony_ci reply.WriteInt32(ret); 4205b8fca66Sopenharmony_ci return NO_ERROR; 4215b8fca66Sopenharmony_ci} 4225b8fca66Sopenharmony_ci 4235b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::OnIccAccountUpdated(MessageParcel &data, MessageParcel &reply) 4245b8fca66Sopenharmony_ci{ 4255b8fca66Sopenharmony_ci int32_t ret = UpdateIccAccount(); 4265b8fca66Sopenharmony_ci TELEPHONY_LOGI("end##ret=%{public}d", ret); 4275b8fca66Sopenharmony_ci reply.WriteInt32(ret); 4285b8fca66Sopenharmony_ci return NO_ERROR; 4295b8fca66Sopenharmony_ci} 4305b8fca66Sopenharmony_ci 4315b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::RegisterStateChange(const sptr<TelephonyObserverBroker> &telephonyObserver, 4325b8fca66Sopenharmony_ci int32_t slotId, uint32_t mask, bool isUpdate) 4335b8fca66Sopenharmony_ci{ 4345b8fca66Sopenharmony_ci int32_t uid = IPCSkeleton::GetCallingUid(); 4355b8fca66Sopenharmony_ci std::string bundleName = ""; 4365b8fca66Sopenharmony_ci TelephonyPermission::GetBundleNameByUid(uid, bundleName); 4375b8fca66Sopenharmony_ci int32_t tokenId = static_cast<int32_t>(IPCSkeleton::GetCallingTokenID()); 4385b8fca66Sopenharmony_ci return RegisterStateChange(telephonyObserver, slotId, mask, bundleName, isUpdate, 4395b8fca66Sopenharmony_ci IPCSkeleton::GetCallingPid(), uid, tokenId); 4405b8fca66Sopenharmony_ci} 4415b8fca66Sopenharmony_ci 4425b8fca66Sopenharmony_ciint32_t TelephonyStateRegistryStub::UnregisterStateChange(int32_t slotId, uint32_t mask) 4435b8fca66Sopenharmony_ci{ 4445b8fca66Sopenharmony_ci int32_t tokenId = static_cast<int32_t>(IPCSkeleton::GetCallingTokenID()); 4455b8fca66Sopenharmony_ci return UnregisterStateChange(slotId, mask, tokenId, IPCSkeleton::GetCallingPid()); 4465b8fca66Sopenharmony_ci} 4475b8fca66Sopenharmony_ci} // namespace Telephony 4485b8fca66Sopenharmony_ci} // namespace OHOS