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