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