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