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_proxy.h"
17
18 #include "network_search_types.h"
19 #include "parameter.h"
20 #include "sim_state_type.h"
21 #include "string_ex.h"
22 #include "telephony_errors.h"
23 #include "telephony_log_wrapper.h"
24 #include "telephony_types.h"
25
26 namespace OHOS {
27 namespace Telephony {
28 constexpr int32_t MAX_SIZE = 1000;
WriteInterfaceToken(MessageParcel & data)29 bool CoreServiceProxy::WriteInterfaceToken(MessageParcel &data)
30 {
31 if (!data.WriteInterfaceToken(CoreServiceProxy::GetDescriptor())) {
32 TELEPHONY_LOGE("write interface token failed");
33 return false;
34 }
35 return true;
36 }
37
GetPsRadioTech(int32_t slotId,int32_t & psRadioTech)38 int32_t CoreServiceProxy::GetPsRadioTech(int32_t slotId, int32_t &psRadioTech)
39 {
40 MessageParcel data;
41 MessageParcel reply;
42 MessageOption option;
43 if (!WriteInterfaceToken(data)) {
44 TELEPHONY_LOGE("GetPsRadioTech WriteInterfaceToken is false");
45 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
46 }
47 data.WriteInt32(slotId);
48 auto remote = Remote();
49 if (remote == nullptr) {
50 TELEPHONY_LOGE("GetPsRadioTech Remote is null");
51 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
52 }
53 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_PS_RADIO_TECH), data, reply, option);
54 if (st != ERR_NONE) {
55 TELEPHONY_LOGE("GetPsRadioTech failed, error code is %{public}d ", st);
56 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
57 }
58 int32_t result = reply.ReadInt32();
59 if (result == TELEPHONY_ERR_SUCCESS) {
60 psRadioTech = reply.ReadInt32();
61 }
62 return result;
63 }
64
GetCsRadioTech(int32_t slotId,int32_t & csRadioTech)65 int32_t CoreServiceProxy::GetCsRadioTech(int32_t slotId, int32_t &csRadioTech)
66 {
67 MessageParcel data;
68 MessageParcel reply;
69 MessageOption option;
70 if (!WriteInterfaceToken(data)) {
71 TELEPHONY_LOGE("GetCsRadioTech WriteInterfaceToken is false");
72 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
73 }
74 data.WriteInt32(slotId);
75 auto remote = Remote();
76 if (remote == nullptr) {
77 TELEPHONY_LOGE("GetCsRadioTech Remote is null");
78 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
79 }
80 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_CS_RADIO_TECH), data, reply, option);
81 if (st != ERR_NONE) {
82 TELEPHONY_LOGE("GetCsRadioTech failed, error code is %{public}d", st);
83 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
84 }
85 int32_t result = reply.ReadInt32();
86 if (result == TELEPHONY_ERR_SUCCESS) {
87 csRadioTech = reply.ReadInt32();
88 } else {
89 TELEPHONY_LOGE("GetCsRadioTech call failed: result=%{public}d", result);
90 }
91 return result;
92 }
93
GetOperatorNumeric(int32_t slotId)94 std::u16string CoreServiceProxy::GetOperatorNumeric(int32_t slotId)
95 {
96 MessageParcel data;
97 MessageParcel reply;
98 MessageOption option;
99 if (!WriteInterfaceToken(data)) {
100 TELEPHONY_LOGE("GetOperatorNumeric WriteInterfaceToken is false");
101 return Str8ToStr16("");
102 }
103 data.WriteInt32(slotId);
104 auto remote = Remote();
105 if (remote == nullptr) {
106 TELEPHONY_LOGE("GetOperatorNumeric Remote is null");
107 return Str8ToStr16("");
108 }
109 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_OPERATOR_NUMERIC), data, reply, option);
110 if (st != ERR_NONE) {
111 TELEPHONY_LOGE("GetCsRadioTech failed, error code is %{public}d", st);
112 return Str8ToStr16("");
113 }
114 std::u16string result = reply.ReadString16();
115 std::string str = Str16ToStr8(result);
116 TELEPHONY_LOGI("CoreServiceProxy GetOperatorNumeric success");
117 return result;
118 }
119
GetResidentNetworkNumeric(int32_t slotId)120 std::string CoreServiceProxy::GetResidentNetworkNumeric(int32_t slotId)
121 {
122 MessageParcel data;
123 MessageParcel reply;
124 MessageOption option;
125 if (!WriteInterfaceToken(data)) {
126 TELEPHONY_LOGE("GetResidentNetworkNumeric WriteInterfaceToken is false");
127 return "";
128 }
129 data.WriteInt32(slotId);
130 auto remote = Remote();
131 if (remote == nullptr) {
132 TELEPHONY_LOGE("GetResidentNetworkNumeric Remote is null");
133 return "";
134 }
135 int32_t st = remote->SendRequest(
136 uint32_t(CoreServiceInterfaceCode::GET_RESIDENT_NETWORK_NUMERIC), data, reply, option);
137 if (st != ERR_NONE) {
138 TELEPHONY_LOGE("GetResidentNetworkNumeric failed, error code is %{public}d", st);
139 return "";
140 }
141 std::string result = reply.ReadString();
142 return result;
143 }
144
GetOperatorName(int32_t slotId,std::u16string & operatorName)145 int32_t CoreServiceProxy::GetOperatorName(int32_t slotId, std::u16string &operatorName)
146 {
147 MessageParcel data;
148 MessageParcel reply;
149 MessageOption option;
150 if (!WriteInterfaceToken(data)) {
151 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
152 }
153 data.WriteInt32(slotId);
154 auto remote = Remote();
155 if (remote == nullptr) {
156 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
157 }
158 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_OPERATOR_NAME), data, reply, option);
159 if (st != ERR_NONE) {
160 TELEPHONY_LOGI("GetOperatorName failed, error code is %{public}d", st);
161 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
162 }
163 int32_t result = reply.ReadInt32();
164 if (result == TELEPHONY_ERR_SUCCESS) {
165 operatorName = reply.ReadString16();
166 } else {
167 TELEPHONY_LOGE("GetOperatorName call fail,slotId:%{public}d", slotId);
168 }
169 return result;
170 }
171
172
GetBasebandVersion(int32_t slotId,std::string & version)173 int32_t CoreServiceProxy::GetBasebandVersion(int32_t slotId, std::string &version)
174 {
175 MessageParcel data;
176 MessageParcel reply;
177 MessageOption option;
178 if (!WriteInterfaceToken(data)) {
179 TELEPHONY_LOGE("GetBasebandVersion WriteInterfaceToken is false");
180 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
181 }
182 data.WriteInt32(slotId);
183 auto remote = Remote();
184 if (remote == nullptr) {
185 TELEPHONY_LOGE("GetBasebandVersion Remote is null");
186 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
187 }
188 int32_t error = remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::GET_BASEBAND_VERSION),
189 data, reply, option);
190 if (error != ERR_NONE) {
191 TELEPHONY_LOGE("GetBasebandVersion failed, error code is %{public}d", error);
192 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
193 }
194 int32_t result = reply.ReadInt32();
195 if (result == TELEPHONY_ERR_SUCCESS) {
196 version = reply.ReadString();
197 }
198 return result;
199 }
200
GetNetworkSearchInformation(int32_t slotId,const sptr<INetworkSearchCallback> & callback)201 int32_t CoreServiceProxy::GetNetworkSearchInformation(int32_t slotId, const sptr<INetworkSearchCallback> &callback)
202 {
203 MessageParcel data;
204 MessageParcel reply;
205 MessageOption option;
206 if (!WriteInterfaceToken(data)) {
207 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
208 }
209 if (!data.WriteInt32(slotId)) {
210 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
211 }
212 if (callback != nullptr) {
213 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
214 }
215 auto remote = Remote();
216 if (remote == nullptr) {
217 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
218 }
219 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_NETWORK_SEARCH_RESULT), data,
220 reply, option);
221 if (error != ERR_NONE) {
222 TELEPHONY_LOGE("GetNetworkSearchInformation failed, error code is: %{public}d", error);
223 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
224 }
225 return reply.ReadInt32();
226 }
227
GetNetworkState(int32_t slotId,sptr<NetworkState> & networkState)228 int32_t CoreServiceProxy::GetNetworkState(int32_t slotId, sptr<NetworkState> &networkState)
229 {
230 MessageParcel data;
231 MessageParcel reply;
232 MessageOption option;
233 if (!WriteInterfaceToken(data)) {
234 TELEPHONY_LOGE("GetNetworkState WriteInterfaceToken is false");
235 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
236 }
237 data.WriteInt32(slotId);
238 auto remote = Remote();
239 if (remote == nullptr) {
240 TELEPHONY_LOGE("GetNetworkState Remote is null");
241 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
242 }
243 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_NETWORK_STATE), data, reply, option);
244 if (st != ERR_NONE) {
245 TELEPHONY_LOGE("GetNetworkState failed, error code is %{public}d", st);
246 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
247 }
248 int32_t result = reply.ReadInt32();
249 if (result == TELEPHONY_ERR_SUCCESS) {
250 networkState = NetworkState::Unmarshalling(reply);
251 }
252 return result;
253 }
254
GetSignalInfoList(int32_t slotId,std::vector<sptr<SignalInformation>> & signals)255 int32_t CoreServiceProxy::GetSignalInfoList(int32_t slotId, std::vector<sptr<SignalInformation>> &signals)
256 {
257 TELEPHONY_LOGD("CoreServiceProxy::GetSignalInfoList slotId : %{public}d", slotId);
258 MessageParcel data;
259 MessageParcel reply;
260 MessageOption option;
261 if (!WriteInterfaceToken(data)) {
262 TELEPHONY_LOGE("GetSignalInfoList WriteInterfaceToken is false");
263 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
264 }
265 data.WriteInt32(slotId);
266 auto remote = Remote();
267 if (remote == nullptr) {
268 TELEPHONY_LOGE("GetSignalInfoList Remote is null");
269 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
270 }
271 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIGNAL_INFO_LIST), data, reply, option);
272 if (st != ERR_NONE) {
273 TELEPHONY_LOGE("GetSignalInfoList failed, error code is %{public}d\n", st);
274 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
275 }
276 int32_t result = reply.ReadInt32();
277 if (result == TELEPHONY_ERR_SUCCESS) {
278 ProcessSignalInfo(reply, signals);
279 }
280 return result;
281 }
282
ProcessSignalInfoGsm(MessageParcel & reply,std::vector<sptr<SignalInformation>> & result)283 static void ProcessSignalInfoGsm(MessageParcel &reply, std::vector<sptr<SignalInformation>> &result)
284 {
285 std::unique_ptr<GsmSignalInformation> signal = std::make_unique<GsmSignalInformation>();
286 if (signal != nullptr) {
287 signal->ReadFromParcel(reply);
288 result.emplace_back(signal.release());
289 }
290 }
291
ProcessSignalInfoCdma(MessageParcel & reply,std::vector<sptr<SignalInformation>> & result)292 static void ProcessSignalInfoCdma(MessageParcel &reply, std::vector<sptr<SignalInformation>> &result)
293 {
294 std::unique_ptr<CdmaSignalInformation> signal = std::make_unique<CdmaSignalInformation>();
295 if (signal != nullptr) {
296 signal->ReadFromParcel(reply);
297 result.emplace_back(signal.release());
298 }
299 }
300
ProcessSignalInfoLte(MessageParcel & reply,std::vector<sptr<SignalInformation>> & result)301 static void ProcessSignalInfoLte(MessageParcel &reply, std::vector<sptr<SignalInformation>> &result)
302 {
303 std::unique_ptr<LteSignalInformation> signal = std::make_unique<LteSignalInformation>();
304 if (signal != nullptr) {
305 signal->ReadFromParcel(reply);
306 result.emplace_back(signal.release());
307 }
308 }
309
ProcessSignalInfoWcdma(MessageParcel & reply,std::vector<sptr<SignalInformation>> & result)310 static void ProcessSignalInfoWcdma(MessageParcel &reply, std::vector<sptr<SignalInformation>> &result)
311 {
312 std::unique_ptr<WcdmaSignalInformation> signal = std::make_unique<WcdmaSignalInformation>();
313 if (signal != nullptr) {
314 signal->ReadFromParcel(reply);
315 result.emplace_back(signal.release());
316 }
317 }
318
ProcessSignalInfoTdscdma(MessageParcel & reply,std::vector<sptr<SignalInformation>> & result)319 static void ProcessSignalInfoTdscdma(MessageParcel &reply, std::vector<sptr<SignalInformation>> &result)
320 {
321 std::unique_ptr<TdScdmaSignalInformation> signal = std::make_unique<TdScdmaSignalInformation>();
322 if (signal != nullptr) {
323 signal->ReadFromParcel(reply);
324 result.emplace_back(signal.release());
325 }
326 }
327
ProcessSignalInfoNr(MessageParcel & reply,std::vector<sptr<SignalInformation>> & result)328 static void ProcessSignalInfoNr(MessageParcel &reply, std::vector<sptr<SignalInformation>> &result)
329 {
330 std::unique_ptr<NrSignalInformation> signal = std::make_unique<NrSignalInformation>();
331 if (signal != nullptr) {
332 signal->ReadFromParcel(reply);
333 result.emplace_back(signal.release());
334 }
335 }
336
ProcessSignalInfo(MessageParcel & reply,std::vector<sptr<SignalInformation>> & result)337 void CoreServiceProxy::ProcessSignalInfo(MessageParcel &reply, std::vector<sptr<SignalInformation>> &result)
338 {
339 int32_t size = reply.ReadInt32();
340 TELEPHONY_LOGD("CoreServiceProxy::GetSignalInfoList size:%{public}d\n", size);
341 if (size >= MAX_SIZE) {
342 TELEPHONY_LOGE("CoreServiceProxy::GetSignalInfoList over max size");
343 return;
344 }
345 SignalInformation::NetworkType type;
346 for (int i = 0; i < size; ++i) {
347 type = static_cast<SignalInformation::NetworkType>(reply.ReadInt32());
348 switch (type) {
349 case SignalInformation::NetworkType::GSM: {
350 ProcessSignalInfoGsm(reply, result);
351 break;
352 }
353 case SignalInformation::NetworkType::CDMA: {
354 ProcessSignalInfoCdma(reply, result);
355 break;
356 }
357 case SignalInformation::NetworkType::LTE: {
358 ProcessSignalInfoLte(reply, result);
359 break;
360 }
361 case SignalInformation::NetworkType::WCDMA: {
362 ProcessSignalInfoWcdma(reply, result);
363 break;
364 }
365 case SignalInformation::NetworkType::TDSCDMA: {
366 ProcessSignalInfoTdscdma(reply, result);
367 break;
368 }
369 case SignalInformation::NetworkType::NR: {
370 ProcessSignalInfoNr(reply, result);
371 break;
372 }
373 default:
374 break;
375 }
376 }
377 }
378
SetRadioState(int32_t slotId,bool isOn,const sptr<INetworkSearchCallback> & callback)379 int32_t CoreServiceProxy::SetRadioState(int32_t slotId, bool isOn, const sptr<INetworkSearchCallback> &callback)
380 {
381 TELEPHONY_LOGI("CoreServiceProxy SetRadioState isOn:%{public}d", isOn);
382 MessageParcel data;
383 MessageParcel reply;
384 MessageOption option;
385 if (!WriteInterfaceToken(data)) {
386 TELEPHONY_LOGE("SetRadioState WriteInterfaceToken is false");
387 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
388 }
389 data.WriteInt32(slotId);
390 if (callback != nullptr) {
391 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
392 }
393 data.WriteBool(isOn);
394 auto remote = Remote();
395 if (remote == nullptr) {
396 TELEPHONY_LOGE("SetRadioState Remote is null");
397 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
398 }
399 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_RADIO_STATE), data, reply, option);
400 if (error != ERR_NONE) {
401 TELEPHONY_LOGE("SetRadioState failed, error code is %{public}d", error);
402 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
403 }
404 return reply.ReadInt32();
405 }
406
GetRadioState(int32_t slotId,const sptr<INetworkSearchCallback> & callback)407 int32_t CoreServiceProxy::GetRadioState(int32_t slotId, const sptr<INetworkSearchCallback> &callback)
408 {
409 MessageParcel data;
410 MessageParcel reply;
411 MessageOption option;
412 if (!WriteInterfaceToken(data)) {
413 TELEPHONY_LOGE("GetRadioState WriteInterfaceToken is false");
414 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
415 }
416 data.WriteInt32(slotId);
417 if (callback != nullptr) {
418 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
419 }
420 auto remote = Remote();
421 if (remote == nullptr) {
422 TELEPHONY_LOGE("GetRadioState Remote is null");
423 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
424 }
425 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_RADIO_STATE), data, reply, option);
426 if (st != ERR_NONE) {
427 TELEPHONY_LOGE("GetRadioState failed, error code is %{public}d", st);
428 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
429 }
430 return reply.ReadInt32();
431 }
432
GetIsoCountryCodeForNetwork(int32_t slotId,std::u16string & countryCode)433 int32_t CoreServiceProxy::GetIsoCountryCodeForNetwork(int32_t slotId, std::u16string &countryCode)
434 {
435 MessageParcel data;
436 MessageParcel reply;
437 MessageOption option;
438 if (!WriteInterfaceToken(data)) {
439 TELEPHONY_LOGE("GetIsoCountryCodeForNetwork WriteInterfaceToken is false");
440 return TELEPHONY_ERR_WRITE_DATA_FAIL;
441 }
442 data.WriteInt32(slotId);
443 auto remote = Remote();
444 if (remote == nullptr) {
445 TELEPHONY_LOGE("GetIsoCountryCodeForNetwork Remote is null");
446 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
447 }
448 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_ISO_COUNTRY_CODE_FOR_NETWORK), data,
449 reply, option);
450 if (st != ERR_NONE) {
451 TELEPHONY_LOGE("GetIsoCountryCodeForNetwork failed, error code is %{public}d", st);
452 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
453 }
454 int32_t result = reply.ReadInt32();
455 if (result == TELEPHONY_ERR_SUCCESS) {
456 countryCode = reply.ReadString16();
457 }
458 TELEPHONY_LOGD("GetIsoCountryCodeForNetwork call end");
459 return result;
460 }
461
GetImei(int32_t slotId,const sptr<IRawParcelCallback> & callback)462 int32_t CoreServiceProxy::GetImei(int32_t slotId, const sptr<IRawParcelCallback> &callback)
463 {
464 MessageParcel data;
465 MessageParcel reply;
466 MessageOption option;
467 if (!WriteInterfaceToken(data)) {
468 TELEPHONY_LOGE("GetImei WriteInterfaceToken is false");
469 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
470 }
471 data.WriteInt32(slotId);
472 if (callback == nullptr) {
473 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
474 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
475 }
476 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
477 auto remote = Remote();
478 if (remote == nullptr) {
479 TELEPHONY_LOGE("GetImei Remote is null");
480 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
481 }
482 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_IMEI), data, reply, option);
483 if (error != ERR_NONE) {
484 TELEPHONY_LOGE("GetImei failed, error code is %{public}d", error);
485 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
486 }
487 TELEPHONY_LOGD("CoreServiceProxy::GetImei success");
488 return reply.ReadInt32();
489 }
490
GetImeiSv(int32_t slotId,const sptr<IRawParcelCallback> & callback)491 int32_t CoreServiceProxy::GetImeiSv(int32_t slotId, const sptr<IRawParcelCallback> &callback)
492 {
493 MessageParcel data;
494 MessageParcel reply;
495 MessageOption option;
496 if (!WriteInterfaceToken(data)) {
497 TELEPHONY_LOGE("GetImeiSv WriteInterfaceToken is false");
498 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
499 }
500 data.WriteInt32(slotId);
501 if (callback == nullptr) {
502 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
503 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
504 }
505 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
506 auto remote = Remote();
507 if (remote == nullptr) {
508 TELEPHONY_LOGE("GetImeiSv Remote is null");
509 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
510 }
511 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_IMEISV), data, reply, option);
512 if (error != ERR_NONE) {
513 TELEPHONY_LOGE("GetImeiSv failed, error code is %{public}d", error);
514 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
515 }
516 return reply.ReadInt32();
517 }
518
GetMeid(int32_t slotId,std::u16string & meid)519 int32_t CoreServiceProxy::GetMeid(int32_t slotId, std::u16string &meid)
520 {
521 MessageParcel data;
522 MessageParcel reply;
523 MessageOption option;
524 if (!WriteInterfaceToken(data)) {
525 TELEPHONY_LOGE("GetMeid WriteInterfaceToken is false");
526 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
527 }
528 data.WriteInt32(slotId);
529 auto remote = Remote();
530 if (remote == nullptr) {
531 TELEPHONY_LOGE("GetMeid Remote is null");
532 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
533 }
534 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_MEID), data, reply, option);
535 if (error != ERR_NONE) {
536 TELEPHONY_LOGE("GetMeid failed, error code is %{public}d", error);
537 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
538 }
539 int32_t result = reply.ReadInt32();
540 if (result == TELEPHONY_ERR_SUCCESS) {
541 meid = reply.ReadString16();
542 }
543 TELEPHONY_LOGI("CoreServiceProxy::GetMeid success");
544 return result;
545 }
546
GetUniqueDeviceId(int32_t slotId,std::u16string & deviceId)547 int32_t CoreServiceProxy::GetUniqueDeviceId(int32_t slotId, std::u16string &deviceId)
548 {
549 MessageParcel data;
550 MessageParcel reply;
551 MessageOption option;
552 if (!WriteInterfaceToken(data)) {
553 TELEPHONY_LOGE("GetUniqueDeviceId WriteInterfaceToken is false");
554 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
555 }
556 data.WriteInt32(slotId);
557 auto remote = Remote();
558 if (remote == nullptr) {
559 TELEPHONY_LOGE("GetUniqueDeviceId Remote is null");
560 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
561 }
562 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_UNIQUE_DEVICE_ID), data, reply, option);
563 if (error != ERR_NONE) {
564 TELEPHONY_LOGE("GetUniqueDeviceId failed, error code is %{public}d", error);
565 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
566 }
567 int32_t result = reply.ReadInt32();
568 if (result == TELEPHONY_ERR_SUCCESS) {
569 deviceId = reply.ReadString16();
570 }
571 return result;
572 }
573
HasSimCard(int32_t slotId,const sptr<IRawParcelCallback> & callback)574 int32_t CoreServiceProxy::HasSimCard(int32_t slotId, const sptr<IRawParcelCallback> &callback)
575 {
576 TELEPHONY_LOGD("CoreServiceProxy HasSimCard ::%{public}d", slotId);
577 MessageParcel data;
578 MessageParcel reply;
579 MessageOption option;
580 if (!WriteInterfaceToken(data)) {
581 TELEPHONY_LOGE("HasSimCard WriteInterfaceToken is false");
582 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
583 }
584 data.WriteInt32(slotId);
585 if (callback == nullptr) {
586 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
587 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
588 }
589 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
590 auto remote = Remote();
591 if (remote == nullptr) {
592 TELEPHONY_LOGE("HasSimCard Remote is null");
593 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
594 }
595 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::HAS_SIM_CARD), data, reply, option);
596 if (st != ERR_NONE) {
597 TELEPHONY_LOGE("HasSimCard failed, error code is %{public}d", st);
598 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
599 }
600 return reply.ReadInt32();
601 }
602
GetSimState(int32_t slotId,const sptr<IRawParcelCallback> & callback)603 int32_t CoreServiceProxy::GetSimState(int32_t slotId, const sptr<IRawParcelCallback> &callback)
604 {
605 if (!IsValidSlotId(slotId)) {
606 return TELEPHONY_ERR_SLOTID_INVALID;
607 }
608 MessageParcel data;
609 MessageParcel reply;
610 MessageOption option;
611 if (!WriteInterfaceToken(data)) {
612 TELEPHONY_LOGE("WriteInterfaceToken is false");
613 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
614 }
615 data.WriteInt32(slotId);
616 if (callback == nullptr) {
617 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
618 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
619 }
620 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
621 auto remote = Remote();
622 if (remote == nullptr) {
623 TELEPHONY_LOGE("Remote is null");
624 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
625 }
626 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_STATE), data, reply, option);
627 if (st != ERR_NONE) {
628 TELEPHONY_LOGE("failed, error code is %{public}d", st);
629 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
630 }
631 TELEPHONY_LOGD("call end: result=%{public}d", reply.ReadInt32());
632 return reply.ReadInt32();
633 }
634
GetDsdsMode(int32_t & dsdsMode)635 int32_t CoreServiceProxy::GetDsdsMode(int32_t &dsdsMode)
636 {
637 MessageParcel data;
638 MessageParcel reply;
639 MessageOption option;
640 if (!WriteInterfaceToken(data)) {
641 TELEPHONY_LOGE("WriteInterfaceToken is false");
642 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
643 }
644 auto remote = Remote();
645 if (remote == nullptr) {
646 TELEPHONY_LOGE("Remote is null");
647 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
648 }
649 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_DSDS_MODE), data, reply, option);
650 if (st != ERR_NONE) {
651 TELEPHONY_LOGE("failed, error code is %{public}d", st);
652 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
653 }
654 int32_t result = reply.ReadInt32();
655 if (result == TELEPHONY_ERR_SUCCESS) {
656 dsdsMode = static_cast<int32_t>(reply.ReadInt32());
657 }
658 TELEPHONY_LOGD("call end: result=%{public}d", result);
659 return result;
660 }
661
GetCardType(int32_t slotId,CardType & cardType)662 int32_t CoreServiceProxy::GetCardType(int32_t slotId, CardType &cardType)
663 {
664 TELEPHONY_LOGI("CoreServiceProxy GetCardType ::%{public}d", slotId);
665 MessageParcel data;
666 MessageParcel reply;
667 MessageOption option;
668 if (!WriteInterfaceToken(data)) {
669 TELEPHONY_LOGE("GetCardType WriteInterfaceToken is false");
670 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
671 }
672 data.WriteInt32(slotId);
673 auto remote = Remote();
674 if (remote == nullptr) {
675 TELEPHONY_LOGE("GetCardType Remote is null");
676 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
677 }
678 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_CARD_TYPE), data, reply, option);
679 if (st != ERR_NONE) {
680 TELEPHONY_LOGE("GetCardType failed, error code is %{public}d", st);
681 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
682 }
683 int32_t result = reply.ReadInt32();
684 if (result == TELEPHONY_ERR_SUCCESS) {
685 cardType = static_cast<CardType>(reply.ReadInt32());
686 }
687 TELEPHONY_LOGI("GetCardType call end: result=%{public}d", result);
688 return result;
689 }
690
GetISOCountryCodeForSim(int32_t slotId,std::u16string & countryCode)691 int32_t CoreServiceProxy::GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode)
692 {
693 if (!IsValidSlotId(slotId)) {
694 return TELEPHONY_ERR_SLOTID_INVALID;
695 }
696 MessageParcel data;
697 MessageParcel reply;
698 MessageOption option;
699 if (!WriteInterfaceToken(data)) {
700 TELEPHONY_LOGE("GetISOCountryCodeForSim WriteInterfaceToken is false");
701 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
702 }
703 data.WriteInt32(slotId);
704 auto remote = Remote();
705 if (remote == nullptr) {
706 TELEPHONY_LOGE("GetISOCountryCodeForSim Remote is null");
707 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
708 }
709 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_ISO_COUNTRY_CODE), data, reply, option);
710 if (st != ERR_NONE) {
711 TELEPHONY_LOGE("GetISOCountryCodeForSim failed, error code is %{public}d", st);
712 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
713 }
714 int32_t result = reply.ReadInt32();
715 if (result == TELEPHONY_ERR_SUCCESS) {
716 countryCode = reply.ReadString16();
717 }
718 TELEPHONY_LOGI("GetISOCountryCodeForSim call end");
719 return result;
720 }
721
GetSimOperatorNumeric(int32_t slotId,std::u16string & operatorNumeric)722 int32_t CoreServiceProxy::GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric)
723 {
724 if (!IsValidSlotIdEx(slotId)) {
725 return TELEPHONY_ERR_SLOTID_INVALID;
726 }
727 MessageParcel data;
728 MessageParcel reply;
729 MessageOption option;
730 if (!WriteInterfaceToken(data)) {
731 TELEPHONY_LOGE("GetSimOperatorNumeric WriteInterfaceToken is false");
732 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
733 }
734 data.WriteInt32(slotId);
735 auto remote = Remote();
736 if (remote == nullptr) {
737 TELEPHONY_LOGE("GetSimOperatorNumeric Remote is null");
738 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
739 }
740 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_OPERATOR_NUMERIC), data, reply, option);
741 if (st != ERR_NONE) {
742 TELEPHONY_LOGE("GetSimOperatorNumeric failed, error code is %{public}d", st);
743 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
744 }
745 int32_t result = reply.ReadInt32();
746 if (result == TELEPHONY_ERR_SUCCESS) {
747 operatorNumeric = reply.ReadString16();
748 }
749 TELEPHONY_LOGD("GetSimOperatorNumeric call end");
750 return result;
751 }
752
GetSimSpn(int32_t slotId,std::u16string & spn)753 int32_t CoreServiceProxy::GetSimSpn(int32_t slotId, std::u16string &spn)
754 {
755 if (!IsValidSlotId(slotId)) {
756 return TELEPHONY_ERR_SLOTID_INVALID;
757 }
758 MessageParcel data;
759 MessageParcel reply;
760 MessageOption option;
761 if (!WriteInterfaceToken(data)) {
762 TELEPHONY_LOGE("GetSimSpn WriteInterfaceToken is false");
763 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
764 }
765 data.WriteInt32(slotId);
766 auto remote = Remote();
767 if (remote == nullptr) {
768 TELEPHONY_LOGE("GetSimSpn Remote is null");
769 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
770 }
771 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SPN), data, reply, option);
772 if (st != ERR_NONE) {
773 TELEPHONY_LOGE("GetSimSpn failed, error code is %{public}d", st);
774 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
775 }
776 int32_t result = reply.ReadInt32();
777 if (result == TELEPHONY_ERR_SUCCESS) {
778 spn = reply.ReadString16();
779 }
780 TELEPHONY_LOGI("GetSimSpn call end");
781 return result;
782 }
783
GetSimIccId(int32_t slotId,std::u16string & iccId)784 int32_t CoreServiceProxy::GetSimIccId(int32_t slotId, std::u16string &iccId)
785 {
786 if (!IsValidSlotId(slotId)) {
787 return TELEPHONY_ERR_SLOTID_INVALID;
788 }
789 MessageParcel data;
790 MessageParcel reply;
791 MessageOption option;
792 if (!WriteInterfaceToken(data)) {
793 TELEPHONY_LOGE("GetSimIccId WriteInterfaceToken is false");
794 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
795 }
796 data.WriteInt32(slotId);
797 auto remote = Remote();
798 if (remote == nullptr) {
799 TELEPHONY_LOGE("GetSimIccId Remote is null");
800 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
801 }
802 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_ICCID), data, reply, option);
803 if (st != ERR_NONE) {
804 TELEPHONY_LOGE("GetSimIccId failed, error code is %{public}d", st);
805 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
806 }
807 int32_t result = reply.ReadInt32();
808 if (result == TELEPHONY_ERR_SUCCESS) {
809 iccId = reply.ReadString16();
810 }
811 return result;
812 }
813
GetIMSI(int32_t slotId,std::u16string & imsi)814 int32_t CoreServiceProxy::GetIMSI(int32_t slotId, std::u16string &imsi)
815 {
816 if (!IsValidSlotId(slotId)) {
817 return TELEPHONY_ERR_SLOTID_INVALID;
818 }
819 MessageParcel data;
820 MessageParcel reply;
821 MessageOption option;
822 if (!WriteInterfaceToken(data)) {
823 TELEPHONY_LOGE("GetIMSI WriteInterfaceToken is false");
824 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
825 }
826 data.WriteInt32(slotId);
827 auto remote = Remote();
828 if (remote == nullptr) {
829 TELEPHONY_LOGE("GetIMSI Remote is null");
830 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
831 }
832 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_IMSI), data, reply, option);
833 if (st != ERR_NONE) {
834 TELEPHONY_LOGE("GetIMSI failed, error code is %{public}d", st);
835 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
836 }
837 int32_t result = reply.ReadInt32();
838 if (result == TELEPHONY_ERR_SUCCESS) {
839 imsi = reply.ReadString16();
840 }
841 return result;
842 }
843
IsCTSimCard(int32_t slotId,const sptr<IRawParcelCallback> & callback)844 int32_t CoreServiceProxy::IsCTSimCard(int32_t slotId, const sptr<IRawParcelCallback> &callback)
845 {
846 if (!IsValidSlotId(slotId)) {
847 return TELEPHONY_ERR_SLOTID_INVALID;
848 }
849 MessageParcel data;
850 MessageParcel reply;
851 MessageOption option;
852 if (!WriteInterfaceToken(data)) {
853 TELEPHONY_LOGE("IsCTSimCard WriteInterfaceToken is false");
854 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
855 }
856 data.WriteInt32(slotId);
857 if (callback == nullptr) {
858 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
859 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
860 }
861 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
862 auto remote = Remote();
863 if (remote == nullptr) {
864 TELEPHONY_LOGE("IsCTSimCard Remote is null");
865 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
866 }
867 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::IS_CT_SIM_CARD), data, reply, option);
868 if (st != ERR_NONE) {
869 TELEPHONY_LOGE("IsCTSimCard failed, error code is %{public}d", st);
870 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
871 }
872 return reply.ReadInt32();
873 }
874
IsSimActive(int32_t slotId,const sptr<IRawParcelCallback> & callback)875 bool CoreServiceProxy::IsSimActive(int32_t slotId, const sptr<IRawParcelCallback> &callback)
876 {
877 TELEPHONY_LOGD("CoreServiceProxy IsSimActive ::%{public}d", slotId);
878 if (!IsValidSlotId(slotId)) {
879 TELEPHONY_LOGE("CoreServiceProxy::IsSimActive invalid simId");
880 return false;
881 }
882 MessageParcel data;
883 MessageParcel reply;
884 MessageOption option;
885 if (!WriteInterfaceToken(data)) {
886 TELEPHONY_LOGE("IsSimActive WriteInterfaceToken is false");
887 return false;
888 }
889 data.WriteInt32(slotId);
890 if (callback == nullptr) {
891 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
892 return false;
893 }
894 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
895 auto remote = Remote();
896 if (remote == nullptr) {
897 TELEPHONY_LOGE("IsSimActive Remote is null");
898 return false;
899 }
900 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::IS_SIM_ACTIVE), data, reply, option);
901 if (st != ERR_NONE) {
902 TELEPHONY_LOGE("IsSimActive failed, error code is %{public}d", st);
903 return false;
904 }
905 return reply.ReadBool();
906 }
907
GetSlotId(int32_t simId)908 int32_t CoreServiceProxy::GetSlotId(int32_t simId)
909 {
910 if (simId <= 0) {
911 TELEPHONY_LOGE("CoreServiceProxy::GetSlotId invalid simId");
912 return ERROR;
913 }
914 MessageParcel data;
915 MessageParcel reply;
916 MessageOption option;
917 if (!WriteInterfaceToken(data)) {
918 TELEPHONY_LOGE("GetSlotId WriteInterfaceToken is false");
919 return ERROR;
920 }
921 data.WriteInt32(simId);
922 auto remote = Remote();
923 if (remote == nullptr) {
924 TELEPHONY_LOGE("GetSlotId Remote is null");
925 return ERROR;
926 }
927 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_SLOTID), data, reply, option);
928 if (st != ERR_NONE) {
929 TELEPHONY_LOGE("GetSlotId failed, error code is %{public}d", st);
930 return ERROR;
931 }
932 return reply.ReadInt32();
933 }
934
GetSimId(int32_t slotId)935 int32_t CoreServiceProxy::GetSimId(int32_t slotId)
936 {
937 if (!IsValidSlotId(slotId)) {
938 TELEPHONY_LOGE("CoreServiceProxy::GetSimId invalid slotId");
939 return ERROR;
940 }
941 MessageParcel data;
942 MessageParcel reply;
943 MessageOption option;
944 if (!WriteInterfaceToken(data)) {
945 TELEPHONY_LOGE("GetSimId WriteInterfaceToken is false");
946 return ERROR;
947 }
948 data.WriteInt32(slotId);
949 auto remote = Remote();
950 if (remote == nullptr) {
951 TELEPHONY_LOGE("GetSimId Remote is null");
952 return ERROR;
953 }
954 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_SIMID), data, reply, option);
955 if (st != ERR_NONE) {
956 TELEPHONY_LOGE("GetSimId failed, error code is %{public}d", st);
957 return ERROR;
958 }
959 return reply.ReadInt32();
960 }
961
GetNetworkSelectionMode(int32_t slotId,const sptr<INetworkSearchCallback> & callback)962 int32_t CoreServiceProxy::GetNetworkSelectionMode(int32_t slotId, const sptr<INetworkSearchCallback> &callback)
963 {
964 MessageParcel data;
965 MessageParcel reply;
966 MessageOption option;
967 if (!WriteInterfaceToken(data)) {
968 TELEPHONY_LOGE("GetNetworkSelectionMode WriteInterfaceToken is false");
969 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
970 }
971 if (!data.WriteInt32(slotId)) {
972 TELEPHONY_LOGE("GetNetworkSelectionMode WriteInt32 slotId is false");
973 return TELEPHONY_ERR_WRITE_DATA_FAIL;
974 }
975 if (callback != nullptr) {
976 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
977 }
978 auto remote = Remote();
979 if (remote == nullptr) {
980 TELEPHONY_LOGE("GetNetworkSelectionMode Remote is null");
981 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
982 }
983 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_NETWORK_SELECTION_MODE), data,
984 reply, option);
985 if (st != TELEPHONY_ERR_SUCCESS) {
986 TELEPHONY_LOGE("GetNetworkSelectionMode failed, error code is %{public}d", st);
987 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
988 }
989 return reply.ReadInt32();
990 }
991
SetNetworkSelectionMode(int32_t slotId,int32_t selectMode,const sptr<NetworkInformation> & networkInformation,bool resumeSelection,const sptr<INetworkSearchCallback> & callback)992 int32_t CoreServiceProxy::SetNetworkSelectionMode(int32_t slotId, int32_t selectMode,
993 const sptr<NetworkInformation> &networkInformation, bool resumeSelection,
994 const sptr<INetworkSearchCallback> &callback)
995 {
996 MessageParcel data;
997 MessageParcel reply;
998 MessageOption option;
999 if (!WriteInterfaceToken(data)) {
1000 TELEPHONY_LOGE("SetNetworkSelectionMode WriteInterfaceToken is false");
1001 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1002 }
1003 if (!data.WriteInt32(slotId)) {
1004 TELEPHONY_LOGE("SetNetworkSelectionMode WriteInt32 slotId is false");
1005 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1006 }
1007 if (!data.WriteInt32(selectMode)) {
1008 TELEPHONY_LOGE("SetNetworkSelectionMode WriteInt32 selectMode is false");
1009 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1010 }
1011 if (!data.WriteBool(resumeSelection)) {
1012 TELEPHONY_LOGE("SetNetworkSelectionMode WriteBool resumeSelection is false");
1013 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1014 }
1015 if (callback != nullptr) {
1016 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1017 }
1018 if (networkInformation != nullptr) {
1019 networkInformation->Marshalling(data);
1020 }
1021 auto remote = Remote();
1022 if (remote == nullptr) {
1023 TELEPHONY_LOGE("SetNetworkSelectionMode Remote is null");
1024 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1025 }
1026 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_NETWORK_SELECTION_MODE), data,
1027 reply, option);
1028 if (error != ERR_NONE) {
1029 TELEPHONY_LOGE("SetNetworkSelectionMode failed, error code is %{public}d", error);
1030 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1031 }
1032 return reply.ReadInt32();
1033 }
1034
GetLocaleFromDefaultSim()1035 std::u16string CoreServiceProxy::GetLocaleFromDefaultSim()
1036 {
1037 MessageParcel data;
1038 MessageParcel reply;
1039 MessageOption option;
1040 if (!WriteInterfaceToken(data)) {
1041 TELEPHONY_LOGE("GetLocaleFromDefaultSim WriteInterfaceToken is false");
1042 return Str8ToStr16("");
1043 }
1044
1045 data.WriteInt32(DEFAULT_SIM_SLOT_ID);
1046 auto remote = Remote();
1047 if (remote == nullptr) {
1048 TELEPHONY_LOGE("GetLocaleFromDefaultSim Remote is null");
1049 return Str8ToStr16("");
1050 }
1051 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_LANGUAGE), data, reply, option);
1052 if (st != ERR_NONE) {
1053 TELEPHONY_LOGE("GetLocaleFromDefaultSim failed, error code is %{public}d", st);
1054 return Str8ToStr16("");
1055 }
1056 std::u16string result = reply.ReadString16();
1057 return result;
1058 }
1059
GetSimGid1(int32_t slotId,std::u16string & gid1)1060 int32_t CoreServiceProxy::GetSimGid1(int32_t slotId, std::u16string &gid1)
1061 {
1062 if (!IsValidSlotId(slotId)) {
1063 return TELEPHONY_ERR_SLOTID_INVALID;
1064 }
1065 MessageParcel data;
1066 MessageParcel reply;
1067 MessageOption option;
1068 if (!WriteInterfaceToken(data)) {
1069 TELEPHONY_LOGE("GetSimGid1 WriteInterfaceToken is false");
1070 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1071 }
1072 data.WriteInt32(slotId);
1073 auto remote = Remote();
1074 if (remote == nullptr) {
1075 TELEPHONY_LOGE("GetSimGid1 Remote is null");
1076 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1077 }
1078 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_GID1), data, reply, option);
1079 if (st != ERR_NONE) {
1080 TELEPHONY_LOGE("GetSimGid1 failed, error code is %{public}d", st);
1081 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1082 }
1083 int32_t result = reply.ReadInt32();
1084 if (result == TELEPHONY_ERR_SUCCESS) {
1085 gid1 = reply.ReadString16();
1086 }
1087 return result;
1088 }
1089
GetSimGid2(int32_t slotId)1090 std::u16string CoreServiceProxy::GetSimGid2(int32_t slotId)
1091 {
1092 if (!IsValidSlotId(slotId)) {
1093 return Str8ToStr16("");
1094 }
1095 MessageParcel data;
1096 MessageParcel reply;
1097 MessageOption option;
1098 if (!WriteInterfaceToken(data)) {
1099 TELEPHONY_LOGE("GetSimGid2 WriteInterfaceToken is false");
1100 return Str8ToStr16("");
1101 }
1102 data.WriteInt32(slotId);
1103 auto remote = Remote();
1104 if (remote == nullptr) {
1105 TELEPHONY_LOGE("GetSimGid2 Remote is null");
1106 return Str8ToStr16("");
1107 }
1108 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_GID2), data, reply, option);
1109 if (st != ERR_NONE) {
1110 TELEPHONY_LOGE("GetSimGid2 failed, error code is %{public}d", st);
1111 return Str8ToStr16("");
1112 }
1113 std::u16string result = reply.ReadString16();
1114 return result;
1115 }
1116
GetSimEons(int32_t slotId,const std::string & plmn,int32_t lac,bool longNameRequired)1117 std::u16string CoreServiceProxy::GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac, bool longNameRequired)
1118 {
1119 if (!IsValidSlotId(slotId)) {
1120 return Str8ToStr16("");
1121 }
1122 MessageParcel data;
1123 MessageParcel reply;
1124 MessageOption option;
1125 if (!WriteInterfaceToken(data)) {
1126 TELEPHONY_LOGE("GetSimEons WriteInterfaceToken is false");
1127 return Str8ToStr16("");
1128 }
1129 data.WriteInt32(slotId);
1130 data.WriteString(plmn);
1131 data.WriteInt32(lac);
1132 data.WriteBool(longNameRequired);
1133 auto remote = Remote();
1134 if (remote == nullptr) {
1135 TELEPHONY_LOGE("GetSimEons Remote is null");
1136 return Str8ToStr16("");
1137 }
1138 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_EONS), data, reply, option);
1139 if (st != ERR_NONE) {
1140 TELEPHONY_LOGE("GetSimEons failed, error code is %{public}d", st);
1141 return Str8ToStr16("");
1142 }
1143 return reply.ReadString16();
1144 }
1145
GetSimAccountInfo(int32_t slotId,IccAccountInfo & info)1146 int32_t CoreServiceProxy::GetSimAccountInfo(int32_t slotId, IccAccountInfo &info)
1147 {
1148 TELEPHONY_LOGD("GetSimAccountInfo slotId = %{public}d", slotId);
1149 if (!IsValidSlotIdEx(slotId)) {
1150 return TELEPHONY_ERR_SLOTID_INVALID;
1151 }
1152 MessageParcel data;
1153 MessageParcel reply;
1154 MessageOption option;
1155 if (!WriteInterfaceToken(data)) {
1156 TELEPHONY_LOGE("GetSimAccountInfo WriteInterfaceToken is false");
1157 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1158 }
1159 data.WriteInt32(slotId);
1160 auto remote = Remote();
1161 if (remote == nullptr) {
1162 TELEPHONY_LOGE("GetSimAccountInfo Remote is null");
1163 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1164 }
1165 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_SUB_INFO), data, reply, option);
1166 if (st != ERR_NONE) {
1167 TELEPHONY_LOGE("GetSimAccountInfo failed, error code is %{public}d", st);
1168 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1169 }
1170 int32_t result = reply.ReadInt32();
1171 if (result == TELEPHONY_ERR_SUCCESS) {
1172 info.ReadFromParcel(reply);
1173 }
1174 return result;
1175 }
1176
SetDefaultVoiceSlotId(int32_t slotId)1177 int32_t CoreServiceProxy::SetDefaultVoiceSlotId(int32_t slotId)
1178 {
1179 TELEPHONY_LOGI("CoreServiceProxy::SetDefaultVoiceSlotId slotId = %{public}d", slotId);
1180 if (!IsValidSlotIdForDefault(slotId)) {
1181 return TELEPHONY_ERR_SLOTID_INVALID;
1182 }
1183 MessageParcel data;
1184 MessageParcel reply;
1185 MessageOption option;
1186 if (!WriteInterfaceToken(data)) {
1187 TELEPHONY_LOGE("SetDefaultVoiceSlotId WriteInterfaceToken is false");
1188 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1189 }
1190 data.WriteInt32(slotId);
1191 auto remote = Remote();
1192 if (remote == nullptr) {
1193 TELEPHONY_LOGE("SetDefaultVoiceSlotId Remote is null");
1194 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1195 }
1196 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_DEFAULT_VOICE_SLOTID), data, reply, option);
1197 if (st != ERR_NONE) {
1198 TELEPHONY_LOGE("SetDefaultVoiceSlotId failed, error code is %{public}d", st);
1199 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1200 }
1201 return reply.ReadInt32();
1202 }
1203
GetDefaultVoiceSlotId()1204 int32_t CoreServiceProxy::GetDefaultVoiceSlotId()
1205 {
1206 MessageParcel data;
1207 MessageParcel reply;
1208 MessageOption option;
1209 if (!WriteInterfaceToken(data)) {
1210 TELEPHONY_LOGE("GetDefaultVoiceSlotId WriteInterfaceToken is false");
1211 return ERROR;
1212 }
1213 auto remote = Remote();
1214 if (remote == nullptr) {
1215 TELEPHONY_LOGE("GetDefaultVoiceSlotId Remote is null");
1216 return ERROR;
1217 }
1218 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_DEFAULT_VOICE_SLOTID), data, reply, option);
1219 if (st != ERR_NONE) {
1220 TELEPHONY_LOGE("GetDefaultVoiceSlotId failed, error code is %{public}d", st);
1221 return ERROR;
1222 }
1223 int32_t result = reply.ReadInt32();
1224 TELEPHONY_LOGI("GetDefaultVoiceSlotId end: result=%{public}d", result);
1225 return result;
1226 }
1227
GetDefaultVoiceSimId(const sptr<IRawParcelCallback> & callback)1228 int32_t CoreServiceProxy::GetDefaultVoiceSimId(const sptr<IRawParcelCallback> &callback)
1229 {
1230 MessageParcel data;
1231 if (!WriteInterfaceToken(data)) {
1232 TELEPHONY_LOGE("WriteInterfaceToken is false");
1233 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1234 }
1235 if (callback == nullptr) {
1236 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1237 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1238 }
1239 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1240 auto remote = Remote();
1241 if (remote == nullptr) {
1242 TELEPHONY_LOGE("Remote is null");
1243 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1244 }
1245 MessageParcel reply;
1246 MessageOption option;
1247 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_DEFAULT_VOICE_SIMID), data, reply, option);
1248 if (st != ERR_NONE) {
1249 TELEPHONY_LOGE("failed, error code is %{public}d", st);
1250 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1251 }
1252 return reply.ReadInt32();
1253 }
1254
SetPrimarySlotId(int32_t slotId)1255 int32_t CoreServiceProxy::SetPrimarySlotId(int32_t slotId)
1256 {
1257 TELEPHONY_LOGI("CoreServiceProxy::SetPrimarySlotId slotId = %{public}d", slotId);
1258 if (!IsValidSlotId(slotId)) {
1259 return TELEPHONY_ERR_SLOTID_INVALID;
1260 }
1261 MessageParcel data;
1262 MessageParcel reply;
1263 MessageOption option;
1264 if (!WriteInterfaceToken(data)) {
1265 TELEPHONY_LOGE("SetPrimarySlotId WriteInterfaceToken is false");
1266 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1267 }
1268 data.WriteInt32(slotId);
1269 auto remote = Remote();
1270 if (remote == nullptr) {
1271 TELEPHONY_LOGE("SetPrimarySlotId Remote is null");
1272 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1273 }
1274 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_PRIMARY_SLOTID), data, reply, option);
1275 if (error != ERR_NONE) {
1276 TELEPHONY_LOGE("SetPrimarySlotId failed, error code is %{public}d", error);
1277 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1278 }
1279 return reply.ReadInt32();
1280 }
1281
GetPrimarySlotId(int32_t & slotId)1282 int32_t CoreServiceProxy::GetPrimarySlotId(int32_t &slotId)
1283 {
1284 MessageParcel data;
1285 MessageParcel reply;
1286 MessageOption option;
1287 if (!WriteInterfaceToken(data)) {
1288 TELEPHONY_LOGE("GetPrimarySlotId WriteInterfaceToken is false");
1289 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1290 }
1291 auto remote = Remote();
1292 if (remote == nullptr) {
1293 TELEPHONY_LOGE("GetPrimarySlotId Remote is null");
1294 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1295 }
1296 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_PRIMARY_SLOTID), data, reply, option);
1297 if (st != ERR_NONE) {
1298 TELEPHONY_LOGE("GetPrimarySlotId failed, error code is %{public}d", st);
1299 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1300 }
1301 int32_t result = reply.ReadInt32();
1302 if (result == TELEPHONY_ERR_SUCCESS) {
1303 slotId = reply.ReadInt32();
1304 } else {
1305 TELEPHONY_LOGE("GetPrimarySlotId failed: result=%{public}d", result);
1306 }
1307 return result;
1308 }
1309
SetShowNumber(int32_t slotId,const std::u16string & number,const sptr<IRawParcelCallback> & callback)1310 int32_t CoreServiceProxy::SetShowNumber(int32_t slotId, const std::u16string &number,
1311 const sptr<IRawParcelCallback> &callback)
1312 {
1313 TELEPHONY_LOGI("CoreServiceProxy::SetShowNumber slotId = %{public}d", slotId);
1314 if (!IsValidSlotId(slotId)) {
1315 return TELEPHONY_ERR_SLOTID_INVALID;
1316 }
1317 if (!IsValidStringLength(number)) {
1318 return TELEPHONY_ERR_ARGUMENT_INVALID;
1319 }
1320 MessageParcel data;
1321 MessageParcel reply;
1322 MessageOption option;
1323 if (!WriteInterfaceToken(data)) {
1324 TELEPHONY_LOGE("SetShowNumber WriteInterfaceToken is false");
1325 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1326 }
1327 data.WriteInt32(slotId);
1328 data.WriteString16(number);
1329 if (callback == nullptr) {
1330 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1331 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1332 }
1333 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1334 auto remote = Remote();
1335 if (remote == nullptr) {
1336 TELEPHONY_LOGE("SetShowNumber Remote is null");
1337 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1338 }
1339 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_SHOW_NUMBER), data, reply, option);
1340 if (st != ERR_NONE) {
1341 TELEPHONY_LOGE("SetShowNumber failed, error code is %{public}d", st);
1342 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1343 }
1344 return reply.ReadInt32();
1345 }
1346
GetShowNumber(int32_t slotId,const sptr<IRawParcelCallback> & callback)1347 int32_t CoreServiceProxy::GetShowNumber(int32_t slotId, const sptr<IRawParcelCallback> &callback)
1348 {
1349 TELEPHONY_LOGI("GetShowNumber slotId = %{public}d", slotId);
1350 if (!IsValidSlotId(slotId)) {
1351 return TELEPHONY_ERR_SLOTID_INVALID;
1352 }
1353 MessageParcel data;
1354 MessageParcel reply;
1355 MessageOption option;
1356 if (!WriteInterfaceToken(data)) {
1357 TELEPHONY_LOGE("GetShowNumber WriteInterfaceToken is false");
1358 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1359 }
1360 data.WriteInt32(slotId);
1361 if (callback == nullptr) {
1362 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1363 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1364 }
1365 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1366 auto remote = Remote();
1367 if (remote == nullptr) {
1368 TELEPHONY_LOGE("GetShowNumber Remote is null");
1369 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1370 }
1371 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SHOW_NUMBER), data, reply, option);
1372 if (st != ERR_NONE) {
1373 TELEPHONY_LOGE("GetShowNumber failed, error code is %{public}d", st);
1374 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1375 }
1376 return reply.ReadInt32();
1377 }
1378
SetShowName(int32_t slotId,const std::u16string & name,const sptr<IRawParcelCallback> & callback)1379 int32_t CoreServiceProxy::SetShowName(int32_t slotId, const std::u16string &name,
1380 const sptr<IRawParcelCallback> &callback)
1381 {
1382 TELEPHONY_LOGI("CoreServiceProxy::SetShowName slotId = %{public}d", slotId);
1383 if (!IsValidSlotId(slotId)) {
1384 return TELEPHONY_ERR_SLOTID_INVALID;
1385 }
1386 if (!IsValidStringLength(name)) {
1387 return TELEPHONY_ERR_ARGUMENT_INVALID;
1388 }
1389 MessageParcel data;
1390 MessageParcel reply;
1391 MessageOption option;
1392 if (!WriteInterfaceToken(data)) {
1393 TELEPHONY_LOGE("SetShowName WriteInterfaceToken is false");
1394 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1395 }
1396 data.WriteInt32(slotId);
1397 data.WriteString16(name);
1398 if (callback == nullptr) {
1399 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1400 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1401 }
1402 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1403 auto remote = Remote();
1404 if (remote == nullptr) {
1405 TELEPHONY_LOGE("SetShowName Remote is null");
1406 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1407 }
1408 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_SHOW_NAME), data, reply, option);
1409 if (st != ERR_NONE) {
1410 TELEPHONY_LOGE("SetShowName failed, error code is %{public}d", st);
1411 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1412 }
1413 return reply.ReadInt32();
1414 }
1415
GetActiveSimAccountInfoList(std::vector<IccAccountInfo> & iccAccountInfoList)1416 int32_t CoreServiceProxy::GetActiveSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList)
1417 {
1418 MessageParcel data;
1419 MessageParcel reply;
1420 MessageOption option;
1421 if (!WriteInterfaceToken(data)) {
1422 TELEPHONY_LOGE("GetActiveSimAccountInfoList WriteInterfaceToken is false");
1423 return false;
1424 }
1425 auto remote = Remote();
1426 if (remote == nullptr) {
1427 TELEPHONY_LOGE("GetActiveSimAccountInfoList Remote is null");
1428 return false;
1429 }
1430 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_ACTIVE_ACCOUNT_INFO_LIST), data,
1431 reply, option);
1432 if (st != ERR_NONE) {
1433 TELEPHONY_LOGE("GetActiveSimAccountInfoList failed, error code is %{public}d", st);
1434 return false;
1435 }
1436 int32_t result = reply.ReadInt32();
1437 if (result == TELEPHONY_ERR_SUCCESS) {
1438 int32_t size = reply.ReadInt32();
1439 TELEPHONY_LOGI("CoreServiceProxy::GetActiveSimAccountInfoList size = %{public}d", size);
1440 if (size > MAX_VECTOR || size < 0) {
1441 return false;
1442 }
1443 iccAccountInfoList.clear();
1444 for (int i = 0; i < size; i++) {
1445 IccAccountInfo accountInfo;
1446 accountInfo.ReadFromParcel(reply);
1447 TELEPHONY_LOGD("CoreServiceProxy::GetActiveSimAccountInfoList success");
1448 iccAccountInfoList.emplace_back(accountInfo);
1449 }
1450 }
1451 return result;
1452 }
1453
GetOperatorConfigs(int32_t slotId,OperatorConfig & poc)1454 int32_t CoreServiceProxy::GetOperatorConfigs(int32_t slotId, OperatorConfig &poc)
1455 {
1456 if (!IsValidSlotId(slotId)) {
1457 TELEPHONY_LOGE("CoreServiceProxy::OperatorConfig invalid slotId");
1458 return TELEPHONY_ERR_SLOTID_INVALID;
1459 }
1460 MessageParcel data;
1461 MessageParcel reply;
1462 MessageOption option;
1463 if (!WriteInterfaceToken(data)) {
1464 TELEPHONY_LOGE("GetOperatorConfigs WriteInterfaceToken is false");
1465 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1466 }
1467 data.WriteInt32(slotId);
1468 auto remote = Remote();
1469 if (remote == nullptr) {
1470 TELEPHONY_LOGE("GetOperatorConfigs Remote is null");
1471 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1472 }
1473 std::lock_guard<std::mutex> lock(mutex_);
1474 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_OPERATOR_CONFIG), data, reply, option);
1475 if (st != ERR_NONE) {
1476 TELEPHONY_LOGE("GetOperatorConfigs failed, error code is %{public}d", st);
1477 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1478 }
1479 int32_t result = reply.ReadInt32();
1480 if (result == TELEPHONY_ERR_SUCCESS) {
1481 poc.ReadFromParcel(reply);
1482 }
1483 return result;
1484 }
1485
IsValidSlotId(int32_t slotId)1486 bool CoreServiceProxy::IsValidSlotId(int32_t slotId)
1487 {
1488 int32_t count = GetMaxSimCount();
1489 if ((slotId >= DEFAULT_SIM_SLOT_ID) && (slotId < count)) {
1490 return true;
1491 }
1492
1493 TELEPHONY_LOGE("SlotId is InValid = %{public}d", slotId);
1494 return false;
1495 }
1496
IsValidSlotIdEx(int32_t slotId)1497 bool CoreServiceProxy::IsValidSlotIdEx(int32_t slotId)
1498 {
1499 int32_t count = GetMaxSimCount();
1500 // One more slot for VSim.
1501 if ((slotId >= DEFAULT_SIM_SLOT_ID) && (slotId < count + 1)) {
1502 return true;
1503 }
1504
1505 TELEPHONY_LOGE("SlotId is InValid = %{public}d", slotId);
1506 return false;
1507 }
1508
IsValidSlotIdForDefault(int32_t slotId)1509 bool CoreServiceProxy::IsValidSlotIdForDefault(int32_t slotId)
1510 {
1511 int32_t count = GetMaxSimCount();
1512 if ((slotId >= DEFAULT_SIM_SLOT_ID_REMOVE) && (slotId < count)) {
1513 return true;
1514 }
1515
1516 TELEPHONY_LOGE("SlotId is InValid = %{public}d", slotId);
1517 return false;
1518 }
1519
IsValidStringLength(std::u16string str)1520 bool CoreServiceProxy::IsValidStringLength(std::u16string str)
1521 {
1522 int32_t length = static_cast<int32_t>(str.length());
1523 if ((length >= MIN_STRING_LE) && (length <= MAX_STRING_LE)) {
1524 return true;
1525 }
1526 TELEPHONY_LOGE("string length is InValid = %{public}d", length);
1527 return false;
1528 }
1529
IsValidServiceType(ImsServiceType serviceType)1530 bool CoreServiceProxy::IsValidServiceType(ImsServiceType serviceType)
1531 {
1532 if (serviceType < ImsServiceType::TYPE_VOICE || serviceType > ImsServiceType::TYPE_SMS) {
1533 TELEPHONY_LOGE("ServiceType is InValid = %{public}d", serviceType);
1534 return false;
1535 }
1536
1537 return true;
1538 }
1539
UnlockPin(const int32_t slotId,const std::u16string & pin,const sptr<IRawParcelCallback> & callback)1540 int32_t CoreServiceProxy::UnlockPin(const int32_t slotId, const std::u16string &pin,
1541 const sptr<IRawParcelCallback> &callback)
1542 {
1543 MessageParcel data;
1544 MessageParcel reply;
1545 MessageOption option;
1546 if (!WriteInterfaceToken(data)) {
1547 TELEPHONY_LOGE("UnlockPin WriteInterfaceToken is false");
1548 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1549 }
1550 data.WriteInt32(slotId);
1551 data.WriteString16(pin);
1552 if (callback == nullptr) {
1553 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1554 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1555 }
1556 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1557 auto remote = Remote();
1558 if (remote == nullptr) {
1559 TELEPHONY_LOGE("UnlockPin Remote is null");
1560 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1561 }
1562 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::UNLOCK_PIN), data, reply, option);
1563 if (st != ERR_NONE) {
1564 TELEPHONY_LOGE("UnlockPin failed, error code is %{public}d", st);
1565 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1566 }
1567 return reply.ReadInt32();
1568 }
1569
UnlockPuk(const int32_t slotId,const std::u16string & newPin,const std::u16string & puk,const sptr<IRawParcelCallback> & callback)1570 int32_t CoreServiceProxy::UnlockPuk(const int32_t slotId, const std::u16string &newPin,
1571 const std::u16string &puk, const sptr<IRawParcelCallback> &callback)
1572 {
1573 MessageParcel data;
1574 MessageParcel reply;
1575 MessageOption option;
1576 if (!WriteInterfaceToken(data)) {
1577 TELEPHONY_LOGE("UnlockPuk WriteInterfaceToken is false");
1578 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1579 }
1580 data.WriteInt32(slotId);
1581 data.WriteString16(newPin);
1582 data.WriteString16(puk);
1583 if (callback == nullptr) {
1584 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1585 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1586 }
1587 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1588 auto remote = Remote();
1589 if (remote == nullptr) {
1590 TELEPHONY_LOGE("UnlockPuk Remote is null");
1591 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1592 }
1593 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::UNLOCK_PUK), data, reply, option);
1594 if (st != ERR_NONE) {
1595 TELEPHONY_LOGE("UnlockPuk failed, error code is %{public}d", st);
1596 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1597 }
1598 return reply.ReadInt32();
1599 }
1600
AlterPin(const int32_t slotId,const std::u16string & newPin,const std::u16string & oldPin,const sptr<IRawParcelCallback> & callback)1601 int32_t CoreServiceProxy::AlterPin(const int32_t slotId, const std::u16string &newPin,
1602 const std::u16string &oldPin, const sptr<IRawParcelCallback> &callback)
1603 {
1604 MessageParcel data;
1605 MessageParcel reply;
1606 MessageOption option;
1607 if (!WriteInterfaceToken(data)) {
1608 TELEPHONY_LOGE("AlterPin WriteInterfaceToken is false");
1609 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1610 }
1611 data.WriteInt32(slotId);
1612 data.WriteString16(newPin);
1613 data.WriteString16(oldPin);
1614 if (callback == nullptr) {
1615 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1616 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1617 }
1618 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1619 auto remote = Remote();
1620 if (remote == nullptr) {
1621 TELEPHONY_LOGE("AlterPin Remote is null");
1622 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1623 }
1624 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::ALTER_PIN), data, reply, option);
1625 if (st != ERR_NONE) {
1626 TELEPHONY_LOGE("AlterPin failed, error code is %{public}d", st);
1627 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1628 }
1629 return reply.ReadInt32();
1630 }
1631
UnlockPin2(const int32_t slotId,const std::u16string & pin2,const sptr<IRawParcelCallback> & callback)1632 int32_t CoreServiceProxy::UnlockPin2(const int32_t slotId, const std::u16string &pin2,
1633 const sptr<IRawParcelCallback> &callback)
1634 {
1635 MessageParcel data;
1636 MessageParcel reply;
1637 MessageOption option;
1638 if (!WriteInterfaceToken(data)) {
1639 TELEPHONY_LOGE("UnlockPin2 WriteInterfaceToken is false");
1640 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1641 }
1642 data.WriteInt32(slotId);
1643 data.WriteString16(pin2);
1644 if (callback == nullptr) {
1645 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1646 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1647 }
1648 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1649 auto remote = Remote();
1650 if (remote == nullptr) {
1651 TELEPHONY_LOGE("UnlockPin2 Remote is null");
1652 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1653 }
1654 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::UNLOCK_PIN2), data, reply, option);
1655 if (st != ERR_NONE) {
1656 TELEPHONY_LOGE("UnlockPin2 failed, error code is %{public}d", st);
1657 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1658 }
1659 return reply.ReadInt32();
1660 }
1661
UnlockPuk2(const int32_t slotId,const std::u16string & newPin2,const std::u16string & puk2,const sptr<IRawParcelCallback> & callback)1662 int32_t CoreServiceProxy::UnlockPuk2(const int32_t slotId, const std::u16string &newPin2,
1663 const std::u16string &puk2, const sptr<IRawParcelCallback> &callback)
1664 {
1665 MessageParcel data;
1666 MessageParcel reply;
1667 MessageOption option;
1668 if (!WriteInterfaceToken(data)) {
1669 TELEPHONY_LOGE("UnlockPuk2 WriteInterfaceToken is false");
1670 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1671 }
1672 data.WriteInt32(slotId);
1673 data.WriteString16(newPin2);
1674 data.WriteString16(puk2);
1675 if (callback == nullptr) {
1676 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1677 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1678 }
1679 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1680 auto remote = Remote();
1681 if (remote == nullptr) {
1682 TELEPHONY_LOGE("UnlockPuk2 Remote is null");
1683 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1684 }
1685 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::UNLOCK_PUK2), data, reply, option);
1686 if (st != ERR_NONE) {
1687 TELEPHONY_LOGE("UnlockPuk2 failed, error code is %{public}d", st);
1688 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1689 }
1690 return reply.ReadInt32();
1691 }
1692
AlterPin2(const int32_t slotId,const std::u16string & newPin2,const std::u16string & oldPin2,const sptr<IRawParcelCallback> & callback)1693 int32_t CoreServiceProxy::AlterPin2(const int32_t slotId, const std::u16string &newPin2,
1694 const std::u16string &oldPin2, const sptr<IRawParcelCallback> &callback)
1695 {
1696 MessageParcel data;
1697 MessageParcel reply;
1698 MessageOption option;
1699 if (!WriteInterfaceToken(data)) {
1700 TELEPHONY_LOGE("AlterPin2 WriteInterfaceToken is false");
1701 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1702 }
1703 data.WriteInt32(slotId);
1704 data.WriteString16(newPin2);
1705 data.WriteString16(oldPin2);
1706 if (callback == nullptr) {
1707 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1708 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1709 }
1710 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1711 auto remote = Remote();
1712 if (remote == nullptr) {
1713 TELEPHONY_LOGE("AlterPin2 Remote is null");
1714 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1715 }
1716 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::ALTER_PIN2), data, reply, option);
1717 if (st != ERR_NONE) {
1718 TELEPHONY_LOGE("AlterPin2 failed, error code is %{public}d", st);
1719 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1720 }
1721 return reply.ReadInt32();
1722 }
1723
SetLockState(const int32_t slotId,const LockInfo & options,const sptr<IRawParcelCallback> & callback)1724 int32_t CoreServiceProxy::SetLockState(const int32_t slotId, const LockInfo &options,
1725 const sptr<IRawParcelCallback> &callback)
1726 {
1727 MessageParcel data;
1728 MessageParcel reply;
1729 MessageOption option;
1730 if (!WriteInterfaceToken(data)) {
1731 TELEPHONY_LOGE("SetLockState WriteInterfaceToken is false");
1732 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1733 }
1734 data.WriteInt32(slotId);
1735 data.WriteInt32(static_cast<int32_t>(options.lockType));
1736 data.WriteInt32(static_cast<int32_t>(options.lockState));
1737 data.WriteString16(options.password);
1738 if (callback == nullptr) {
1739 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1740 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1741 }
1742 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1743 auto remote = Remote();
1744 if (remote == nullptr) {
1745 TELEPHONY_LOGE("SetLockState Remote is null");
1746 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1747 }
1748 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SWITCH_LOCK), data, reply, option);
1749 if (st != ERR_NONE) {
1750 TELEPHONY_LOGE("SetLockState failed, error code is %{public}d", st);
1751 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1752 }
1753 TELEPHONY_LOGI("SetLockState successful");
1754 return reply.ReadInt32();
1755 }
1756
GetLockState(int32_t slotId,LockType lockType,const sptr<IRawParcelCallback> & callback)1757 int32_t CoreServiceProxy::GetLockState(int32_t slotId, LockType lockType, const sptr<IRawParcelCallback> &callback)
1758 {
1759 MessageParcel data;
1760 MessageParcel reply;
1761 MessageOption option;
1762 if (!WriteInterfaceToken(data)) {
1763 TELEPHONY_LOGE("GetLockState WriteInterfaceToken is false");
1764 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1765 }
1766 TELEPHONY_LOGI("GetLockState WriteInterfaceToken is true");
1767 data.WriteInt32(slotId);
1768 data.WriteInt32(static_cast<int32_t>(lockType));
1769 if (callback == nullptr) {
1770 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
1771 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1772 }
1773 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1774 auto remote = Remote();
1775 if (remote == nullptr) {
1776 TELEPHONY_LOGE("GetLockState Remote is null");
1777 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1778 }
1779 TELEPHONY_LOGI("GetLockState Remote is != null");
1780 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::CHECK_LOCK), data, reply, option);
1781 if (st != ERR_NONE) {
1782 TELEPHONY_LOGE("GetLockState failed, error code is %{public}d", st);
1783 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1784 }
1785 return reply.ReadInt32();
1786 }
1787
RefreshSimState(int32_t slotId)1788 int32_t CoreServiceProxy::RefreshSimState(int32_t slotId)
1789 {
1790 TELEPHONY_LOGI("CoreServiceProxy RefreshSimState ::%{public}d", slotId);
1791 MessageParcel data;
1792 MessageParcel reply;
1793 MessageOption option;
1794 if (!WriteInterfaceToken(data)) {
1795 TELEPHONY_LOGE("RefreshSimState WriteInterfaceToken is false");
1796 return TELEPHONY_ERROR;
1797 }
1798 data.WriteInt32(slotId);
1799 auto remote = Remote();
1800 if (remote == nullptr) {
1801 TELEPHONY_LOGE("RefreshSimState Remote is null");
1802 return TELEPHONY_ERROR;
1803 }
1804 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::REFRESH_SIM_STATE), data, reply, option);
1805 if (st != ERR_NONE) {
1806 TELEPHONY_LOGE("RefreshSimState failed, error code is %{public}d", st);
1807 return TELEPHONY_ERROR;
1808 }
1809 int32_t result = reply.ReadInt32();
1810 TELEPHONY_LOGI("RefreshSimState call end:: result = %{public}d", result);
1811 return result;
1812 }
1813
SetActiveSim(int32_t slotId,int32_t enable)1814 int32_t CoreServiceProxy::SetActiveSim(int32_t slotId, int32_t enable)
1815 {
1816 TELEPHONY_LOGI("CoreServiceProxy SetActiveSim ::%{public}d", slotId);
1817 if (!IsValidSlotId(slotId)) {
1818 TELEPHONY_LOGE("CoreServiceProxy::SetActiveSim invalid simId");
1819 return TELEPHONY_ERR_SLOTID_INVALID;
1820 }
1821 static const int32_t DISABLE = 0;
1822 static const int32_t ENABLE = 1;
1823 if (enable != DISABLE && enable != ENABLE) {
1824 TELEPHONY_LOGE("CoreServiceProxy::SetActiveSim invalid enable status");
1825 return TELEPHONY_ERR_ARGUMENT_INVALID;
1826 }
1827 MessageParcel data;
1828 MessageParcel reply;
1829 MessageOption option;
1830 if (!WriteInterfaceToken(data)) {
1831 TELEPHONY_LOGE("SetActiveSim WriteInterfaceToken is false");
1832 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1833 }
1834 data.WriteInt32(slotId);
1835 data.WriteInt32(enable);
1836 auto remote = Remote();
1837 if (remote == nullptr) {
1838 TELEPHONY_LOGE("SetActiveSim Remote is null");
1839 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1840 }
1841 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_SIM_ACTIVE), data, reply, option);
1842 if (st != ERR_NONE) {
1843 TELEPHONY_LOGE("SetActiveSim failed, error code is %{public}d", st);
1844 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1845 }
1846 int32_t result = reply.ReadInt32();
1847 TELEPHONY_LOGI("SetActiveSim call end:: result = %{public}d", result);
1848 return result;
1849 }
1850
SetActiveSimSatellite(int32_t slotId,int32_t enable)1851 int32_t CoreServiceProxy::SetActiveSimSatellite(int32_t slotId, int32_t enable)
1852 {
1853 if (!IsValidSlotId(slotId)) {
1854 TELEPHONY_LOGE("CoreServiceProxy::SetActiveSimSatellite invalid simId");
1855 return TELEPHONY_ERR_SLOTID_INVALID;
1856 }
1857 if (enable != DISABLE && enable != ENABLE) {
1858 TELEPHONY_LOGE("CoreServiceProxy::SetActiveSimSatellite invalid enable status");
1859 return TELEPHONY_ERR_ARGUMENT_INVALID;
1860 }
1861 MessageParcel data;
1862 MessageParcel reply;
1863 MessageOption option;
1864 if (!WriteInterfaceToken(data)) {
1865 TELEPHONY_LOGE("SetActiveSimSatellite WriteInterfaceToken is false");
1866 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1867 }
1868 data.WriteInt32(slotId);
1869 data.WriteInt32(enable);
1870 auto remote = Remote();
1871 if (remote == nullptr) {
1872 TELEPHONY_LOGE("SetActiveSimSatellite Remote is null");
1873 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1874 }
1875 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_SIM_ACTIVE_SATELLITE), data, reply, option);
1876 if (st != ERR_NONE) {
1877 TELEPHONY_LOGE("SetActiveSimSatellite failed, error code is %{public}d", st);
1878 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1879 }
1880 int32_t result = reply.ReadInt32();
1881 return result;
1882 }
1883
GetPreferredNetwork(int32_t slotId,const sptr<INetworkSearchCallback> & callback)1884 int32_t CoreServiceProxy::GetPreferredNetwork(int32_t slotId, const sptr<INetworkSearchCallback> &callback)
1885 {
1886 TELEPHONY_LOGI("CoreServiceProxy GetPreferredNetwork");
1887 MessageParcel data;
1888 MessageParcel reply;
1889 MessageOption option;
1890 if (!WriteInterfaceToken(data)) {
1891 TELEPHONY_LOGE("GetPreferredNetwork WriteInterfaceToken is false");
1892 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1893 }
1894 if (!data.WriteInt32(slotId)) {
1895 TELEPHONY_LOGE("GetPreferredNetwork WriteInt32 slotId is false");
1896 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1897 }
1898 if (callback != nullptr) {
1899 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1900 }
1901 auto remote = Remote();
1902 if (remote == nullptr) {
1903 TELEPHONY_LOGE("GetPreferredNetwork Remote is null");
1904 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1905 }
1906 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_PREFERRED_NETWORK_MODE), data,
1907 reply, option);
1908 if (error != ERR_NONE) {
1909 TELEPHONY_LOGE("GetPreferredNetwork failed, error code is %{public}d", error);
1910 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1911 }
1912 return reply.ReadInt32();
1913 }
1914
SetPreferredNetwork(int32_t slotId,int32_t networkMode,const sptr<INetworkSearchCallback> & callback)1915 int32_t CoreServiceProxy::SetPreferredNetwork(
1916 int32_t slotId, int32_t networkMode, const sptr<INetworkSearchCallback> &callback)
1917 {
1918 MessageParcel data;
1919 MessageParcel reply;
1920 MessageOption option;
1921 if (!WriteInterfaceToken(data)) {
1922 TELEPHONY_LOGE("SetPreferredNetwork WriteInterfaceToken is false");
1923 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1924 }
1925 if (!data.WriteInt32(slotId)) {
1926 TELEPHONY_LOGE("SetPreferredNetwork WriteInt32 slotId is false");
1927 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1928 }
1929 if (!data.WriteInt32(networkMode)) {
1930 TELEPHONY_LOGE("SetPreferredNetwork WriteInt32 networkMode is false");
1931 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
1932 }
1933 if (callback != nullptr) {
1934 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
1935 }
1936 auto remote = Remote();
1937 if (remote == nullptr) {
1938 TELEPHONY_LOGE("SetPreferredNetwork Remote is null");
1939 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1940 }
1941 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_PREFERRED_NETWORK_MODE), data,
1942 reply, option);
1943 if (error != ERR_NONE) {
1944 TELEPHONY_LOGE("SetPreferredNetwork failed, error code is %{public}d", error);
1945 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1946 }
1947 return reply.ReadInt32();
1948 }
1949
GetNetworkCapability(int32_t slotId,int32_t networkCapabilityType,int32_t & networkCapabilityState)1950 int32_t CoreServiceProxy::GetNetworkCapability(
1951 int32_t slotId, int32_t networkCapabilityType, int32_t &networkCapabilityState)
1952 {
1953 TELEPHONY_LOGD("CoreServiceProxy GetNetworkCapability");
1954 MessageParcel data;
1955 if (!WriteInterfaceToken(data)) {
1956 TELEPHONY_LOGE("GetNetworkCapability WriteInterfaceToken is false");
1957 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1958 }
1959 if (!data.WriteInt32(slotId)) {
1960 TELEPHONY_LOGE("GetNetworkCapability WriteInt32 slotId is false");
1961 return TELEPHONY_ERR_WRITE_DATA_FAIL;
1962 }
1963 if (!data.WriteInt32(networkCapabilityType)) {
1964 TELEPHONY_LOGE("GetNetworkCapability WriteInt32 deviceType is false");
1965 return TELEPHONY_ERR_WRITE_DATA_FAIL;
1966 }
1967 auto remote = Remote();
1968 if (remote == nullptr) {
1969 TELEPHONY_LOGE("GetNetworkCapability Remote is null");
1970 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1971 }
1972 MessageParcel reply;
1973 MessageOption option;
1974 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_NETWORK_CAPABILITY), data,
1975 reply, option);
1976 if (error != ERR_NONE) {
1977 TELEPHONY_LOGE("GetNetworkCapability failed, error code is %{public}d", error);
1978 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1979 }
1980 int32_t ret = reply.ReadInt32();
1981 if (ret != TELEPHONY_ERR_SUCCESS) {
1982 TELEPHONY_LOGE("GetNetworkCapability failed!");
1983 return ret;
1984 }
1985 networkCapabilityState = reply.ReadInt32();
1986 return TELEPHONY_ERR_SUCCESS;
1987 }
1988
SetNetworkCapability(int32_t slotId,int32_t networkCapabilityType,int32_t networkCapabilityState)1989 int32_t CoreServiceProxy::SetNetworkCapability(
1990 int32_t slotId, int32_t networkCapabilityType, int32_t networkCapabilityState)
1991 {
1992 TELEPHONY_LOGD("CoreServiceProxy SetNetworkCapability");
1993 MessageParcel data;
1994 if (!WriteInterfaceToken(data)) {
1995 TELEPHONY_LOGE("SetNetworkCapability WriteInterfaceToken is false");
1996 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1997 }
1998 if (!data.WriteInt32(slotId)) {
1999 TELEPHONY_LOGE("SetNetworkCapability WriteInt32 slotId is false");
2000 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2001 }
2002 if (!data.WriteInt32(networkCapabilityType)) {
2003 TELEPHONY_LOGE("SetNetworkCapability WriteInt32 type is false");
2004 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2005 }
2006 if (!data.WriteInt32(networkCapabilityState)) {
2007 TELEPHONY_LOGE("SetNetworkCapability WriteInt32 enabled is false");
2008 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2009 }
2010 auto remote = Remote();
2011 if (remote == nullptr) {
2012 TELEPHONY_LOGE("SetNetworkCapability Remote is null");
2013 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2014 }
2015 MessageParcel reply;
2016 MessageOption option;
2017 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_NETWORK_CAPABILITY), data,
2018 reply, option);
2019 if (error != ERR_NONE) {
2020 TELEPHONY_LOGE("SetNetworkCapability failed, error code is %{public}d \n", error);
2021 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2022 }
2023 return reply.ReadInt32();
2024 }
2025
GetSimTelephoneNumber(int32_t slotId,std::u16string & telephoneNumber)2026 int32_t CoreServiceProxy::GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber)
2027 {
2028 if (!IsValidSlotId(slotId)) {
2029 return TELEPHONY_ERR_SLOTID_INVALID;
2030 }
2031 MessageParcel data;
2032 MessageParcel reply;
2033 MessageOption option;
2034 if (!WriteInterfaceToken(data)) {
2035 TELEPHONY_LOGE("GetSimTelephoneNumber WriteInterfaceToken is false");
2036 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2037 }
2038 data.WriteInt32(slotId);
2039 auto remote = Remote();
2040 if (remote == nullptr) {
2041 TELEPHONY_LOGE("GetSimTelephoneNumber Remote is null");
2042 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2043 }
2044 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_PHONE_NUMBER), data, reply, option);
2045 if (st != ERR_NONE) {
2046 TELEPHONY_LOGE("GetSimTelephoneNumber failed, error code is %{public}d", st);
2047 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2048 }
2049 int32_t result = reply.ReadInt32();
2050 if (result == TELEPHONY_ERR_SUCCESS) {
2051 telephoneNumber = reply.ReadString16();
2052 }
2053 return result;
2054 }
2055
GetSimTeleNumberIdentifier(const int32_t slotId)2056 std::u16string CoreServiceProxy::GetSimTeleNumberIdentifier(const int32_t slotId)
2057 {
2058 if (!IsValidSlotId(slotId)) {
2059 return u"";
2060 }
2061 MessageParcel data;
2062 MessageParcel reply;
2063 MessageOption option;
2064 if (!WriteInterfaceToken(data)) {
2065 TELEPHONY_LOGE("GetSimTeleNumberIdentifier WriteInterfaceToken is false");
2066 return Str8ToStr16("");
2067 }
2068 data.WriteInt32(slotId);
2069 auto remote = Remote();
2070 if (remote == nullptr) {
2071 TELEPHONY_LOGE("GetSimTeleNumberIdentifier Remote is null");
2072 return Str8ToStr16("");
2073 }
2074 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_TELENUMBER_IDENTIFIER), data,
2075 reply, option);
2076 if (st != ERR_NONE) {
2077 TELEPHONY_LOGE("GetSimTeleNumberIdentifier failed, error code is %{public}d", st);
2078 return Str8ToStr16("");
2079 }
2080 std::u16string result = reply.ReadString16();
2081 return result;
2082 }
2083
GetVoiceMailIdentifier(int32_t slotId,std::u16string & voiceMailIdentifier)2084 int32_t CoreServiceProxy::GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier)
2085 {
2086 if (!IsValidSlotId(slotId)) {
2087 return TELEPHONY_ERR_SLOTID_INVALID;
2088 }
2089 MessageParcel data;
2090 MessageParcel reply;
2091 MessageOption option;
2092 if (!WriteInterfaceToken(data)) {
2093 TELEPHONY_LOGE("GetVoiceMailIdentifier WriteInterfaceToken is false");
2094 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2095 }
2096 data.WriteInt32(slotId);
2097 auto remote = Remote();
2098 if (remote == nullptr) {
2099 TELEPHONY_LOGE("GetVoiceMailIdentifier Remote is null");
2100 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2101 }
2102 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_VOICE_MAIL_TAG), data, reply, option);
2103 if (st != ERR_NONE) {
2104 TELEPHONY_LOGE("GetVoiceMailIdentifier failed, error code is %{public}d", st);
2105 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2106 }
2107 int32_t result = reply.ReadInt32();
2108 if (result == TELEPHONY_ERR_SUCCESS) {
2109 voiceMailIdentifier = reply.ReadString16();
2110 }
2111 return result;
2112 }
2113
GetVoiceMailNumber(int32_t slotId,std::u16string & voiceMailNumber)2114 int32_t CoreServiceProxy::GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber)
2115 {
2116 if (!IsValidSlotId(slotId)) {
2117 return TELEPHONY_ERR_SLOTID_INVALID;
2118 }
2119 MessageParcel data;
2120 MessageParcel reply;
2121 MessageOption option;
2122 if (!WriteInterfaceToken(data)) {
2123 TELEPHONY_LOGE("GetVoiceMailNumber WriteInterfaceToken is false");
2124 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2125 }
2126 data.WriteInt32(slotId);
2127 auto remote = Remote();
2128 if (remote == nullptr) {
2129 TELEPHONY_LOGE("GetVoiceMailNumber Remote is null");
2130 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2131 }
2132 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_VOICE_MAIL_NUMBER), data, reply, option);
2133 if (st != ERR_NONE) {
2134 TELEPHONY_LOGE("GetVoiceMailNumber failed, error code is %{public}d", st);
2135 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2136 }
2137 int32_t result = reply.ReadInt32();
2138 if (result == TELEPHONY_ERR_SUCCESS) {
2139 voiceMailNumber = reply.ReadString16();
2140 }
2141 return result;
2142 }
2143
GetVoiceMailCount(int32_t slotId,int32_t & voiceMailCount)2144 int32_t CoreServiceProxy::GetVoiceMailCount(int32_t slotId, int32_t &voiceMailCount)
2145 {
2146 if (!IsValidSlotId(slotId)) {
2147 return TELEPHONY_ERR_SLOTID_INVALID;
2148 }
2149 MessageParcel data;
2150 MessageParcel reply;
2151 MessageOption option;
2152 if (!WriteInterfaceToken(data)) {
2153 TELEPHONY_LOGE("GetVoiceMailCount WriteInterfaceToken is false");
2154 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2155 }
2156 data.WriteInt32(slotId);
2157 auto remote = Remote();
2158 if (remote == nullptr) {
2159 TELEPHONY_LOGE("GetVoiceMailCount Remote is null");
2160 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2161 }
2162 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_VOICE_MAIL_COUNT), data, reply, option);
2163 if (st != ERR_NONE) {
2164 TELEPHONY_LOGE("GetVoiceMailCount failed, error code is %{public}d", st);
2165 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2166 }
2167 int32_t result = reply.ReadInt32();
2168 if (result == TELEPHONY_ERR_SUCCESS) {
2169 voiceMailCount = reply.ReadInt32();
2170 }
2171 return result;
2172 }
2173
SetVoiceMailCount(int32_t slotId,int32_t voiceMailCount)2174 int32_t CoreServiceProxy::SetVoiceMailCount(int32_t slotId, int32_t voiceMailCount)
2175 {
2176 if (!IsValidSlotId(slotId)) {
2177 return TELEPHONY_ERR_SLOTID_INVALID;
2178 }
2179 MessageParcel data;
2180 MessageParcel reply;
2181 MessageOption option;
2182 if (!WriteInterfaceToken(data)) {
2183 TELEPHONY_LOGE("SetVoiceMailCount WriteInterfaceToken is false");
2184 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2185 }
2186 data.WriteInt32(slotId);
2187 data.WriteInt32(voiceMailCount);
2188 auto remote = Remote();
2189 if (remote == nullptr) {
2190 TELEPHONY_LOGE("SetVoiceMailCount Remote is null");
2191 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2192 }
2193 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_VOICE_MAIL_COUNT), data, reply, option);
2194 if (st != ERR_NONE) {
2195 TELEPHONY_LOGE("SetVoiceMailCount failed, error code is %{public}d", st);
2196 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2197 }
2198 return reply.ReadInt32();
2199 }
2200
SetVoiceCallForwarding(int32_t slotId,bool enable,const std::string & number)2201 int32_t CoreServiceProxy::SetVoiceCallForwarding(int32_t slotId, bool enable, const std::string &number)
2202 {
2203 if (!IsValidSlotId(slotId)) {
2204 return TELEPHONY_ERR_SLOTID_INVALID;
2205 }
2206 MessageParcel data;
2207 MessageParcel reply;
2208 MessageOption option;
2209 if (!WriteInterfaceToken(data)) {
2210 TELEPHONY_LOGE("SetVoiceCallForwarding WriteInterfaceToken is false");
2211 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2212 }
2213 data.WriteInt32(slotId);
2214 data.WriteBool(enable);
2215 data.WriteString(number);
2216 auto remote = Remote();
2217 if (remote == nullptr) {
2218 TELEPHONY_LOGE("SetVoiceCallForwarding Remote is null");
2219 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2220 }
2221 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_VOICE_CALL_FORWARDING), data,
2222 reply, option);
2223 if (st != ERR_NONE) {
2224 TELEPHONY_LOGE("SetVoiceCallForwarding failed, error code is %{public}d", st);
2225 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2226 }
2227 return reply.ReadInt32();
2228 }
2229
QueryIccDiallingNumbers(int slotId,int type,std::vector<std::shared_ptr<DiallingNumbersInfo>> & result)2230 int32_t CoreServiceProxy::QueryIccDiallingNumbers(
2231 int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result)
2232 {
2233 if (!IsValidSlotId(slotId)) {
2234 return TELEPHONY_ERR_SLOTID_INVALID;
2235 }
2236 MessageParcel data;
2237 MessageParcel reply;
2238 MessageOption option;
2239 if (!WriteInterfaceToken(data)) {
2240 TELEPHONY_LOGE("QueryIccDiallingNumbers WriteInterfaceToken is false");
2241 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2242 }
2243 if (!data.WriteInt32(slotId)) {
2244 TELEPHONY_LOGE("QueryIccDiallingNumbers WriteInt32 slotId is false");
2245 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2246 }
2247 if (!data.WriteInt32(type)) {
2248 TELEPHONY_LOGE("QueryIccDiallingNumbers WriteInt32 type is false");
2249 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2250 }
2251 auto remote = Remote();
2252 if (remote == nullptr) {
2253 TELEPHONY_LOGE("QueryIccDiallingNumbers Remote is null");
2254 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2255 }
2256 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_GET), data, reply, option);
2257 if (st != ERR_NONE) {
2258 TELEPHONY_LOGE("QueryIccDiallingNumbers failed, error code is %{public}d", st);
2259 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2260 }
2261 int32_t errorCode = reply.ReadInt32();
2262 if (errorCode != TELEPHONY_ERR_SUCCESS) {
2263 return errorCode;
2264 }
2265 int32_t size = reply.ReadInt32();
2266 TELEPHONY_LOGI("CoreServiceProxy::QueryIccDiallingNumbers size:%{public}d", size);
2267 if (size >= MAX_SIZE) {
2268 TELEPHONY_LOGE("CoreServiceProxy::QueryIccDiallingNumbers over max size");
2269 return TELEPHONY_ERR_READ_DATA_FAIL;
2270 }
2271 for (int i = 0; i < size; i++) {
2272 std::shared_ptr<DiallingNumbersInfo> diallingNumber = DiallingNumbersInfo::UnMarshalling(reply);
2273 if (diallingNumber != nullptr) {
2274 result.emplace_back(diallingNumber);
2275 }
2276 }
2277 return TELEPHONY_ERR_SUCCESS;
2278 }
2279
AddIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)2280 int32_t CoreServiceProxy::AddIccDiallingNumbers(
2281 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
2282 {
2283 TELEPHONY_LOGI("CoreServiceProxy AddIccDiallingNumbers ::%{public}d", slotId);
2284 if (!IsValidSlotId(slotId)) {
2285 return TELEPHONY_ERR_SLOTID_INVALID;
2286 }
2287 MessageParcel data;
2288 MessageParcel reply;
2289 MessageOption option;
2290 if (!WriteInterfaceToken(data)) {
2291 TELEPHONY_LOGE("AddIccDiallingNumbers WriteInterfaceToken is false");
2292 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2293 }
2294 if (!data.WriteInt32(slotId)) {
2295 TELEPHONY_LOGE("AddIccDiallingNumbers WriteInt32 slotId is false");
2296 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2297 }
2298 if (!data.WriteInt32(type)) {
2299 TELEPHONY_LOGE("AddIccDiallingNumbers WriteInt32 type is false");
2300 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2301 }
2302 if (diallingNumber != nullptr) {
2303 diallingNumber->Marshalling(data);
2304 }
2305 auto remote = Remote();
2306 if (remote == nullptr) {
2307 TELEPHONY_LOGE("AddIccDiallingNumbers Remote is null");
2308 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2309 }
2310 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_INSERT), data,
2311 reply, option);
2312 if (st != ERR_NONE) {
2313 TELEPHONY_LOGE("AddIccDiallingNumbers failed, error code is %{public}d", st);
2314 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2315 }
2316 return reply.ReadInt32();
2317 }
2318
DelIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)2319 int32_t CoreServiceProxy::DelIccDiallingNumbers(
2320 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
2321 {
2322 TELEPHONY_LOGI("CoreServiceProxy DelIccDiallingNumbers ::%{public}d", slotId);
2323 if (!IsValidSlotId(slotId)) {
2324 return TELEPHONY_ERR_SLOTID_INVALID;
2325 }
2326 MessageParcel data;
2327 MessageParcel reply;
2328 MessageOption option;
2329 if (!WriteInterfaceToken(data)) {
2330 TELEPHONY_LOGE("DelIccDiallingNumbers WriteInterfaceToken is false");
2331 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2332 }
2333 if (!data.WriteInt32(slotId)) {
2334 TELEPHONY_LOGE("DelIccDiallingNumbers WriteInt32 slotId is false");
2335 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2336 }
2337 if (!data.WriteInt32(type)) {
2338 TELEPHONY_LOGE("DelIccDiallingNumbers WriteInt32 type is false");
2339 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2340 }
2341 if (diallingNumber != nullptr) {
2342 diallingNumber->Marshalling(data);
2343 }
2344 auto remote = Remote();
2345 if (remote == nullptr) {
2346 TELEPHONY_LOGE("DelIccDiallingNumbers Remote is null");
2347 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2348 }
2349 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_DELETE), data,
2350 reply, option);
2351 if (st != ERR_NONE) {
2352 TELEPHONY_LOGE("DelIccDiallingNumbers failed, error code is %{public}d", st);
2353 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2354 }
2355 return reply.ReadInt32();
2356 }
2357
UpdateIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)2358 int32_t CoreServiceProxy::UpdateIccDiallingNumbers(
2359 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
2360 {
2361 TELEPHONY_LOGI("CoreServiceProxy UpdateIccDiallingNumbers ::%{public}d", slotId);
2362 if (!IsValidSlotId(slotId)) {
2363 return TELEPHONY_ERR_SLOTID_INVALID;
2364 }
2365 MessageParcel data;
2366 MessageParcel reply;
2367 MessageOption option;
2368 if (!WriteInterfaceToken(data)) {
2369 TELEPHONY_LOGE("UpdateIccDiallingNumbers WriteInterfaceToken is false");
2370 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2371 }
2372 if (!data.WriteInt32(slotId)) {
2373 TELEPHONY_LOGE("UpdateIccDiallingNumbers WriteInt32 slotId is false");
2374 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2375 }
2376 if (!data.WriteInt32(type)) {
2377 TELEPHONY_LOGE("UpdateIccDiallingNumbers WriteInt32 type is false");
2378 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2379 }
2380 if (diallingNumber != nullptr) {
2381 diallingNumber->Marshalling(data);
2382 }
2383 auto remote = Remote();
2384 if (remote == nullptr) {
2385 TELEPHONY_LOGE("UpdateIccDiallingNumbers Remote is null");
2386 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2387 }
2388 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::ICC_DIALLING_NUMBERS_UPDATE), data,
2389 reply, option);
2390 if (st != ERR_NONE) {
2391 TELEPHONY_LOGE("UpdateIccDiallingNumbers failed, error code is %{public}d", st);
2392 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2393 }
2394 return reply.ReadInt32();
2395 }
2396
SetVoiceMailInfo(const int32_t slotId,const std::u16string & mailName,const std::u16string & mailNumber)2397 int32_t CoreServiceProxy::SetVoiceMailInfo(
2398 const int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber)
2399 {
2400 TELEPHONY_LOGI("slotId = %{public}d", slotId);
2401 if (!IsValidSlotId(slotId)) {
2402 return TELEPHONY_ERR_SLOTID_INVALID;
2403 }
2404 if (!IsValidStringLength(mailName) || !IsValidStringLength(mailNumber)) {
2405 return TELEPHONY_ERR_ARGUMENT_INVALID;
2406 }
2407 MessageParcel data;
2408 MessageParcel reply;
2409 MessageOption option;
2410 if (!WriteInterfaceToken(data)) {
2411 TELEPHONY_LOGE("WriteInterfaceToken is false");
2412 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2413 }
2414 if (!data.WriteInt32(slotId)) {
2415 TELEPHONY_LOGE("WriteInt32 slotId is false");
2416 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2417 }
2418 if (!data.WriteString16(mailName)) {
2419 TELEPHONY_LOGE("WriteString16 mailName is false");
2420 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2421 }
2422 if (!data.WriteString16(mailNumber)) {
2423 TELEPHONY_LOGE("WriteString16 mailNumber is false");
2424 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2425 }
2426 auto remote = Remote();
2427 if (remote == nullptr) {
2428 TELEPHONY_LOGE("Remote is null");
2429 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2430 }
2431 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SET_VOICE_MAIL), data, reply, option);
2432 if (st != ERR_NONE) {
2433 TELEPHONY_LOGE("failed, error code is %{public}d", st);
2434 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2435 }
2436 return reply.ReadInt32();
2437 }
2438
GetOpKey(int32_t slotId,std::u16string & opkey)2439 int32_t CoreServiceProxy::GetOpKey(int32_t slotId, std::u16string &opkey)
2440 {
2441 if (!IsValidSlotId(slotId)) {
2442 return TELEPHONY_ERR_SLOTID_INVALID;
2443 }
2444 MessageParcel data;
2445 MessageParcel reply;
2446 MessageOption option;
2447 if (!WriteInterfaceToken(data)) {
2448 TELEPHONY_LOGE("GetOpKey WriteInterfaceToken is false");
2449 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2450 }
2451 data.WriteInt32(slotId);
2452 auto remote = Remote();
2453 if (remote == nullptr) {
2454 TELEPHONY_LOGE("GetOpKey Remote is null");
2455 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2456 }
2457 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_OPKEY), data, reply, option);
2458 if (error != ERR_NONE) {
2459 TELEPHONY_LOGE("GetOpKey failed, error code is %{public}d", error);
2460 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2461 }
2462 int32_t result = reply.ReadInt32();
2463 if (result == TELEPHONY_ERR_SUCCESS) {
2464 opkey = reply.ReadString16();
2465 }
2466 return result;
2467 }
2468
GetOpKeyExt(int32_t slotId,std::u16string & opkeyExt)2469 int32_t CoreServiceProxy::GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt)
2470 {
2471 if (!IsValidSlotId(slotId)) {
2472 return TELEPHONY_ERR_SLOTID_INVALID;
2473 }
2474 MessageParcel data;
2475 MessageParcel reply;
2476 MessageOption option;
2477 if (!WriteInterfaceToken(data)) {
2478 TELEPHONY_LOGE("WriteInterfaceToken is false");
2479 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2480 }
2481 data.WriteInt32(slotId);
2482 auto remote = Remote();
2483 if (remote == nullptr) {
2484 TELEPHONY_LOGE("Remote is null");
2485 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2486 }
2487 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_OPKEY_EXT), data, reply, option);
2488 if (error != ERR_NONE) {
2489 TELEPHONY_LOGE("failed, error code is %{public}d", error);
2490 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2491 }
2492 int32_t result = reply.ReadInt32();
2493 if (result == TELEPHONY_ERR_SUCCESS) {
2494 opkeyExt = reply.ReadString16();
2495 }
2496 return result;
2497 }
2498
GetOpName(int32_t slotId,std::u16string & opname)2499 int32_t CoreServiceProxy::GetOpName(int32_t slotId, std::u16string &opname)
2500 {
2501 if (!IsValidSlotId(slotId)) {
2502 return TELEPHONY_ERR_SLOTID_INVALID;
2503 }
2504 MessageParcel data;
2505 MessageParcel reply;
2506 MessageOption option;
2507 if (!WriteInterfaceToken(data)) {
2508 TELEPHONY_LOGE("GetOpName WriteInterfaceToken is false");
2509 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2510 }
2511 data.WriteInt32(slotId);
2512 auto remote = Remote();
2513 if (remote == nullptr) {
2514 TELEPHONY_LOGE("GetOpName Remote is null");
2515 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2516 }
2517 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_OPNAME), data, reply, option);
2518 if (error != ERR_NONE) {
2519 TELEPHONY_LOGE("GetOpName failed, error code is %{public}d", error);
2520 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2521 }
2522 int32_t result = reply.ReadInt32();
2523 if (result == TELEPHONY_ERR_SUCCESS) {
2524 opname = reply.ReadString16();
2525 }
2526 return result;
2527 }
2528
GetMaxSimCount()2529 int32_t CoreServiceProxy::GetMaxSimCount()
2530 {
2531 return SIM_SLOT_COUNT_REAL;
2532 }
2533
SendEnvelopeCmd(int32_t slotId,const std::string & cmd)2534 int32_t CoreServiceProxy::SendEnvelopeCmd(int32_t slotId, const std::string &cmd)
2535 {
2536 if (!IsValidSlotId(slotId)) {
2537 return TELEPHONY_ERR_SLOTID_INVALID;
2538 }
2539 if (cmd.empty()) {
2540 return TELEPHONY_ERR_ARGUMENT_INVALID;
2541 }
2542 MessageParcel data;
2543 MessageParcel reply;
2544 MessageOption option;
2545 if (!WriteInterfaceToken(data)) {
2546 TELEPHONY_LOGE("WriteInterfaceToken is false");
2547 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2548 }
2549 data.WriteInt32(slotId);
2550 data.WriteString(cmd);
2551 auto remote = Remote();
2552 if (remote == nullptr) {
2553 TELEPHONY_LOGE("Remote is null");
2554 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2555 }
2556 std::lock_guard<std::mutex> lock(mutex_);
2557 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::STK_CMD_FROM_APP_ENVELOPE), data,
2558 reply, option);
2559 if (st != ERR_NONE) {
2560 TELEPHONY_LOGE("failed, error code is %{public}d", st);
2561 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2562 }
2563 int32_t result = reply.ReadInt32();
2564 TELEPHONY_LOGI("end: result=%{public}d", result);
2565 return result;
2566 }
2567
SendTerminalResponseCmd(int32_t slotId,const std::string & cmd)2568 int32_t CoreServiceProxy::SendTerminalResponseCmd(int32_t slotId, const std::string &cmd)
2569 {
2570 if (!IsValidSlotId(slotId)) {
2571 return TELEPHONY_ERR_SLOTID_INVALID;
2572 }
2573 if (cmd.empty()) {
2574 return TELEPHONY_ERR_ARGUMENT_INVALID;
2575 }
2576 MessageParcel data;
2577 MessageParcel reply;
2578 MessageOption option;
2579 if (!WriteInterfaceToken(data)) {
2580 TELEPHONY_LOGE("SendTerminalResponseCmd WriteInterfaceToken is false");
2581 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2582 }
2583 data.WriteInt32(slotId);
2584 data.WriteString(cmd);
2585 auto remote = Remote();
2586 if (remote == nullptr) {
2587 TELEPHONY_LOGE("SendTerminalResponseCmd Remote is null");
2588 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2589 }
2590 std::lock_guard<std::mutex> lock(mutex_);
2591 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::STK_CMD_FROM_APP_TERMINAL_RESPONSE), data,
2592 reply, option);
2593 if (st != ERR_NONE) {
2594 TELEPHONY_LOGE("SendTerminalResponseCmd failed, error code is %{public}d", st);
2595 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2596 }
2597 int32_t result = reply.ReadInt32();
2598 TELEPHONY_LOGI("SendTerminalResponseCmd end: result=%{public}d", result);
2599 return result;
2600 }
2601
SendCallSetupRequestResult(int32_t slotId,bool accept)2602 int32_t CoreServiceProxy::SendCallSetupRequestResult(int32_t slotId, bool accept)
2603 {
2604 MessageParcel data;
2605 MessageParcel reply;
2606 MessageOption option;
2607 if (!WriteInterfaceToken(data)) {
2608 TELEPHONY_LOGE("SendCallSetupRequestResult WriteInterfaceToken is false");
2609 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2610 }
2611 data.WriteInt32(slotId);
2612 data.WriteInt32(accept);
2613 auto remote = Remote();
2614 if (remote == nullptr) {
2615 TELEPHONY_LOGE("SendCallSetupRequestResult Remote is null");
2616 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2617 }
2618 std::lock_guard<std::mutex> lock(mutex_);
2619 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::STK_RESULT_FROM_APP_CALL_SETUP_REQUEST),
2620 data, reply, option);
2621 if (st != ERR_NONE) {
2622 TELEPHONY_LOGE("SendCallSetupRequestResult failed, error code is %{public}d", st);
2623 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2624 }
2625 int32_t result = reply.ReadInt32();
2626 TELEPHONY_LOGI("SendCallSetupRequestResult end: result=%{public}d", result);
2627 return result;
2628 }
2629
UnlockSimLock(int32_t slotId,const PersoLockInfo & lockInfo,LockStatusResponse & response)2630 int32_t CoreServiceProxy::UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response)
2631 {
2632 if (!IsValidSlotId(slotId)) {
2633 return TELEPHONY_ERR_SLOTID_INVALID;
2634 }
2635 MessageParcel data;
2636 MessageParcel reply;
2637 MessageOption option;
2638 if (!WriteInterfaceToken(data)) {
2639 TELEPHONY_LOGE("UnlockSimLock WriteInterfaceToken is false");
2640 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2641 }
2642 data.WriteInt32(slotId);
2643 data.WriteInt32(static_cast<int32_t>(lockInfo.lockType));
2644 data.WriteString16(lockInfo.password);
2645 auto remote = Remote();
2646 if (remote == nullptr) {
2647 TELEPHONY_LOGE("UnlockSimLock Remote is null");
2648 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2649 }
2650 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::UNLOCK_SIMLOCK), data, reply, option);
2651 if (st != ERR_NONE) {
2652 TELEPHONY_LOGE("UnlockSimLock failed, error code is %{public}d", st);
2653 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2654 }
2655 int32_t result = reply.ReadInt32();
2656 if (result == TELEPHONY_ERR_SUCCESS) {
2657 response.result = reply.ReadInt32();
2658 response.remain = reply.ReadInt32();
2659 }
2660 return result;
2661 }
2662
GetImsRegStatus(int32_t slotId,ImsServiceType imsSrvType,ImsRegInfo & info)2663 int32_t CoreServiceProxy::GetImsRegStatus(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info)
2664 {
2665 if (!IsValidSlotId(slotId)) {
2666 TELEPHONY_LOGE("invalid slotId!");
2667 return TELEPHONY_ERR_SLOTID_INVALID;
2668 }
2669 TELEPHONY_LOGD("slotId:%{public}d", slotId);
2670 MessageParcel data;
2671 MessageParcel reply;
2672 MessageOption option;
2673 if (!WriteInterfaceToken(data)) {
2674 TELEPHONY_LOGE("WriteInterfaceToken is false");
2675 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2676 }
2677 if (!data.WriteInt32(slotId)) {
2678 TELEPHONY_LOGE("WriteInt32 slotId is false");
2679 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2680 }
2681 if (!data.WriteInt32(imsSrvType)) {
2682 TELEPHONY_LOGE("WriteInt32 imsSrvType is false");
2683 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2684 }
2685 sptr<IRemoteObject> remote = Remote();
2686 if (remote == nullptr) {
2687 TELEPHONY_LOGE("Remote is null");
2688 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2689 }
2690 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_IMS_REG_STATUS), data, reply, option);
2691 if (st != ERR_NONE) {
2692 TELEPHONY_LOGE("failed, error code is %{public}d", st);
2693 return st;
2694 }
2695 int32_t ret = reply.ReadInt32();
2696 info.imsRegState = static_cast<ImsRegState>(reply.ReadInt32());
2697 info.imsRegTech = static_cast<ImsRegTech>(reply.ReadInt32());
2698 return ret;
2699 }
2700
GetCellInfoList(int32_t slotId,std::vector<sptr<CellInformation>> & cellInfo)2701 int32_t CoreServiceProxy::GetCellInfoList(int32_t slotId, std::vector<sptr<CellInformation>> &cellInfo)
2702 {
2703 MessageParcel data;
2704 MessageParcel reply;
2705 MessageOption option;
2706 if (!WriteInterfaceToken(data)) {
2707 TELEPHONY_LOGE("GetCellInfoList WriteInterfaceToken is false");
2708 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2709 }
2710 if (!data.WriteInt32(slotId)) {
2711 TELEPHONY_LOGE("GetCellInfoList WriteInt32 imsSrvType is false");
2712 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2713 }
2714 auto remote = Remote();
2715 if (remote == nullptr) {
2716 TELEPHONY_LOGE("GetCellInfoList Remote is null");
2717 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2718 }
2719 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_CELL_INFO_LIST), data, reply, option);
2720 if (error != ERR_NONE) {
2721 TELEPHONY_LOGE("GetCellInfoList failed, error code is %{public}d\n", error);
2722 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2723 }
2724 int32_t result = reply.ReadInt32();
2725 if (result == TELEPHONY_ERR_SUCCESS) {
2726 ProcessCellInfo(reply, cellInfo);
2727 }
2728 TELEPHONY_LOGD("CoreServiceProxy::GetCellInfoList cell size:%{public}zu\n", cellInfo.size());
2729 return result;
2730 }
2731
GetNeighboringCellInfoList(int32_t slotId,std::vector<sptr<CellInformation>> & cellInfo)2732 int32_t CoreServiceProxy::GetNeighboringCellInfoList(int32_t slotId, std::vector<sptr<CellInformation>> &cellInfo)
2733 {
2734 MessageParcel data;
2735 MessageParcel reply;
2736 MessageOption option;
2737 if (!WriteInterfaceToken(data)) {
2738 TELEPHONY_LOGE("GetNeighboringCellInfoList WriteInterfaceToken is false");
2739 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2740 }
2741 if (!data.WriteInt32(slotId)) {
2742 TELEPHONY_LOGE("GetNeighboringCellInfoList WriteInt32 imsSrvType is false");
2743 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2744 }
2745 auto remote = Remote();
2746 if (remote == nullptr) {
2747 TELEPHONY_LOGE("GetNeighboringCellInfoList Remote is null");
2748 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2749 }
2750 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_NEIGHBORING_CELL_INFO_LIST),
2751 data, reply, option);
2752 if (error != ERR_NONE) {
2753 TELEPHONY_LOGE("GET_NEIGHBORING_CELL_INFO_LIST failed, error code is %{public}d\n", error);
2754 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2755 }
2756 int32_t result = reply.ReadInt32();
2757 if (result == TELEPHONY_ERR_SUCCESS) {
2758 ProcessCellInfo(reply, cellInfo);
2759 }
2760 TELEPHONY_LOGD("CoreServiceProxy::GetNeighboringCellInfoList cell size:%{public}zu\n", cellInfo.size());
2761 return result;
2762 }
2763
ProcessCellInfo(MessageParcel & reply,std::vector<sptr<CellInformation>> & cells)2764 void CoreServiceProxy::ProcessCellInfo(MessageParcel &reply, std::vector<sptr<CellInformation>> &cells)
2765 {
2766 int32_t size = reply.ReadInt32();
2767 TELEPHONY_LOGD("CoreServiceProxy::ProcessCellInfo size:%{public}d\n", size);
2768 if (size >= MAX_SIZE) {
2769 TELEPHONY_LOGE("CoreServiceProxy::ProcessCellInfo over max size");
2770 return;
2771 }
2772 CellInformation::CellType type;
2773 for (int i = 0; i < size; ++i) {
2774 type = static_cast<CellInformation::CellType>(reply.ReadInt32());
2775 switch (type) {
2776 case CellInformation::CellType::CELL_TYPE_GSM: {
2777 ProcessReply<GsmCellInformation>(reply, cells);
2778 break;
2779 }
2780 case CellInformation::CellType::CELL_TYPE_LTE: {
2781 ProcessReply<LteCellInformation>(reply, cells);
2782 break;
2783 }
2784 case CellInformation::CellType::CELL_TYPE_WCDMA: {
2785 ProcessReply<WcdmaCellInformation>(reply, cells);
2786 break;
2787 }
2788 case CellInformation::CellType::CELL_TYPE_CDMA: {
2789 ProcessReply<CdmaCellInformation>(reply, cells);
2790 break;
2791 }
2792 case CellInformation::CellType::CELL_TYPE_TDSCDMA: {
2793 ProcessReply<TdscdmaCellInformation>(reply, cells);
2794 break;
2795 }
2796 case CellInformation::CellType::CELL_TYPE_NR: {
2797 ProcessReply<NrCellInformation>(reply, cells);
2798 break;
2799 }
2800 default:
2801 break;
2802 }
2803 }
2804 }
2805
SendUpdateCellLocationRequest(int32_t slotId)2806 int32_t CoreServiceProxy::SendUpdateCellLocationRequest(int32_t slotId)
2807 {
2808 MessageParcel data;
2809 MessageParcel reply;
2810 MessageOption option;
2811 if (!WriteInterfaceToken(data)) {
2812 TELEPHONY_LOGE("SendUpdateCellLocationRequest WriteInterfaceToken is false");
2813 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2814 }
2815 auto remote = Remote();
2816 if (remote == nullptr) {
2817 TELEPHONY_LOGE("SendUpdateCellLocationRequest Remote is null");
2818 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2819 }
2820 data.WriteInt32(slotId);
2821 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_CELL_LOCATION), data, reply, option);
2822 if (error != ERR_NONE) {
2823 TELEPHONY_LOGE("SendUpdateCellLocationRequest failed, error code is %{public}d", error);
2824 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2825 }
2826
2827 return reply.ReadInt32();
2828 }
2829
HasOperatorPrivileges(const int32_t slotId,const sptr<IRawParcelCallback> & callback)2830 int32_t CoreServiceProxy::HasOperatorPrivileges(const int32_t slotId, const sptr<IRawParcelCallback> &callback)
2831 {
2832 MessageParcel data;
2833 MessageParcel reply;
2834 MessageOption option;
2835 if (!WriteInterfaceToken(data)) {
2836 TELEPHONY_LOGE("HasOperatorPrivileges WriteInterfaceToken is false");
2837 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2838 }
2839 data.WriteInt32(slotId);
2840 if (callback == nullptr) {
2841 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
2842 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2843 }
2844 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
2845 auto remote = Remote();
2846 if (remote == nullptr) {
2847 TELEPHONY_LOGE("HasOperatorPrivileges Remote is null");
2848 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2849 }
2850 std::lock_guard<std::mutex> lock(mutex_);
2851 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::HAS_OPERATOR_PRIVILEGES), data, reply, option);
2852 if (st != ERR_NONE) {
2853 TELEPHONY_LOGE("HasOperatorPrivileges failed, error code is %{public}d", st);
2854 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2855 }
2856 return reply.ReadInt32();
2857 }
2858
SimAuthentication(int32_t slotId,AuthType authType,const std::string & authData,SimAuthenticationResponse & response)2859 int32_t CoreServiceProxy::SimAuthentication(
2860 int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response)
2861 {
2862 MessageParcel data;
2863 MessageParcel reply;
2864 MessageOption option;
2865 if (!WriteInterfaceToken(data)) {
2866 TELEPHONY_LOGE("SimAuthentication WriteInterfaceToken is false");
2867 return ERROR;
2868 }
2869 data.WriteInt32(slotId);
2870 data.WriteInt32(static_cast<int32_t>(authType));
2871 data.WriteString(authData);
2872 auto remote = Remote();
2873 if (remote == nullptr) {
2874 TELEPHONY_LOGE("SimAuthentication Remote is null");
2875 return ERROR;
2876 }
2877 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::SIM_AUTHENTICATION), data, reply, option);
2878 if (st != ERR_NONE) {
2879 TELEPHONY_LOGE("SimAuthentication failed, error code is %{public}d", st);
2880 return ERROR;
2881 }
2882 int32_t ret = reply.ReadInt32();
2883 response.sw1 = reply.ReadInt32();
2884 response.sw2 = reply.ReadInt32();
2885 response.response = reply.ReadString();
2886 TELEPHONY_LOGI("SimAuthentication end: result=%{public}d", ret);
2887 return ret;
2888 }
2889
IsNrSupported(int32_t slotId)2890 bool CoreServiceProxy::IsNrSupported(int32_t slotId)
2891 {
2892 MessageParcel data;
2893 MessageParcel reply;
2894 MessageOption option;
2895 if (!WriteInterfaceToken(data)) {
2896 TELEPHONY_LOGE("IsNrSupported WriteInterfaceToken is false");
2897 return false;
2898 }
2899 auto remote = Remote();
2900 data.WriteInt32(slotId);
2901 if (remote == nullptr) {
2902 TELEPHONY_LOGE("SimAuthentication Remote is null");
2903 return false;
2904 }
2905 int32_t st = remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::IS_NR_SUPPORTED), data,
2906 reply, option);
2907 if (st != ERR_NONE) {
2908 TELEPHONY_LOGE("IsNrSupported failed, error code is %{public}d", st);
2909 return false;
2910 }
2911 bool result = reply.ReadBool();
2912 return result;
2913 }
2914
SetNrOptionMode(int32_t slotId,int32_t mode,const sptr<INetworkSearchCallback> & callback)2915 int32_t CoreServiceProxy::SetNrOptionMode(int32_t slotId, int32_t mode, const sptr<INetworkSearchCallback> &callback)
2916 {
2917 MessageParcel data;
2918 MessageParcel reply;
2919 MessageOption option;
2920 if (!WriteInterfaceToken(data)) {
2921 TELEPHONY_LOGE("SetNrOptionMode WriteInterfaceToken is false");
2922 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2923 }
2924 if (!data.WriteInt32(slotId)) {
2925 TELEPHONY_LOGE("SetNrOptionMode WriteInt32 slotId is false");
2926 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
2927 }
2928 if (!data.WriteInt32(mode)) {
2929 TELEPHONY_LOGE("SetNrOptionMode WriteInt32 mode is false");
2930 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
2931 }
2932 if (callback != nullptr) {
2933 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
2934 }
2935 auto remote = Remote();
2936 if (remote == nullptr) {
2937 TELEPHONY_LOGE("SetNrOptionMode Remote is null");
2938 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2939 }
2940 int32_t error = remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::SET_NR_OPTION_MODE), data,
2941 reply, option);
2942 if (error != ERR_NONE) {
2943 TELEPHONY_LOGE("SetNrOptionMode failed, error code is %{public}d", error);
2944 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2945 }
2946 return reply.ReadInt32();
2947 }
2948
GetNrOptionMode(int32_t slotId,const sptr<INetworkSearchCallback> & callback)2949 int32_t CoreServiceProxy::GetNrOptionMode(int32_t slotId, const sptr<INetworkSearchCallback> &callback)
2950 {
2951 MessageParcel data;
2952 MessageParcel reply;
2953 MessageOption option;
2954 if (!WriteInterfaceToken(data)) {
2955 TELEPHONY_LOGE("GetNrOptionMode WriteInterfaceToken is false");
2956 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2957 }
2958 data.WriteInt32(slotId);
2959 if (callback != nullptr) {
2960 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
2961 }
2962 auto remote = Remote();
2963 if (remote == nullptr) {
2964 TELEPHONY_LOGE("GetNrOptionMode Remote is null");
2965 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2966 }
2967 int32_t error = remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::GET_NR_OPTION_MODE), data,
2968 reply, option);
2969 if (error != ERR_NONE) {
2970 TELEPHONY_LOGE("GetNrOptionMode failed, error code is %{public}d", error);
2971 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2972 }
2973 return reply.ReadInt32();
2974 }
2975
RegisterImsRegInfoCallback(int32_t slotId,ImsServiceType imsSrvType,const sptr<ImsRegInfoCallback> & callback)2976 int32_t CoreServiceProxy::RegisterImsRegInfoCallback(
2977 int32_t slotId, ImsServiceType imsSrvType, const sptr<ImsRegInfoCallback> &callback)
2978 {
2979 if (callback == nullptr) {
2980 TELEPHONY_LOGE("callback is nullptr!");
2981 return TELEPHONY_ERR_ARGUMENT_NULL;
2982 }
2983 MessageParcel data;
2984 MessageParcel reply;
2985 MessageOption option;
2986 int32_t ret = SerializeImsRegInfoData(slotId, imsSrvType, data);
2987 if (ret != TELEPHONY_SUCCESS) {
2988 TELEPHONY_LOGE("serialize data failed, result is %{public}d", ret);
2989 return ret;
2990 }
2991 if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
2992 TELEPHONY_LOGE("write remote object failed!");
2993 return TELEPHONY_ERR_WRITE_DATA_FAIL;
2994 }
2995 sptr<OHOS::IRemoteObject> remote = Remote();
2996 if (remote == nullptr) {
2997 TELEPHONY_LOGE("remote is nullptr!");
2998 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
2999 }
3000 int32_t error = remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::REG_IMS_CALLBACK), data,
3001 reply, option);
3002 if (error != TELEPHONY_SUCCESS) {
3003 TELEPHONY_LOGE("error! errCode:%{public}d", error);
3004 return error;
3005 }
3006 return reply.ReadInt32();
3007 }
3008
UnregisterImsRegInfoCallback(int32_t slotId,ImsServiceType imsSrvType)3009 int32_t CoreServiceProxy::UnregisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType)
3010 {
3011 MessageParcel data;
3012 MessageParcel reply;
3013 MessageOption option;
3014 int32_t ret = SerializeImsRegInfoData(slotId, imsSrvType, data);
3015 if (ret != TELEPHONY_SUCCESS) {
3016 TELEPHONY_LOGE("serialize data failed, result is %{public}d", ret);
3017 return ret;
3018 }
3019 sptr<OHOS::IRemoteObject> remote = Remote();
3020 if (remote == nullptr) {
3021 TELEPHONY_LOGE("remote is nullptr!");
3022 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3023 }
3024 int32_t error = remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::UN_REG_IMS_CALLBACK), data,
3025 reply, option);
3026 if (error != TELEPHONY_SUCCESS) {
3027 TELEPHONY_LOGE("error! errCode:%{public}d", error);
3028 return error;
3029 }
3030 return reply.ReadInt32();
3031 }
3032
SerializeImsRegInfoData(int32_t slotId,ImsServiceType imsSrvType,MessageParcel & data)3033 int32_t CoreServiceProxy::SerializeImsRegInfoData(int32_t slotId, ImsServiceType imsSrvType, MessageParcel &data)
3034 {
3035 if (!IsValidSlotId(slotId)) {
3036 TELEPHONY_LOGE("invalid slotId");
3037 return TELEPHONY_ERR_SLOTID_INVALID;
3038 }
3039 if (!IsValidServiceType(imsSrvType)) {
3040 TELEPHONY_LOGE("invalid serviceType!");
3041 return TELEPHONY_ERR_ARGUMENT_INVALID;
3042 }
3043 if (!WriteInterfaceToken(data)) {
3044 TELEPHONY_LOGE("write interface token failed!");
3045 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
3046 }
3047 if (!data.WriteInt32(slotId)) {
3048 TELEPHONY_LOGE("write slotId failed!");
3049 return TELEPHONY_ERR_WRITE_DATA_FAIL;
3050 }
3051 if (!data.WriteInt32(static_cast<int32_t>(imsSrvType))) {
3052 TELEPHONY_LOGE("write imsSrvType failed!");
3053 return TELEPHONY_ERR_WRITE_DATA_FAIL;
3054 }
3055 return TELEPHONY_SUCCESS;
3056 }
3057
GetNrSsbIdInfo(int32_t slotId,const std::shared_ptr<NrSsbInformation> & nrSsbInformation)3058 int32_t CoreServiceProxy::GetNrSsbIdInfo(int32_t slotId, const std::shared_ptr<NrSsbInformation> &nrSsbInformation)
3059 {
3060 MessageParcel data;
3061 MessageParcel reply;
3062 MessageOption option;
3063 if (!WriteInterfaceToken(data)) {
3064 TELEPHONY_LOGE("WriteInterfaceToken is false");
3065 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
3066 }
3067 if (!data.WriteInt32(slotId)) {
3068 TELEPHONY_LOGE("WriteInt32 slotId is false");
3069 return TELEPHONY_ERR_WRITE_DATA_FAIL;
3070 }
3071 auto remote = Remote();
3072 if (remote == nullptr) {
3073 TELEPHONY_LOGE("Remote is null");
3074 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3075 }
3076 if (nrSsbInformation == nullptr) {
3077 TELEPHONY_LOGE("nrSsbInformation is null");
3078 return TELEPHONY_ERR_ARGUMENT_NULL;
3079 }
3080 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_NR_SSB_ID_INFO), data, reply, option);
3081 if (error != ERR_NONE) {
3082 TELEPHONY_LOGE("Failed, error code is %{public}d\n", error);
3083 return error;
3084 }
3085 int32_t result = reply.ReadInt32();
3086 if (result == TELEPHONY_ERR_SUCCESS) {
3087 if (!nrSsbInformation->ReadFromParcel(reply)) {
3088 TELEPHONY_LOGE("ReadFromParcel is failed");
3089 return TELEPHONY_ERR_READ_DATA_FAIL;
3090 }
3091 }
3092 return result;
3093 }
3094
FactoryReset(int32_t slotId)3095 int32_t CoreServiceProxy::FactoryReset(int32_t slotId)
3096 {
3097 MessageParcel data;
3098 if (!WriteInterfaceToken(data)) {
3099 TELEPHONY_LOGE("WriteInterfaceToken is false");
3100 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
3101 }
3102 auto remote = Remote();
3103 if (remote == nullptr) {
3104 TELEPHONY_LOGE("Remote is null");
3105 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3106 }
3107 data.WriteInt32(slotId);
3108 MessageParcel reply;
3109 MessageOption option;
3110 int32_t error =
3111 remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::FACTORY_RESET), data, reply, option);
3112 if (error != ERR_NONE) {
3113 TELEPHONY_LOGE("Error code is %{public}d", error);
3114 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3115 }
3116 return reply.ReadInt32();
3117 }
3118
IsAllowedInsertApn(std::string & value)3119 bool CoreServiceProxy::IsAllowedInsertApn(std::string &value)
3120 {
3121 MessageParcel data;
3122 if (!WriteInterfaceToken(data)) {
3123 TELEPHONY_LOGE("WriteInterfaceToken is false");
3124 return true;
3125 }
3126
3127 if (!data.WriteString(value)) {
3128 TELEPHONY_LOGE("WriteString is false");
3129 return true;
3130 }
3131
3132 auto remote = Remote();
3133 if (remote == nullptr) {
3134 TELEPHONY_LOGE("Remote is null");
3135 return true;
3136 }
3137 MessageParcel reply;
3138 MessageOption option;
3139 int32_t error = remote->SendRequest(
3140 static_cast<uint32_t>(CoreServiceInterfaceCode::IS_ALLOWED_INSERT_APN), data, reply, option);
3141 if (error != ERR_NONE) {
3142 TELEPHONY_LOGE("Error code is %{public}d", error);
3143 return true;
3144 }
3145 return reply.ReadBool();
3146 }
3147
GetTargetOpkey(int32_t slotId,std::u16string & opkey)3148 int32_t CoreServiceProxy::GetTargetOpkey(int32_t slotId, std::u16string &opkey)
3149 {
3150 MessageParcel data;
3151 if (!WriteInterfaceToken(data)) {
3152 TELEPHONY_LOGE("WriteInterfaceToken is false");
3153 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
3154 }
3155
3156 if (!data.WriteInt32(slotId)) {
3157 TELEPHONY_LOGE("WriteInt32 slotId is false");
3158 return TELEPHONY_ERR_WRITE_DATA_FAIL;
3159 }
3160
3161 auto remote = Remote();
3162 if (remote == nullptr) {
3163 TELEPHONY_LOGE("Remote is null");
3164 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3165 }
3166 MessageParcel reply;
3167 MessageOption option;
3168 int32_t error =
3169 remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::GET_TARGET_OPKEY), data, reply, option);
3170 if (error != ERR_NONE) {
3171 TELEPHONY_LOGE("Error code is %{public}d", error);
3172 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3173 }
3174 opkey = reply.ReadString16();
3175 return reply.ReadInt32();
3176 }
3177
GetOpkeyVersion(std::string & versionInfo)3178 int32_t CoreServiceProxy::GetOpkeyVersion(std::string &versionInfo)
3179 {
3180 MessageParcel data;
3181 if (!WriteInterfaceToken(data)) {
3182 TELEPHONY_LOGE("WriteInterfaceToken is false");
3183 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
3184 }
3185 auto remote = Remote();
3186 if (remote == nullptr) {
3187 TELEPHONY_LOGE("Remote is null");
3188 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3189 }
3190 MessageParcel reply;
3191 MessageOption option;
3192 int32_t error =
3193 remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::GET_OPKEY_VERSION), data, reply, option);
3194 if (error != ERR_NONE) {
3195 TELEPHONY_LOGE("Error code is %{public}d", error);
3196 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3197 }
3198 versionInfo = reply.ReadString();
3199 return reply.ReadInt32();
3200 }
3201
GetOpnameVersion(std::string & versionInfo)3202 int32_t CoreServiceProxy::GetOpnameVersion(std::string &versionInfo)
3203 {
3204 MessageParcel data;
3205 if (!WriteInterfaceToken(data)) {
3206 TELEPHONY_LOGE("WriteInterfaceToken is false");
3207 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
3208 }
3209 auto remote = Remote();
3210 if (remote == nullptr) {
3211 TELEPHONY_LOGE("Remote is null");
3212 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3213 }
3214 MessageParcel reply;
3215 MessageOption option;
3216 int32_t error =
3217 remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::GET_OPNAME_VERSION), data, reply, option);
3218 if (error != ERR_NONE) {
3219 TELEPHONY_LOGE("Error code is %{public}d", error);
3220 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3221 }
3222 versionInfo = reply.ReadString();
3223 return reply.ReadInt32();
3224 }
3225
GetSimIO(int32_t slotId,int32_t command,int32_t fileId,const std::string & dataStr,const std::string & path,SimAuthenticationResponse & response)3226 int32_t CoreServiceProxy::GetSimIO(int32_t slotId, int32_t command,
3227 int32_t fileId, const std::string &dataStr, const std::string &path, SimAuthenticationResponse &response)
3228 {
3229 MessageParcel data;
3230 MessageParcel reply;
3231 MessageOption option;
3232 if (!WriteInterfaceToken(data)) {
3233 TELEPHONY_LOGE("GetSimIO WriteInterfaceToken is false");
3234 return ERROR;
3235 }
3236 data.WriteInt32(slotId);
3237 data.WriteInt32(static_cast<int32_t>(command));
3238 data.WriteInt32(static_cast<int32_t>(fileId));
3239 data.WriteString(dataStr);
3240 data.WriteString(path);
3241 auto remote = Remote();
3242 if (remote == nullptr) {
3243 TELEPHONY_LOGE("GetSimIO Remote is null");
3244 return ERROR;
3245 }
3246 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_IO_DONE), data, reply, option);
3247 if (st != ERR_NONE) {
3248 TELEPHONY_LOGE("GetSimIO failed, error code is %{public}d", st);
3249 return ERROR;
3250 }
3251 int32_t ret = reply.ReadInt32();
3252 response.sw1 = reply.ReadInt32();
3253 response.sw2 = reply.ReadInt32();
3254 response.response = reply.ReadString();
3255 return ret;
3256 }
3257
GetShowName(int32_t slotId,const sptr<IRawParcelCallback> & callback)3258 int32_t CoreServiceProxy::GetShowName(int32_t slotId, const sptr<IRawParcelCallback> &callback)
3259 {
3260 TELEPHONY_LOGD("GetShowName slotId = %{public}d", slotId);
3261 if (!IsValidSlotId(slotId)) {
3262 return TELEPHONY_ERR_SLOTID_INVALID;
3263 }
3264 MessageParcel data;
3265 MessageParcel reply;
3266 MessageOption option;
3267 if (!WriteInterfaceToken(data)) {
3268 TELEPHONY_LOGE("GetShowName WriteInterfaceToken is false");
3269 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
3270 }
3271 data.WriteInt32(slotId);
3272 if (callback == nullptr) {
3273 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
3274 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3275 }
3276 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
3277 auto remote = Remote();
3278 if (remote == nullptr) {
3279 TELEPHONY_LOGE("GetShowName Remote is null");
3280 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3281 }
3282 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SHOW_NAME), data, reply, option);
3283 if (st != ERR_NONE) {
3284 TELEPHONY_LOGE("GetShowName failed, error code is %{public}d", st);
3285 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3286 }
3287 return reply.ReadInt32();
3288 }
3289
GetAllSimAccountInfoList(std::vector<IccAccountInfo> & iccAccountInfoList)3290 int32_t CoreServiceProxy::GetAllSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList)
3291 {
3292 MessageParcel data;
3293 MessageParcel reply;
3294 MessageOption option;
3295 if (!WriteInterfaceToken(data)) {
3296 TELEPHONY_LOGE("GetAllSimAccountInfoList WriteInterfaceToken is false");
3297 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3298 }
3299 auto remote = Remote();
3300 if (remote == nullptr) {
3301 TELEPHONY_LOGE("GetAllSimAccountInfoList Remote is null");
3302 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3303 }
3304 int32_t st = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_ALL_ACCOUNT_INFO_LIST), data,
3305 reply, option);
3306 if (st != ERR_NONE) {
3307 TELEPHONY_LOGE("GetAllSimAccountInfoList failed, error code is %{public}d", st);
3308 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3309 }
3310 int32_t result = reply.ReadInt32();
3311 if (result == TELEPHONY_ERR_SUCCESS) {
3312 int32_t size = reply.ReadInt32();
3313 TELEPHONY_LOGI("CoreServiceProxy::GetAllSimAccountInfoList size = %{public}d", size);
3314 if (size > MAX_VECTOR || size < 0) {
3315 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3316 }
3317 iccAccountInfoList.clear();
3318 for (int i = 0; i < size; i++) {
3319 IccAccountInfo accountInfo;
3320 accountInfo.ReadFromParcel(reply);
3321 TELEPHONY_LOGD("CoreServiceProxy::GetAllSimAccountInfoList success");
3322 iccAccountInfoList.emplace_back(accountInfo);
3323 }
3324 }
3325 return result;
3326 }
3327
GetSimLabel(int32_t slotId,SimLabel & simLabel,const sptr<IRawParcelCallback> & callback)3328 int32_t CoreServiceProxy::GetSimLabel(int32_t slotId, SimLabel &simLabel, const sptr<IRawParcelCallback> &callback)
3329 {
3330 MessageParcel data;
3331 MessageParcel reply;
3332 MessageOption option;
3333 if (!WriteInterfaceToken(data)) {
3334 TELEPHONY_LOGE("GetSimLabel WriteInterfaceToken is false");
3335 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3336 }
3337 data.WriteInt32(slotId);
3338 if (callback == nullptr) {
3339 TELEPHONY_LOGE("IRawParcelCallback is nullptr");
3340 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3341 }
3342 data.WriteRemoteObject(callback->AsObject().GetRefPtr());
3343 auto remote = Remote();
3344 if (remote == nullptr) {
3345 TELEPHONY_LOGE("GetSimLabel Remote is null");
3346 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3347 }
3348 int32_t error = remote->SendRequest(uint32_t(CoreServiceInterfaceCode::GET_SIM_LABEL), data, reply, option);
3349 if (error != ERR_NONE) {
3350 TELEPHONY_LOGE("GetSimLabel failed, error code is %{public}d", error);
3351 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3352 }
3353 int32_t result = reply.ReadInt32();
3354 if (result == TELEPHONY_ERR_SUCCESS) {
3355 simLabel.simType = static_cast<SimType>(reply.ReadInt32());
3356 simLabel.index = reply.ReadInt32();
3357 }
3358 return result;
3359 }
3360
WriteEsimApduData(MessageParcel & data,const EsimApduData & apduData)3361 bool CoreServiceProxy::WriteEsimApduData(MessageParcel &data, const EsimApduData &apduData)
3362 {
3363 if (!data.WriteBool(apduData.closeChannelFlag_)) {
3364 TELEPHONY_LOGE("WriteBool closeChannelFlag is failed");
3365 return false;
3366 }
3367 if (!data.WriteBool(apduData.unusedDefaultReqHeadFlag_)) {
3368 TELEPHONY_LOGE("WriteBool unusedDefaultReqHeadFlag is failed");
3369 return false;
3370 }
3371 if (!data.WriteString16(apduData.data_)) {
3372 TELEPHONY_LOGE("WriteString16 data is failed");
3373 return false;
3374 }
3375 if (!data.WriteInt32(apduData.instructionType_)) {
3376 TELEPHONY_LOGE("WriteInt32 instructionType_ is failed");
3377 return false;
3378 }
3379 if (!data.WriteInt32(apduData.instruction_)) {
3380 TELEPHONY_LOGE("WriteInt32 instruction_ is failed");
3381 return false;
3382 }
3383 if (!data.WriteInt32(apduData.p1_)) {
3384 TELEPHONY_LOGE("WriteInt32 p1 is failed");
3385 return false;
3386 }
3387 if (!data.WriteInt32(apduData.p2_)) {
3388 TELEPHONY_LOGE("WriteInt32 p2 is failed");
3389 return false;
3390 }
3391 if (!data.WriteInt32(apduData.p3_)) {
3392 TELEPHONY_LOGE("WriteInt32 p3 is failed");
3393 return false;
3394 }
3395 return true;
3396 }
3397
SendApduData(int32_t slotId,const std::u16string & aid,const EsimApduData & apduData,ResponseEsimResult & responseResult)3398 int32_t CoreServiceProxy::SendApduData(
3399 int32_t slotId, const std::u16string &aid, const EsimApduData &apduData, ResponseEsimResult &responseResult)
3400 {
3401 MessageParcel data;
3402 MessageParcel reply;
3403 MessageOption option;
3404 if (!WriteInterfaceToken(data)) {
3405 TELEPHONY_LOGE("WriteInterfaceToken is false");
3406 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3407 }
3408 if (!data.WriteInt32(slotId)) {
3409 TELEPHONY_LOGE("WriteInt32 slotId is false");
3410 return TELEPHONY_ERR_WRITE_DATA_FAIL;
3411 }
3412 if (!data.WriteString16(aid)) {
3413 TELEPHONY_LOGE("WriteString16 aid is false");
3414 return TELEPHONY_ERR_WRITE_DATA_FAIL;
3415 }
3416 if (!WriteEsimApduData(data, apduData)) {
3417 TELEPHONY_LOGE("WriteEsimApduData is false");
3418 return TELEPHONY_ERR_WRITE_DATA_FAIL;
3419 }
3420 auto remote = Remote();
3421 if (remote == nullptr) {
3422 TELEPHONY_LOGE("Remote is null");
3423 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3424 }
3425 int32_t requestResult =
3426 remote->SendRequest(static_cast<uint32_t>(CoreServiceInterfaceCode::SEND_APDU_DATA), data, reply, option);
3427 if (requestResult != ERR_NONE) {
3428 TELEPHONY_LOGE("SendApduData sendRequest failed, error code is %{public}d", requestResult);
3429 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
3430 }
3431 int32_t result = reply.ReadInt32();
3432 if (result == TELEPHONY_ERR_SUCCESS) {
3433 responseResult.resultCode_ = static_cast<EsimResultCode>(reply.ReadInt32());
3434 responseResult.response_ = reply.ReadString16();
3435 responseResult.sw1_ = reply.ReadInt32();
3436 responseResult.sw2_ = reply.ReadInt32();
3437 }
3438 return result;
3439 }
3440
3441 } // namespace Telephony
3442 } // namespace OHOS
3443