1 /*
2  * Copyright (C) 2021-2023 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 "core_service_stub.h"
17 
18 #include "string_ex.h"
19 #include "telephony_errors.h"
20 #include "telephony_log_wrapper.h"
21 
22 #ifdef HICOLLIE_ENABLE
23 #include "xcollie/xcollie.h"
24 #include "xcollie/xcollie_define.h"
25 #define XCOLLIE_TIMEOUT_SECONDS 30
26 #endif
27 
28 namespace OHOS {
29 namespace Telephony {
30 constexpr int32_t INVALID_VALUE = -1;
31 
CoreServiceStub()32 CoreServiceStub::CoreServiceStub()
33 {
34     AddHandlerNetWorkToMap();
35     AddHandlerDeviceToMap();
36     AddHandlerImsToMap();
37     AddHandlerSimToMap();
38     AddHandlerSimLockToMap();
39     AddHandlerSimToMapExt();
40     AddHandlerVoiceMailToMap();
41     AddHandlerPdpProfileToMap();
42     AddHandlerOpkeyVersionToMap();
43 }
44 
AddHandlerNetWorkToMap()45 void CoreServiceStub::AddHandlerNetWorkToMap()
46 {
47     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_PS_RADIO_TECH)] =
48         [this](MessageParcel &data, MessageParcel &reply) { return OnGetPsRadioTech(data, reply); };
49     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_CS_RADIO_TECH)] =
50         [this](MessageParcel &data, MessageParcel &reply) { return OnGetCsRadioTech(data, reply); };
51     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_OPERATOR_NUMERIC)] =
52         [this](MessageParcel &data, MessageParcel &reply) { return OnGetOperatorNumeric(data, reply); };
53     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_RESIDENT_NETWORK_NUMERIC)] =
54         [this](MessageParcel &data, MessageParcel &reply) { return OnGetResidentNetworkNumeric(data, reply); };
55     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_OPERATOR_NAME)] =
56         [this](MessageParcel &data, MessageParcel &reply) { return OnGetOperatorName(data, reply); };
57     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIGNAL_INFO_LIST)] =
58         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSignalInfoList(data, reply); };
59     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_NETWORK_STATE)] =
60         [this](MessageParcel &data, MessageParcel &reply) { return OnGetNetworkState(data, reply); };
61     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_RADIO_STATE)] =
62         [this](MessageParcel &data, MessageParcel &reply) { return OnSetRadioState(data, reply); };
63     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_RADIO_STATE)] =
64         [this](MessageParcel &data, MessageParcel &reply) { return OnGetRadioState(data, reply); };
65     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_NETWORK_SEARCH_RESULT)] =
66         [this](MessageParcel &data, MessageParcel &reply) { return OnGetNetworkSearchInformation(data, reply); };
67     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_NETWORK_SELECTION_MODE)] =
68         [this](MessageParcel &data, MessageParcel &reply) { return OnGetNetworkSelectionMode(data, reply); };
69     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_NETWORK_SELECTION_MODE)] =
70         [this](MessageParcel &data, MessageParcel &reply) { return OnSetNetworkSelectionMode(data, reply); };
71     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_ISO_COUNTRY_CODE_FOR_NETWORK)] =
72         [this](MessageParcel &data, MessageParcel &reply) { return OnGetIsoCountryCodeForNetwork(data, reply); };
73     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_CELL_INFO_LIST)] =
74         [this](MessageParcel &data, MessageParcel &reply) { return OnGetCellInfoList(data, reply); };
75     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_CELL_LOCATION)] =
76         [this](MessageParcel &data, MessageParcel &reply) { return OnGetCellLocation(data, reply); };
77     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_PREFERRED_NETWORK_MODE)] =
78         [this](MessageParcel &data, MessageParcel &reply) { return OnGetPreferredNetwork(data, reply); };
79     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_PREFERRED_NETWORK_MODE)] =
80         [this](MessageParcel &data, MessageParcel &reply) { return OnSetPreferredNetwork(data, reply); };
81     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_NETWORK_CAPABILITY)] =
82         [this](MessageParcel &data, MessageParcel &reply) { return OnGetNetworkCapability(data, reply); };
83     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_NETWORK_CAPABILITY)] =
84         [this](MessageParcel &data, MessageParcel &reply) { return OnSetNetworkCapability(data, reply); };
85     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_NR_OPTION_MODE)] =
86         [this](MessageParcel &data, MessageParcel &reply) { return OnSetNrOptionMode(data, reply); };
87     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_NR_OPTION_MODE)] =
88         [this](MessageParcel &data, MessageParcel &reply) { return OnGetNrOptionMode(data, reply); };
89     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_NR_SSB_ID_INFO)] =
90         [this](MessageParcel &data, MessageParcel &reply) { return OnGetNrSsbIdInfo(data, reply); };
91 }
92 
AddHandlerDeviceToMap()93 void CoreServiceStub::AddHandlerDeviceToMap()
94 {
95     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_IMEI)] =
96         [this](MessageParcel &data, MessageParcel &reply) { return OnGetImei(data, reply); };
97     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_IMEISV)] =
98         [this](MessageParcel &data, MessageParcel &reply) { return OnGetImeiSv(data, reply); };
99     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_MEID)] =
100         [this](MessageParcel &data, MessageParcel &reply) { return OnGetMeid(data, reply); };
101     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_UNIQUE_DEVICE_ID)] =
102         [this](MessageParcel &data, MessageParcel &reply) { return OnGetUniqueDeviceId(data, reply); };
103     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_BASEBAND_VERSION)] =
104         [this](MessageParcel &data, MessageParcel &reply) { return OnGetBasebandVersion(data, reply); };
105     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::FACTORY_RESET)] =
106         [this](MessageParcel &data, MessageParcel &reply) { return OnFactoryReset(data, reply); };
107 }
108 
AddHandlerImsToMap()109 void CoreServiceStub::AddHandlerImsToMap()
110 {
111     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_IMS_REG_STATUS)] =
112         [this](MessageParcel &data, MessageParcel &reply) { return OnGetImsRegStatus(data, reply); };
113     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::REG_IMS_CALLBACK)] =
114         [this](MessageParcel &data, MessageParcel &reply) { return OnRegisterImsRegInfoCallback(data, reply); };
115     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::UN_REG_IMS_CALLBACK)] =
116         [this](MessageParcel &data, MessageParcel &reply) { return OnUnregisterImsRegInfoCallback(data, reply); };
117 }
118 
AddHandlerSimToMap()119 void CoreServiceStub::AddHandlerSimToMap()
120 {
121     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::HAS_SIM_CARD)] =
122         [this](MessageParcel &data, MessageParcel &reply) { return OnHasSimCard(data, reply); };
123     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_STATE)] =
124         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimState(data, reply); };
125     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_DSDS_MODE)] =
126         [this](MessageParcel &data, MessageParcel &reply) { return OnGetDsdsMode(data, reply); };
127     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SPN)] =
128         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimSpn(data, reply); };
129     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_ICCID)] =
130         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimIccId(data, reply); };
131     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_OPERATOR_NUMERIC)] =
132         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimOperatorNumeric(data, reply); };
133     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_IMSI)] =
134         [this](MessageParcel &data, MessageParcel &reply) { return OnGetIMSI(data, reply); };
135     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::IS_CT_SIM_CARD)] =
136         [this](MessageParcel &data, MessageParcel &reply) { return OnIsCTSimCard(data, reply); };
137     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::IS_SIM_ACTIVE)] =
138         [this](MessageParcel &data, MessageParcel &reply) { return OnIsSimActive(data, reply); };
139     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_LANGUAGE)] =
140         [this](MessageParcel &data, MessageParcel &reply) { return OnGetLocaleFromDefaultSim(data, reply); };
141     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_GID1)] =
142         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimGid1(data, reply); };
143     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_GID2)] =
144         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimGid2(data, reply); };
145     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_EONS)] =
146         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimEons(data, reply); };
147     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_SUB_INFO)] =
148         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimSubscriptionInfo(data, reply); };
149     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_DEFAULT_VOICE_SLOTID)] =
150         [this](MessageParcel &data, MessageParcel &reply) { return OnSetDefaultVoiceSlotId(data, reply); };
151     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_DEFAULT_VOICE_SLOTID)] =
152         [this](MessageParcel &data, MessageParcel &reply) { return OnGetDefaultVoiceSlotId(data, reply); };
153     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_DEFAULT_VOICE_SIMID)] =
154         [this](MessageParcel &data, MessageParcel &reply) { return OnGetDefaultVoiceSimId(data, reply); };
155     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_PRIMARY_SLOTID)] =
156         [this](MessageParcel &data, MessageParcel &reply) { return OnSetPrimarySlotId(data, reply); };
157     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_PRIMARY_SLOTID)] =
158         [this](MessageParcel &data, MessageParcel &reply) { return OnGetPrimarySlotId(data, reply); };
159     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_SHOW_NUMBER)] =
160         [this](MessageParcel &data, MessageParcel &reply) { return OnSetShowNumber(data, reply); };
161     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SHOW_NUMBER)] =
162         [this](MessageParcel &data, MessageParcel &reply) { return OnGetShowNumber(data, reply); };
163     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_SHOW_NAME)] =
164         [this](MessageParcel &data, MessageParcel &reply) { return OnSetShowName(data, reply); };
165     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SHOW_NAME)] =
166         [this](MessageParcel &data, MessageParcel &reply) { return OnGetShowName(data, reply); };
167 }
168 
AddHandlerSimLockToMap()169 void CoreServiceStub::AddHandlerSimLockToMap()
170 {
171     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::UNLOCK_PIN)] =
172         [this](MessageParcel &data, MessageParcel &reply) { return OnUnlockPin(data, reply); };
173     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::UNLOCK_PUK)] =
174         [this](MessageParcel &data, MessageParcel &reply) { return OnUnlockPuk(data, reply); };
175     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::ALTER_PIN)] =
176         [this](MessageParcel &data, MessageParcel &reply) { return OnAlterPin(data, reply); };
177     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::CHECK_LOCK)] =
178         [this](MessageParcel &data, MessageParcel &reply) { return OnGetLockState(data, reply); };
179     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SWITCH_LOCK)] =
180         [this](MessageParcel &data, MessageParcel &reply) { return OnSetLockState(data, reply); };
181     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::UNLOCK_PIN2)] =
182         [this](MessageParcel &data, MessageParcel &reply) { return OnUnlockPin2(data, reply); };
183     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::UNLOCK_PUK2)] =
184         [this](MessageParcel &data, MessageParcel &reply) { return OnUnlockPuk2(data, reply); };
185     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::ALTER_PIN2)] =
186         [this](MessageParcel &data, MessageParcel &reply) { return OnAlterPin2(data, reply); };
187     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::UNLOCK_SIMLOCK)] =
188         [this](MessageParcel &data, MessageParcel &reply) { return OnUnlockSimLock(data, reply); };
189     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::HAS_OPERATOR_PRIVILEGES)] =
190         [this](MessageParcel &data, MessageParcel &reply) { return OnHasOperatorPrivileges(data, reply); };
191     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SIM_AUTHENTICATION)] =
192         [this](MessageParcel &data, MessageParcel &reply) { return OnSimAuthentication(data, reply); };
193 }
194 
AddHandlerSimToMapExt()195 void CoreServiceStub::AddHandlerSimToMapExt()
196 {
197     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_ISO_COUNTRY_CODE)] =
198         [this](MessageParcel &data, MessageParcel &reply) { return OnGetISOCountryCodeForSim(data, reply); };
199     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_ACTIVE_ACCOUNT_INFO_LIST)] =
200         [this](MessageParcel &data, MessageParcel &reply) { return OnGetActiveSimAccountInfoList(data, reply); };
201     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_OPERATOR_CONFIG)] =
202         [this](MessageParcel &data, MessageParcel &reply) { return OnGetOperatorConfig(data, reply); };
203     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::REFRESH_SIM_STATE)] =
204         [this](MessageParcel &data, MessageParcel &reply) { return OnRefreshSimState(data, reply); };
205     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_SIM_ACTIVE)] =
206         [this](MessageParcel &data, MessageParcel &reply) { return OnSetActiveSim(data, reply); };
207     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_PHONE_NUMBER)] =
208         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimPhoneNumber(data, reply); };
209     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_TELENUMBER_IDENTIFIER)] =
210         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimTeleNumberIdentifier(data, reply); };
211     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_VOICE_CALL_FORWARDING)] =
212         [this](MessageParcel &data, MessageParcel &reply) { return OnSetVoiceCallForwarding(data, reply); };
213     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_GET)] =
214         [this](MessageParcel &data, MessageParcel &reply) { return OnDiallingNumbersGet(data, reply); };
215     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_INSERT)] =
216         [this](MessageParcel &data, MessageParcel &reply) { return OnAddIccDiallingNumbers(data, reply); };
217     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_UPDATE)] =
218         [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateIccDiallingNumbers(data, reply); };
219     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_DELETE)] =
220         [this](MessageParcel &data, MessageParcel &reply) { return OnDelIccDiallingNumbers(data, reply); };
221     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_MAX_SIM_COUNT)] =
222         [this](MessageParcel &data, MessageParcel &reply) { return OnGetMaxSimCount(data, reply); };
223     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::STK_CMD_FROM_APP_ENVELOPE)] =
224         [this](MessageParcel &data, MessageParcel &reply) { return OnSendEnvelopeCmd(data, reply); };
225     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::STK_CMD_FROM_APP_TERMINAL_RESPONSE)] =
226         [this](MessageParcel &data, MessageParcel &reply) { return OnSendTerminalResponseCmd(data, reply); };
227     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::STK_RESULT_FROM_APP_CALL_SETUP_REQUEST)] =
228         [this](MessageParcel &data, MessageParcel &reply) { return OnSendCallSetupRequestResult(data, reply); };
229     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_CARD_TYPE)] =
230         [this](MessageParcel &data, MessageParcel &reply) { return OnGetCardType(data, reply); };
231     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::IS_NR_SUPPORTED)] =
232         [this](MessageParcel &data, MessageParcel &reply) { return OnIsNrSupported(data, reply); };
233     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_SLOTID)] =
234         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSlotId(data, reply); };
235     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_SIMID)] =
236         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimId(data, reply); };
237     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::INIT_EXTRA_MODULE)] =
238         [this](MessageParcel &data, MessageParcel &reply) { return OnInitExtraModule(data, reply); };
239     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_SIM_IO_DONE)] =
240         [this](MessageParcel &data, MessageParcel &reply) { return OnGetSimIO(data, reply); };
241 }
242 
AddHandlerVoiceMailToMap()243 void CoreServiceStub::AddHandlerVoiceMailToMap()
244 {
245     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_VOICE_MAIL_TAG)] =
246         [this](MessageParcel &data, MessageParcel &reply) { return OnGetVoiceMailInfor(data, reply); };
247     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_VOICE_MAIL_NUMBER)] =
248         [this](MessageParcel &data, MessageParcel &reply) { return OnGetVoiceMailNumber(data, reply); };
249     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_VOICE_MAIL_COUNT)] =
250         [this](MessageParcel &data, MessageParcel &reply) { return OnGetVoiceMailCount(data, reply); };
251     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_VOICE_MAIL_COUNT)] =
252         [this](MessageParcel &data, MessageParcel &reply) { return OnSetVoiceMailCount(data, reply); };
253     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::SET_VOICE_MAIL)] =
254         [this](MessageParcel &data, MessageParcel &reply) { return OnSetVoiceMailInfo(data, reply); };
255 }
256 
AddHandlerPdpProfileToMap()257 void CoreServiceStub::AddHandlerPdpProfileToMap()
258 {
259     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::IS_ALLOWED_INSERT_APN)] =
260         [this](MessageParcel &data, MessageParcel &reply) { return OnIsAllowedInsertApn(data, reply); };
261     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_TARGET_OPKEY)] =
262         [this](MessageParcel &data, MessageParcel &reply) { return OnGetTargetOpkey(data, reply); };
263 }
264 
AddHandlerOpkeyVersionToMap()265 void CoreServiceStub::AddHandlerOpkeyVersionToMap()
266 {
267     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_OPKEY)] =
268         [this](MessageParcel &data, MessageParcel &reply) { return OnGetOpKey(data, reply); };
269     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_OPNAME)] =
270         [this](MessageParcel &data, MessageParcel &reply) { return OnGetOpName(data, reply); };
271     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_OPKEY_EXT)] =
272         [this](MessageParcel &data, MessageParcel &reply) { return OnGetOpKeyExt(data, reply); };
273     memberFuncMap_[uint32_t(CoreServiceInterfaceCode::GET_OPKEY_VERSION)] =
274         [this](MessageParcel &data, MessageParcel &reply) { return OnGetOpkeyVersion(data, reply); };
275 }
276 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)277 int32_t CoreServiceStub::OnRemoteRequest(
278     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
279 {
280     TELEPHONY_LOGD("CoreServiceStub OnRemoteRequest code %{public}u", code);
281     std::u16string myDescripter = CoreServiceStub::GetDescriptor();
282     std::u16string remoteDescripter = data.ReadInterfaceToken();
283     if (myDescripter != remoteDescripter) {
284         TELEPHONY_LOGE("descriptor checked fail");
285         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
286     }
287     auto itFunc = memberFuncMap_.find(code);
288     if (itFunc != memberFuncMap_.end()) {
289         auto memberFunc = itFunc->second;
290         if (memberFunc != nullptr) {
291             int32_t idTimer = SetTimer(code);
292             int32_t result = memberFunc(data, reply);
293             CancelTimer(idTimer);
294             return result;
295         }
296     }
297     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
298 }
299 
SetTimer(uint32_t code)300 int32_t CoreServiceStub::SetTimer(uint32_t code)
301 {
302 #ifdef HICOLLIE_ENABLE
303     int32_t idTimer = HiviewDFX::INVALID_ID;
304     std::map<uint32_t, std::string>::iterator itCollieId = collieCodeStringMap_.find(code);
305     if (itCollieId != collieCodeStringMap_.end()) {
306         std::string collieStr = itCollieId->second;
307         std::string collieName = "CoreServiceStub: " + collieStr;
308         unsigned int flag = HiviewDFX::XCOLLIE_FLAG_NOOP;
309         auto TimerCallback = [collieStr](void *) {
310             TELEPHONY_LOGE("OnRemoteRequest timeout func: %{public}s", collieStr.c_str());
311         };
312         idTimer = HiviewDFX::XCollie::GetInstance().SetTimer(
313             collieName, XCOLLIE_TIMEOUT_SECONDS, TimerCallback, nullptr, flag);
314         TELEPHONY_LOGD("SetTimer id: %{public}d, name: %{public}s.", idTimer, collieStr.c_str());
315     }
316     return idTimer;
317 #else
318     TELEPHONY_LOGD("No HICOLLIE_ENABLE");
319     return -1;
320 #endif
321 }
322 
CancelTimer(int32_t id)323 void CoreServiceStub::CancelTimer(int32_t id)
324 {
325 #ifdef HICOLLIE_ENABLE
326     if (id == HiviewDFX::INVALID_ID) {
327         return;
328     }
329     TELEPHONY_LOGD("CancelTimer id: %{public}d.", id);
330     HiviewDFX::XCollie::GetInstance().CancelTimer(id);
331 #else
332     return;
333 #endif
334 }
335 
OnGetPsRadioTech(MessageParcel & data,MessageParcel & reply)336 int32_t CoreServiceStub::OnGetPsRadioTech(MessageParcel &data, MessageParcel &reply)
337 {
338     auto slotId = data.ReadInt32();
339     int32_t radioTech = 0;
340     int32_t result = GetPsRadioTech(slotId, radioTech);
341     bool ret = reply.WriteInt32(result);
342     if (result == TELEPHONY_ERR_SUCCESS) {
343         ret = (ret && reply.WriteInt32(radioTech));
344     }
345     if (!ret) {
346         TELEPHONY_LOGE("write reply failed.");
347         return TELEPHONY_ERR_WRITE_DATA_FAIL;
348     }
349     return NO_ERROR;
350 }
351 
OnGetCsRadioTech(MessageParcel & data,MessageParcel & reply)352 int32_t CoreServiceStub::OnGetCsRadioTech(MessageParcel &data, MessageParcel &reply)
353 {
354     auto slotId = data.ReadInt32();
355     int32_t radioTech = 0;
356     int32_t result = GetCsRadioTech(slotId, radioTech);
357     bool ret = reply.WriteInt32(result);
358     if (result == TELEPHONY_ERR_SUCCESS) {
359         ret = (ret && reply.WriteInt32(radioTech));
360     }
361     if (!ret) {
362         TELEPHONY_LOGE("write reply failed.");
363         return TELEPHONY_ERR_WRITE_DATA_FAIL;
364     }
365     return NO_ERROR;
366 }
367 
OnGetOperatorNumeric(MessageParcel & data,MessageParcel & reply)368 int32_t CoreServiceStub::OnGetOperatorNumeric(MessageParcel &data, MessageParcel &reply)
369 {
370     auto slotId = data.ReadInt32();
371     std::u16string result = GetOperatorNumeric(slotId);
372     reply.WriteString16(result);
373     return NO_ERROR;
374 }
375 
OnGetResidentNetworkNumeric(MessageParcel & data,MessageParcel & reply)376 int32_t CoreServiceStub::OnGetResidentNetworkNumeric(MessageParcel &data, MessageParcel &reply)
377 {
378     auto slotId = data.ReadInt32();
379     std::string result = GetResidentNetworkNumeric(slotId);
380     reply.WriteString(result);
381     return NO_ERROR;
382 }
383 
OnGetOperatorName(MessageParcel & data,MessageParcel & reply)384 int32_t CoreServiceStub::OnGetOperatorName(MessageParcel &data, MessageParcel &reply)
385 {
386     auto slotId = data.ReadInt32();
387     std::u16string operatorName = u"";
388     int32_t result = GetOperatorName(slotId, operatorName);
389     bool ret = reply.WriteInt32(result);
390     if (result == TELEPHONY_ERR_SUCCESS) {
391         ret = (ret && reply.WriteString16(operatorName));
392     }
393     if (!ret) {
394         TELEPHONY_LOGE("write reply failed.");
395         return TELEPHONY_ERR_WRITE_DATA_FAIL;
396     }
397     return NO_ERROR;
398 }
399 
OnGetSignalInfoList(MessageParcel & data,MessageParcel & reply)400 int32_t CoreServiceStub::OnGetSignalInfoList(MessageParcel &data, MessageParcel &reply)
401 {
402     auto slotId = data.ReadInt32();
403     std::vector<sptr<SignalInformation>> signals;
404     int32_t result = GetSignalInfoList(slotId, signals);
405     if (!reply.WriteInt32(result)) {
406         TELEPHONY_LOGE("write reply failed.");
407         return TELEPHONY_ERR_WRITE_DATA_FAIL;
408     }
409     if (result == TELEPHONY_ERR_SUCCESS) {
410         reply.WriteInt32(static_cast<int32_t>(signals.size()));
411         for (const auto &v : signals) {
412             v->Marshalling(reply);
413         }
414     }
415     return NO_ERROR;
416 }
417 
OnGetNetworkState(MessageParcel & data,MessageParcel & reply)418 int32_t CoreServiceStub::OnGetNetworkState(MessageParcel &data, MessageParcel &reply)
419 {
420     auto slotId = data.ReadInt32();
421     sptr<NetworkState> networkState = nullptr;
422     int32_t result = GetNetworkState(slotId, networkState);
423     if ((networkState == nullptr) && (result != TELEPHONY_ERR_PERMISSION_ERR)) {
424         TELEPHONY_LOGE("networkState is nullptr and permission is not denied.");
425         result = TELEPHONY_ERR_LOCAL_PTR_NULL;
426     }
427     if (!reply.WriteInt32(result)) {
428         TELEPHONY_LOGE("write reply failed.");
429         return TELEPHONY_ERR_WRITE_DATA_FAIL;
430     }
431     if (result == TELEPHONY_ERR_SUCCESS) {
432         networkState->Marshalling(reply);
433     }
434     return NO_ERROR;
435 }
436 
OnSetRadioState(MessageParcel & data,MessageParcel & reply)437 int32_t CoreServiceStub::OnSetRadioState(MessageParcel &data, MessageParcel &reply)
438 {
439     int32_t slotId = data.ReadInt32();
440     sptr<INetworkSearchCallback> callback = nullptr;
441     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
442     if (remoteCallback == nullptr) {
443         TELEPHONY_LOGE("CoreServiceStub::OnSetRadioState remoteCallback is nullptr.");
444         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
445     }
446     callback = iface_cast<INetworkSearchCallback>(remoteCallback);
447     if (callback == nullptr) {
448         TELEPHONY_LOGE("CoreServiceStub::OnSetRadioState callback is nullptr.");
449         return TELEPHONY_ERR_LOCAL_PTR_NULL;
450     }
451     bool isOn = data.ReadBool();
452     TELEPHONY_LOGD("CoreServiceStub::OnSetRadioState isOn:%{public}d", isOn);
453     int32_t result = SetRadioState(slotId, isOn, callback);
454     if (!reply.WriteInt32(result)) {
455         TELEPHONY_LOGE("CoreServiceStub::OnSetRadioState write reply failed.");
456         return TELEPHONY_ERR_WRITE_DATA_FAIL;
457     }
458     return NO_ERROR;
459 }
460 
OnGetRadioState(MessageParcel & data,MessageParcel & reply)461 int32_t CoreServiceStub::OnGetRadioState(MessageParcel &data, MessageParcel &reply)
462 {
463     int32_t slotId = data.ReadInt32();
464     sptr<INetworkSearchCallback> callback = nullptr;
465     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
466     if (remoteCallback == nullptr) {
467         TELEPHONY_LOGE("CoreServiceStub::OnGetRadioState remoteCallback is nullptr.");
468         return TELEPHONY_ERR_LOCAL_PTR_NULL;
469     }
470     callback = iface_cast<INetworkSearchCallback>(remoteCallback);
471     if (callback == nullptr) {
472         TELEPHONY_LOGE("CoreServiceStub::OnGetRadioState callback is nullptr.");
473         return TELEPHONY_ERR_LOCAL_PTR_NULL;
474     }
475     int32_t result = GetRadioState(slotId, callback);
476     if (!reply.WriteInt32(result)) {
477         TELEPHONY_LOGE("CoreServiceStub::OnGetRadioState write reply failed.");
478         return TELEPHONY_ERR_WRITE_DATA_FAIL;
479     }
480     TELEPHONY_LOGD("CoreServiceStub::OnGetRadioState result:%{public}d", result);
481     return NO_ERROR;
482 }
483 
OnGetIsoCountryCodeForNetwork(MessageParcel & data,MessageParcel & reply)484 int32_t CoreServiceStub::OnGetIsoCountryCodeForNetwork(MessageParcel &data, MessageParcel &reply)
485 {
486     int32_t slotId = data.ReadInt32();
487     std::u16string countryCode;
488     int32_t result = GetIsoCountryCodeForNetwork(slotId, countryCode);
489     bool ret = reply.WriteInt32(result);
490     if (result == TELEPHONY_ERR_SUCCESS) {
491         ret = (ret && reply.WriteString16(countryCode));
492     }
493     if (!ret) {
494         TELEPHONY_LOGE("write reply failed.");
495         return TELEPHONY_ERR_WRITE_DATA_FAIL;
496     }
497     return NO_ERROR;
498 }
499 
OnGetImei(MessageParcel & data,MessageParcel & reply)500 int32_t CoreServiceStub::OnGetImei(MessageParcel &data, MessageParcel &reply)
501 {
502     int32_t slotId = data.ReadInt32();
503     std::u16string imei = u"";
504     int32_t result = GetImei(slotId, imei);
505     if (!reply.WriteInt32(result)) {
506         TELEPHONY_LOGE("OnRemoteRequest::OnGetImei write reply failed.");
507         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
508     }
509     if (result == TELEPHONY_ERR_SUCCESS) {
510         if (!reply.WriteString16(imei)) {
511             TELEPHONY_LOGE("OnRemoteRequest::OnGetImei write reply failed.");
512             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
513         }
514     }
515     return NO_ERROR;
516 }
517 
OnGetImeiSv(MessageParcel & data,MessageParcel & reply)518 int32_t CoreServiceStub::OnGetImeiSv(MessageParcel &data, MessageParcel &reply)
519 {
520     int32_t slotId = data.ReadInt32();
521     std::u16string imeiSv = u"";
522     int32_t result = GetImeiSv(slotId, imeiSv);
523     if (!reply.WriteInt32(result)) {
524         TELEPHONY_LOGE("OnRemoteRequest::OnGetImeiSv write reply failed.");
525         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
526     }
527     if (result == TELEPHONY_ERR_SUCCESS) {
528         if (!reply.WriteString16(imeiSv)) {
529             TELEPHONY_LOGE("OnRemoteRequest::OnGetImeiSv write reply failed.");
530             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
531         }
532     }
533     return NO_ERROR;
534 }
535 
OnGetMeid(MessageParcel & data,MessageParcel & reply)536 int32_t CoreServiceStub::OnGetMeid(MessageParcel &data, MessageParcel &reply)
537 {
538     int32_t slotId = data.ReadInt32();
539     std::u16string meid = u"";
540     int32_t result = GetMeid(slotId, meid);
541     if (!reply.WriteInt32(result)) {
542         TELEPHONY_LOGE("OnRemoteRequest::OnGetMeid write reply failed.");
543         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
544     }
545     if (result == TELEPHONY_ERR_SUCCESS) {
546         if (!reply.WriteString16(meid)) {
547             TELEPHONY_LOGE("OnRemoteRequest::OnGetMeid write reply failed.");
548             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
549         }
550     }
551     return NO_ERROR;
552 }
553 
OnGetUniqueDeviceId(MessageParcel & data,MessageParcel & reply)554 int32_t CoreServiceStub::OnGetUniqueDeviceId(MessageParcel &data, MessageParcel &reply)
555 {
556     int32_t slotId = data.ReadInt32();
557     std::u16string deviceId = u"";
558     int32_t result = GetUniqueDeviceId(slotId, deviceId);
559     if (!reply.WriteInt32(result)) {
560         TELEPHONY_LOGE("OnRemoteRequest::OnGetUniqueDeviceId write reply failed.");
561         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
562     }
563     if (result == TELEPHONY_ERR_SUCCESS) {
564         if (!reply.WriteString16(deviceId)) {
565             TELEPHONY_LOGE("OnRemoteRequest::OnGetUniqueDeviceId write reply failed.");
566             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
567         }
568     }
569     return NO_ERROR;
570 }
571 
OnIsNrSupported(MessageParcel & data,MessageParcel & reply)572 int32_t CoreServiceStub::OnIsNrSupported(MessageParcel &data, MessageParcel &reply)
573 {
574     int32_t slotId = data.ReadInt32();
575     bool result = IsNrSupported(slotId);
576     bool ret = reply.WriteBool(result);
577     if (!ret) {
578         TELEPHONY_LOGE("OnRemoteRequest::IS_NR_SUPPORTED write reply failed.");
579         return ERR_FLATTEN_OBJECT;
580     }
581     return NO_ERROR;
582 }
583 
OnSetNrOptionMode(MessageParcel & data,MessageParcel & reply)584 int32_t CoreServiceStub::OnSetNrOptionMode(MessageParcel &data, MessageParcel &reply)
585 {
586     int32_t slotId = data.ReadInt32();
587     int32_t nrMode = data.ReadInt32();
588     sptr<INetworkSearchCallback> callback = nullptr;
589     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
590     if (remoteCallback == nullptr) {
591         TELEPHONY_LOGE("CoreServiceStub::OnSetNrOptionMode remoteCallback is nullptr.");
592         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
593     }
594     callback = iface_cast<INetworkSearchCallback>(remoteCallback);
595     if (callback == nullptr) {
596         TELEPHONY_LOGE("CoreServiceStub::OnSetNrOptionMode callback is null");
597         return TELEPHONY_ERR_LOCAL_PTR_NULL;
598     }
599     int32_t result = SetNrOptionMode(slotId, nrMode, callback);
600     if (!reply.WriteInt32(result)) {
601         TELEPHONY_LOGE("OnRemoteRequest::OnSetNrOptionMode write reply failed.");
602         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
603     }
604     return NO_ERROR;
605 }
606 
OnGetNrOptionMode(MessageParcel & data,MessageParcel & reply)607 int32_t CoreServiceStub::OnGetNrOptionMode(MessageParcel &data, MessageParcel &reply)
608 {
609     int32_t slotId = data.ReadInt32();
610     sptr<INetworkSearchCallback> callback = nullptr;
611     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
612     if (remoteCallback == nullptr) {
613         TELEPHONY_LOGE("CoreServiceStub::OnGetNrOptionMode remoteCallback is nullptr.");
614         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
615     }
616     callback = iface_cast<INetworkSearchCallback>(remoteCallback);
617     if (callback == nullptr) {
618         TELEPHONY_LOGE("CoreServiceStub::OnGetNrOptionMode callback is null");
619         return TELEPHONY_ERR_LOCAL_PTR_NULL;
620     }
621     int32_t result = GetNrOptionMode(slotId, callback);
622     if (!reply.WriteInt32(result)) {
623         TELEPHONY_LOGE("OnRemoteRequest::OnGetNrOptionMode write reply failed.");
624         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
625     }
626     return NO_ERROR;
627 }
628 
OnHasSimCard(MessageParcel & data,MessageParcel & reply)629 int32_t CoreServiceStub::OnHasSimCard(MessageParcel &data, MessageParcel &reply)
630 {
631     int32_t slotId = data.ReadInt32();
632     bool hasSimCard = false;
633     int32_t result = HasSimCard(slotId, hasSimCard);
634     TELEPHONY_LOGD("result is %{public}s", hasSimCard ? "true" : "false");
635     bool ret = reply.WriteInt32(result);
636     if (result == TELEPHONY_ERR_SUCCESS) {
637         ret = (ret && reply.WriteBool(hasSimCard));
638     }
639     if (!ret) {
640         TELEPHONY_LOGE("write reply failed.");
641         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
642     }
643     return NO_ERROR;
644 }
645 
OnGetSimState(MessageParcel & data,MessageParcel & reply)646 int32_t CoreServiceStub::OnGetSimState(MessageParcel &data, MessageParcel &reply)
647 {
648     int32_t slotId = data.ReadInt32();
649     SimState simState = SimState::SIM_STATE_UNKNOWN;
650     int32_t result = GetSimState(slotId, simState);
651     bool ret = reply.WriteInt32(result);
652     if (result == TELEPHONY_ERR_SUCCESS) {
653         ret = (ret && reply.WriteInt32(static_cast<int32_t>(simState)));
654     }
655     if (!ret) {
656         TELEPHONY_LOGE("OnRemoteRequest::GET_SIM_STATE write reply failed.");
657         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
658     }
659     return NO_ERROR;
660 }
661 
OnGetDsdsMode(MessageParcel & data,MessageParcel & reply)662 int32_t CoreServiceStub::OnGetDsdsMode(MessageParcel &data, MessageParcel &reply)
663 {
664     int32_t dsdsMode = 0; /*0 means DSDS_MODE_V2*/
665     int32_t result = GetDsdsMode(dsdsMode);
666     bool ret = reply.WriteInt32(result);
667     if (result == TELEPHONY_ERR_SUCCESS) {
668         ret = (ret && reply.WriteInt32(static_cast<int32_t>(dsdsMode)));
669     }
670     if (!ret) {
671         TELEPHONY_LOGE("OnRemoteRequest::GET_DSDS_MODE write reply failed.");
672         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
673     }
674     return NO_ERROR;
675 }
676 
OnGetCardType(MessageParcel & data,MessageParcel & reply)677 int32_t CoreServiceStub::OnGetCardType(MessageParcel &data, MessageParcel &reply)
678 {
679     int32_t slotId = data.ReadInt32();
680     CardType cardType = CardType::UNKNOWN_CARD;
681     int32_t result = GetCardType(slotId, cardType);
682     bool ret = reply.WriteInt32(result);
683     if (result == TELEPHONY_ERR_SUCCESS) {
684         ret = (ret && reply.WriteInt32(static_cast<int32_t>(cardType)));
685     }
686     if (!ret) {
687         TELEPHONY_LOGE("OnRemoteRequest::GET_CARD_TYPE write reply failed.");
688         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
689     }
690     return NO_ERROR;
691 }
692 
OnGetISOCountryCodeForSim(MessageParcel & data,MessageParcel & reply)693 int32_t CoreServiceStub::OnGetISOCountryCodeForSim(MessageParcel &data, MessageParcel &reply)
694 {
695     int32_t slotId = data.ReadInt32();
696     std::u16string countryCode;
697     int32_t result = GetISOCountryCodeForSim(slotId, countryCode);
698     bool ret = reply.WriteInt32(result);
699     if (result == TELEPHONY_ERR_SUCCESS) {
700         ret = (ret && reply.WriteString16(countryCode));
701     }
702     if (!ret) {
703         TELEPHONY_LOGE("OnRemoteRequest::GET_ISO_COUNTRY_CODE write reply failed.");
704         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
705     }
706     return NO_ERROR;
707 }
708 
OnGetSimSpn(MessageParcel & data,MessageParcel & reply)709 int32_t CoreServiceStub::OnGetSimSpn(MessageParcel &data, MessageParcel &reply)
710 {
711     int32_t slotId = data.ReadInt32();
712     std::u16string spn;
713     int32_t result = GetSimSpn(slotId, spn);
714     bool ret = reply.WriteInt32(result);
715     if (result == TELEPHONY_ERR_SUCCESS) {
716         ret = (ret && reply.WriteString16(spn));
717     }
718     if (!ret) {
719         TELEPHONY_LOGE("OnRemoteRequest::GET_SPN write reply failed.");
720         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
721     }
722     return NO_ERROR;
723 }
724 
OnGetSimIccId(MessageParcel & data,MessageParcel & reply)725 int32_t CoreServiceStub::OnGetSimIccId(MessageParcel &data, MessageParcel &reply)
726 {
727     int32_t slotId = data.ReadInt32();
728     std::u16string iccId;
729     int32_t result = GetSimIccId(slotId, iccId);
730     bool ret = reply.WriteInt32(result);
731     if (result == TELEPHONY_ERR_SUCCESS) {
732         ret = (ret && reply.WriteString16(iccId));
733     }
734     if (!ret) {
735         TELEPHONY_LOGE("OnRemoteRequest::GET_ICCID write reply failed.");
736         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
737     }
738     return NO_ERROR;
739 }
740 
OnGetSimOperatorNumeric(MessageParcel & data,MessageParcel & reply)741 int32_t CoreServiceStub::OnGetSimOperatorNumeric(MessageParcel &data, MessageParcel &reply)
742 {
743     int32_t slotId = data.ReadInt32();
744     std::u16string operatorNumeric;
745     int32_t result = GetSimOperatorNumeric(slotId, operatorNumeric);
746     bool ret = reply.WriteInt32(result);
747     if (result == TELEPHONY_ERR_SUCCESS) {
748         ret = (ret && reply.WriteString16(operatorNumeric));
749     }
750     if (!ret) {
751         TELEPHONY_LOGE("OnRemoteRequest::GET_SIM_OPERATOR_NUMERIC write reply failed.");
752         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
753     }
754     return NO_ERROR;
755 }
756 
OnGetIMSI(MessageParcel & data,MessageParcel & reply)757 int32_t CoreServiceStub::OnGetIMSI(MessageParcel &data, MessageParcel &reply)
758 {
759     int32_t slotId = data.ReadInt32();
760     std::u16string imsi;
761     int32_t result = GetIMSI(slotId, imsi);
762     bool ret = reply.WriteInt32(result);
763     if (result == TELEPHONY_ERR_SUCCESS) {
764         ret = (ret && reply.WriteString16(imsi));
765     }
766     if (!ret) {
767         TELEPHONY_LOGE("OnRemoteRequest::GET_IMSI write reply failed.");
768         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
769     }
770     return NO_ERROR;
771 }
772 
OnIsCTSimCard(MessageParcel & data,MessageParcel & reply)773 int32_t CoreServiceStub::OnIsCTSimCard(MessageParcel &data, MessageParcel &reply)
774 {
775     int32_t slotId = data.ReadInt32();
776     bool isCTSimCard = false;
777     int32_t result = IsCTSimCard(slotId, isCTSimCard);
778     bool ret = reply.WriteInt32(result);
779     if (result == TELEPHONY_ERR_SUCCESS) {
780         ret = (ret && reply.WriteBool(isCTSimCard));
781     }
782     if (!ret) {
783         TELEPHONY_LOGE("OnRemoteRequest::IS_CT_SIM_CARD write reply failed.");
784         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
785     }
786     return NO_ERROR;
787 }
788 
OnIsSimActive(MessageParcel & data,MessageParcel & reply)789 int32_t CoreServiceStub::OnIsSimActive(MessageParcel &data, MessageParcel &reply)
790 {
791     int32_t slotId = data.ReadInt32();
792     bool result = IsSimActive(slotId);
793     TELEPHONY_LOGD("OnRemoteRequest::IsSimActive result is %{public}d", result);
794     bool ret = reply.WriteBool(result);
795     if (!ret) {
796         TELEPHONY_LOGE("OnRemoteRequest::IsSimActive write reply failed.");
797         return ERR_FLATTEN_OBJECT;
798     }
799     return NO_ERROR;
800 }
801 
OnGetSlotId(MessageParcel & data,MessageParcel & reply)802 int32_t CoreServiceStub::OnGetSlotId(MessageParcel &data, MessageParcel &reply)
803 {
804     int32_t simId = data.ReadInt32();
805     int32_t result = GetSlotId(simId);
806     TELEPHONY_LOGD("OnRemoteRequest::OnGetSlotId result is %{public}d", result);
807     bool ret = reply.WriteInt32(result);
808     if (!ret) {
809         TELEPHONY_LOGE("OnRemoteRequest::OnGetSlotId write reply failed.");
810         return ERR_FLATTEN_OBJECT;
811     }
812     return NO_ERROR;
813 }
814 
OnGetSimId(MessageParcel & data,MessageParcel & reply)815 int32_t CoreServiceStub::OnGetSimId(MessageParcel &data, MessageParcel &reply)
816 {
817     int32_t slotId = data.ReadInt32();
818     int32_t result = GetSimId(slotId);
819     TELEPHONY_LOGD("OnRemoteRequest::OnGetSimId result is %{public}d", result);
820     bool ret = reply.WriteInt32(result);
821     if (!ret) {
822         TELEPHONY_LOGE("OnRemoteRequest::OnGetSimId write reply failed.");
823         return ERR_FLATTEN_OBJECT;
824     }
825     return NO_ERROR;
826 }
827 
OnGetNetworkSearchInformation(MessageParcel & data,MessageParcel & reply)828 int32_t CoreServiceStub::OnGetNetworkSearchInformation(MessageParcel &data, MessageParcel &reply)
829 {
830     sptr<INetworkSearchCallback> callback = nullptr;
831     int32_t slotId = data.ReadInt32();
832     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
833     if (remoteCallback != nullptr) {
834         callback = iface_cast<INetworkSearchCallback>(remoteCallback);
835     }
836     if (callback == nullptr) {
837         TELEPHONY_LOGE("CoreServiceStub::OnGetNetworkSearchInformation callback is null");
838         return TELEPHONY_ERR_LOCAL_PTR_NULL;
839     }
840     int32_t result = GetNetworkSearchInformation(slotId, callback);
841     if (!reply.WriteInt32(result)) {
842         TELEPHONY_LOGE("OnRemoteRequest::OnGetNetworkSearchInformation write reply failed.");
843         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
844     }
845     return NO_ERROR;
846 }
847 
OnGetNetworkSelectionMode(MessageParcel & data,MessageParcel & reply)848 int32_t CoreServiceStub::OnGetNetworkSelectionMode(MessageParcel &data, MessageParcel &reply)
849 {
850     sptr<INetworkSearchCallback> callback = nullptr;
851     int32_t slotId = data.ReadInt32();
852     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
853     if (remoteCallback != nullptr) {
854         callback = iface_cast<INetworkSearchCallback>(remoteCallback);
855     }
856     if (callback == nullptr) {
857         TELEPHONY_LOGE("CoreServiceStub::OnGetNetworkSelectionMode callback is null");
858         return TELEPHONY_ERR_LOCAL_PTR_NULL;
859     }
860     int32_t result = GetNetworkSelectionMode(slotId, callback);
861     if (!reply.WriteInt32(result)) {
862         TELEPHONY_LOGE("CoreServiceStub::OnGetNetworkSelectionMode write reply failed.");
863         return TELEPHONY_ERR_WRITE_DATA_FAIL;
864     }
865     return NO_ERROR;
866 }
867 
OnSetNetworkSelectionMode(MessageParcel & data,MessageParcel & reply)868 int32_t CoreServiceStub::OnSetNetworkSelectionMode(MessageParcel &data, MessageParcel &reply)
869 {
870     sptr<INetworkSearchCallback> callback = nullptr;
871     int32_t slotId = data.ReadInt32();
872     int32_t selectMode = data.ReadInt32();
873     TELEPHONY_LOGD("CoreServiceStub::OnSetNetworkSelectionMode selectMode:%{public}d", selectMode);
874     bool resumeSelection = data.ReadBool();
875     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
876     if (remoteCallback != nullptr) {
877         callback = iface_cast<INetworkSearchCallback>(remoteCallback);
878     } else {
879         TELEPHONY_LOGE("CoreServiceStub::OnSetNetworkSelectionMode remoteCallback is null");
880     }
881     sptr<NetworkInformation> networkState = NetworkInformation::Unmarshalling(data);
882     if (callback == nullptr) {
883         TELEPHONY_LOGE("CoreServiceStub::OnSetNetworkSelectionMode callback is null");
884         return TELEPHONY_ERR_LOCAL_PTR_NULL;
885     }
886     int32_t result = SetNetworkSelectionMode(slotId, selectMode, networkState, resumeSelection, callback);
887     if (!reply.WriteInt32(result)) {
888         TELEPHONY_LOGE("OnRemoteRequest::OnSetNetworkSelectionMode write reply failed.");
889         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
890     }
891     return NO_ERROR;
892 }
893 
OnGetLocaleFromDefaultSim(MessageParcel & data,MessageParcel & reply)894 int32_t CoreServiceStub::OnGetLocaleFromDefaultSim(MessageParcel &data, MessageParcel &reply)
895 {
896     std::u16string result = GetLocaleFromDefaultSim();
897     bool ret = reply.WriteString16(result);
898     if (!ret) {
899         TELEPHONY_LOGE("OnRemoteRequest::GetLocaleFromDefaultSim write reply failed.");
900         return ERR_FLATTEN_OBJECT;
901     }
902     return NO_ERROR;
903 }
904 
OnGetSimGid1(MessageParcel & data,MessageParcel & reply)905 int32_t CoreServiceStub::OnGetSimGid1(MessageParcel &data, MessageParcel &reply)
906 {
907     int32_t slotId = data.ReadInt32();
908     std::u16string gid1;
909     int32_t result = GetSimGid1(slotId, gid1);
910     bool ret = reply.WriteInt32(result);
911     if (result == TELEPHONY_ERR_SUCCESS) {
912         ret = (ret && reply.WriteString16(gid1));
913     }
914     if (!ret) {
915         TELEPHONY_LOGE("OnRemoteRequest::GetSimGid1 write reply failed.");
916         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
917     }
918     return NO_ERROR;
919 }
920 
OnGetSimGid2(MessageParcel & data,MessageParcel & reply)921 int32_t CoreServiceStub::OnGetSimGid2(MessageParcel &data, MessageParcel &reply)
922 {
923     int32_t slotId = data.ReadInt32();
924     std::u16string result = GetSimGid2(slotId);
925     bool ret = reply.WriteString16(result);
926     if (!ret) {
927         TELEPHONY_LOGE("OnRemoteRequest::GetSimGid2 write reply failed.");
928         return ERR_FLATTEN_OBJECT;
929     }
930     return NO_ERROR;
931 }
932 
OnGetSimEons(MessageParcel & data,MessageParcel & reply)933 int32_t CoreServiceStub::OnGetSimEons(MessageParcel &data, MessageParcel &reply)
934 {
935     int32_t slotId = data.ReadInt32();
936     const std::string plmn = data.ReadString();
937     int32_t lac = data.ReadInt32();
938     bool longNameRequired = data.ReadBool();
939     std::u16string result = GetSimEons(slotId, plmn, lac, longNameRequired);
940     bool ret = reply.WriteString16(result);
941     if (!ret) {
942         TELEPHONY_LOGE("OnRemoteRequest::GetSimEons write reply failed.");
943         return ERR_FLATTEN_OBJECT;
944     }
945     return NO_ERROR;
946 }
947 
OnGetSimSubscriptionInfo(MessageParcel & data,MessageParcel & reply)948 int32_t CoreServiceStub::OnGetSimSubscriptionInfo(MessageParcel &data, MessageParcel &reply)
949 {
950     int32_t slotId = data.ReadInt32();
951     IccAccountInfo iccAccountInfo;
952     int32_t result = GetSimAccountInfo(slotId, iccAccountInfo);
953     bool ret = reply.WriteInt32(result);
954     if (!iccAccountInfo.Marshalling(reply)) {
955         TELEPHONY_LOGE("OnGetSimSubscriptionInfo IccAccountInfo reply Marshalling is false");
956         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
957     }
958     if (!ret) {
959         TELEPHONY_LOGE("OnGetSimSubscriptionInfo write reply failed.");
960         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
961     }
962     return NO_ERROR;
963 }
964 
OnSetDefaultVoiceSlotId(MessageParcel & data,MessageParcel & reply)965 int32_t CoreServiceStub::OnSetDefaultVoiceSlotId(MessageParcel &data, MessageParcel &reply)
966 {
967     int32_t slotId = data.ReadInt32();
968     int32_t result = SetDefaultVoiceSlotId(slotId);
969     bool ret = reply.WriteInt32(result);
970     if (!ret) {
971         TELEPHONY_LOGE("OnSetDefaultVoiceSlotId write reply failed.");
972         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
973     }
974     return NO_ERROR;
975 }
976 
OnGetDefaultVoiceSlotId(MessageParcel & data,MessageParcel & reply)977 int32_t CoreServiceStub::OnGetDefaultVoiceSlotId(MessageParcel &data, MessageParcel &reply)
978 {
979     int32_t result = GetDefaultVoiceSlotId();
980     bool ret = reply.WriteInt32(result);
981     if (!ret) {
982         TELEPHONY_LOGE("OnGetDefaultVoiceSlotId write reply failed.");
983         return ERR_FLATTEN_OBJECT;
984     }
985     return NO_ERROR;
986 }
987 
OnGetDefaultVoiceSimId(MessageParcel & data,MessageParcel & reply)988 int32_t CoreServiceStub::OnGetDefaultVoiceSimId(MessageParcel &data, MessageParcel &reply)
989 {
990     int32_t simId = 0;
991     int32_t result = GetDefaultVoiceSimId(simId);
992     if (!reply.WriteInt32(result)) {
993         TELEPHONY_LOGE("write int32 reply failed.");
994         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
995     }
996     if (result == TELEPHONY_ERR_SUCCESS) {
997         if (!reply.WriteInt32(simId)) {
998             TELEPHONY_LOGE("write int32 reply failed.");
999             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1000         }
1001     }
1002     return NO_ERROR;
1003 }
1004 
OnSetPrimarySlotId(MessageParcel & data,MessageParcel & reply)1005 int32_t CoreServiceStub::OnSetPrimarySlotId(MessageParcel &data, MessageParcel &reply)
1006 {
1007     int32_t slotId = data.ReadInt32();
1008     int32_t result = SetPrimarySlotId(slotId);
1009     if (!reply.WriteInt32(result)) {
1010         TELEPHONY_LOGE("OnRemoteRequest::OnSetPrimarySlotId write reply failed.");
1011         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1012     }
1013     return NO_ERROR;
1014 }
1015 
OnGetPrimarySlotId(MessageParcel & data,MessageParcel & reply)1016 int32_t CoreServiceStub::OnGetPrimarySlotId(MessageParcel &data, MessageParcel &reply)
1017 {
1018     int32_t slotId = INVALID_VALUE;
1019     int32_t result = GetPrimarySlotId(slotId);
1020     bool ret = reply.WriteInt32(result);
1021     if (result == TELEPHONY_ERR_SUCCESS) {
1022         ret = (ret && reply.WriteInt32(slotId));
1023     }
1024     if (!ret) {
1025         TELEPHONY_LOGE("write reply failed.");
1026         return TELEPHONY_ERR_WRITE_DATA_FAIL;
1027     }
1028     return NO_ERROR;
1029 }
1030 
OnUnlockPin(MessageParcel & data,MessageParcel & reply)1031 int32_t CoreServiceStub::OnUnlockPin(MessageParcel &data, MessageParcel &reply)
1032 {
1033     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1034     int32_t slotId = data.ReadInt32();
1035     std::u16string pin = data.ReadString16();
1036     int32_t result = UnlockPin(slotId, pin, response);
1037     bool ret = reply.WriteInt32(result);
1038     TELEPHONY_LOGI(
1039         "OnUnlockPin, response.result :%{public}d, response.remain :%{public}d", response.result, response.remain);
1040     if (result == TELEPHONY_ERR_SUCCESS) {
1041         ret = (ret && reply.WriteInt32(response.result));
1042         ret = (ret && reply.WriteInt32(response.remain));
1043     }
1044     if (!ret) {
1045         TELEPHONY_LOGE("CoreServiceStub::OnUnlockPin write reply failed.");
1046         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1047     }
1048     return NO_ERROR;
1049 }
1050 
OnUnlockPuk(MessageParcel & data,MessageParcel & reply)1051 int32_t CoreServiceStub::OnUnlockPuk(MessageParcel &data, MessageParcel &reply)
1052 {
1053     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1054     int32_t slotId = data.ReadInt32();
1055     std::u16string newPin = data.ReadString16();
1056     std::u16string puk = data.ReadString16();
1057     int32_t result = UnlockPuk(slotId, newPin, puk, response);
1058     bool ret = reply.WriteInt32(result);
1059     TELEPHONY_LOGI(
1060         "OnUnlockPuk, response.result :%{public}d, response.remain :%{public}d", response.result, response.remain);
1061     if (result == TELEPHONY_ERR_SUCCESS) {
1062         ret = (ret && reply.WriteInt32(response.result));
1063         ret = (ret && reply.WriteInt32(response.remain));
1064     }
1065     if (!ret) {
1066         TELEPHONY_LOGE("CoreServiceStub::OnUnlockPuk write reply failed.");
1067         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1068     }
1069     return NO_ERROR;
1070 }
1071 
OnAlterPin(MessageParcel & data,MessageParcel & reply)1072 int32_t CoreServiceStub::OnAlterPin(MessageParcel &data, MessageParcel &reply)
1073 {
1074     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1075     int32_t slotId = data.ReadInt32();
1076     std::u16string newPin = data.ReadString16();
1077     std::u16string oldPin = data.ReadString16();
1078     int32_t result = AlterPin(slotId, newPin, oldPin, response);
1079     bool ret = reply.WriteInt32(result);
1080     TELEPHONY_LOGI(
1081         "OnAlterPin, response.result :%{public}d, response.remain :%{public}d", response.result, response.remain);
1082     if (result == TELEPHONY_ERR_SUCCESS) {
1083         ret = (ret && reply.WriteInt32(response.result));
1084         ret = (ret && reply.WriteInt32(response.remain));
1085     }
1086     if (!ret) {
1087         TELEPHONY_LOGE("CoreServiceStub::OnAlterPin write reply failed.");
1088         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1089     }
1090     return NO_ERROR;
1091 }
1092 
OnUnlockPin2(MessageParcel & data,MessageParcel & reply)1093 int32_t CoreServiceStub::OnUnlockPin2(MessageParcel &data, MessageParcel &reply)
1094 {
1095     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1096     int32_t slotId = data.ReadInt32();
1097     std::u16string pin2 = data.ReadString16();
1098     int32_t result = UnlockPin2(slotId, pin2, response);
1099     bool ret = reply.WriteInt32(result);
1100     TELEPHONY_LOGI(
1101         "OnUnlockPin2, response.result :%{public}d, response.remain :%{public}d", response.result, response.remain);
1102     if (result == TELEPHONY_ERR_SUCCESS) {
1103         ret = (ret && reply.WriteInt32(response.result));
1104         ret = (ret && reply.WriteInt32(response.remain));
1105     }
1106     if (!ret) {
1107         TELEPHONY_LOGE("CoreServiceStub::OnUnlockPin2 write reply failed.");
1108         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1109     }
1110     return NO_ERROR;
1111 }
1112 
OnUnlockPuk2(MessageParcel & data,MessageParcel & reply)1113 int32_t CoreServiceStub::OnUnlockPuk2(MessageParcel &data, MessageParcel &reply)
1114 {
1115     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1116     int32_t slotId = data.ReadInt32();
1117     std::u16string newPin2 = data.ReadString16();
1118     std::u16string puk2 = data.ReadString16();
1119     int32_t result = UnlockPuk2(slotId, newPin2, puk2, response);
1120     bool ret = reply.WriteInt32(result);
1121     TELEPHONY_LOGI(
1122         "OnUnlockPuk2, response.result :%{public}d, response.remain :%{public}d", response.result, response.remain);
1123     if (result == TELEPHONY_ERR_SUCCESS) {
1124         ret = (ret && reply.WriteInt32(response.result));
1125         ret = (ret && reply.WriteInt32(response.remain));
1126     }
1127     if (!ret) {
1128         TELEPHONY_LOGE("CoreServiceStub::OnUnlockPuk2 write reply failed.");
1129         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1130     }
1131     return NO_ERROR;
1132 }
1133 
OnAlterPin2(MessageParcel & data,MessageParcel & reply)1134 int32_t CoreServiceStub::OnAlterPin2(MessageParcel &data, MessageParcel &reply)
1135 {
1136     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1137     int32_t slotId = data.ReadInt32();
1138     std::u16string newPin2 = data.ReadString16();
1139     std::u16string oldPin2 = data.ReadString16();
1140     int32_t result = AlterPin2(slotId, newPin2, oldPin2, response);
1141     bool ret = reply.WriteInt32(result);
1142     TELEPHONY_LOGI(
1143         "OnAlterPin2, response.result :%{public}d, response.remain :%{public}d", response.result, response.remain);
1144     if (result == TELEPHONY_ERR_SUCCESS) {
1145         ret = (ret && reply.WriteInt32(response.result));
1146         ret = (ret && reply.WriteInt32(response.remain));
1147     }
1148     if (!ret) {
1149         TELEPHONY_LOGE("CoreServiceStub::OnAlterPin2 write reply failed.");
1150         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1151     }
1152     return NO_ERROR;
1153 }
1154 
OnSetLockState(MessageParcel & data,MessageParcel & reply)1155 int32_t CoreServiceStub::OnSetLockState(MessageParcel &data, MessageParcel &reply)
1156 {
1157     LockInfo options;
1158     int32_t slotId = data.ReadInt32();
1159     options.lockType = static_cast<LockType>(data.ReadInt32());
1160     options.lockState = static_cast<LockState>(data.ReadInt32());
1161     options.password = data.ReadString16();
1162     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1163     TELEPHONY_LOGI("CoreServiceStub::OnSetLockState(), lockType = %{public}d, lockState = %{public}d, "
1164                    "slotId = %{public}d",
1165         options.lockType, options.lockState, slotId);
1166     int32_t result = SetLockState(slotId, options, response);
1167     bool ret = reply.WriteInt32(result);
1168     TELEPHONY_LOGI(
1169         "OnSetLockState, response.result :%{public}d, response.remain :%{public}d", response.result, response.remain);
1170     if (result == TELEPHONY_ERR_SUCCESS) {
1171         ret = (ret && reply.WriteInt32(response.result));
1172         ret = (ret && reply.WriteInt32(response.remain));
1173     }
1174     if (!ret) {
1175         TELEPHONY_LOGE("CoreServiceStub::OnSetLockState write reply failed.");
1176         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1177     }
1178     return NO_ERROR;
1179 }
1180 
OnGetLockState(MessageParcel & data,MessageParcel & reply)1181 int32_t CoreServiceStub::OnGetLockState(MessageParcel &data, MessageParcel &reply)
1182 {
1183     LockState lockState = LockState::LOCK_ERROR;
1184     LockType lockType;
1185     int32_t slotId = data.ReadInt32();
1186     lockType = static_cast<LockType>(data.ReadInt32());
1187     TELEPHONY_LOGI("CoreServiceStub::OnGetLockState(),lockType = %{public}d, slotId = %{public}d", lockType, slotId);
1188     int32_t result = GetLockState(slotId, lockType, lockState);
1189     bool ret = reply.WriteInt32(result);
1190     if (result == TELEPHONY_ERR_SUCCESS) {
1191         ret = (ret && reply.WriteInt32(static_cast<int32_t>(lockState)));
1192     }
1193     if (!ret) {
1194         TELEPHONY_LOGE("CoreServiceStub::OnGetLockState write reply failed.");
1195         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1196     }
1197     return NO_ERROR;
1198 }
1199 
OnRefreshSimState(MessageParcel & data,MessageParcel & reply)1200 int32_t CoreServiceStub::OnRefreshSimState(MessageParcel &data, MessageParcel &reply)
1201 {
1202     int32_t slotId = data.ReadInt32();
1203     TELEPHONY_LOGD("CoreServiceStub::OnRefreshSimState(), slotId = %{public}d", slotId);
1204     int32_t result = RefreshSimState(slotId);
1205     bool ret = reply.WriteInt32(result);
1206     if (!ret) {
1207         TELEPHONY_LOGE("CoreServiceStub::OnRefreshSimState write reply failed.");
1208         return ERR_FLATTEN_OBJECT;
1209     }
1210     return NO_ERROR;
1211 }
1212 
OnSetActiveSim(MessageParcel & data,MessageParcel & reply)1213 int32_t CoreServiceStub::OnSetActiveSim(MessageParcel &data, MessageParcel &reply)
1214 {
1215     int32_t slotId = data.ReadInt32();
1216     int32_t enable = data.ReadInt32();
1217     TELEPHONY_LOGD("CoreServiceStub::OnSetActiveSim(), slotId = %{public}d", slotId);
1218     int32_t result = SetActiveSim(slotId, enable);
1219     bool ret = reply.WriteInt32(result);
1220     if (!ret) {
1221         TELEPHONY_LOGE("CoreServiceStub::OnSetActiveSim write reply failed.");
1222         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1223     }
1224     return NO_ERROR;
1225 }
1226 
OnGetPreferredNetwork(MessageParcel & data,MessageParcel & reply)1227 int32_t CoreServiceStub::OnGetPreferredNetwork(MessageParcel &data, MessageParcel &reply)
1228 {
1229     sptr<INetworkSearchCallback> callback = nullptr;
1230     int32_t slotId = data.ReadInt32();
1231     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
1232     if (remoteCallback != nullptr) {
1233         TELEPHONY_LOGD("CoreServiceStub::OnGetPreferredNetwork remote callback is not null.");
1234         callback = iface_cast<INetworkSearchCallback>(remoteCallback);
1235     }
1236     if (callback == nullptr) {
1237         TELEPHONY_LOGE("CoreServiceStub::OnGetPreferredNetwork callback is null");
1238         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1239     }
1240     int32_t result = GetPreferredNetwork(slotId, callback);
1241     if (!reply.WriteInt32(result)) {
1242         TELEPHONY_LOGE("OnRemoteRequest::OnGetPreferredNetwork write reply failed.");
1243         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1244     }
1245     return NO_ERROR;
1246 }
1247 
OnGetNetworkCapability(MessageParcel & data,MessageParcel & reply)1248 int32_t CoreServiceStub::OnGetNetworkCapability(MessageParcel &data, MessageParcel &reply)
1249 {
1250     int32_t slotId = data.ReadInt32();
1251     int32_t networkCapabilityType = data.ReadInt32();
1252     int32_t networkCapabilityState = 0;
1253     int32_t result = GetNetworkCapability(slotId, networkCapabilityType, networkCapabilityState);
1254     bool ret = reply.WriteInt32(result);
1255     if (result == TELEPHONY_ERR_SUCCESS) {
1256         ret = (ret && reply.WriteInt32(networkCapabilityState));
1257     }
1258     if (!ret) {
1259         TELEPHONY_LOGE("OnRemoteRequest::OnGetNetworkCapability write reply failed.");
1260         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1261     }
1262     return NO_ERROR;
1263 }
1264 
OnSetNetworkCapability(MessageParcel & data,MessageParcel & reply)1265 int32_t CoreServiceStub::OnSetNetworkCapability(MessageParcel &data, MessageParcel &reply)
1266 {
1267     int32_t slotId = data.ReadInt32();
1268     int32_t networkCapabilityType = data.ReadInt32();
1269     int32_t networkCapabilityState = data.ReadInt32();
1270     int32_t result = SetNetworkCapability(slotId, networkCapabilityType, networkCapabilityState);
1271     if (!reply.WriteInt32(result)) {
1272         TELEPHONY_LOGE("OnRemoteRequest::OnSetNetworkCapability write reply failed.");
1273         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1274     }
1275     return NO_ERROR;
1276 }
1277 
OnSetShowNumber(MessageParcel & data,MessageParcel & reply)1278 int32_t CoreServiceStub::OnSetShowNumber(MessageParcel &data, MessageParcel &reply)
1279 {
1280     int32_t slotId = data.ReadInt32();
1281     std::u16string number = data.ReadString16();
1282     int32_t result = SetShowNumber(slotId, number);
1283     bool ret = reply.WriteInt32(result);
1284     if (!ret) {
1285         TELEPHONY_LOGE("OnSetShowNumber write reply failed.");
1286         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1287     }
1288     return result;
1289 }
1290 
OnGetShowNumber(OHOS::MessageParcel & data,OHOS::MessageParcel & reply)1291 int32_t CoreServiceStub::OnGetShowNumber(OHOS::MessageParcel &data, OHOS::MessageParcel &reply)
1292 {
1293     int32_t slotId = data.ReadInt32();
1294     std::u16string showNumber;
1295     int32_t result = GetShowNumber(slotId, showNumber);
1296     bool ret = reply.WriteInt32(result);
1297     if (result == TELEPHONY_ERR_SUCCESS) {
1298         ret = (ret && reply.WriteString16(showNumber));
1299     }
1300     if (!ret) {
1301         TELEPHONY_LOGE("OnGetShowNumber write reply failed.");
1302         return ERR_FLATTEN_OBJECT;
1303     }
1304     return NO_ERROR;
1305 }
1306 
OnSetShowName(MessageParcel & data,MessageParcel & reply)1307 int32_t CoreServiceStub::OnSetShowName(MessageParcel &data, MessageParcel &reply)
1308 {
1309     int32_t slotId = data.ReadInt32();
1310     std::u16string name = data.ReadString16();
1311     int32_t result = SetShowName(slotId, name);
1312     bool ret = reply.WriteInt32(result);
1313     if (!ret) {
1314         TELEPHONY_LOGE("OnSetShowName write reply failed.");
1315         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1316     }
1317     return NO_ERROR;
1318 }
1319 
OnSetPreferredNetwork(MessageParcel & data,MessageParcel & reply)1320 int32_t CoreServiceStub::OnSetPreferredNetwork(MessageParcel &data, MessageParcel &reply)
1321 {
1322     sptr<INetworkSearchCallback> callback = nullptr;
1323     int32_t slotId = data.ReadInt32();
1324     int32_t networkMode = data.ReadInt32();
1325     TELEPHONY_LOGI("CoreServiceStub::OnSetPreferredNetwork selectMode:%{public}d", networkMode);
1326     sptr<IRemoteObject> remoteCallback = data.ReadRemoteObject();
1327     if (remoteCallback != nullptr) {
1328         callback = iface_cast<INetworkSearchCallback>(remoteCallback);
1329     } else {
1330         TELEPHONY_LOGE("CoreServiceStub::OnSetPreferredNetwork remoteCallback is null");
1331     }
1332     if (callback == nullptr) {
1333         TELEPHONY_LOGE("CoreServiceStub::OnSetPreferredNetwork callback is null");
1334         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1335     }
1336     int32_t result = SetPreferredNetwork(slotId, networkMode, callback);
1337     if (!reply.WriteInt32(result)) {
1338         TELEPHONY_LOGE("OnRemoteRequest::OnSetPreferredNetwork write reply failed.");
1339         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1340     }
1341     return NO_ERROR;
1342 }
1343 
OnGetShowName(OHOS::MessageParcel & data,OHOS::MessageParcel & reply)1344 int32_t CoreServiceStub::OnGetShowName(OHOS::MessageParcel &data, OHOS::MessageParcel &reply)
1345 {
1346     int32_t slotId = data.ReadInt32();
1347     std::u16string showName;
1348     int32_t result = GetShowName(slotId, showName);
1349     bool ret = reply.WriteInt32(result);
1350     if (result == TELEPHONY_ERR_SUCCESS) {
1351         ret = (ret && reply.WriteString16(showName));
1352     }
1353     if (!ret) {
1354         TELEPHONY_LOGE("OnGetShowName write reply failed.");
1355         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1356     }
1357     return NO_ERROR;
1358 }
1359 
OnGetActiveSimAccountInfoList(MessageParcel & data,MessageParcel & reply)1360 int32_t CoreServiceStub::OnGetActiveSimAccountInfoList(MessageParcel &data, MessageParcel &reply)
1361 {
1362     std::vector<IccAccountInfo> iccAccountInfoList;
1363     int32_t result = GetActiveSimAccountInfoList(iccAccountInfoList);
1364     int32_t size = static_cast<int32_t>(iccAccountInfoList.size());
1365     bool ret = reply.WriteInt32(result);
1366     ret = (ret && reply.WriteInt32(size));
1367     if (!ret) {
1368         TELEPHONY_LOGE("OnGetActiveSimAccountInfoList write reply failed.");
1369         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1370     }
1371     std::vector<IccAccountInfo>::iterator it = iccAccountInfoList.begin();
1372     while (it != iccAccountInfoList.end()) {
1373         TELEPHONY_LOGI("OnGetActiveSimAccountInfoList slotIndex = %{public}d", (*it).slotIndex);
1374         if (!(*it).Marshalling(reply)) {
1375             TELEPHONY_LOGE("OnGetActiveSimAccountInfoList IccAccountInfo reply Marshalling is false");
1376             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1377         }
1378         ++it;
1379     }
1380     return NO_ERROR;
1381 }
1382 
OnGetOperatorConfig(MessageParcel & data,MessageParcel & reply)1383 int32_t CoreServiceStub::OnGetOperatorConfig(MessageParcel &data, MessageParcel &reply)
1384 {
1385     int32_t slotId = data.ReadInt32();
1386     OperatorConfig operatorConfig;
1387     int32_t result = GetOperatorConfigs(slotId, operatorConfig);
1388     bool ret = reply.WriteInt32(result);
1389     if (!ret) {
1390         TELEPHONY_LOGE("OnGetOperatorConfig write reply failed.");
1391         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1392     }
1393     if (result == TELEPHONY_ERR_SUCCESS) {
1394         if (!operatorConfig.Marshalling(reply)) {
1395             TELEPHONY_LOGE("OnGetOperatorConfig operatorConfig reply Marshalling is false");
1396             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1397         }
1398     }
1399     return NO_ERROR;
1400 }
1401 
OnGetSimPhoneNumber(MessageParcel & data,MessageParcel & reply)1402 int32_t CoreServiceStub::OnGetSimPhoneNumber(MessageParcel &data, MessageParcel &reply)
1403 {
1404     int32_t slotId = data.ReadInt32();
1405     std::u16string telephoneNumber;
1406     int32_t result = GetSimTelephoneNumber(slotId, telephoneNumber);
1407     bool ret = reply.WriteInt32(result);
1408     if (result == TELEPHONY_ERR_SUCCESS) {
1409         ret = (ret && reply.WriteString16(telephoneNumber));
1410     }
1411     if (!ret) {
1412         TELEPHONY_LOGE("OnRemoteRequest::OnGetSimPhoneNumber write reply failed.");
1413         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1414     }
1415     return NO_ERROR;
1416 }
1417 
OnGetSimTeleNumberIdentifier(MessageParcel & data,MessageParcel & reply)1418 int32_t CoreServiceStub::OnGetSimTeleNumberIdentifier(MessageParcel &data, MessageParcel &reply)
1419 {
1420     const int32_t slotId = data.ReadInt32();
1421     std::u16string result = GetSimTeleNumberIdentifier(slotId);
1422     bool ret = reply.WriteString16(result);
1423     if (!ret) {
1424         TELEPHONY_LOGE("OnRemoteRequest::OnGetSimPhoneNumber write reply failed.");
1425         return ERR_FLATTEN_OBJECT;
1426     }
1427     return NO_ERROR;
1428 }
1429 
OnGetVoiceMailInfor(MessageParcel & data,MessageParcel & reply)1430 int32_t CoreServiceStub::OnGetVoiceMailInfor(MessageParcel &data, MessageParcel &reply)
1431 {
1432     int32_t slotId = data.ReadInt32();
1433     std::u16string voiceMailIdentifier;
1434     int32_t result = GetVoiceMailIdentifier(slotId, voiceMailIdentifier);
1435     bool ret = reply.WriteInt32(result);
1436     if (result == TELEPHONY_ERR_SUCCESS) {
1437         ret = (ret && reply.WriteString16(voiceMailIdentifier));
1438     }
1439     if (!ret) {
1440         TELEPHONY_LOGE("OnRemoteRequest::OnGetVoiceMailInfor write reply failed.");
1441         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1442     }
1443     return NO_ERROR;
1444 }
1445 
OnGetVoiceMailNumber(MessageParcel & data,MessageParcel & reply)1446 int32_t CoreServiceStub::OnGetVoiceMailNumber(MessageParcel &data, MessageParcel &reply)
1447 {
1448     int32_t slotId = data.ReadInt32();
1449     std::u16string voiceMailNumber;
1450     int32_t result = GetVoiceMailNumber(slotId, voiceMailNumber);
1451     bool ret = reply.WriteInt32(result);
1452     if (result == TELEPHONY_ERR_SUCCESS) {
1453         ret = (ret && reply.WriteString16(voiceMailNumber));
1454     }
1455     if (!ret) {
1456         TELEPHONY_LOGE("OnRemoteRequest::OnGetVoiceMailNumber write reply failed.");
1457         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1458     }
1459     return NO_ERROR;
1460 }
1461 
OnGetVoiceMailCount(MessageParcel & data,MessageParcel & reply)1462 int32_t CoreServiceStub::OnGetVoiceMailCount(MessageParcel &data, MessageParcel &reply)
1463 {
1464     int32_t slotId = data.ReadInt32();
1465     int32_t voiceMailCount;
1466     int32_t result = GetVoiceMailCount(slotId, voiceMailCount);
1467     bool ret = reply.WriteInt32(result);
1468     if (result == TELEPHONY_ERR_SUCCESS) {
1469         ret = (ret && reply.WriteInt32(voiceMailCount));
1470     }
1471     if (!ret) {
1472         TELEPHONY_LOGE("OnRemoteRequest::OnGetVoiceMailCount write reply failed.");
1473         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1474     }
1475     return NO_ERROR;
1476 }
1477 
OnSetVoiceMailCount(MessageParcel & data,MessageParcel & reply)1478 int32_t CoreServiceStub::OnSetVoiceMailCount(MessageParcel &data, MessageParcel &reply)
1479 {
1480     int32_t slotId = data.ReadInt32();
1481     int32_t voiceMailCount = data.ReadInt32();
1482     int32_t result = SetVoiceMailCount(slotId, voiceMailCount);
1483     if (!reply.WriteInt32(result)) {
1484         TELEPHONY_LOGE("OnRemoteRequest::OnSetVoiceMailCount write reply failed.");
1485         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1486     }
1487     return NO_ERROR;
1488 }
1489 
OnSetVoiceCallForwarding(MessageParcel & data,MessageParcel & reply)1490 int32_t CoreServiceStub::OnSetVoiceCallForwarding(MessageParcel &data, MessageParcel &reply)
1491 {
1492     int32_t slotId = data.ReadInt32();
1493     bool enable = data.ReadBool();
1494     std::string number = data.ReadString();
1495     int32_t result = SetVoiceCallForwarding(slotId, enable, number);
1496     if (!reply.WriteInt32(result)) {
1497         TELEPHONY_LOGE("OnRemoteRequest::OnSetVoiceCallForwarding write reply failed.");
1498         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1499     }
1500     return NO_ERROR;
1501 }
1502 
OnDiallingNumbersGet(MessageParcel & data,MessageParcel & reply)1503 int32_t CoreServiceStub::OnDiallingNumbersGet(MessageParcel &data, MessageParcel &reply)
1504 {
1505     int32_t slotId = data.ReadInt32();
1506     int32_t type = data.ReadInt32();
1507     std::vector<std::shared_ptr<DiallingNumbersInfo>> diallingNumbers;
1508     int32_t result = QueryIccDiallingNumbers(slotId, type, diallingNumbers);
1509     bool ret = reply.WriteInt32(result);
1510     if (!ret) {
1511         TELEPHONY_LOGE("OnRemoteRequest::OnDiallingNumbersGet write reply failed.");
1512         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1513     }
1514     if (result == TELEPHONY_ERR_SUCCESS) {
1515         reply.WriteInt32(static_cast<int32_t>(diallingNumbers.size()));
1516         for (const auto &v : diallingNumbers) {
1517             v->Marshalling(reply);
1518         }
1519     }
1520     return NO_ERROR;
1521 }
1522 
OnAddIccDiallingNumbers(MessageParcel & data,MessageParcel & reply)1523 int32_t CoreServiceStub::OnAddIccDiallingNumbers(MessageParcel &data, MessageParcel &reply)
1524 {
1525     int32_t slotId = data.ReadInt32();
1526     int32_t type = data.ReadInt32();
1527     std::shared_ptr<DiallingNumbersInfo> diallingNumber = DiallingNumbersInfo::UnMarshalling(data);
1528     if (diallingNumber == nullptr) {
1529         TELEPHONY_LOGE("CoreServiceStub::OnAddIccDiallingNumbers diallingNumber is null");
1530         return TELEPHONY_ERR_READ_DATA_FAIL;
1531     }
1532     int32_t result = AddIccDiallingNumbers(slotId, type, diallingNumber);
1533     bool ret = reply.WriteInt32(result);
1534     if (!ret) {
1535         TELEPHONY_LOGE("OnAddIccDiallingNumbers write reply failed.");
1536         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1537     }
1538     return NO_ERROR;
1539 }
1540 
OnUpdateIccDiallingNumbers(MessageParcel & data,MessageParcel & reply)1541 int32_t CoreServiceStub::OnUpdateIccDiallingNumbers(MessageParcel &data, MessageParcel &reply)
1542 {
1543     int32_t slotId = data.ReadInt32();
1544     int32_t type = data.ReadInt32();
1545     std::shared_ptr<DiallingNumbersInfo> diallingNumber = DiallingNumbersInfo::UnMarshalling(data);
1546     if (diallingNumber == nullptr) {
1547         TELEPHONY_LOGE("CoreServiceStub::OnUpdateIccDiallingNumbers diallingNumber is null");
1548         return TELEPHONY_ERR_READ_DATA_FAIL;
1549     }
1550     int32_t result = UpdateIccDiallingNumbers(slotId, type, diallingNumber);
1551     bool ret = reply.WriteInt32(result);
1552     if (!ret) {
1553         TELEPHONY_LOGE("OnUpdateIccDiallingNumbers write reply failed.");
1554         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1555     }
1556     return NO_ERROR;
1557 }
1558 
OnDelIccDiallingNumbers(MessageParcel & data,MessageParcel & reply)1559 int32_t CoreServiceStub::OnDelIccDiallingNumbers(MessageParcel &data, MessageParcel &reply)
1560 {
1561     int32_t slotId = data.ReadInt32();
1562     int32_t type = data.ReadInt32();
1563     std::shared_ptr<DiallingNumbersInfo> diallingNumber = DiallingNumbersInfo::UnMarshalling(data);
1564     if (diallingNumber == nullptr) {
1565         TELEPHONY_LOGE("CoreServiceStub::OnDelIccDiallingNumbers diallingNumber is null");
1566         return TELEPHONY_ERR_READ_DATA_FAIL;
1567     }
1568     int32_t result = DelIccDiallingNumbers(slotId, type, diallingNumber);
1569     bool ret = reply.WriteInt32(result);
1570     if (!ret) {
1571         TELEPHONY_LOGE("OnDelIccDiallingNumbers write reply failed.");
1572         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1573     }
1574     return NO_ERROR;
1575 }
1576 
OnSetVoiceMailInfo(MessageParcel & data,MessageParcel & reply)1577 int32_t CoreServiceStub::OnSetVoiceMailInfo(MessageParcel &data, MessageParcel &reply)
1578 {
1579     int32_t slotId = data.ReadInt32();
1580     std::u16string name = data.ReadString16();
1581     std::u16string number = data.ReadString16();
1582     int32_t result = SetVoiceMailInfo(slotId, name, number);
1583 
1584     bool ret = reply.WriteInt32(result);
1585     if (!ret) {
1586         TELEPHONY_LOGE("OnSetVoiceMailInfo write reply failed.");
1587         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1588     }
1589     return NO_ERROR;
1590 }
1591 
OnGetMaxSimCount(MessageParcel & data,MessageParcel & reply)1592 int32_t CoreServiceStub::OnGetMaxSimCount(MessageParcel &data, MessageParcel &reply)
1593 {
1594     int32_t result = GetMaxSimCount();
1595     int32_t ret = reply.WriteInt32(result);
1596     if (!ret) {
1597         TELEPHONY_LOGE("OnGetMaxSimCount write reply failed.");
1598         return ERR_FLATTEN_OBJECT;
1599     }
1600     return NO_ERROR;
1601 }
1602 
OnGetOpKey(MessageParcel & data,MessageParcel & reply)1603 int32_t CoreServiceStub::OnGetOpKey(MessageParcel &data, MessageParcel &reply)
1604 {
1605     int32_t slotId = data.ReadInt32();
1606     std::u16string opkey;
1607     int32_t result = GetOpKey(slotId, opkey);
1608     if (!reply.WriteInt32(result)) {
1609         TELEPHONY_LOGE("OnRemoteRequest::OnGetOpKey write reply failed.");
1610         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1611     }
1612     if (result == TELEPHONY_ERR_SUCCESS) {
1613         if (!reply.WriteString16(opkey)) {
1614             TELEPHONY_LOGE("OnRemoteRequest::OnGetOpKey write reply failed.");
1615             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1616         }
1617     }
1618     return NO_ERROR;
1619 }
1620 
OnGetOpKeyExt(MessageParcel & data,MessageParcel & reply)1621 int32_t CoreServiceStub::OnGetOpKeyExt(MessageParcel &data, MessageParcel &reply)
1622 {
1623     int32_t slotId = data.ReadInt32();
1624     std::u16string opkeyExt;
1625     int32_t result = GetOpKeyExt(slotId, opkeyExt);
1626     if (!reply.WriteInt32(result)) {
1627         TELEPHONY_LOGE("OnRemoteRequest::OnGetOpKeyExt write reply failed.");
1628         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1629     }
1630     if (result == TELEPHONY_ERR_SUCCESS) {
1631         if (!reply.WriteString16(opkeyExt)) {
1632             TELEPHONY_LOGE("OnRemoteRequest::OnGetOpKeyExt write reply failed.");
1633             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1634         }
1635     }
1636     return NO_ERROR;
1637 }
1638 
OnGetOpName(MessageParcel & data,MessageParcel & reply)1639 int32_t CoreServiceStub::OnGetOpName(MessageParcel &data, MessageParcel &reply)
1640 {
1641     int32_t slotId = data.ReadInt32();
1642     std::u16string opname;
1643     int32_t result = GetOpName(slotId, opname);
1644     if (!reply.WriteInt32(result)) {
1645         TELEPHONY_LOGE("OnRemoteRequest::OnGetOpName write reply failed.");
1646         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1647     }
1648     if (result == TELEPHONY_ERR_SUCCESS) {
1649         if (!reply.WriteString16(opname)) {
1650             TELEPHONY_LOGE("OnRemoteRequest::OnGetOpName write reply failed.");
1651             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1652         }
1653     }
1654     return NO_ERROR;
1655 }
1656 
OnSendEnvelopeCmd(MessageParcel & data,MessageParcel & reply)1657 int32_t CoreServiceStub::OnSendEnvelopeCmd(MessageParcel &data, MessageParcel &reply)
1658 {
1659     int32_t slotId = data.ReadInt32();
1660     std::string cmd = data.ReadString();
1661     int32_t result = SendEnvelopeCmd(slotId, cmd);
1662     TELEPHONY_LOGI("OnRemoteRequest::OnSendEnvelopeCmd result is %{public}s", result ? "true" : "false");
1663     bool ret = reply.WriteInt32(result);
1664     if (!ret) {
1665         TELEPHONY_LOGE("OnRemoteRequest::OnSendEnvelopeCmd write reply failed.");
1666         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1667     }
1668     return NO_ERROR;
1669 }
1670 
OnSendTerminalResponseCmd(MessageParcel & data,MessageParcel & reply)1671 int32_t CoreServiceStub::OnSendTerminalResponseCmd(MessageParcel &data, MessageParcel &reply)
1672 {
1673     int32_t slotId = data.ReadInt32();
1674     std::string cmd = data.ReadString();
1675     int32_t result = SendTerminalResponseCmd(slotId, cmd);
1676     TELEPHONY_LOGD("OnRemoteRequest::OnSendTerminalResponseCmd result is %{public}s", result ? "true" : "false");
1677     bool ret = reply.WriteInt32(result);
1678     if (!ret) {
1679         TELEPHONY_LOGE("OnRemoteRequest::OnSendTerminalResponseCmd write reply failed.");
1680         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1681     }
1682     return NO_ERROR;
1683 }
1684 
OnSendCallSetupRequestResult(MessageParcel & data,MessageParcel & reply)1685 int32_t CoreServiceStub::OnSendCallSetupRequestResult(MessageParcel &data, MessageParcel &reply)
1686 {
1687     int32_t slotId = data.ReadInt32();
1688     bool accept = data.ReadInt32();
1689     int32_t result = SendCallSetupRequestResult(slotId, accept);
1690     TELEPHONY_LOGD("OnRemoteRequest::OnSendCallSetupRequestResult result is %{public}d", result);
1691     bool ret = reply.WriteInt32(result);
1692     if (!ret) {
1693         TELEPHONY_LOGE("OnRemoteRequest::OnSendCallSetupRequestResult write reply failed.");
1694         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1695     }
1696     return NO_ERROR;
1697 }
1698 
OnUnlockSimLock(MessageParcel & data,MessageParcel & reply)1699 int32_t CoreServiceStub::OnUnlockSimLock(MessageParcel &data, MessageParcel &reply)
1700 {
1701     PersoLockInfo lockInfo;
1702     int32_t slotId = data.ReadInt32();
1703     lockInfo.lockType = static_cast<PersoLockType>(data.ReadInt32());
1704     lockInfo.password = data.ReadString16();
1705     LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1706 
1707     TELEPHONY_LOGI("CoreServiceStub::OnUnlockSimLock(), lockType = %{public}d", lockInfo.lockType);
1708     int32_t result = UnlockSimLock(slotId, lockInfo, response);
1709     bool ret = reply.WriteInt32(result);
1710     if (result == TELEPHONY_ERR_SUCCESS) {
1711         ret = (ret && reply.WriteInt32(response.result));
1712         ret = (ret && reply.WriteInt32(response.remain));
1713     }
1714     if (!ret) {
1715         TELEPHONY_LOGE("CoreServiceStub::OnUnlockSimLock write reply failed.");
1716         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1717     }
1718     return NO_ERROR;
1719 }
1720 
OnGetImsRegStatus(MessageParcel & data,MessageParcel & reply)1721 int32_t CoreServiceStub::OnGetImsRegStatus(MessageParcel &data, MessageParcel &reply)
1722 {
1723     int32_t slotId = data.ReadInt32();
1724     ImsServiceType imsSrvType = static_cast<ImsServiceType>(data.ReadInt32());
1725     ImsRegInfo info;
1726     int32_t result = GetImsRegStatus(slotId, imsSrvType, info);
1727     bool ret = reply.WriteInt32(result);
1728     ret = (ret && reply.WriteInt32(info.imsRegState));
1729     ret = (ret && reply.WriteInt32(info.imsRegTech));
1730     if (!ret) {
1731         TELEPHONY_LOGE("write reply failed.");
1732         return ERR_FLATTEN_OBJECT;
1733     }
1734     return NO_ERROR;
1735 }
1736 
OnGetCellInfoList(MessageParcel & data,MessageParcel & reply)1737 int32_t CoreServiceStub::OnGetCellInfoList(MessageParcel &data, MessageParcel &reply)
1738 {
1739     auto slotId = data.ReadInt32();
1740     std::vector<sptr<CellInformation>> cellInfo;
1741     int32_t result = GetCellInfoList(slotId, cellInfo);
1742     if (!reply.WriteInt32(result)) {
1743         TELEPHONY_LOGE("OnRemoteRequest::OnGetCellInfoList write reply failed.");
1744         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1745     }
1746     if (result == TELEPHONY_ERR_SUCCESS) {
1747         reply.WriteInt32(static_cast<int32_t>(cellInfo.size()));
1748         for (const auto &v : cellInfo) {
1749             v->Marshalling(reply);
1750         }
1751     }
1752     return NO_ERROR;
1753 }
1754 
OnGetCellLocation(MessageParcel & data,MessageParcel & reply)1755 int32_t CoreServiceStub::OnGetCellLocation(MessageParcel &data, MessageParcel &reply)
1756 {
1757     int32_t slotId = data.ReadInt32();
1758     int32_t result = SendUpdateCellLocationRequest(slotId);
1759     if (!reply.WriteInt32(result)) {
1760         TELEPHONY_LOGE("OnRemoteRequest::OnGetCellLocation write reply failed.");
1761         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1762     }
1763     return NO_ERROR;
1764 }
1765 
OnHasOperatorPrivileges(MessageParcel & data,MessageParcel & reply)1766 int32_t CoreServiceStub::OnHasOperatorPrivileges(MessageParcel &data, MessageParcel &reply)
1767 {
1768     int32_t slotId = data.ReadInt32();
1769     bool hasOperatorPrivileges = false;
1770     int32_t result = HasOperatorPrivileges(slotId, hasOperatorPrivileges);
1771     bool ret = reply.WriteInt32(result);
1772     if (result == TELEPHONY_ERR_SUCCESS) {
1773         ret = (ret && reply.WriteBool(hasOperatorPrivileges));
1774     }
1775     if (!ret) {
1776         TELEPHONY_LOGE("OnHasOperatorPrivileges write reply failed.");
1777         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1778     }
1779     return NO_ERROR;
1780 }
1781 
OnSimAuthentication(MessageParcel & data,MessageParcel & reply)1782 int32_t CoreServiceStub::OnSimAuthentication(MessageParcel &data, MessageParcel &reply)
1783 {
1784     int32_t slotId = data.ReadInt32();
1785     AuthType authType = static_cast<AuthType>(data.ReadInt32());
1786     std::string authData = data.ReadString();
1787     SimAuthenticationResponse response = { 0 };
1788     int32_t result = SimAuthentication(slotId, authType, authData, response);
1789     reply.WriteInt32(result);
1790     reply.WriteInt32(response.sw1);
1791     reply.WriteInt32(response.sw2);
1792     reply.WriteString(response.response);
1793 
1794     return NO_ERROR;
1795 }
1796 
OnRegisterImsRegInfoCallback(MessageParcel & data,MessageParcel & reply)1797 int32_t CoreServiceStub::OnRegisterImsRegInfoCallback(MessageParcel &data, MessageParcel &reply)
1798 {
1799     int32_t slotId = data.ReadInt32();
1800     ImsServiceType imsSrvType = static_cast<ImsServiceType>(data.ReadInt32());
1801     sptr<ImsRegInfoCallback> callback = iface_cast<ImsRegInfoCallback>(data.ReadRemoteObject());
1802     int32_t result;
1803     if (callback == nullptr) {
1804         TELEPHONY_LOGE("callback is nullptr!");
1805         result = TELEPHONY_ERR_ARGUMENT_NULL;
1806     } else {
1807         result = RegisterImsRegInfoCallback(slotId, imsSrvType, callback);
1808     }
1809     bool ret = reply.WriteInt32(result);
1810     if (!ret) {
1811         TELEPHONY_LOGE("write reply failed.");
1812         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1813     }
1814     return NO_ERROR;
1815 }
1816 
OnUnregisterImsRegInfoCallback(MessageParcel & data,MessageParcel & reply)1817 int32_t CoreServiceStub::OnUnregisterImsRegInfoCallback(MessageParcel &data, MessageParcel &reply)
1818 {
1819     int32_t slotId = data.ReadInt32();
1820     ImsServiceType imsSrvType = static_cast<ImsServiceType>(data.ReadInt32());
1821     int32_t result = UnregisterImsRegInfoCallback(slotId, imsSrvType);
1822     bool ret = reply.WriteInt32(result);
1823     if (!ret) {
1824         TELEPHONY_LOGE("write reply failed.");
1825         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1826     }
1827     return NO_ERROR;
1828 }
1829 
OnGetBasebandVersion(MessageParcel & data,MessageParcel & reply)1830 int32_t CoreServiceStub::OnGetBasebandVersion(MessageParcel &data, MessageParcel &reply)
1831 {
1832     int32_t slotId = data.ReadInt32();
1833     std::string version = "";
1834     int32_t result = GetBasebandVersion(slotId, version);
1835     if (!reply.WriteInt32(result)) {
1836         TELEPHONY_LOGE("OnRemoteRequest::OnGetBasebandVersion write reply failed.");
1837         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1838     }
1839     if (result == TELEPHONY_ERR_SUCCESS) {
1840         if (!reply.WriteString(version)) {
1841             TELEPHONY_LOGE("OnRemoteRequest::OnGetBasebandVersion write reply failed.");
1842             return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1843         }
1844     }
1845     return NO_ERROR;
1846 }
1847 
OnGetNrSsbIdInfo(MessageParcel & data,MessageParcel & reply)1848 int32_t CoreServiceStub::OnGetNrSsbIdInfo(MessageParcel &data, MessageParcel &reply)
1849 {
1850     int32_t slotId = data.ReadInt32();
1851     std::shared_ptr<NrSsbInformation> nrSsbInformation = std::make_shared<NrSsbInformation>();
1852     if (nrSsbInformation == nullptr) {
1853         TELEPHONY_LOGE("nrSsbInformation is null.");
1854         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1855     }
1856     int32_t result = GetNrSsbIdInfo(slotId, nrSsbInformation);
1857     if (!reply.WriteInt32(result)) {
1858         TELEPHONY_LOGE("Write reply failed.");
1859         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1860     }
1861     if (result == TELEPHONY_ERR_SUCCESS) {
1862         if (!nrSsbInformation->Marshalling(reply)) {
1863             TELEPHONY_LOGE("Marshalling is failed.");
1864             return TELEPHONY_ERR_WRITE_DATA_FAIL;
1865         }
1866     }
1867     return NO_ERROR;
1868 }
1869 
OnFactoryReset(MessageParcel & data,MessageParcel & reply)1870 int32_t CoreServiceStub::OnFactoryReset(MessageParcel &data, MessageParcel &reply)
1871 {
1872     int32_t slotId = data.ReadInt32();
1873     int32_t result = FactoryReset(slotId);
1874     if (!reply.WriteInt32(result)) {
1875         TELEPHONY_LOGE("Write reply failed.");
1876         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1877     }
1878     return NO_ERROR;
1879 }
1880 
OnInitExtraModule(MessageParcel & data,MessageParcel & reply)1881 int32_t CoreServiceStub::OnInitExtraModule(MessageParcel &data, MessageParcel &reply)
1882 {
1883     int32_t slotId = data.ReadInt32();
1884     int32_t result = InitExtraModule(slotId);
1885     if (!reply.WriteInt32(result)) {
1886         TELEPHONY_LOGE("Write reply failed.");
1887         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1888     }
1889     return NO_ERROR;
1890 }
1891 
OnIsAllowedInsertApn(MessageParcel & data,MessageParcel & reply)1892 int32_t CoreServiceStub::OnIsAllowedInsertApn(MessageParcel &data, MessageParcel &reply)
1893 {
1894     std::string value = data.ReadString();
1895     bool result = IsAllowedInsertApn(value);
1896     if (!reply.WriteBool(result)) {
1897         TELEPHONY_LOGE("Write reply failed.");
1898         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1899     }
1900     return NO_ERROR;
1901 }
1902 
OnGetTargetOpkey(MessageParcel & data,MessageParcel & reply)1903 int32_t CoreServiceStub::OnGetTargetOpkey(MessageParcel &data, MessageParcel &reply)
1904 {
1905     int32_t slotId = data.ReadInt32();
1906     std::u16string opkey;
1907     int32_t result = GetTargetOpkey(slotId, opkey);
1908     if (!reply.WriteString16(opkey)) {
1909         TELEPHONY_LOGE("Write reply opkey failed.");
1910         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1911     }
1912     if (!reply.WriteInt32(result)) {
1913         TELEPHONY_LOGE("Write reply result failed.");
1914         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1915     }
1916     return NO_ERROR;
1917 }
1918 
OnGetOpkeyVersion(MessageParcel & data,MessageParcel & reply)1919 int32_t CoreServiceStub::OnGetOpkeyVersion(MessageParcel &data, MessageParcel &reply)
1920 {
1921     std::string versionInfo;
1922     int32_t result = GetOpkeyVersion(versionInfo);
1923     if (!reply.WriteString(versionInfo)) {
1924         TELEPHONY_LOGE("Write versionInfo result failed.");
1925         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1926     }
1927     if (!reply.WriteInt32(result)) {
1928         TELEPHONY_LOGE("Write reply result failed.");
1929         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1930     }
1931     return NO_ERROR;
1932 }
1933 
OnGetSimIO(MessageParcel & data,MessageParcel & reply)1934 int32_t CoreServiceStub::OnGetSimIO(MessageParcel &data, MessageParcel &reply)
1935 {
1936     int32_t slotId = data.ReadInt32();
1937     int32_t command = data.ReadInt32();
1938     int32_t fileId = data.ReadInt32();
1939     std::string dataStr = data.ReadString();
1940     std::string path = data.ReadString();
1941     SimAuthenticationResponse response = { 0 };
1942     int32_t result = GetSimIO(slotId, command, fileId, dataStr, path, response);
1943     if (!reply.WriteInt32(result)) {
1944         TELEPHONY_LOGE("Write reply result failed.");
1945         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1946     }
1947     reply.WriteInt32(result);
1948     reply.WriteInt32(response.sw1);
1949     reply.WriteInt32(response.sw2);
1950     reply.WriteString(response.response);
1951 
1952     return NO_ERROR;
1953 }
1954 } // namespace Telephony
1955 } // namespace OHOS
1956