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 "cellular_data_service_proxy.h"
17 
18 #include "iremote_object.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 #include "telephony_errors.h"
22 #include "telephony_log_wrapper.h"
23 #include "securec.h"
24 
25 namespace OHOS {
26 namespace Telephony {
IsCellularDataEnabled(bool &dataEnabled)27 int32_t CellularDataServiceProxy::IsCellularDataEnabled(bool &dataEnabled)
28 {
29     MessageParcel data;
30     MessageParcel reply;
31     MessageOption option;
32     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
33     if (Remote() == nullptr) {
34         TELEPHONY_LOGE("remote is null");
35         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
36     }
37     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::IS_CELLULAR_DATA_ENABLED, data,
38         reply, option);
39     if (error != TELEPHONY_SUCCESS) {
40         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
41         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
42     }
43     int32_t result = reply.ReadInt32();
44     if (result == TELEPHONY_SUCCESS) {
45         dataEnabled = reply.ReadBool();
46     }
47 
48     return result;
49 }
50 
EnableCellularData(bool enable)51 int32_t CellularDataServiceProxy::EnableCellularData(bool enable)
52 {
53     MessageParcel data;
54     MessageParcel reply;
55     MessageOption option;
56     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
57     data.WriteBool(enable);
58     if (Remote() == nullptr) {
59         TELEPHONY_LOGE("remote is null");
60         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
61     }
62     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ENABLE_CELLULAR_DATA, data,
63         reply, option);
64     if (error != TELEPHONY_SUCCESS) {
65         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
66         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
67     }
68     int32_t result = reply.ReadInt32();
69     return result;
70 }
71 
GetIntelligenceSwitchState(bool &state)72 int32_t CellularDataServiceProxy::GetIntelligenceSwitchState(bool &state)
73 {
74     MessageParcel data;
75     MessageParcel reply;
76     MessageOption option;
77     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
78     if (Remote() == nullptr) {
79         TELEPHONY_LOGE("remote is null");
80         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
81     }
82     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_INTELLIGENCE_SWITCH_STATE, data,
83         reply, option);
84     if (error != TELEPHONY_SUCCESS) {
85         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
86         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
87     }
88     int32_t result = reply.ReadInt32();
89     state = reply.ReadBool();
90     return result;
91 }
92 
EnableIntelligenceSwitch(bool enable)93 int32_t CellularDataServiceProxy::EnableIntelligenceSwitch(bool enable)
94 {
95     MessageParcel data;
96     MessageParcel reply;
97     MessageOption option;
98     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
99     data.WriteBool(enable);
100     if (Remote() == nullptr) {
101         TELEPHONY_LOGE("remote is null");
102         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
103     }
104     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ENABLE_INTELLIGENCE_SWITCH, data,
105         reply, option);
106     if (error != TELEPHONY_SUCCESS) {
107         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
108         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
109     }
110     int32_t result = reply.ReadInt32();
111     return result;
112 }
113 
GetCellularDataState()114 int32_t CellularDataServiceProxy::GetCellularDataState()
115 {
116     MessageParcel data;
117     MessageParcel reply;
118     MessageOption option;
119     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
120     if (Remote() == nullptr) {
121         TELEPHONY_LOGE("remote is null");
122         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
123     }
124     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_CELLULAR_DATA_STATE, data,
125         reply, option);
126     if (error != TELEPHONY_SUCCESS) {
127         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
128         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
129     }
130     int32_t result = reply.ReadInt32();
131     return result;
132 }
133 
GetApnState(int32_t slotId, const std::string &apnType)134 int32_t CellularDataServiceProxy::GetApnState(int32_t slotId, const std::string &apnType)
135 {
136     MessageParcel data;
137     MessageParcel reply;
138     MessageOption option;
139     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
140     data.WriteInt32(slotId);
141     data.WriteString(apnType);
142     if (Remote() == nullptr) {
143         TELEPHONY_LOGE("remote is null");
144         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
145     }
146     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_CELLULAR_DATA_APN_STATE, data,
147         reply, option);
148     if (error != TELEPHONY_SUCCESS) {
149         TELEPHONY_LOGE("function GetCellularDataState call failed! errCode:%{public}d", error);
150         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
151     }
152     int32_t result = reply.ReadInt32();
153     return result;
154 }
155 
GetDataRecoveryState()156 int32_t CellularDataServiceProxy::GetDataRecoveryState()
157 {
158     MessageParcel data;
159     MessageParcel reply;
160     MessageOption option;
161     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
162     if (Remote() == nullptr) {
163         TELEPHONY_LOGE("remote is null");
164         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
165     }
166     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_RECOVERY_STATE, data,
167         reply, option);
168     if (error != TELEPHONY_SUCCESS) {
169         TELEPHONY_LOGE("function GetDefaultCellularDataSlotId call failed! errCode:%{public}d", error);
170         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
171     }
172     int32_t result = reply.ReadInt32();
173     return result;
174 }
175 
IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled)176 int32_t CellularDataServiceProxy::IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled)
177 {
178     MessageParcel data;
179     MessageParcel reply;
180     MessageOption option;
181     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
182     data.WriteInt32(slotId);
183     if (Remote() == nullptr) {
184         TELEPHONY_LOGE("remote is null");
185         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
186     }
187     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::IS_DATA_ROAMING_ENABLED, data,
188         reply, option);
189     if (error != TELEPHONY_SUCCESS) {
190         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
191         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
192     }
193     int32_t result = reply.ReadInt32();
194     if (result == TELEPHONY_SUCCESS) {
195         dataRoamingEnabled = reply.ReadBool();
196     }
197 
198     return result;
199 }
200 
EnableCellularDataRoaming(int32_t slotId, bool enable)201 int32_t CellularDataServiceProxy::EnableCellularDataRoaming(int32_t slotId, bool enable)
202 {
203     MessageParcel data;
204     MessageParcel reply;
205     MessageOption option;
206     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
207     data.WriteInt32(slotId);
208     data.WriteBool(enable);
209     if (Remote() == nullptr) {
210         TELEPHONY_LOGE("remote is null");
211         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
212     }
213     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ENABLE_DATA_ROAMING, data,
214         reply, option);
215     if (error != TELEPHONY_SUCCESS) {
216         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
217         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
218     }
219     int32_t result = reply.ReadInt32();
220     return result;
221 }
222 
HandleApnChanged(int32_t slotId)223 int32_t CellularDataServiceProxy::HandleApnChanged(int32_t slotId)
224 {
225     MessageParcel data;
226     MessageParcel reply;
227     MessageOption option;
228     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
229     data.WriteInt32(slotId);
230     if (Remote() == nullptr) {
231         TELEPHONY_LOGE("remote is null");
232         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
233     }
234     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::APN_DATA_CHANGED, data, reply, option);
235     if (error != TELEPHONY_SUCCESS) {
236         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
237         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
238     }
239     int32_t result = reply.ReadInt32();
240     return result;
241 }
242 
GetDefaultCellularDataSlotId()243 int32_t CellularDataServiceProxy::GetDefaultCellularDataSlotId()
244 {
245     MessageParcel data;
246     MessageParcel reply;
247     MessageOption option;
248     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
249     if (Remote() == nullptr) {
250         TELEPHONY_LOGE("remote is null");
251         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
252     }
253     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DEFAULT_SLOT_ID, data,
254         reply, option);
255     if (error != TELEPHONY_SUCCESS) {
256         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
257         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
258     }
259     int32_t result = reply.ReadInt32();
260     return result;
261 }
262 
GetDefaultCellularDataSimId(int32_t &simId)263 int32_t CellularDataServiceProxy::GetDefaultCellularDataSimId(int32_t &simId)
264 {
265     MessageParcel data;
266     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
267     if (Remote() == nullptr) {
268         TELEPHONY_LOGE("failed: remote is null");
269         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
270     }
271     MessageParcel reply;
272     MessageOption option;
273     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DEFAULT_SIM_ID, data, reply, option);
274     if (error != TELEPHONY_SUCCESS) {
275         TELEPHONY_LOGE("SendRequest failed! errCode:%{public}d", error);
276         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
277     }
278     int32_t result = reply.ReadInt32();
279     TELEPHONY_LOGD("end: result=%{public}d", result);
280     if (result == TELEPHONY_ERR_SUCCESS) {
281         simId = reply.ReadInt32();
282     }
283     return result;
284 }
285 
SetDefaultCellularDataSlotId(int32_t slotId)286 int32_t CellularDataServiceProxy::SetDefaultCellularDataSlotId(int32_t slotId)
287 {
288     MessageParcel data;
289     MessageParcel reply;
290     MessageOption option;
291     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
292     data.WriteInt32(slotId);
293     if (Remote() == nullptr) {
294         TELEPHONY_LOGE("remote is null");
295         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
296     }
297     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::SET_DEFAULT_SLOT_ID, data,
298         reply, option);
299     if (error != TELEPHONY_SUCCESS) {
300         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
301         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
302     }
303     int32_t result = reply.ReadInt32();
304     return result;
305 }
306 
GetCellularDataFlowType()307 int32_t CellularDataServiceProxy::GetCellularDataFlowType()
308 {
309     MessageParcel data;
310     MessageParcel reply;
311     MessageOption option;
312     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
313     if (Remote() == nullptr) {
314         TELEPHONY_LOGE("remote is null");
315         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
316     }
317     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_FLOW_TYPE_ID, data, reply, option);
318     if (error != TELEPHONY_SUCCESS) {
319         TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
320         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
321     }
322     int32_t result = reply.ReadInt32();
323     return result;
324 }
325 
HasInternetCapability(int32_t slotId, int32_t cid)326 int32_t CellularDataServiceProxy::HasInternetCapability(int32_t slotId, int32_t cid)
327 {
328     MessageParcel data;
329     MessageParcel reply;
330     MessageOption option;
331     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
332     data.WriteInt32(slotId);
333     data.WriteInt32(cid);
334     if (Remote() == nullptr) {
335         TELEPHONY_LOGE("remote is null");
336         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
337     }
338     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::HAS_CAPABILITY, data, reply, option);
339     if (error != TELEPHONY_SUCCESS) {
340         TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
341         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
342     }
343     int32_t result = reply.ReadInt32();
344     return result;
345 }
346 
ClearCellularDataConnections(int32_t slotId)347 int32_t CellularDataServiceProxy::ClearCellularDataConnections(int32_t slotId)
348 {
349     MessageParcel data;
350     MessageParcel reply;
351     MessageOption option;
352     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
353     data.WriteInt32(slotId);
354     if (Remote() == nullptr) {
355         TELEPHONY_LOGE("remote is null");
356         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
357     }
358     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::CLEAR_ALL_CONNECTIONS, data,
359         reply, option);
360     if (error != TELEPHONY_SUCCESS) {
361         TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
362         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
363     }
364     int32_t result = reply.ReadInt32();
365     return result;
366 }
367 
ClearAllConnections(int32_t slotId, DisConnectionReason reason)368 int32_t CellularDataServiceProxy::ClearAllConnections(int32_t slotId, DisConnectionReason reason)
369 {
370     MessageParcel data;
371     MessageParcel reply;
372     MessageOption option;
373     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
374     data.WriteInt32(slotId);
375     data.WriteInt32(static_cast<int32_t>(reason));
376     if (Remote() == nullptr) {
377         TELEPHONY_LOGE("remote is null");
378         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
379     }
380     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::CLEAR_ALL_CONNECTIONS_USE_REASON, data,
381         reply, option);
382     if (error != TELEPHONY_SUCCESS) {
383         TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
384         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
385     }
386     int32_t result = reply.ReadInt32();
387     return result;
388 }
389 
RegisterSimAccountCallback(const sptr<SimAccountCallback> callback)390 int32_t CellularDataServiceProxy::RegisterSimAccountCallback(const sptr<SimAccountCallback> callback)
391 {
392     if (callback == nullptr) {
393         TELEPHONY_LOGE("callback is nullptr!");
394         return TELEPHONY_ERR_ARGUMENT_NULL;
395     }
396     MessageParcel data;
397     MessageParcel reply;
398     MessageOption option;
399     if (!data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
400         TELEPHONY_LOGE("write interface token failed!");
401         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
402     }
403     if (!data.WriteRemoteObject(callback->AsObject())) {
404         TELEPHONY_LOGE("write remote object failed!");
405         return TELEPHONY_ERR_WRITE_DATA_FAIL;
406     }
407     sptr<OHOS::IRemoteObject> remote = Remote();
408     if (remote == nullptr) {
409         TELEPHONY_LOGE("remote is nullptr!");
410         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
411     }
412     int32_t error = remote->SendRequest(static_cast<uint32_t>(CellularDataInterfaceCode::REG_SIM_ACCOUNT_CALLBACK),
413         data, reply, option);
414     if (error != TELEPHONY_SUCCESS) {
415         TELEPHONY_LOGD("error! errCode:%{public}d", error);
416         return error;
417     }
418     return reply.ReadInt32();
419 }
420 
UnregisterSimAccountCallback()421 int32_t CellularDataServiceProxy::UnregisterSimAccountCallback()
422 {
423     MessageParcel data;
424     MessageParcel reply;
425     MessageOption option;
426     if (!data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
427         TELEPHONY_LOGE("write interface token failed!");
428         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
429     }
430     sptr<OHOS::IRemoteObject> remote = Remote();
431     if (remote == nullptr) {
432         TELEPHONY_LOGE("remote is nullptr!");
433         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
434     }
435     int32_t error = remote->SendRequest(static_cast<uint32_t>(CellularDataInterfaceCode::UN_REG_SIM_ACCOUNT_CALLBACK),
436         data, reply, option);
437     if (error != TELEPHONY_SUCCESS) {
438         TELEPHONY_LOGE("error! errCode:%{public}d", error);
439         return error;
440     }
441     return reply.ReadInt32();
442 }
443 
GetDataConnApnAttr(int32_t slotId, ApnItem::Attribute &apnAttr)444 int32_t CellularDataServiceProxy::GetDataConnApnAttr(int32_t slotId, ApnItem::Attribute &apnAttr)
445 {
446     MessageParcel dataParcel;
447     MessageParcel replyParcel;
448     MessageOption option;
449     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
450         TELEPHONY_LOGE("write interface token failed!");
451         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
452     }
453     if (!dataParcel.WriteInt32(slotId)) {
454         TELEPHONY_LOGE("write userId failed!");
455         return TELEPHONY_ERR_WRITE_DATA_FAIL;
456     }
457     sptr<OHOS::IRemoteObject> remote = Remote();
458     if (remote == nullptr) {
459         TELEPHONY_LOGE("remote is nullptr!");
460         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
461     }
462     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DATA_CONN_APN_ATTR,
463         dataParcel, replyParcel, option);
464     if (error != TELEPHONY_SUCCESS) {
465         TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
466         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
467     }
468     int32_t result = replyParcel.ReadInt32();
469     if (result == TELEPHONY_ERR_SUCCESS) {
470         auto apnAttrPtr = replyParcel.ReadRawData(sizeof(ApnItem::Attribute));
471         if (apnAttrPtr == nullptr) {
472             return TELEPHONY_ERR_READ_DATA_FAIL;
473         }
474         if (memcpy_s(&apnAttr, sizeof(ApnItem::Attribute), apnAttrPtr, sizeof(ApnItem::Attribute)) != EOK) {
475             return TELEPHONY_ERR_MEMCPY_FAIL;
476         }
477     } else {
478         TELEPHONY_LOGE("end failed: result=%{public}d", result);
479     }
480 
481     return TELEPHONY_ERR_SUCCESS;
482 }
483 
GetDataConnIpType(int32_t slotId, std::string &ipType)484 int32_t CellularDataServiceProxy::GetDataConnIpType(int32_t slotId, std::string &ipType)
485 {
486     MessageParcel dataParcel;
487     MessageParcel replyParcel;
488     MessageOption option;
489     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
490         TELEPHONY_LOGE("write interface token failed!");
491         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
492     }
493     if (!dataParcel.WriteInt32(slotId)) {
494         TELEPHONY_LOGE("write userId failed!");
495         return TELEPHONY_ERR_WRITE_DATA_FAIL;
496     }
497     sptr<OHOS::IRemoteObject> remote = Remote();
498     if (remote == nullptr) {
499         TELEPHONY_LOGE("remote is nullptr!");
500         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
501     }
502     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DATA_CONN_IP_TYPE, dataParcel,
503         replyParcel, option);
504     if (error != TELEPHONY_SUCCESS) {
505         TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
506         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
507     }
508     int32_t result = replyParcel.ReadInt32();
509     TELEPHONY_LOGI("end: result=%{public}d", result);
510     if (result == TELEPHONY_ERR_SUCCESS) {
511         ipType = replyParcel.ReadString();
512     }
513 
514     return TELEPHONY_ERR_SUCCESS;
515 }
516 
IsNeedDoRecovery(int32_t slotId, bool needDoRecovery)517 int32_t CellularDataServiceProxy::IsNeedDoRecovery(int32_t slotId, bool needDoRecovery)
518 {
519     MessageParcel dataParcel;
520     MessageParcel replyParcel;
521     MessageOption option;
522     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
523         TELEPHONY_LOGE("write interface token failed!");
524         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
525     }
526     dataParcel.WriteInt32(slotId);
527     dataParcel.WriteBool(needDoRecovery);
528     sptr<OHOS::IRemoteObject> remote = Remote();
529     if (remote == nullptr) {
530         TELEPHONY_LOGE("remote is nullptr!");
531         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
532     }
533     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::IS_NEED_DO_RECOVERY, dataParcel,
534         replyParcel, option);
535     if (error != TELEPHONY_SUCCESS) {
536         TELEPHONY_LOGE("function IsNeedDoRecovery call failed! errCode:%{public}d", error);
537         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
538     }
539     int32_t result = replyParcel.ReadInt32();
540     return result;
541 }
542 
InitCellularDataController(int32_t slotId)543 int32_t CellularDataServiceProxy::InitCellularDataController(int32_t slotId)
544 {
545     MessageParcel dataParcel;
546     MessageParcel replyParcel;
547     MessageOption option;
548     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
549         TELEPHONY_LOGE("write interface token failed!");
550         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
551     }
552     dataParcel.WriteInt32(slotId);
553     sptr<OHOS::IRemoteObject> remote = Remote();
554     if (remote == nullptr) {
555         TELEPHONY_LOGE("remote is nullptr!");
556         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
557     }
558     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::INIT_CELLULAR_DATA_CONTROLLER, dataParcel,
559         replyParcel, option);
560     if (error != TELEPHONY_SUCCESS) {
561         TELEPHONY_LOGE("function InitCellularDataController call failed! errCode:%{public}d", error);
562         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
563     }
564     int32_t result = replyParcel.ReadInt32();
565     return result;
566 }
567 
EstablishAllApnsIfConnectable(int32_t slotId)568 int32_t CellularDataServiceProxy::EstablishAllApnsIfConnectable(int32_t slotId)
569 {
570     MessageParcel data;
571     MessageParcel reply;
572     MessageOption option;
573     data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
574     data.WriteInt32(slotId);
575     if (Remote() == nullptr) {
576         TELEPHONY_LOGE("remote is null");
577         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
578     }
579 
580     int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ESTABLISH_ALL_APNS_IF_CONNECTABLE,
581         data, reply, option);
582     if (error != TELEPHONY_SUCCESS) {
583         TELEPHONY_LOGE("EstablishAllApnsIfConnectable fail! errCode: %{public}d", error);
584         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
585     }
586     int32_t result = reply.ReadInt32();
587     return result;
588 }
589 
ReleaseCellularDataConnection(int32_t slotId)590 int32_t CellularDataServiceProxy::ReleaseCellularDataConnection(int32_t slotId)
591 {
592     MessageParcel dataParcel;
593     MessageParcel replyParcel;
594     MessageOption option;
595     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
596         TELEPHONY_LOGE("write interface token failed!");
597         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
598     }
599     if (!dataParcel.WriteInt32(slotId)) {
600         TELEPHONY_LOGE("write slotId failed");
601         return TELEPHONY_ERR_WRITE_DATA_FAIL;
602     }
603     sptr<OHOS::IRemoteObject> remote = Remote();
604     if (remote == nullptr) {
605         TELEPHONY_LOGE("remote is nullptr!");
606         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
607     }
608     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::RELEASE_CELLULAR_DATA_CONNECTION,
609                                         dataParcel, replyParcel, option);
610     if (error != TELEPHONY_SUCCESS) {
611         TELEPHONY_LOGE("function ReleaseCellularDataConnection call failed! errCode:%{public}d", error);
612         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
613     }
614     int32_t result;
615     if (!replyParcel.ReadInt32(result)) {
616         TELEPHONY_LOGE("read reply result failed");
617     }
618     return result;
619 }
620 
GetCellularDataSupplierId(int32_t slotId, uint64_t capability, uint32_t &supplierId)621 int32_t CellularDataServiceProxy::GetCellularDataSupplierId(int32_t slotId, uint64_t capability, uint32_t &supplierId)
622 {
623     MessageParcel dataParcel;
624     MessageParcel replyParcel;
625     MessageOption option;
626     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
627         TELEPHONY_LOGE("write interface token failed!");
628         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
629     }
630     dataParcel.WriteInt32(slotId);
631     dataParcel.WriteUint64(capability);
632     sptr<OHOS::IRemoteObject> remote = Remote();
633     if (remote == nullptr) {
634         TELEPHONY_LOGE("remote is nullptr!");
635         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
636     }
637     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_CELLULAR_DATA_SUPPLIERID,
638         dataParcel, replyParcel, option);
639     if (error != TELEPHONY_SUCCESS) {
640         TELEPHONY_LOGE("function GetCellularDataSupplierId call failed! errCode:%{public}d", error);
641         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
642     }
643     int32_t result = replyParcel.ReadInt32();
644     TELEPHONY_LOGD("end: result=%{public}d", result);
645     if (result == TELEPHONY_ERR_SUCCESS) {
646         supplierId = replyParcel.ReadUint32();
647     }
648     return result;
649 }
650 
CorrectNetSupplierNoAvailable(int32_t slotId)651 int32_t CellularDataServiceProxy::CorrectNetSupplierNoAvailable(int32_t slotId)
652 {
653     MessageParcel dataParcel;
654     MessageParcel replyParcel;
655     MessageOption option;
656     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
657         TELEPHONY_LOGE("write interface token failed!");
658         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
659     }
660     dataParcel.WriteInt32(slotId);
661     sptr<OHOS::IRemoteObject> remote = Remote();
662     if (remote == nullptr) {
663         TELEPHONY_LOGE("remote is nullptr!");
664         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
665     }
666     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::CORRECT_NET_SUPPLIER_NO_AVAILABLE,
667         dataParcel, replyParcel, option);
668     if (error != TELEPHONY_SUCCESS) {
669         TELEPHONY_LOGE("function CorrectNetSupplierNoAvailable call failed! errCode:%{public}d", error);
670         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
671     }
672     int32_t result = replyParcel.ReadInt32();
673     return result;
674 }
675 
GetSupplierRegisterState(uint32_t supplierId, int32_t &regState)676 int32_t CellularDataServiceProxy::GetSupplierRegisterState(uint32_t supplierId, int32_t &regState)
677 {
678     MessageParcel dataParcel;
679     MessageParcel replyParcel;
680     MessageOption option;
681     if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
682         TELEPHONY_LOGE("write interface token failed!");
683         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
684     }
685     dataParcel.WriteUint32(supplierId);
686     sptr<OHOS::IRemoteObject> remote = Remote();
687     if (remote == nullptr) {
688         TELEPHONY_LOGE("remote is nullptr!");
689         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
690     }
691     int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_SUPPLIER_REGISTER_STATE,
692         dataParcel, replyParcel, option);
693     if (error != TELEPHONY_SUCCESS) {
694         TELEPHONY_LOGE("function GetSupplierRegisterState call failed! errCode:%{public}d", error);
695         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
696     }
697     int32_t result = replyParcel.ReadInt32();
698     TELEPHONY_LOGD("end: result=%{public}d", result);
699     if (result == TELEPHONY_ERR_SUCCESS) {
700         regState = replyParcel.ReadInt32();
701     }
702     return result;
703 }
704 } // namespace Telephony
705 } // namespace OHOS
706